blob: 524f38e43b73ad74448608149f7e7a291f0a1a53 [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
12 * \endsection
13 *
Gong Ke80b8d2a2020-02-04 18:34:35 +080014 * \file
Gong Ke497c4c22020-03-20 10:15:42 +080015 * \brief libdvr wrapper layer
16 *
17 * Wrapper layer is upper layer of libdvr.
18 * It is on top of dvr_record and dvr_playback.
19 * It supports:
20 * \li Separate record segments automatically.
21 * \li Load segments automatically.
Gong Ke80b8d2a2020-02-04 18:34:35 +080022 */
23
24#ifndef DVR_WRAPPER_H_
25#define DVR_WRAPPER_H_
26
27#include "dvr_types.h"
28#include "dvr_crypto.h"
29#include "dvr_playback.h"
30#include "dvr_record.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/**Record wrapper handle.*/
37typedef void* DVR_WrapperRecord_t;
38/**Playback wrapper handle.*/
39typedef void* DVR_WrapperPlayback_t;
40
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080041typedef void* Playback_DeviceHandle_t;
42
43typedef struct {
44 time_t time; /**< time duration, unit on ms*/
45 loff_t size; /**< size*/
46 uint32_t pkts; /**< number of ts packets*/
47} DVR_WrapperInfo_t;
48
49typedef struct {
50 uint32_t nb_pids; /**< Number of PIDs.*/
51 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs to be recorded.*/
52} DVR_WrapperPidsInfo_t;
53
54typedef struct {
55 DVR_PlaybackPlayState_t state;
56 DVR_WrapperInfo_t info_cur;
57 DVR_WrapperInfo_t info_full;
58 DVR_PlaybackPids_t pids;
59 float speed;
60 DVR_PlaybackSegmentFlag_t flags;
61} 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*/
67} DVR_WrapperRecordStatus_t;
68
Gong Ke80b8d2a2020-02-04 18:34:35 +080069/**Record wrapper open parameters.*/
70typedef struct {
71 int dmx_dev_id; /**< Demux device's index.*/
72 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
73 DVR_Bool_t is_timeshift; /**< The record file is used by timeshift.*/
74 loff_t segment_size; /**< Segment file's size.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080075 loff_t max_size; /**< Maximum record file size in bytes.*/
76 time_t max_time; /**< Maximum record time in seconds.*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080077 DVR_RecordFlag_t flags; /**< Flags.*/
78 DVR_CryptoPeriod_t crypto_period; /**< Crypto period.*/
79 DVR_CryptoFunction_t crypto_fn; /**< Crypto callback function.*/
80 void *crypto_data; /**< User data of crypto function.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080081 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/
82 void *event_userdata; /**< DVR event userdata*/
Gong Ke80b8d2a2020-02-04 18:34:35 +080083} DVR_WrapperRecordOpenParams_t;
84
Gong Ke80b8d2a2020-02-04 18:34:35 +080085typedef struct {
Zhiqiang Han2d8cd822020-03-16 13:58:10 +080086 DVR_WrapperPidsInfo_t pids_info;
Gong Ke80b8d2a2020-02-04 18:34:35 +080087} DVR_WrapperRecordStartParams_t;
88
Gong Ke80b8d2a2020-02-04 18:34:35 +080089typedef struct {
90 uint32_t nb_pids; /**< Number of PID actions.*/
91 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< PIDs.*/
92 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Actions.*/
93} DVR_WrapperUpdatePidsParams_t;
94
95/**Playback wrapper open parameters.*/
96typedef struct {
97 int dmx_dev_id; /**< playback used dmx device index*/
98 char location[DVR_MAX_LOCATION_SIZE]; /**< Location of the record file.*/
99 int block_size; /**< playback inject block size*/
100 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
101 Playback_DeviceHandle_t playback_handle; /**< Playback device handle.*/
102 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
103 void *crypto_data; /**< Crypto function's user data.*/
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800104 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
105 void *event_userdata; /**< event userdata*/
Gong Ke80b8d2a2020-02-04 18:34:35 +0800106} DVR_WrapperPlaybackOpenParams_t;
107
108/**
109 * Open a new record wrapper.
110 * \param[out] rec Return the new record handle.
111 * \param params Record open parameters.
112 * \retval DVR_SUCCESS On success.
113 * \return Error code.
114 */
115int dvr_wrapper_open_record (DVR_WrapperRecord_t *rec, DVR_WrapperRecordOpenParams_t *params);
116
117/**
118 * Close an unused record wrapper.
119 * \param rec The record handle.
120 * \retval DVR_SUCCESS On success.
121 * \return Error code.
122 */
123int dvr_wrapper_close_record (DVR_WrapperRecord_t rec);
124
125/**
126 * Start recording.
127 * \param rec The record handle.
128 * \param params Record start parameters.
129 * \retval DVR_SUCCESS On success.
130 * \return Error code.
131 */
132int dvr_wrapper_start_record (DVR_WrapperRecord_t rec, DVR_WrapperRecordStartParams_t *params);
133
134/**
135 * Stop recording..
136 * \param rec The record handle.
137 * \retval DVR_SUCCESS On success.
138 * \return Error code.
139 */
140int dvr_wrapper_stop_record (DVR_WrapperRecord_t rec);
141
142/**
143 * Update the recording PIDs.
144 * \param rec The record handle.
145 * \param params The new PIDs.
146 * \retval DVR_SUCCESS On success.
147 * \return Error code.
148 */
149int dvr_wrapper_update_record_pids (DVR_WrapperRecord_t rec, DVR_WrapperUpdatePidsParams_t *params);
150
151/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800152 * Get the current recording status.
153 * \param rec The record handle.
154 * \param status The recording status returned.
155 * \retval DVR_SUCCESS On success.
156 * \return Error code.
157 */
158int dvr_wrapper_get_record_status (DVR_WrapperRecord_t rec, DVR_WrapperRecordStatus_t *status);
159
160/**
hualing chen266b9502020-04-04 17:39:39 +0800161 * Set record secure buffer.
162 * \param rec The record handle.
163 * \param p_secure_buf record p_secure_buf addr.
164 * \param len record p_secure_buf len.
165 * \retval DVR_SUCCESS On success.
166 * \return Error code.
167 */
168int dvr_wrapper_set_record_secure_buffer (DVR_WrapperRecord_t rec, uint8_t *p_secure_buf, uint32_t len);
169
170/**
171 * Set record decrypt callback.
172 * \param rec The record handle.
173 * \param func record dec cb.
174 * \param userdata cb user data.
175 * \retval DVR_SUCCESS On success.
176 * \return Error code.
177 */
178int dvr_wrapper_set_record_decrypt_callback (DVR_WrapperRecord_t rec, DVR_CryptoFunction_t func, void *userdata);
179
180/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800181 * Open a new playback wrapper handle.
182 * \param[out] playback Return the new playback handle.
183 * \param params Playback handle open parameters.
184 * \retval DVR_SUCCESS On success.
185 * \return Error code.
186 */
187int dvr_wrapper_open_playback (DVR_WrapperPlayback_t *playback, DVR_WrapperPlaybackOpenParams_t *params);
188
189/**
190 * Close a unused playback handle.
191 * \param playback The playback handle to be closed.
192 * \retval DVR_SUCCESS On success.
193 * \return Error code.
194 */
195int dvr_wrapper_close_playback (DVR_WrapperPlayback_t playback);
196
197/**
198 * Start playback.
199 * \param playback The playback handle.
200 * \param flags Playback flags.
201 * \retval DVR_SUCCESS On success.
202 * \return Error code.
203 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800204int dvr_wrapper_start_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackFlag_t flags, DVR_PlaybackPids_t *p_pids);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800205
206/**
207 * Stop playback.
208 * \param playback The playback handle.
209 * \retval DVR_SUCCESS On success.
210 * \return Error code.
211 */
212int dvr_wrapper_stop_playback (DVR_WrapperPlayback_t playback);
213
214/**
215 * Pause the playback.
216 * \param playback The playback handle.
217 * \retval DVR_SUCCESS On success.
218 * \return Error code.
219 */
220int dvr_wrapper_pause_playback (DVR_WrapperPlayback_t playback);
221
222/**
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800223 * resume the playback.
224 * \param playback The playback handle.
225 * \retval DVR_SUCCESS On success.
226 * \return Error code.
227 */
228int dvr_wrapper_resume_playback (DVR_WrapperPlayback_t playback);
229
230/**
Gong Ke80b8d2a2020-02-04 18:34:35 +0800231 * Set the playback speed.
232 * \param playback The playback handle.
233 * \param speed The new speed.
234 * \retval DVR_SUCCESS On success.
235 * \return Error code.
236 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800237int dvr_wrapper_set_playback_speed (DVR_WrapperPlayback_t playback, float speed);
Gong Ke80b8d2a2020-02-04 18:34:35 +0800238
239/**
240 * Seek the current playback position.
241 * \param playback The playback handle.
242 * \param time_offset The current time in milliseconds.
243 * \retval DVR_SUCCESS On success.
244 * \return Error code.
245 */
Zhiqiang Han2d8cd822020-03-16 13:58:10 +0800246int dvr_wrapper_seek_playback (DVR_WrapperPlayback_t playback, uint32_t time_offset);
247
248/**
249 * Get the current playback status.
250 * \param playback The playback handle.
251 * \param status The playback status returned.
252 * \retval DVR_SUCCESS On success.
253 * \return Error code.
254 */
255int dvr_wrapper_get_playback_status (DVR_WrapperPlayback_t playback, DVR_WrapperPlaybackStatus_t *status);
256
257/**
258 * Update playback.
259 * \param playback The playback handle.
260 * \param flags Playback flags.
261 * \retval DVR_SUCCESS On success.
262 * \return Error code.
263 */
264int dvr_wrapper_update_playback (DVR_WrapperPlayback_t playback, DVR_PlaybackPids_t *p_pids);
265
hualing chen266b9502020-04-04 17:39:39 +0800266/**
267 * Set playback secure buffer.
268 * \param playback The playback handle.
269 * \param p_secure_buf Playback p_secure_buf addr.
270 * \param len Playback p_secure_buf len.
271 * \retval DVR_SUCCESS On success.
272 * \return Error code.
273 */
274int dvr_wrapper_set_secure_buffer (DVR_WrapperPlayback_t playback, uint8_t *p_secure_buf, uint32_t len);
275
276/**
277 * Set playback decrypt callback.
278 * \param playback The playback handle.
279 * \param func Playback dec cb.
280 * \param userdata cb user data.
281 * \retval DVR_SUCCESS On success.
282 * \return Error code.
283 */
284int dvr_wrapper_set_decrypt_callback (DVR_WrapperPlayback_t playback, DVR_CryptoFunction_t func, void *userdata);
285
286
Gong Ke80b8d2a2020-02-04 18:34:35 +0800287
288#ifdef __cplusplus
289}
290#endif
291
292#endif /*DVR_WRAPPER_H_*/
293