Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 1 | /** |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 2 | * \mainpage Amlogic DVR library |
| 3 | * |
| 4 | * \section Introduction |
| 5 | * "libdvr" is a library provides basic DVR functions used by Amlogic platform. |
| 6 | * It supports: |
| 7 | * \li Record |
| 8 | * \li Playback |
| 9 | * \li Index file generated |
| 10 | * \li Segment split |
| 11 | * \li Encrypt and decrypt |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 12 | * |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 13 | * \file |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 14 | * \brief libdvr wrapper layer |
| 15 | * |
| 16 | * Wrapper layer is upper layer of libdvr. |
| 17 | * It is on top of dvr_record and dvr_playback. |
| 18 | * It supports: |
| 19 | * \li Separate record segments automatically. |
| 20 | * \li Load segments automatically. |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifndef DVR_WRAPPER_H_ |
| 24 | #define DVR_WRAPPER_H_ |
| 25 | |
| 26 | #include "dvr_types.h" |
| 27 | #include "dvr_crypto.h" |
| 28 | #include "dvr_playback.h" |
| 29 | #include "dvr_record.h" |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | /**Record wrapper handle.*/ |
| 36 | typedef void* DVR_WrapperRecord_t; |
| 37 | /**Playback wrapper handle.*/ |
| 38 | typedef void* DVR_WrapperPlayback_t; |
| 39 | |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 40 | typedef void* Playback_DeviceHandle_t; |
| 41 | |
| 42 | typedef struct { |
| 43 | time_t time; /**< time duration, unit on ms*/ |
| 44 | loff_t size; /**< size*/ |
| 45 | uint32_t pkts; /**< number of ts packets*/ |
| 46 | } DVR_WrapperInfo_t; |
| 47 | |
| 48 | typedef struct { |
| 49 | uint32_t nb_pids; /**< Number of PIDs.*/ |
| 50 | DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs to be recorded.*/ |
| 51 | } DVR_WrapperPidsInfo_t; |
| 52 | |
| 53 | typedef struct { |
Zhiqiang Han | aeb0c71 | 2020-04-30 15:17:26 +0800 | [diff] [blame] | 54 | DVR_PlaybackPlayState_t state; /**< DVR playback state*/ |
| 55 | DVR_WrapperInfo_t info_cur; /**< DVR playback current information*/ |
| 56 | DVR_WrapperInfo_t info_full; /**< DVR playback total(non-obsolete) infomation*/ |
| 57 | DVR_PlaybackPids_t pids; /**< DVR playback pids information*/ |
| 58 | float speed; /**< DVR playback current speed*/ |
| 59 | DVR_PlaybackSegmentFlag_t flags; /**< DVR playback flags*/ |
| 60 | DVR_WrapperInfo_t info_obsolete; /**< DVR playback obsolete information, take into account for timeshift*/ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 61 | } DVR_WrapperPlaybackStatus_t; |
| 62 | |
| 63 | typedef struct { |
| 64 | DVR_RecordState_t state; /**< DVR record state*/ |
| 65 | DVR_WrapperInfo_t info; /**< DVR record information*/ |
| 66 | DVR_WrapperPidsInfo_t pids; /**< DVR record pids info*/ |
Zhiqiang Han | aeb0c71 | 2020-04-30 15:17:26 +0800 | [diff] [blame] | 67 | DVR_WrapperInfo_t info_obsolete; /**< DVR record obsolete information, take into account for timeshift*/ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 68 | } DVR_WrapperRecordStatus_t; |
| 69 | |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 70 | /**Record wrapper open parameters.*/ |
| 71 | typedef struct { |
Yahui Han | ce15e9c | 2020-12-08 18:08:32 +0800 | [diff] [blame] | 72 | int fend_dev_id; /**< Frontend device's index.*/ |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 73 | int dmx_dev_id; /**< Demux device's index.*/ |
| 74 | char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/ |
| 75 | DVR_Bool_t is_timeshift; /**< The record file is used by timeshift.*/ |
| 76 | loff_t segment_size; /**< Segment file's size.*/ |
Zhiqiang Han | aeb0c71 | 2020-04-30 15:17:26 +0800 | [diff] [blame] | 77 | loff_t max_size; /**< Maximum record file size in bytes(for timeshift).*/ |
| 78 | time_t max_time; /**< Maximum record time in milliseconds(for timeshift).*/ |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 79 | DVR_RecordFlag_t flags; /**< Flags.*/ |
| 80 | DVR_CryptoPeriod_t crypto_period; /**< Crypto period.*/ |
| 81 | DVR_CryptoFunction_t crypto_fn; /**< Crypto callback function.*/ |
| 82 | void *crypto_data; /**< User data of crypto function.*/ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 83 | DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/ |
| 84 | void *event_userdata; /**< DVR event userdata*/ |
Zhiqiang Han | 3150545 | 2020-05-06 15:08:10 +0800 | [diff] [blame] | 85 | int flush_size; /**< DVR flush size*/ |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 86 | } DVR_WrapperRecordOpenParams_t; |
| 87 | |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 88 | typedef struct { |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 89 | DVR_WrapperPidsInfo_t pids_info; |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 90 | } DVR_WrapperRecordStartParams_t; |
| 91 | |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 92 | typedef struct { |
| 93 | uint32_t nb_pids; /**< Number of PID actions.*/ |
| 94 | DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/ |
| 95 | DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/ |
| 96 | } DVR_WrapperUpdatePidsParams_t; |
| 97 | |
| 98 | /**Playback wrapper open parameters.*/ |
| 99 | typedef struct { |
| 100 | int dmx_dev_id; /**< playback used dmx device index*/ |
| 101 | char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/ |
| 102 | int block_size; /**< playback inject block size*/ |
| 103 | DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/ |
| 104 | Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/ |
| 105 | DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/ |
| 106 | void *crypto_data; /**< Crypto function's user data.*/ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 107 | DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/ |
| 108 | void *event_userdata; /**< event userdata*/ |
hualing chen | 90b3ae6 | 2021-03-30 10:49:28 +0800 | [diff] [blame] | 109 | DVR_Bool_t is_notify_time; /**< 0:not notify time, 1 : notify*/ |
| 110 | DVR_PlaybackVendor_t vendor; /**< vendor type*/ |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 111 | } DVR_WrapperPlaybackOpenParams_t; |
| 112 | |
| 113 | /** |
| 114 | * Open a new record wrapper. |
| 115 | * \param[out] rec Return the new record handle. |
| 116 | * \param params Record open parameters. |
| 117 | * \retval DVR_SUCCESS On success. |
| 118 | * \return Error code. |
| 119 | */ |
| 120 | int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params); |
| 121 | |
| 122 | /** |
| 123 | * Close an unused record wrapper. |
| 124 | * \param rec The record handle. |
| 125 | * \retval DVR_SUCCESS On success. |
| 126 | * \return Error code. |
| 127 | */ |
| 128 | int dvr_wrapper_close_record (DVR_WrapperRecord_t rec); |
| 129 | |
| 130 | /** |
| 131 | * Start recording. |
| 132 | * \param rec The record handle. |
| 133 | * \param params Record start parameters. |
| 134 | * \retval DVR_SUCCESS On success. |
| 135 | * \return Error code. |
| 136 | */ |
| 137 | int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params); |
| 138 | |
| 139 | /** |
| 140 | * Stop recording.. |
| 141 | * \param rec The record handle. |
| 142 | * \retval DVR_SUCCESS On success. |
| 143 | * \return Error code. |
| 144 | */ |
| 145 | int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec); |
| 146 | |
| 147 | /** |
| 148 | * Update the recording PIDs. |
| 149 | * \param rec The record handle. |
| 150 | * \param params The new PIDs. |
| 151 | * \retval DVR_SUCCESS On success. |
| 152 | * \return Error code. |
| 153 | */ |
| 154 | int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params); |
| 155 | |
| 156 | /** |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 157 | * Get the current recording status. |
| 158 | * \param rec The record handle. |
| 159 | * \param status The recording status returned. |
| 160 | * \retval DVR_SUCCESS On success. |
| 161 | * \return Error code. |
| 162 | */ |
| 163 | int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status); |
| 164 | |
| 165 | /** |
hualing chen | 4fe3bee | 2020-10-23 13:58:52 +0800 | [diff] [blame] | 166 | * check record mode is secure or free. |
| 167 | * \param rec The record handle. |
| 168 | * \retval 1:secure 0: free mode. |
| 169 | * \return secure or free. |
| 170 | */ |
| 171 | int dvr_wrapper_record_is_secure_mode(DVR_WrapperRecord_t rec); |
| 172 | |
| 173 | /** |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 174 | * Set record secure buffer. |
| 175 | * \param rec The record handle. |
| 176 | * \param p_secure_buf record p_secure_buf addr. |
| 177 | * \param len record p_secure_buf len. |
| 178 | * \retval DVR_SUCCESS On success. |
| 179 | * \return Error code. |
| 180 | */ |
| 181 | int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len); |
| 182 | |
| 183 | /** |
| 184 | * Set record decrypt callback. |
| 185 | * \param rec The record handle. |
| 186 | * \param func record dec cb. |
| 187 | * \param userdata cb user data. |
| 188 | * \retval DVR_SUCCESS On success. |
| 189 | * \return Error code. |
| 190 | */ |
| 191 | int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata); |
| 192 | |
| 193 | /** |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 194 | * Open a new playback wrapper handle. |
| 195 | * \param[out] playback Return the new playback handle. |
| 196 | * \param params Playback handle open parameters. |
| 197 | * \retval DVR_SUCCESS On success. |
| 198 | * \return Error code. |
| 199 | */ |
| 200 | int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params); |
| 201 | |
| 202 | /** |
| 203 | * Close a unused playback handle. |
| 204 | * \param playback The playback handle to be closed. |
| 205 | * \retval DVR_SUCCESS On success. |
| 206 | * \return Error code. |
| 207 | */ |
| 208 | int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback); |
| 209 | |
| 210 | /** |
| 211 | * Start playback. |
| 212 | * \param playback The playback handle. |
| 213 | * \param flags Playback flags. |
| 214 | * \retval DVR_SUCCESS On success. |
| 215 | * \return Error code. |
| 216 | */ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 217 | int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids); |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * Stop playback. |
| 221 | * \param playback The playback handle. |
| 222 | * \retval DVR_SUCCESS On success. |
| 223 | * \return Error code. |
| 224 | */ |
| 225 | int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback); |
| 226 | |
| 227 | /** |
| 228 | * Pause the playback. |
| 229 | * \param playback The playback handle. |
| 230 | * \retval DVR_SUCCESS On success. |
| 231 | * \return Error code. |
| 232 | */ |
| 233 | int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback); |
| 234 | |
| 235 | /** |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 236 | * resume the playback. |
| 237 | * \param playback The playback handle. |
| 238 | * \retval DVR_SUCCESS On success. |
| 239 | * \return Error code. |
| 240 | */ |
| 241 | int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback); |
| 242 | |
| 243 | /** |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 244 | * Set the playback speed. |
| 245 | * \param playback The playback handle. |
| 246 | * \param speed The new speed. |
| 247 | * \retval DVR_SUCCESS On success. |
| 248 | * \return Error code. |
| 249 | */ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 250 | int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed); |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 251 | |
| 252 | /** |
| 253 | * Seek the current playback position. |
| 254 | * \param playback The playback handle. |
| 255 | * \param time_offset The current time in milliseconds. |
| 256 | * \retval DVR_SUCCESS On success. |
| 257 | * \return Error code. |
| 258 | */ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 259 | int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset); |
| 260 | |
| 261 | /** |
| 262 | * Get the current playback status. |
| 263 | * \param playback The playback handle. |
| 264 | * \param status The playback status returned. |
| 265 | * \retval DVR_SUCCESS On success. |
| 266 | * \return Error code. |
| 267 | */ |
| 268 | int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status); |
| 269 | |
| 270 | /** |
| 271 | * Update playback. |
| 272 | * \param playback The playback handle. |
| 273 | * \param flags Playback flags. |
| 274 | * \retval DVR_SUCCESS On success. |
| 275 | * \return Error code. |
| 276 | */ |
| 277 | int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids); |
| 278 | |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 279 | /** |
| 280 | * Set playback secure buffer. |
| 281 | * \param playback The playback handle. |
| 282 | * \param p_secure_buf Playback p_secure_buf addr. |
| 283 | * \param len Playback p_secure_buf len. |
| 284 | * \retval DVR_SUCCESS On success. |
| 285 | * \return Error code. |
| 286 | */ |
| 287 | int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len); |
| 288 | |
| 289 | /** |
| 290 | * Set playback decrypt callback. |
| 291 | * \param playback The playback handle. |
| 292 | * \param func Playback dec cb. |
| 293 | * \param userdata cb user data. |
| 294 | * \retval DVR_SUCCESS On success. |
| 295 | * \return Error code. |
| 296 | */ |
| 297 | int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata); |
| 298 | |
| 299 | |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 300 | |
| 301 | #ifdef __cplusplus |
| 302 | } |
| 303 | #endif |
| 304 | |
| 305 | #endif /*DVR_WRAPPER_H_*/ |
| 306 | |