blob: 7b0323b2a9103588d929595b52e37f3711253f6b [file] [log] [blame]
Gong Ke80b8d2a2020-02-04 18:34:35 +08001/**
Gong Ke497c4c22020-03-20 10:15:42 +08002 * \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 Ke497c4c22020-03-20 10:15:42 +080012 *
Gong Ke80b8d2a2020-02-04 18:34:35 +080013 * \file
Gong Ke497c4c22020-03-20 10:15:42 +080014 * \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 Ke80b8d2a2020-02-04 18:34:35 +080021 */
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
32extern "C" {
33#endif
34
35/**Record wrapper handle.*/
36typedef void* DVR_WrapperRecord_t;
37/**Playback wrapper handle.*/
38typedef void* DVR_WrapperPlayback_t;
39
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080040typedef void* Playback_DeviceHandle_t;
41
42typedef 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
48typedef 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
53typedef struct {
Zhiqiang Hanaeb0c712020-04-30 15:17:26 +080054 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 Han2d8cd822020-03-16 13:58:10 +080061} DVR_WrapperPlaybackStatus_t;
62
63typedef 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 Hanaeb0c712020-04-30 15:17:26 +080067 DVR_WrapperInfo_t info_obsolete; /**< DVR record obsolete information, take into account for timeshift*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080068} DVR_WrapperRecordStatus_t;
69
Gong Ke80b8d2a2020-02-04 18:34:35 +080070/**Record wrapper open parameters.*/
71typedef struct {
Yahui Hance15e9c2020-12-08 18:08:32 +080072 int fend_dev_id; /**< Frontend device's index.*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080073 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 Hanaeb0c712020-04-30 15:17:26 +080077 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 Ke80b8d2a2020-02-04 18:34:35 +080079 DVR_RecordFlag_t flags; /**< Flags.*/
80 DVR_CryptoPeriod_t crypto_period; /**< Crypto period.*/
81 DVR_CryptoFunction_t crypto_fn; /**< Crypto callback function.*/
Yahui Han1fbf3292021-11-08 18:17:19 +080082 void *crypto_data; /**< User data of crypto function.*/
83 uint8_t *clearkey; /**< key for encrypted PVR on FTA.*/
84 uint8_t *cleariv; /**< iv for encrpted PVR on FTA.*/
85 uint32_t keylen; /**< key/iv length.*/
86 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function.*/
87 void *event_userdata; /**< DVR event userdata.*/
88 int flush_size; /**< DVR flush size.*/
89 int ringbuf_size; /**< DVR ringbuf size.*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080090} DVR_WrapperRecordOpenParams_t;
91
Gong Ke80b8d2a2020-02-04 18:34:35 +080092typedef struct {
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080093 DVR_WrapperPidsInfo_t pids_info;
hualing chena5f03222021-12-02 11:22:35 +080094 int save_rec_file; /**< save rec file with same location,defaule is 0.*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080095} DVR_WrapperRecordStartParams_t;
96
Gong Ke80b8d2a2020-02-04 18:34:35 +080097typedef struct {
98 uint32_t nb_pids; /**< Number of PID actions.*/
99 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/
100 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/
101} DVR_WrapperUpdatePidsParams_t;
102
103/**Playback wrapper open parameters.*/
104typedef struct {
105 int dmx_dev_id; /**< playback used dmx device index*/
106 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
107 int block_size; /**< playback inject block size*/
108 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
109 Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/
110 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
Yahui Han1fbf3292021-11-08 18:17:19 +0800111 void *crypto_data; /**< Crypto function's user data.*/
112 uint8_t *clearkey; /**< key for encrypted PVR on FTA.*/
113 uint8_t *cleariv; /**< iv for encrpted PVR on FTA.*/
114 uint32_t keylen; /**< key/iv length.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800115 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
116 void *event_userdata; /**< event userdata*/
hualing chen90b3ae62021-03-30 10:49:28 +0800117 DVR_Bool_t is_notify_time; /**< 0:not notify time, 1 : notify*/
118 DVR_PlaybackVendor_t vendor; /**< vendor type*/
Gong Ke80b8d2a2020-02-04 18:34:35 +0800119} DVR_WrapperPlaybackOpenParams_t;
120
121/**
122 * Open a new record wrapper.
123 * \param[out] rec Return the new record handle.
124 * \param params Record open parameters.
125 * \retval DVR_SUCCESS On success.
126 * \return Error code.
127 */
128int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params);
129
130/**
131 * Close an unused record wrapper.
132 * \param rec The record handle.
133 * \retval DVR_SUCCESS On success.
134 * \return Error code.
135 */
136int dvr_wrapper_close_record (DVR_WrapperRecord_t rec);
137
138/**
139 * Start recording.
140 * \param rec The record handle.
141 * \param params Record start parameters.
142 * \retval DVR_SUCCESS On success.
143 * \return Error code.
144 */
145int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params);
146
147/**
148 * Stop recording..
149 * \param rec The record handle.
150 * \retval DVR_SUCCESS On success.
151 * \return Error code.
152 */
153int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec);
154
155/**
hualing chen03fd4942021-07-15 15:56:41 +0800156 * Pause recording..
157 * \param rec The record handle.
158 * \retval DVR_SUCCESS On success.
159 * \return Error code.
160 */
161int dvr_wrapper_pause_record (DVR_WrapperRecord_t rec);
162
163/**
164 * Resume recording..
165 * \param rec The record handle.
166 * \retval DVR_SUCCESS On success.
167 * \return Error code.
168 */
169int dvr_wrapper_resume_record (DVR_WrapperRecord_t rec);
170
171/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800172 * Update the recording PIDs.
173 * \param rec The record handle.
174 * \param params The new PIDs.
175 * \retval DVR_SUCCESS On success.
176 * \return Error code.
177 */
178int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params);
179
180/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800181 * Get the current recording status.
182 * \param rec The record handle.
183 * \param status The recording status returned.
184 * \retval DVR_SUCCESS On success.
185 * \return Error code.
186 */
187int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status);
188
189/**
hualing chen4fe3bee2020-10-23 13:58:52 +0800190 * check record mode is secure or free.
191 * \param rec The record handle.
192 * \retval 1:secure 0: free mode.
193 * \return secure or free.
194 */
195int dvr_wrapper_record_is_secure_mode(DVR_WrapperRecord_t rec);
196
197/**
hualing chen266b9502020-04-04 17:39:39 +0800198 * Set record secure buffer.
199 * \param rec The record handle.
200 * \param p_secure_buf record p_secure_buf addr.
201 * \param len record p_secure_buf len.
202 * \retval DVR_SUCCESS On success.
203 * \return Error code.
204 */
205int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len);
206
207/**
208 * Set record decrypt callback.
209 * \param rec The record handle.
210 * \param func record dec cb.
211 * \param userdata cb user data.
212 * \retval DVR_SUCCESS On success.
213 * \return Error code.
214 */
215int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata);
216
217/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800218 * Open a new playback wrapper handle.
219 * \param[out] playback Return the new playback handle.
220 * \param params Playback handle open parameters.
221 * \retval DVR_SUCCESS On success.
222 * \return Error code.
223 */
224int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params);
225
226/**
227 * Close a unused playback handle.
228 * \param playback The playback handle to be closed.
229 * \retval DVR_SUCCESS On success.
230 * \return Error code.
231 */
232int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback);
233
234/**
235 * Start playback.
236 * \param playback The playback handle.
237 * \param flags Playback flags.
238 * \retval DVR_SUCCESS On success.
239 * \return Error code.
240 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800241int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800242
243/**
244 * Stop playback.
245 * \param playback The playback handle.
246 * \retval DVR_SUCCESS On success.
247 * \return Error code.
248 */
249int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback);
250
251/**
252 * Pause the playback.
253 * \param playback The playback handle.
254 * \retval DVR_SUCCESS On success.
255 * \return Error code.
256 */
257int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback);
258
259/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800260 * resume the playback.
261 * \param playback The playback handle.
262 * \retval DVR_SUCCESS On success.
263 * \return Error code.
264 */
265int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback);
266
267/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800268 * Set the playback speed.
269 * \param playback The playback handle.
270 * \param speed The new speed.
271 * \retval DVR_SUCCESS On success.
272 * \return Error code.
273 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800274int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800275
276/**
hualing chen03fd4942021-07-15 15:56:41 +0800277 * set the current playback limit info.
278 * \param playback The playback handle.
279 * \param time The rec time in milliseconds.
280 * \param limit The rec limit time in milliseconds.
281 * \retval DVR_SUCCESS On success.
282 * \return Error code.
283 */
284int dvr_wrapper_setlimit_playback (DVR_WrapperPlayback_t playback, uint64_t time, int32_t limit);
285
286/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800287 * Seek the current playback position.
288 * \param playback The playback handle.
289 * \param time_offset The current time in milliseconds.
290 * \retval DVR_SUCCESS On success.
291 * \return Error code.
292 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800293int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset);
294
295/**
296 * Get the current playback status.
297 * \param playback The playback handle.
298 * \param status The playback status returned.
299 * \retval DVR_SUCCESS On success.
300 * \return Error code.
301 */
302int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status);
303
304/**
305 * Update playback.
306 * \param playback The playback handle.
307 * \param flags Playback flags.
308 * \retval DVR_SUCCESS On success.
309 * \return Error code.
310 */
311int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
312
hualing chen266b9502020-04-04 17:39:39 +0800313/**
hualing chena5f03222021-12-02 11:22:35 +0800314 * only Update playback info.
315 * \param playback The playback handle.
316 * \param flags Playback flags.
317 * \retval DVR_SUCCESS On success.
318 * \return Error code.
319 */
320int dvr_wrapper_only_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
321
322/**
hualing chen266b9502020-04-04 17:39:39 +0800323 * Set playback secure buffer.
324 * \param playback The playback handle.
325 * \param p_secure_buf Playback p_secure_buf addr.
326 * \param len Playback p_secure_buf len.
327 * \retval DVR_SUCCESS On success.
328 * \return Error code.
329 */
330int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len);
331
332/**
333 * Set playback decrypt callback.
334 * \param playback The playback handle.
335 * \param func Playback dec cb.
336 * \param userdata cb user data.
337 * \retval DVR_SUCCESS On success.
338 * \return Error code.
339 */
340int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata);
341
Zhiqiang Han620b9252021-11-09 14:23:20 +0800342/**
343 * Delete all info of segment whose location is "*location"
344 * \param[in] location The record of need del file's location
345 * \retval DVR_SUCCESS On success.
346 * \return Error code.
347 */
348int dvr_wrapper_segment_del_by_location (const char *location);
349
350/**
351 * Get the info of segment whose location is "*location"
352 * \param[in] location The record file's location
353 * \retval DVR_SUCCESS On success.
354 * \return Error code.
355 */
356int dvr_wrapper_segment_get_info_by_location (const char *location, DVR_WrapperInfo_t *p_info);
357
hualing chen266b9502020-04-04 17:39:39 +0800358
Gong Ke80b8d2a2020-02-04 18:34:35 +0800359
360#ifdef __cplusplus
361}
362#endif
363
364#endif /*DVR_WRAPPER_H_*/
365