blob: f36ecb49ed718c433907a497e707e8892199269a [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;
Gong Ke80b8d2a2020-02-04 18:34:35 +080094} DVR_WrapperRecordStartParams_t;
95
Gong Ke80b8d2a2020-02-04 18:34:35 +080096typedef struct {
97 uint32_t nb_pids; /**< Number of PID actions.*/
98 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/
99 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/
100} DVR_WrapperUpdatePidsParams_t;
101
102/**Playback wrapper open parameters.*/
103typedef struct {
104 int dmx_dev_id; /**< playback used dmx device index*/
105 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
106 int block_size; /**< playback inject block size*/
107 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
108 Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/
109 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
Yahui Han1fbf3292021-11-08 18:17:19 +0800110 void *crypto_data; /**< Crypto function's user data.*/
111 uint8_t *clearkey; /**< key for encrypted PVR on FTA.*/
112 uint8_t *cleariv; /**< iv for encrpted PVR on FTA.*/
113 uint32_t keylen; /**< key/iv length.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800114 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
115 void *event_userdata; /**< event userdata*/
hualing chen90b3ae62021-03-30 10:49:28 +0800116 DVR_Bool_t is_notify_time; /**< 0:not notify time, 1 : notify*/
117 DVR_PlaybackVendor_t vendor; /**< vendor type*/
Gong Ke80b8d2a2020-02-04 18:34:35 +0800118} DVR_WrapperPlaybackOpenParams_t;
119
120/**
121 * Open a new record wrapper.
122 * \param[out] rec Return the new record handle.
123 * \param params Record open parameters.
124 * \retval DVR_SUCCESS On success.
125 * \return Error code.
126 */
127int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params);
128
129/**
130 * Close an unused record wrapper.
131 * \param rec The record handle.
132 * \retval DVR_SUCCESS On success.
133 * \return Error code.
134 */
135int dvr_wrapper_close_record (DVR_WrapperRecord_t rec);
136
137/**
138 * Start recording.
139 * \param rec The record handle.
140 * \param params Record start parameters.
141 * \retval DVR_SUCCESS On success.
142 * \return Error code.
143 */
144int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params);
145
146/**
147 * Stop recording..
148 * \param rec The record handle.
149 * \retval DVR_SUCCESS On success.
150 * \return Error code.
151 */
152int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec);
153
154/**
hualing chen03fd4942021-07-15 15:56:41 +0800155 * Pause recording..
156 * \param rec The record handle.
157 * \retval DVR_SUCCESS On success.
158 * \return Error code.
159 */
160int dvr_wrapper_pause_record (DVR_WrapperRecord_t rec);
161
162/**
163 * Resume recording..
164 * \param rec The record handle.
165 * \retval DVR_SUCCESS On success.
166 * \return Error code.
167 */
168int dvr_wrapper_resume_record (DVR_WrapperRecord_t rec);
169
170/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800171 * Update the recording PIDs.
172 * \param rec The record handle.
173 * \param params The new PIDs.
174 * \retval DVR_SUCCESS On success.
175 * \return Error code.
176 */
177int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params);
178
179/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800180 * Get the current recording status.
181 * \param rec The record handle.
182 * \param status The recording status returned.
183 * \retval DVR_SUCCESS On success.
184 * \return Error code.
185 */
186int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status);
187
188/**
hualing chen4fe3bee2020-10-23 13:58:52 +0800189 * check record mode is secure or free.
190 * \param rec The record handle.
191 * \retval 1:secure 0: free mode.
192 * \return secure or free.
193 */
194int dvr_wrapper_record_is_secure_mode(DVR_WrapperRecord_t rec);
195
196/**
hualing chen266b9502020-04-04 17:39:39 +0800197 * Set record secure buffer.
198 * \param rec The record handle.
199 * \param p_secure_buf record p_secure_buf addr.
200 * \param len record p_secure_buf len.
201 * \retval DVR_SUCCESS On success.
202 * \return Error code.
203 */
204int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len);
205
206/**
207 * Set record decrypt callback.
208 * \param rec The record handle.
209 * \param func record dec cb.
210 * \param userdata cb user data.
211 * \retval DVR_SUCCESS On success.
212 * \return Error code.
213 */
214int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata);
215
216/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800217 * Open a new playback wrapper handle.
218 * \param[out] playback Return the new playback handle.
219 * \param params Playback handle open parameters.
220 * \retval DVR_SUCCESS On success.
221 * \return Error code.
222 */
223int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params);
224
225/**
226 * Close a unused playback handle.
227 * \param playback The playback handle to be closed.
228 * \retval DVR_SUCCESS On success.
229 * \return Error code.
230 */
231int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback);
232
233/**
234 * Start playback.
235 * \param playback The playback handle.
236 * \param flags Playback flags.
237 * \retval DVR_SUCCESS On success.
238 * \return Error code.
239 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800240int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800241
242/**
243 * Stop playback.
244 * \param playback The playback handle.
245 * \retval DVR_SUCCESS On success.
246 * \return Error code.
247 */
248int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback);
249
250/**
251 * Pause the playback.
252 * \param playback The playback handle.
253 * \retval DVR_SUCCESS On success.
254 * \return Error code.
255 */
256int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback);
257
258/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800259 * resume the playback.
260 * \param playback The playback handle.
261 * \retval DVR_SUCCESS On success.
262 * \return Error code.
263 */
264int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback);
265
266/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800267 * Set the playback speed.
268 * \param playback The playback handle.
269 * \param speed The new speed.
270 * \retval DVR_SUCCESS On success.
271 * \return Error code.
272 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800273int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800274
275/**
hualing chen03fd4942021-07-15 15:56:41 +0800276 * set the current playback limit info.
277 * \param playback The playback handle.
278 * \param time The rec time in milliseconds.
279 * \param limit The rec limit time in milliseconds.
280 * \retval DVR_SUCCESS On success.
281 * \return Error code.
282 */
283int dvr_wrapper_setlimit_playback (DVR_WrapperPlayback_t playback, uint64_t time, int32_t limit);
284
285/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800286 * Seek the current playback position.
287 * \param playback The playback handle.
288 * \param time_offset The current time in milliseconds.
289 * \retval DVR_SUCCESS On success.
290 * \return Error code.
291 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800292int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset);
293
294/**
295 * Get the current playback status.
296 * \param playback The playback handle.
297 * \param status The playback status returned.
298 * \retval DVR_SUCCESS On success.
299 * \return Error code.
300 */
301int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status);
302
303/**
304 * Update playback.
305 * \param playback The playback handle.
306 * \param flags Playback flags.
307 * \retval DVR_SUCCESS On success.
308 * \return Error code.
309 */
310int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
311
hualing chen266b9502020-04-04 17:39:39 +0800312/**
313 * Set playback secure buffer.
314 * \param playback The playback handle.
315 * \param p_secure_buf Playback p_secure_buf addr.
316 * \param len Playback p_secure_buf len.
317 * \retval DVR_SUCCESS On success.
318 * \return Error code.
319 */
320int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len);
321
322/**
323 * Set playback decrypt callback.
324 * \param playback The playback handle.
325 * \param func Playback dec cb.
326 * \param userdata cb user data.
327 * \retval DVR_SUCCESS On success.
328 * \return Error code.
329 */
330int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata);
331
332
Gong Ke80b8d2a2020-02-04 18:34:35 +0800333
334#ifdef __cplusplus
335}
336#endif
337
338#endif /*DVR_WRAPPER_H_*/
339