blob: 335dfbfa8f8fcc15f5d69548b44994cfbdaad6b7 [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 {
54 DVR_PlaybackPlayState_t state;
55 DVR_WrapperInfo_t info_cur;
56 DVR_WrapperInfo_t info_full;
57 DVR_PlaybackPids_t pids;
58 float speed;
59 DVR_PlaybackSegmentFlag_t flags;
60} DVR_WrapperPlaybackStatus_t;
61
62typedef struct {
63 DVR_RecordState_t state; /**< DVR record state*/
64 DVR_WrapperInfo_t info; /**< DVR record information*/
65 DVR_WrapperPidsInfo_t pids; /**< DVR record pids info*/
66} DVR_WrapperRecordStatus_t;
67
Gong Ke80b8d2a2020-02-04 18:34:35 +080068/**Record wrapper open parameters.*/
69typedef struct {
70 int dmx_dev_id; /**< Demux device's index.*/
71 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
72 DVR_Bool_t is_timeshift; /**< The record file is used by timeshift.*/
73 loff_t segment_size; /**< Segment file's size.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080074 loff_t max_size; /**< Maximum record file size in bytes.*/
Zhiqiang Hanade34ff2020-04-17 16:50:59 +080075 time_t max_time; /**< Maximum record time in milliseconds.*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080076 DVR_RecordFlag_t flags; /**< Flags.*/
77 DVR_CryptoPeriod_t crypto_period; /**< Crypto period.*/
78 DVR_CryptoFunction_t crypto_fn; /**< Crypto callback function.*/
79 void *crypto_data; /**< User data of crypto function.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080080 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/
81 void *event_userdata; /**< DVR event userdata*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080082} DVR_WrapperRecordOpenParams_t;
83
Gong Ke80b8d2a2020-02-04 18:34:35 +080084typedef struct {
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080085 DVR_WrapperPidsInfo_t pids_info;
Gong Ke80b8d2a2020-02-04 18:34:35 +080086} DVR_WrapperRecordStartParams_t;
87
Gong Ke80b8d2a2020-02-04 18:34:35 +080088typedef struct {
89 uint32_t nb_pids; /**< Number of PID actions.*/
90 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/
91 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/
92} DVR_WrapperUpdatePidsParams_t;
93
94/**Playback wrapper open parameters.*/
95typedef struct {
96 int dmx_dev_id; /**< playback used dmx device index*/
97 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
98 int block_size; /**< playback inject block size*/
99 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
100 Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/
101 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
102 void *crypto_data; /**< Crypto function's user data.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800103 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
104 void *event_userdata; /**< event userdata*/
Gong Ke80b8d2a2020-02-04 18:34:35 +0800105} DVR_WrapperPlaybackOpenParams_t;
106
107/**
108 * Open a new record wrapper.
109 * \param[out] rec Return the new record handle.
110 * \param params Record open parameters.
111 * \retval DVR_SUCCESS On success.
112 * \return Error code.
113 */
114int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params);
115
116/**
117 * Close an unused record wrapper.
118 * \param rec The record handle.
119 * \retval DVR_SUCCESS On success.
120 * \return Error code.
121 */
122int dvr_wrapper_close_record (DVR_WrapperRecord_t rec);
123
124/**
125 * Start recording.
126 * \param rec The record handle.
127 * \param params Record start parameters.
128 * \retval DVR_SUCCESS On success.
129 * \return Error code.
130 */
131int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params);
132
133/**
134 * Stop recording..
135 * \param rec The record handle.
136 * \retval DVR_SUCCESS On success.
137 * \return Error code.
138 */
139int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec);
140
141/**
142 * Update the recording PIDs.
143 * \param rec The record handle.
144 * \param params The new PIDs.
145 * \retval DVR_SUCCESS On success.
146 * \return Error code.
147 */
148int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params);
149
150/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800151 * Get the current recording status.
152 * \param rec The record handle.
153 * \param status The recording status returned.
154 * \retval DVR_SUCCESS On success.
155 * \return Error code.
156 */
157int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status);
158
159/**
hualing chen266b9502020-04-04 17:39:39 +0800160 * Set record secure buffer.
161 * \param rec The record handle.
162 * \param p_secure_buf record p_secure_buf addr.
163 * \param len record p_secure_buf len.
164 * \retval DVR_SUCCESS On success.
165 * \return Error code.
166 */
167int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len);
168
169/**
170 * Set record decrypt callback.
171 * \param rec The record handle.
172 * \param func record dec cb.
173 * \param userdata cb user data.
174 * \retval DVR_SUCCESS On success.
175 * \return Error code.
176 */
177int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata);
178
179/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800180 * Open a new playback wrapper handle.
181 * \param[out] playback Return the new playback handle.
182 * \param params Playback handle open parameters.
183 * \retval DVR_SUCCESS On success.
184 * \return Error code.
185 */
186int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params);
187
188/**
189 * Close a unused playback handle.
190 * \param playback The playback handle to be closed.
191 * \retval DVR_SUCCESS On success.
192 * \return Error code.
193 */
194int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback);
195
196/**
197 * Start playback.
198 * \param playback The playback handle.
199 * \param flags Playback flags.
200 * \retval DVR_SUCCESS On success.
201 * \return Error code.
202 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800203int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800204
205/**
206 * Stop playback.
207 * \param playback The playback handle.
208 * \retval DVR_SUCCESS On success.
209 * \return Error code.
210 */
211int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback);
212
213/**
214 * Pause the playback.
215 * \param playback The playback handle.
216 * \retval DVR_SUCCESS On success.
217 * \return Error code.
218 */
219int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback);
220
221/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800222 * resume the playback.
223 * \param playback The playback handle.
224 * \retval DVR_SUCCESS On success.
225 * \return Error code.
226 */
227int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback);
228
229/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800230 * Set the playback speed.
231 * \param playback The playback handle.
232 * \param speed The new speed.
233 * \retval DVR_SUCCESS On success.
234 * \return Error code.
235 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800236int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800237
238/**
239 * Seek the current playback position.
240 * \param playback The playback handle.
241 * \param time_offset The current time in milliseconds.
242 * \retval DVR_SUCCESS On success.
243 * \return Error code.
244 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800245int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset);
246
247/**
248 * Get the current playback status.
249 * \param playback The playback handle.
250 * \param status The playback status returned.
251 * \retval DVR_SUCCESS On success.
252 * \return Error code.
253 */
254int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status);
255
256/**
257 * Update playback.
258 * \param playback The playback handle.
259 * \param flags Playback flags.
260 * \retval DVR_SUCCESS On success.
261 * \return Error code.
262 */
263int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
264
hualing chen266b9502020-04-04 17:39:39 +0800265/**
266 * Set playback secure buffer.
267 * \param playback The playback handle.
268 * \param p_secure_buf Playback p_secure_buf addr.
269 * \param len Playback p_secure_buf len.
270 * \retval DVR_SUCCESS On success.
271 * \return Error code.
272 */
273int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len);
274
275/**
276 * Set playback decrypt callback.
277 * \param playback The playback handle.
278 * \param func Playback dec cb.
279 * \param userdata cb user data.
280 * \retval DVR_SUCCESS On success.
281 * \return Error code.
282 */
283int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata);
284
285
Gong Ke80b8d2a2020-02-04 18:34:35 +0800286
287#ifdef __cplusplus
288}
289#endif
290
291#endif /*DVR_WRAPPER_H_*/
292