blob: f9469c8034b3e5736a1ac2891ec61e0b2d25a070 [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 {
72 int dmx_dev_id; /**< Demux device's index.*/
73 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
74 DVR_Bool_t is_timeshift; /**< The record file is used by timeshift.*/
75 loff_t segment_size; /**< Segment file's size.*/
Zhiqiang Hanaeb0c712020-04-30 15:17:26 +080076 loff_t max_size; /**< Maximum record file size in bytes(for timeshift).*/
77 time_t max_time; /**< Maximum record time in milliseconds(for timeshift).*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080078 DVR_RecordFlag_t flags; /**< Flags.*/
79 DVR_CryptoPeriod_t crypto_period; /**< Crypto period.*/
80 DVR_CryptoFunction_t crypto_fn; /**< Crypto callback function.*/
81 void *crypto_data; /**< User data of crypto function.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080082 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/
83 void *event_userdata; /**< DVR event userdata*/
Zhiqiang Han31505452020-05-06 15:08:10 +080084 int flush_size; /**< DVR flush size*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080085} DVR_WrapperRecordOpenParams_t;
86
Gong Ke80b8d2a2020-02-04 18:34:35 +080087typedef struct {
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080088 DVR_WrapperPidsInfo_t pids_info;
Gong Ke80b8d2a2020-02-04 18:34:35 +080089} DVR_WrapperRecordStartParams_t;
90
Gong Ke80b8d2a2020-02-04 18:34:35 +080091typedef struct {
92 uint32_t nb_pids; /**< Number of PID actions.*/
93 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/
94 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/
95} DVR_WrapperUpdatePidsParams_t;
96
97/**Playback wrapper open parameters.*/
98typedef struct {
99 int dmx_dev_id; /**< playback used dmx device index*/
100 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
101 int block_size; /**< playback inject block size*/
102 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
103 Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/
104 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
105 void *crypto_data; /**< Crypto function's user data.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800106 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
107 void *event_userdata; /**< event userdata*/
Gong Ke80b8d2a2020-02-04 18:34:35 +0800108} DVR_WrapperPlaybackOpenParams_t;
109
110/**
111 * Open a new record wrapper.
112 * \param[out] rec Return the new record handle.
113 * \param params Record open parameters.
114 * \retval DVR_SUCCESS On success.
115 * \return Error code.
116 */
117int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params);
118
119/**
120 * Close an unused record wrapper.
121 * \param rec The record handle.
122 * \retval DVR_SUCCESS On success.
123 * \return Error code.
124 */
125int dvr_wrapper_close_record (DVR_WrapperRecord_t rec);
126
127/**
128 * Start recording.
129 * \param rec The record handle.
130 * \param params Record start parameters.
131 * \retval DVR_SUCCESS On success.
132 * \return Error code.
133 */
134int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params);
135
136/**
137 * Stop recording..
138 * \param rec The record handle.
139 * \retval DVR_SUCCESS On success.
140 * \return Error code.
141 */
142int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec);
143
144/**
145 * Update the recording PIDs.
146 * \param rec The record handle.
147 * \param params The new PIDs.
148 * \retval DVR_SUCCESS On success.
149 * \return Error code.
150 */
151int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params);
152
153/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800154 * Get the current recording status.
155 * \param rec The record handle.
156 * \param status The recording status returned.
157 * \retval DVR_SUCCESS On success.
158 * \return Error code.
159 */
160int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status);
161
162/**
hualing chen4fe3bee2020-10-23 13:58:52 +0800163 * check record mode is secure or free.
164 * \param rec The record handle.
165 * \retval 1:secure 0: free mode.
166 * \return secure or free.
167 */
168int dvr_wrapper_record_is_secure_mode(DVR_WrapperRecord_t rec);
169
170/**
hualing chen266b9502020-04-04 17:39:39 +0800171 * Set record secure buffer.
172 * \param rec The record handle.
173 * \param p_secure_buf record p_secure_buf addr.
174 * \param len record p_secure_buf len.
175 * \retval DVR_SUCCESS On success.
176 * \return Error code.
177 */
178int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len);
179
180/**
181 * Set record decrypt callback.
182 * \param rec The record handle.
183 * \param func record dec cb.
184 * \param userdata cb user data.
185 * \retval DVR_SUCCESS On success.
186 * \return Error code.
187 */
188int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata);
189
190/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800191 * Open a new playback wrapper handle.
192 * \param[out] playback Return the new playback handle.
193 * \param params Playback handle open parameters.
194 * \retval DVR_SUCCESS On success.
195 * \return Error code.
196 */
197int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params);
198
199/**
200 * Close a unused playback handle.
201 * \param playback The playback handle to be closed.
202 * \retval DVR_SUCCESS On success.
203 * \return Error code.
204 */
205int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback);
206
207/**
208 * Start playback.
209 * \param playback The playback handle.
210 * \param flags Playback flags.
211 * \retval DVR_SUCCESS On success.
212 * \return Error code.
213 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800214int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800215
216/**
217 * Stop playback.
218 * \param playback The playback handle.
219 * \retval DVR_SUCCESS On success.
220 * \return Error code.
221 */
222int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback);
223
224/**
225 * Pause the playback.
226 * \param playback The playback handle.
227 * \retval DVR_SUCCESS On success.
228 * \return Error code.
229 */
230int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback);
231
232/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800233 * resume the playback.
234 * \param playback The playback handle.
235 * \retval DVR_SUCCESS On success.
236 * \return Error code.
237 */
238int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback);
239
240/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800241 * Set the playback speed.
242 * \param playback The playback handle.
243 * \param speed The new speed.
244 * \retval DVR_SUCCESS On success.
245 * \return Error code.
246 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800247int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800248
249/**
250 * Seek the current playback position.
251 * \param playback The playback handle.
252 * \param time_offset The current time in milliseconds.
253 * \retval DVR_SUCCESS On success.
254 * \return Error code.
255 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800256int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset);
257
258/**
259 * Get the current playback status.
260 * \param playback The playback handle.
261 * \param status The playback status returned.
262 * \retval DVR_SUCCESS On success.
263 * \return Error code.
264 */
265int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status);
266
267/**
268 * Update playback.
269 * \param playback The playback handle.
270 * \param flags Playback flags.
271 * \retval DVR_SUCCESS On success.
272 * \return Error code.
273 */
274int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
275
hualing chen266b9502020-04-04 17:39:39 +0800276/**
277 * Set playback secure buffer.
278 * \param playback The playback handle.
279 * \param p_secure_buf Playback p_secure_buf addr.
280 * \param len Playback p_secure_buf len.
281 * \retval DVR_SUCCESS On success.
282 * \return Error code.
283 */
284int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len);
285
286/**
287 * Set playback decrypt callback.
288 * \param playback The playback handle.
289 * \param func Playback dec cb.
290 * \param userdata cb user data.
291 * \retval DVR_SUCCESS On success.
292 * \return Error code.
293 */
294int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata);
295
296
Gong Ke80b8d2a2020-02-04 18:34:35 +0800297
298#ifdef __cplusplus
299}
300#endif
301
302#endif /*DVR_WRAPPER_H_*/
303