blob: 470026be2e8287c49baff2d136da9019c560decf [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*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080086} DVR_WrapperRecordOpenParams_t;
87
Gong Ke80b8d2a2020-02-04 18:34:35 +080088typedef struct {
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080089 DVR_WrapperPidsInfo_t pids_info;
Gong Ke80b8d2a2020-02-04 18:34:35 +080090} DVR_WrapperRecordStartParams_t;
91
Gong Ke80b8d2a2020-02-04 18:34:35 +080092typedef struct {
93 uint32_t nb_pids; /**< Number of PID actions.*/
94 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/
95 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/
96} DVR_WrapperUpdatePidsParams_t;
97
98/**Playback wrapper open parameters.*/
99typedef struct {
100 int dmx_dev_id; /**< playback used dmx device index*/
101 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
102 int block_size; /**< playback inject block size*/
103 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
104 Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/
105 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
106 void *crypto_data; /**< Crypto function's user data.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800107 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
108 void *event_userdata; /**< event userdata*/
Gong Ke80b8d2a2020-02-04 18:34:35 +0800109} DVR_WrapperPlaybackOpenParams_t;
110
111/**
112 * Open a new record wrapper.
113 * \param[out] rec Return the new record handle.
114 * \param params Record open parameters.
115 * \retval DVR_SUCCESS On success.
116 * \return Error code.
117 */
118int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params);
119
120/**
121 * Close an unused record wrapper.
122 * \param rec The record handle.
123 * \retval DVR_SUCCESS On success.
124 * \return Error code.
125 */
126int dvr_wrapper_close_record (DVR_WrapperRecord_t rec);
127
128/**
129 * Start recording.
130 * \param rec The record handle.
131 * \param params Record start parameters.
132 * \retval DVR_SUCCESS On success.
133 * \return Error code.
134 */
135int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params);
136
137/**
138 * Stop recording..
139 * \param rec The record handle.
140 * \retval DVR_SUCCESS On success.
141 * \return Error code.
142 */
143int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec);
144
145/**
146 * Update the recording PIDs.
147 * \param rec The record handle.
148 * \param params The new PIDs.
149 * \retval DVR_SUCCESS On success.
150 * \return Error code.
151 */
152int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params);
153
154/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800155 * Get the current recording status.
156 * \param rec The record handle.
157 * \param status The recording status returned.
158 * \retval DVR_SUCCESS On success.
159 * \return Error code.
160 */
161int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status);
162
163/**
hualing chen4fe3bee2020-10-23 13:58:52 +0800164 * check record mode is secure or free.
165 * \param rec The record handle.
166 * \retval 1:secure 0: free mode.
167 * \return secure or free.
168 */
169int dvr_wrapper_record_is_secure_mode(DVR_WrapperRecord_t rec);
170
171/**
hualing chen266b9502020-04-04 17:39:39 +0800172 * Set record secure buffer.
173 * \param rec The record handle.
174 * \param p_secure_buf record p_secure_buf addr.
175 * \param len record p_secure_buf len.
176 * \retval DVR_SUCCESS On success.
177 * \return Error code.
178 */
179int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len);
180
181/**
182 * Set record decrypt callback.
183 * \param rec The record handle.
184 * \param func record dec cb.
185 * \param userdata cb user data.
186 * \retval DVR_SUCCESS On success.
187 * \return Error code.
188 */
189int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata);
190
191/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800192 * Open a new playback wrapper handle.
193 * \param[out] playback Return the new playback handle.
194 * \param params Playback handle open parameters.
195 * \retval DVR_SUCCESS On success.
196 * \return Error code.
197 */
198int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params);
199
200/**
201 * Close a unused playback handle.
202 * \param playback The playback handle to be closed.
203 * \retval DVR_SUCCESS On success.
204 * \return Error code.
205 */
206int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback);
207
208/**
209 * Start playback.
210 * \param playback The playback handle.
211 * \param flags Playback flags.
212 * \retval DVR_SUCCESS On success.
213 * \return Error code.
214 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800215int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800216
217/**
218 * Stop playback.
219 * \param playback The playback handle.
220 * \retval DVR_SUCCESS On success.
221 * \return Error code.
222 */
223int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback);
224
225/**
226 * Pause the playback.
227 * \param playback The playback handle.
228 * \retval DVR_SUCCESS On success.
229 * \return Error code.
230 */
231int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback);
232
233/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800234 * resume the playback.
235 * \param playback The playback handle.
236 * \retval DVR_SUCCESS On success.
237 * \return Error code.
238 */
239int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback);
240
241/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800242 * Set the playback speed.
243 * \param playback The playback handle.
244 * \param speed The new speed.
245 * \retval DVR_SUCCESS On success.
246 * \return Error code.
247 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800248int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800249
250/**
251 * Seek the current playback position.
252 * \param playback The playback handle.
253 * \param time_offset The current time in milliseconds.
254 * \retval DVR_SUCCESS On success.
255 * \return Error code.
256 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800257int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset);
258
259/**
260 * Get the current playback status.
261 * \param playback The playback handle.
262 * \param status The playback status returned.
263 * \retval DVR_SUCCESS On success.
264 * \return Error code.
265 */
266int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status);
267
268/**
269 * Update playback.
270 * \param playback The playback handle.
271 * \param flags Playback flags.
272 * \retval DVR_SUCCESS On success.
273 * \return Error code.
274 */
275int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
276
hualing chen266b9502020-04-04 17:39:39 +0800277/**
278 * Set playback secure buffer.
279 * \param playback The playback handle.
280 * \param p_secure_buf Playback p_secure_buf addr.
281 * \param len Playback p_secure_buf len.
282 * \retval DVR_SUCCESS On success.
283 * \return Error code.
284 */
285int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len);
286
287/**
288 * Set playback decrypt callback.
289 * \param playback The playback handle.
290 * \param func Playback dec cb.
291 * \param userdata cb user data.
292 * \retval DVR_SUCCESS On success.
293 * \return Error code.
294 */
295int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata);
296
297
Gong Ke80b8d2a2020-02-04 18:34:35 +0800298
299#ifdef __cplusplus
300}
301#endif
302
303#endif /*DVR_WRAPPER_H_*/
304