blob: 7e53a46aac78a8123d2c065fd7b76a112bdbdc32 [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.*/
82 void *crypto_data; /**< User data of crypto function.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080083 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/
84 void *event_userdata; /**< DVR event userdata*/
Zhiqiang Han31505452020-05-06 15:08:10 +080085 int flush_size; /**< DVR flush size*/
hualing chen03fd4942021-07-15 15:56:41 +080086 int ringbuf_size; /**< DVR ringbuf size*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080087} DVR_WrapperRecordOpenParams_t;
88
Gong Ke80b8d2a2020-02-04 18:34:35 +080089typedef struct {
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080090 DVR_WrapperPidsInfo_t pids_info;
Gong Ke80b8d2a2020-02-04 18:34:35 +080091} DVR_WrapperRecordStartParams_t;
92
Gong Ke80b8d2a2020-02-04 18:34:35 +080093typedef struct {
94 uint32_t nb_pids; /**< Number of PID actions.*/
95 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/
96 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/
97} DVR_WrapperUpdatePidsParams_t;
98
99/**Playback wrapper open parameters.*/
100typedef struct {
101 int dmx_dev_id; /**< playback used dmx device index*/
102 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
103 int block_size; /**< playback inject block size*/
104 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
105 Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/
106 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
107 void *crypto_data; /**< Crypto function's user data.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800108 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
109 void *event_userdata; /**< event userdata*/
hualing chen90b3ae62021-03-30 10:49:28 +0800110 DVR_Bool_t is_notify_time; /**< 0:not notify time, 1 : notify*/
111 DVR_PlaybackVendor_t vendor; /**< vendor type*/
Gong Ke80b8d2a2020-02-04 18:34:35 +0800112} DVR_WrapperPlaybackOpenParams_t;
113
114/**
115 * Open a new record wrapper.
116 * \param[out] rec Return the new record handle.
117 * \param params Record open parameters.
118 * \retval DVR_SUCCESS On success.
119 * \return Error code.
120 */
121int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params);
122
123/**
124 * Close an unused record wrapper.
125 * \param rec The record handle.
126 * \retval DVR_SUCCESS On success.
127 * \return Error code.
128 */
129int dvr_wrapper_close_record (DVR_WrapperRecord_t rec);
130
131/**
132 * Start recording.
133 * \param rec The record handle.
134 * \param params Record start parameters.
135 * \retval DVR_SUCCESS On success.
136 * \return Error code.
137 */
138int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params);
139
140/**
141 * Stop recording..
142 * \param rec The record handle.
143 * \retval DVR_SUCCESS On success.
144 * \return Error code.
145 */
146int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec);
147
148/**
hualing chen03fd4942021-07-15 15:56:41 +0800149 * Pause recording..
150 * \param rec The record handle.
151 * \retval DVR_SUCCESS On success.
152 * \return Error code.
153 */
154int dvr_wrapper_pause_record (DVR_WrapperRecord_t rec);
155
156/**
157 * Resume recording..
158 * \param rec The record handle.
159 * \retval DVR_SUCCESS On success.
160 * \return Error code.
161 */
162int dvr_wrapper_resume_record (DVR_WrapperRecord_t rec);
163
164/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800165 * Update the recording PIDs.
166 * \param rec The record handle.
167 * \param params The new PIDs.
168 * \retval DVR_SUCCESS On success.
169 * \return Error code.
170 */
171int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params);
172
173/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800174 * Get the current recording status.
175 * \param rec The record handle.
176 * \param status The recording status returned.
177 * \retval DVR_SUCCESS On success.
178 * \return Error code.
179 */
180int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status);
181
182/**
hualing chen4fe3bee2020-10-23 13:58:52 +0800183 * check record mode is secure or free.
184 * \param rec The record handle.
185 * \retval 1:secure 0: free mode.
186 * \return secure or free.
187 */
188int dvr_wrapper_record_is_secure_mode(DVR_WrapperRecord_t rec);
189
190/**
hualing chen266b9502020-04-04 17:39:39 +0800191 * Set record secure buffer.
192 * \param rec The record handle.
193 * \param p_secure_buf record p_secure_buf addr.
194 * \param len record p_secure_buf len.
195 * \retval DVR_SUCCESS On success.
196 * \return Error code.
197 */
198int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len);
199
200/**
201 * Set record decrypt callback.
202 * \param rec The record handle.
203 * \param func record dec cb.
204 * \param userdata cb user data.
205 * \retval DVR_SUCCESS On success.
206 * \return Error code.
207 */
208int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata);
209
210/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800211 * Open a new playback wrapper handle.
212 * \param[out] playback Return the new playback handle.
213 * \param params Playback handle open parameters.
214 * \retval DVR_SUCCESS On success.
215 * \return Error code.
216 */
217int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params);
218
219/**
220 * Close a unused playback handle.
221 * \param playback The playback handle to be closed.
222 * \retval DVR_SUCCESS On success.
223 * \return Error code.
224 */
225int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback);
226
227/**
228 * Start playback.
229 * \param playback The playback handle.
230 * \param flags Playback flags.
231 * \retval DVR_SUCCESS On success.
232 * \return Error code.
233 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800234int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800235
236/**
237 * Stop playback.
238 * \param playback The playback handle.
239 * \retval DVR_SUCCESS On success.
240 * \return Error code.
241 */
242int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback);
243
244/**
245 * Pause the playback.
246 * \param playback The playback handle.
247 * \retval DVR_SUCCESS On success.
248 * \return Error code.
249 */
250int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback);
251
252/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800253 * resume the playback.
254 * \param playback The playback handle.
255 * \retval DVR_SUCCESS On success.
256 * \return Error code.
257 */
258int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback);
259
260/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800261 * Set the playback speed.
262 * \param playback The playback handle.
263 * \param speed The new speed.
264 * \retval DVR_SUCCESS On success.
265 * \return Error code.
266 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800267int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800268
269/**
hualing chen03fd4942021-07-15 15:56:41 +0800270 * set the current playback limit info.
271 * \param playback The playback handle.
272 * \param time The rec time in milliseconds.
273 * \param limit The rec limit time in milliseconds.
274 * \retval DVR_SUCCESS On success.
275 * \return Error code.
276 */
277int dvr_wrapper_setlimit_playback (DVR_WrapperPlayback_t playback, uint64_t time, int32_t limit);
278
279/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800280 * Seek the current playback position.
281 * \param playback The playback handle.
282 * \param time_offset The current time in milliseconds.
283 * \retval DVR_SUCCESS On success.
284 * \return Error code.
285 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800286int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset);
287
288/**
289 * Get the current playback status.
290 * \param playback The playback handle.
291 * \param status The playback status returned.
292 * \retval DVR_SUCCESS On success.
293 * \return Error code.
294 */
295int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status);
296
297/**
298 * Update playback.
299 * \param playback The playback handle.
300 * \param flags Playback flags.
301 * \retval DVR_SUCCESS On success.
302 * \return Error code.
303 */
304int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
305
hualing chen266b9502020-04-04 17:39:39 +0800306/**
307 * Set playback secure buffer.
308 * \param playback The playback handle.
309 * \param p_secure_buf Playback p_secure_buf addr.
310 * \param len Playback p_secure_buf len.
311 * \retval DVR_SUCCESS On success.
312 * \return Error code.
313 */
314int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len);
315
316/**
317 * Set playback decrypt callback.
318 * \param playback The playback handle.
319 * \param func Playback dec cb.
320 * \param userdata cb user data.
321 * \retval DVR_SUCCESS On success.
322 * \return Error code.
323 */
324int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata);
325
326
Gong Ke80b8d2a2020-02-04 18:34:35 +0800327
328#ifdef __cplusplus
329}
330#endif
331
332#endif /*DVR_WRAPPER_H_*/
333