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 |
| 12 | * \endsection |
| 13 | * |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 14 | * \file |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 15 | * \brief libdvr wrapper layer |
| 16 | * |
| 17 | * Wrapper layer is upper layer of libdvr. |
| 18 | * It is on top of dvr_record and dvr_playback. |
| 19 | * It supports: |
| 20 | * \li Separate record segments automatically. |
| 21 | * \li Load segments automatically. |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #ifndef DVR_WRAPPER_H_ |
| 25 | #define DVR_WRAPPER_H_ |
| 26 | |
| 27 | #include "dvr_types.h" |
| 28 | #include "dvr_crypto.h" |
| 29 | #include "dvr_playback.h" |
| 30 | #include "dvr_record.h" |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | /**Record wrapper handle.*/ |
| 37 | typedef void* DVR_WrapperRecord_t; |
| 38 | /**Playback wrapper handle.*/ |
| 39 | typedef void* DVR_WrapperPlayback_t; |
| 40 | |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 41 | typedef void* Playback_DeviceHandle_t; |
| 42 | |
| 43 | typedef struct { |
| 44 | time_t time; /**< time duration, unit on ms*/ |
| 45 | loff_t size; /**< size*/ |
| 46 | uint32_t pkts; /**< number of ts packets*/ |
| 47 | } DVR_WrapperInfo_t; |
| 48 | |
| 49 | typedef struct { |
| 50 | uint32_t nb_pids; /**< Number of PIDs.*/ |
| 51 | DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs to be recorded.*/ |
| 52 | } DVR_WrapperPidsInfo_t; |
| 53 | |
| 54 | typedef struct { |
| 55 | DVR_PlaybackPlayState_t state; |
| 56 | DVR_WrapperInfo_t info_cur; |
| 57 | DVR_WrapperInfo_t info_full; |
| 58 | DVR_PlaybackPids_t pids; |
| 59 | float speed; |
| 60 | DVR_PlaybackSegmentFlag_t flags; |
| 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*/ |
| 67 | } DVR_WrapperRecordStatus_t; |
| 68 | |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 69 | /**Record wrapper open parameters.*/ |
| 70 | typedef struct { |
| 71 | int dmx_dev_id; /**< Demux device's index.*/ |
| 72 | char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/ |
| 73 | DVR_Bool_t is_timeshift; /**< The record file is used by timeshift.*/ |
| 74 | loff_t segment_size; /**< Segment file's size.*/ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 75 | loff_t max_size; /**< Maximum record file size in bytes.*/ |
| 76 | time_t max_time; /**< Maximum record time in seconds.*/ |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 77 | DVR_RecordFlag_t flags; /**< Flags.*/ |
| 78 | DVR_CryptoPeriod_t crypto_period; /**< Crypto period.*/ |
| 79 | DVR_CryptoFunction_t crypto_fn; /**< Crypto callback function.*/ |
| 80 | void *crypto_data; /**< User data of crypto function.*/ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 81 | DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/ |
| 82 | void *event_userdata; /**< DVR event userdata*/ |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 83 | } DVR_WrapperRecordOpenParams_t; |
| 84 | |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 85 | typedef struct { |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 86 | DVR_WrapperPidsInfo_t pids_info; |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 87 | } DVR_WrapperRecordStartParams_t; |
| 88 | |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 89 | typedef struct { |
| 90 | uint32_t nb_pids; /**< Number of PID actions.*/ |
| 91 | DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/ |
| 92 | DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/ |
| 93 | } DVR_WrapperUpdatePidsParams_t; |
| 94 | |
| 95 | /**Playback wrapper open parameters.*/ |
| 96 | typedef struct { |
| 97 | int dmx_dev_id; /**< playback used dmx device index*/ |
| 98 | char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/ |
| 99 | int block_size; /**< playback inject block size*/ |
| 100 | DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/ |
| 101 | Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/ |
| 102 | DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/ |
| 103 | void *crypto_data; /**< Crypto function's user data.*/ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 104 | DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/ |
| 105 | void *event_userdata; /**< event userdata*/ |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 106 | } DVR_WrapperPlaybackOpenParams_t; |
| 107 | |
| 108 | /** |
| 109 | * Open a new record wrapper. |
| 110 | * \param[out] rec Return the new record handle. |
| 111 | * \param params Record open parameters. |
| 112 | * \retval DVR_SUCCESS On success. |
| 113 | * \return Error code. |
| 114 | */ |
| 115 | int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params); |
| 116 | |
| 117 | /** |
| 118 | * Close an unused record wrapper. |
| 119 | * \param rec The record handle. |
| 120 | * \retval DVR_SUCCESS On success. |
| 121 | * \return Error code. |
| 122 | */ |
| 123 | int dvr_wrapper_close_record (DVR_WrapperRecord_t rec); |
| 124 | |
| 125 | /** |
| 126 | * Start recording. |
| 127 | * \param rec The record handle. |
| 128 | * \param params Record start parameters. |
| 129 | * \retval DVR_SUCCESS On success. |
| 130 | * \return Error code. |
| 131 | */ |
| 132 | int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params); |
| 133 | |
| 134 | /** |
| 135 | * Stop recording.. |
| 136 | * \param rec The record handle. |
| 137 | * \retval DVR_SUCCESS On success. |
| 138 | * \return Error code. |
| 139 | */ |
| 140 | int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec); |
| 141 | |
| 142 | /** |
| 143 | * Update the recording PIDs. |
| 144 | * \param rec The record handle. |
| 145 | * \param params The new PIDs. |
| 146 | * \retval DVR_SUCCESS On success. |
| 147 | * \return Error code. |
| 148 | */ |
| 149 | int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params); |
| 150 | |
| 151 | /** |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 152 | * Get the current recording status. |
| 153 | * \param rec The record handle. |
| 154 | * \param status The recording status returned. |
| 155 | * \retval DVR_SUCCESS On success. |
| 156 | * \return Error code. |
| 157 | */ |
| 158 | int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status); |
| 159 | |
| 160 | /** |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 161 | * Open a new playback wrapper handle. |
| 162 | * \param[out] playback Return the new playback handle. |
| 163 | * \param params Playback handle open parameters. |
| 164 | * \retval DVR_SUCCESS On success. |
| 165 | * \return Error code. |
| 166 | */ |
| 167 | int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params); |
| 168 | |
| 169 | /** |
| 170 | * Close a unused playback handle. |
| 171 | * \param playback The playback handle to be closed. |
| 172 | * \retval DVR_SUCCESS On success. |
| 173 | * \return Error code. |
| 174 | */ |
| 175 | int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback); |
| 176 | |
| 177 | /** |
| 178 | * Start playback. |
| 179 | * \param playback The playback handle. |
| 180 | * \param flags Playback flags. |
| 181 | * \retval DVR_SUCCESS On success. |
| 182 | * \return Error code. |
| 183 | */ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 184 | 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] | 185 | |
| 186 | /** |
| 187 | * Stop playback. |
| 188 | * \param playback The playback handle. |
| 189 | * \retval DVR_SUCCESS On success. |
| 190 | * \return Error code. |
| 191 | */ |
| 192 | int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback); |
| 193 | |
| 194 | /** |
| 195 | * Pause the playback. |
| 196 | * \param playback The playback handle. |
| 197 | * \retval DVR_SUCCESS On success. |
| 198 | * \return Error code. |
| 199 | */ |
| 200 | int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback); |
| 201 | |
| 202 | /** |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 203 | * resume the playback. |
| 204 | * \param playback The playback handle. |
| 205 | * \retval DVR_SUCCESS On success. |
| 206 | * \return Error code. |
| 207 | */ |
| 208 | int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback); |
| 209 | |
| 210 | /** |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 211 | * Set the playback speed. |
| 212 | * \param playback The playback handle. |
| 213 | * \param speed The new speed. |
| 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_set_playback_speed (DVR_WrapperPlayback_t playback, float speed); |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * Seek the current playback position. |
| 221 | * \param playback The playback handle. |
| 222 | * \param time_offset The current time in milliseconds. |
| 223 | * \retval DVR_SUCCESS On success. |
| 224 | * \return Error code. |
| 225 | */ |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 226 | int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset); |
| 227 | |
| 228 | /** |
| 229 | * Get the current playback status. |
| 230 | * \param playback The playback handle. |
| 231 | * \param status The playback status returned. |
| 232 | * \retval DVR_SUCCESS On success. |
| 233 | * \return Error code. |
| 234 | */ |
| 235 | int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status); |
| 236 | |
| 237 | /** |
| 238 | * Update playback. |
| 239 | * \param playback The playback handle. |
| 240 | * \param flags Playback flags. |
| 241 | * \retval DVR_SUCCESS On success. |
| 242 | * \return Error code. |
| 243 | */ |
| 244 | int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids); |
| 245 | |
Gong Ke | 80b8d2a | 2020-02-04 18:34:35 +0800 | [diff] [blame] | 246 | |
| 247 | #ifdef __cplusplus |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | #endif /*DVR_WRAPPER_H_*/ |
| 252 | |