blob: 0f7a0d85a551a683acfc54ec1e7be804be6a1940 [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*/
hualing chen56c0a162022-01-27 17:01:50 +080061 DVR_WrapperInfo_t disguised_info_obsolete; /**< DVR playback disguised obsolete information, take into account for timeshift*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080062} DVR_WrapperPlaybackStatus_t;
63
64typedef struct {
65 DVR_RecordState_t state; /**< DVR record state*/
66 DVR_WrapperInfo_t info; /**< DVR record information*/
67 DVR_WrapperPidsInfo_t pids; /**< DVR record pids info*/
Zhiqiang Hanaeb0c712020-04-30 15:17:26 +080068 DVR_WrapperInfo_t info_obsolete; /**< DVR record obsolete information, take into account for timeshift*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080069} DVR_WrapperRecordStatus_t;
70
Gong Ke80b8d2a2020-02-04 18:34:35 +080071/**Record wrapper open parameters.*/
72typedef struct {
Yahui Hance15e9c2020-12-08 18:08:32 +080073 int fend_dev_id; /**< Frontend device's index.*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080074 int dmx_dev_id; /**< Demux device's index.*/
75 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
76 DVR_Bool_t is_timeshift; /**< The record file is used by timeshift.*/
77 loff_t segment_size; /**< Segment file's size.*/
Zhiqiang Hanaeb0c712020-04-30 15:17:26 +080078 loff_t max_size; /**< Maximum record file size in bytes(for timeshift).*/
79 time_t max_time; /**< Maximum record time in milliseconds(for timeshift).*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080080 DVR_RecordFlag_t flags; /**< Flags.*/
81 DVR_CryptoPeriod_t crypto_period; /**< Crypto period.*/
82 DVR_CryptoFunction_t crypto_fn; /**< Crypto callback function.*/
Yahui Han1fbf3292021-11-08 18:17:19 +080083 void *crypto_data; /**< User data of crypto function.*/
84 uint8_t *clearkey; /**< key for encrypted PVR on FTA.*/
85 uint8_t *cleariv; /**< iv for encrpted PVR on FTA.*/
86 uint32_t keylen; /**< key/iv length.*/
87 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function.*/
88 void *event_userdata; /**< DVR event userdata.*/
89 int flush_size; /**< DVR flush size.*/
90 int ringbuf_size; /**< DVR ringbuf size.*/
wentao.ma35a69d42022-03-10 18:08:40 +080091 DVR_Bool_t force_sysclock; /**< If ture, force to use system clock as PVR index time source. If false, libdvr can determine index time source based on actual situation*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080092} DVR_WrapperRecordOpenParams_t;
93
Gong Ke80b8d2a2020-02-04 18:34:35 +080094typedef struct {
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080095 DVR_WrapperPidsInfo_t pids_info;
hualing chena5f03222021-12-02 11:22:35 +080096 int save_rec_file; /**< save rec file with same location,defaule is 0.*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080097} DVR_WrapperRecordStartParams_t;
98
Gong Ke80b8d2a2020-02-04 18:34:35 +080099typedef struct {
100 uint32_t nb_pids; /**< Number of PID actions.*/
101 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/
102 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/
103} DVR_WrapperUpdatePidsParams_t;
104
105/**Playback wrapper open parameters.*/
106typedef struct {
107 int dmx_dev_id; /**< playback used dmx device index*/
108 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
109 int block_size; /**< playback inject block size*/
110 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
111 Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/
112 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
Yahui Han1fbf3292021-11-08 18:17:19 +0800113 void *crypto_data; /**< Crypto function's user data.*/
114 uint8_t *clearkey; /**< key for encrypted PVR on FTA.*/
115 uint8_t *cleariv; /**< iv for encrpted PVR on FTA.*/
116 uint32_t keylen; /**< key/iv length.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800117 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
118 void *event_userdata; /**< event userdata*/
hualing chen90b3ae62021-03-30 10:49:28 +0800119 DVR_Bool_t is_notify_time; /**< 0:not notify time, 1 : notify*/
120 DVR_PlaybackVendor_t vendor; /**< vendor type*/
Gong Ke80b8d2a2020-02-04 18:34:35 +0800121} DVR_WrapperPlaybackOpenParams_t;
122
123/**
124 * Open a new record wrapper.
125 * \param[out] rec Return the new record handle.
126 * \param params Record open parameters.
127 * \retval DVR_SUCCESS On success.
128 * \return Error code.
129 */
130int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params);
131
132/**
133 * Close an unused record wrapper.
134 * \param rec The record handle.
135 * \retval DVR_SUCCESS On success.
136 * \return Error code.
137 */
138int dvr_wrapper_close_record (DVR_WrapperRecord_t rec);
139
140/**
141 * Start recording.
142 * \param rec The record handle.
143 * \param params Record start parameters.
144 * \retval DVR_SUCCESS On success.
145 * \return Error code.
146 */
147int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params);
148
149/**
150 * Stop recording..
151 * \param rec The record handle.
152 * \retval DVR_SUCCESS On success.
153 * \return Error code.
154 */
155int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec);
156
157/**
hualing chen03fd4942021-07-15 15:56:41 +0800158 * Pause recording..
159 * \param rec The record handle.
160 * \retval DVR_SUCCESS On success.
161 * \return Error code.
162 */
163int dvr_wrapper_pause_record (DVR_WrapperRecord_t rec);
164
165/**
166 * Resume recording..
167 * \param rec The record handle.
168 * \retval DVR_SUCCESS On success.
169 * \return Error code.
170 */
171int dvr_wrapper_resume_record (DVR_WrapperRecord_t rec);
172
173/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800174 * Update the recording PIDs.
175 * \param rec The record handle.
176 * \param params The new PIDs.
177 * \retval DVR_SUCCESS On success.
178 * \return Error code.
179 */
180int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params);
181
182/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800183 * Get the current recording status.
184 * \param rec The record handle.
185 * \param status The recording status returned.
186 * \retval DVR_SUCCESS On success.
187 * \return Error code.
188 */
189int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status);
190
191/**
hualing chen4fe3bee2020-10-23 13:58:52 +0800192 * check record mode is secure or free.
193 * \param rec The record handle.
194 * \retval 1:secure 0: free mode.
195 * \return secure or free.
196 */
197int dvr_wrapper_record_is_secure_mode(DVR_WrapperRecord_t rec);
198
199/**
hualing chen266b9502020-04-04 17:39:39 +0800200 * Set record secure buffer.
201 * \param rec The record handle.
202 * \param p_secure_buf record p_secure_buf addr.
203 * \param len record p_secure_buf len.
204 * \retval DVR_SUCCESS On success.
205 * \return Error code.
206 */
207int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len);
208
209/**
210 * Set record decrypt callback.
211 * \param rec The record handle.
212 * \param func record dec cb.
213 * \param userdata cb user data.
214 * \retval DVR_SUCCESS On success.
215 * \return Error code.
216 */
217int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata);
218
219/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800220 * Open a new playback wrapper handle.
221 * \param[out] playback Return the new playback handle.
222 * \param params Playback handle open parameters.
223 * \retval DVR_SUCCESS On success.
224 * \return Error code.
225 */
226int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params);
227
228/**
229 * Close a unused playback handle.
230 * \param playback The playback handle to be closed.
231 * \retval DVR_SUCCESS On success.
232 * \return Error code.
233 */
234int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback);
235
236/**
237 * Start playback.
238 * \param playback The playback handle.
239 * \param flags Playback flags.
240 * \retval DVR_SUCCESS On success.
241 * \return Error code.
242 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800243int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800244
245/**
246 * Stop playback.
247 * \param playback The playback handle.
248 * \retval DVR_SUCCESS On success.
249 * \return Error code.
250 */
251int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback);
252
253/**
254 * Pause the playback.
255 * \param playback The playback handle.
256 * \retval DVR_SUCCESS On success.
257 * \return Error code.
258 */
259int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback);
260
261/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800262 * resume the playback.
263 * \param playback The playback handle.
264 * \retval DVR_SUCCESS On success.
265 * \return Error code.
266 */
267int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback);
268
269/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800270 * Set the playback speed.
271 * \param playback The playback handle.
272 * \param speed The new speed.
273 * \retval DVR_SUCCESS On success.
274 * \return Error code.
275 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800276int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800277
278/**
hualing chen03fd4942021-07-15 15:56:41 +0800279 * set the current playback limit info.
280 * \param playback The playback handle.
281 * \param time The rec time in milliseconds.
282 * \param limit The rec limit time in milliseconds.
283 * \retval DVR_SUCCESS On success.
284 * \return Error code.
285 */
286int dvr_wrapper_setlimit_playback (DVR_WrapperPlayback_t playback, uint64_t time, int32_t limit);
287
288/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800289 * Seek the current playback position.
290 * \param playback The playback handle.
291 * \param time_offset The current time in milliseconds.
292 * \retval DVR_SUCCESS On success.
293 * \return Error code.
294 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800295int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset);
296
297/**
298 * Get the current playback status.
299 * \param playback The playback handle.
300 * \param status The playback status returned.
301 * \retval DVR_SUCCESS On success.
302 * \return Error code.
303 */
304int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status);
305
306/**
307 * Update playback.
308 * \param playback The playback handle.
309 * \param flags Playback flags.
310 * \retval DVR_SUCCESS On success.
311 * \return Error code.
312 */
313int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
314
hualing chen266b9502020-04-04 17:39:39 +0800315/**
hualing chena5f03222021-12-02 11:22:35 +0800316 * only Update playback info.
317 * \param playback The playback handle.
318 * \param flags Playback flags.
319 * \retval DVR_SUCCESS On success.
320 * \return Error code.
321 */
322int dvr_wrapper_only_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
323
324/**
hualing chen266b9502020-04-04 17:39:39 +0800325 * Set playback secure buffer.
326 * \param playback The playback handle.
327 * \param p_secure_buf Playback p_secure_buf addr.
328 * \param len Playback p_secure_buf len.
329 * \retval DVR_SUCCESS On success.
330 * \return Error code.
331 */
332int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len);
333
334/**
335 * Set playback decrypt callback.
336 * \param playback The playback handle.
337 * \param func Playback dec cb.
338 * \param userdata cb user data.
339 * \retval DVR_SUCCESS On success.
340 * \return Error code.
341 */
342int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata);
343
Zhiqiang Han620b9252021-11-09 14:23:20 +0800344/**
345 * Delete all info of segment whose location is "*location"
346 * \param[in] location The record of need del file's location
347 * \retval DVR_SUCCESS On success.
348 * \return Error code.
349 */
350int dvr_wrapper_segment_del_by_location (const char *location);
351
352/**
353 * Get the info of segment whose location is "*location"
354 * \param[in] location The record file's location
355 * \retval DVR_SUCCESS On success.
356 * \return Error code.
357 */
358int dvr_wrapper_segment_get_info_by_location (const char *location, DVR_WrapperInfo_t *p_info);
359
hualing chen002e5b92022-02-23 17:51:21 +0800360/**
361 * Stop timeshit.
362 * \param playback The playback handle.
363 * \retval DVR_SUCCESS On success.
364 * \return Error code.
365 */
366int dvr_wrapper_stop_timeshift (DVR_WrapperPlayback_t playback);
367/**
368 * reStart timeshift.
369 * \param playback The playback handle.
370 * \param flags Playback flags.
371 * \param p_pids playback pids info
372 * \retval DVR_SUCCESS On success.
373 * \return Error code.
374 */
375int dvr_wrapper_restart_timeshift(DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800376
377#ifdef __cplusplus
378}
379#endif
380
381#endif /*DVR_WRAPPER_H_*/
382