blob: 626250ab23f23562ab90fd8a2ffa8415336f4456 [file] [log] [blame]
Gong Ke497c4c22020-03-20 10:15:42 +08001/**
Pengfei Liub4734232020-01-17 18:25:10 +08002 * \file
Gong Ke497c4c22020-03-20 10:15:42 +08003 * \brief Record module
Pengfei Liub4734232020-01-17 18:25:10 +08004 */
5
Pengfei Liuc181a982020-01-07 19:27:13 +08006#ifndef _DVR_RECORD_H_
7#define _DVR_RECORD_H_
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
Pengfei Liub038b6a2020-01-14 15:57:01 +080013#include "dvr_types.h"
Pengfei Liu47ed6c92020-01-17 11:23:41 +080014#include "dvr_crypto.h"
Pengfei Liuc181a982020-01-07 19:27:13 +080015
Pengfei Liub4734232020-01-17 18:25:10 +080016/**\brief DVR record handle*/
Gong Ke3489c0f2020-01-16 18:11:44 +080017typedef void* DVR_RecordHandle_t;
Pengfei Liuc181a982020-01-07 19:27:13 +080018
Pengfei Liub4734232020-01-17 18:25:10 +080019/**\brief DVR record state*/
Pengfei Liuc181a982020-01-07 19:27:13 +080020typedef enum {
Pengfei Liu47ed6c92020-01-17 11:23:41 +080021 DVR_RECORD_STATE_OPENED, /**< Record state is opened*/
22 DVR_RECORD_STATE_STARTED, /**< Record state is started*/
23 DVR_RECORD_STATE_STOPPED, /**< Record state is stopped*/
24 DVR_RECORD_STATE_CLOSED, /**< Record state is closed*/
hualing chen03fd4942021-07-15 15:56:41 +080025 DVR_RECORD_STATE_PAUSE, /**< Record state is pause*/
Pengfei Liu47ed6c92020-01-17 11:23:41 +080026} DVR_RecordState_t;
Pengfei Liuc181a982020-01-07 19:27:13 +080027
Pengfei Liub4734232020-01-17 18:25:10 +080028/**\brief DVR record pid action*/
Pengfei Liuc181a982020-01-07 19:27:13 +080029typedef enum
30{
Pengfei Liu47ed6c92020-01-17 11:23:41 +080031 DVR_RECORD_PID_CREATE, /**< Create a new pid used to record*/
32 DVR_RECORD_PID_KEEP, /**< Indicate this pid keep last state*/
33 DVR_RECORD_PID_CLOSE /**< Close this pid record*/
Pengfei Liuc181a982020-01-07 19:27:13 +080034} DVR_RecordPidAction_t;
35
Yahui Han1fbf3292021-11-08 18:17:19 +080036/**\brief DVR record flag*/
Pengfei Liuc181a982020-01-07 19:27:13 +080037typedef enum {
38 DVR_RECORD_FLAG_SCRAMBLED = (1 << 0),
39 DVR_RECORD_FLAG_ACCURATE = (1 << 1),
40} DVR_RecordFlag_t;
41
Pengfei Liub4734232020-01-17 18:25:10 +080042/**\brief DVR crypto parity flag*/
Pengfei Liuc181a982020-01-07 19:27:13 +080043typedef enum {
Pengfei Liu47ed6c92020-01-17 11:23:41 +080044 DVR_CRYPTO_PARITY_CLEAR, /**< Current period is clear*/
45 DVR_CRYPTO_PARITY_ODD, /**< Current period is ODD*/
46 DVR_CRYPTO_PARITY_EVEN, /**< Current period is EVEN*/
Pengfei Liuc181a982020-01-07 19:27:13 +080047} DVR_CryptoParity_t;
48
Pengfei Liub4734232020-01-17 18:25:10 +080049/**\brief DVR crypto filter type*/
Pengfei Liuc181a982020-01-07 19:27:13 +080050typedef enum {
Pengfei Liu47ed6c92020-01-17 11:23:41 +080051 DVR_CRYPTO_FILTER_TYPE_AUDIO, /**< Indicate current notification concerns audio packets*/
52 DVR_CRYPTO_FILTER_TYPE_VIDEO, /**< Indicate current notification concerns video packets*/
Pengfei Liuc181a982020-01-07 19:27:13 +080053} DVR_CryptoFilterType_t;
54
Pengfei Liub4734232020-01-17 18:25:10 +080055/**\brief DVR record event*/
56typedef enum {
57 DVR_RECORD_EVENT_ERROR = 0x1000, /**< Signal a critical DVR error*/
58 DVR_RECORD_EVENT_STATUS = 0x1001, /**< Signal the current record status which reach a certain size*/
59 DVR_RECORD_EVENT_SYNC_END = 0x1002, /**< Signal that data sync has ended*/
60 DVR_RECORD_EVENT_CRYPTO_STATUS = 0x2001, /**< Signal the current crypto status*/
hualing chen626204e2020-04-07 11:55:08 +080061 DVR_RECORD_EVENT_WRITE_ERROR = 0x9001, /**< Signal the current crypto status*/
Pengfei Liub4734232020-01-17 18:25:10 +080062} DVR_RecordEvent_t;
63
64/**\brief DVR crypto period information*/
Pengfei Liuc181a982020-01-07 19:27:13 +080065typedef struct
66{
Pengfei Liu47ed6c92020-01-17 11:23:41 +080067 DVR_Bool_t transition; /**< DVR_TRUE is transition, DVR_FALSE is not transition. At the start of a recording this shall be set to DVR_TRUE*/
68 DVR_CryptoParity_t parity; /**< The crypto parity at the ts_offset*/
Wentao MAe8ba5172022-08-09 11:18:17 +080069 loff_t ts_offset; /**< TS packet offset corresponding to this crypto period*/
Pengfei Liu47ed6c92020-01-17 11:23:41 +080070 DVR_CryptoFilterType_t filter_type; /**< Indicate this notification concerns audio or video*/
Pengfei Liuc181a982020-01-07 19:27:13 +080071} DVR_CryptoPeriodInfo_t;
72
Pengfei Liub4734232020-01-17 18:25:10 +080073/**\brief DVR crypto period information*/
Pengfei Liuc181a982020-01-07 19:27:13 +080074typedef struct {
Wentao MAe8ba5172022-08-09 11:18:17 +080075 uint64_t interval_bytes; /**< The interval between two regular notification of crypto period. For example, if the current segment is always ODD for a long time, record module would notify the current crypto period status when segment size reached the interval_bytes*/
76 DVR_Bool_t notify_clear_periods; /**< Indicate whether it shall track the transition to clear period. DVR_TRUE means it shall not notify clear periods, but only transition between ODD and EVEN. DVR_FALSE means it shall notify transition between ODD, EVEN and clear periods*/
Pengfei Liub4734232020-01-17 18:25:10 +080077} DVR_CryptoPeriod_t;
Pengfei Liuc181a982020-01-07 19:27:13 +080078
Pengfei Liub4734232020-01-17 18:25:10 +080079/**\brief DVR record event notify function*/
80typedef DVR_Result_t (*DVR_RecordEventFunction_t) (DVR_RecordEvent_t event, void *params, void *userdata);
81
82/**\brief DVR record open parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +080083typedef struct {
Yahui Hance15e9c2020-12-08 18:08:32 +080084 int fend_dev_id; /**< Frontend device id */
Pengfei Liub4734232020-01-17 18:25:10 +080085 int dmx_dev_id; /**< Demux device id*/
pengfei.liuab5a2262020-02-14 17:33:40 +080086 int data_from_memory; /**< Indicate record data from demux or memory*/
Pengfei Liub4734232020-01-17 18:25:10 +080087 DVR_RecordFlag_t flags; /**< DVR record flag*/
pengfei.liu07ddc8a2020-03-24 23:36:53 +080088 int flush_size; /**< DVR record interrupt flush size*/
Pengfei Liub4734232020-01-17 18:25:10 +080089 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/
90 void *event_userdata; /**< DVR event userdata*/
Wentao MAe8ba5172022-08-09 11:18:17 +080091 size_t notification_size; /**< DVR record notification size, record module would send a notification when the size of current segment is multiple of this value. Put 0 in this argument if you don't want to receive the notification*/
Yahui Han1fbf3292021-11-08 18:17:19 +080092 uint8_t *clearkey; /**< key for encrypted PVR on FTA.*/
Wentao MAe8ba5172022-08-09 11:18:17 +080093 uint8_t *cleariv; /**< iv for encrypted PVR on FTA.*/
Yahui Han1fbf3292021-11-08 18:17:19 +080094 uint32_t keylen; /**< key/iv length.*/
hualing chen03fd4942021-07-15 15:56:41 +080095 int ringbuf_size; /**< DVR record ring buf size*/
Wentao MAe8ba5172022-08-09 11:18:17 +080096 int notification_time; /**< DVR record notification time, record module would send a notification when the size of current segment is multiple of this value. Put 0 in this argument if you don't want to receive the notification*/
wentao.ma35a69d42022-03-10 18:08:40 +080097 DVR_Bool_t force_sysclock; /**< If ture, force to use system clock as PVR index time source. If false, libdvr can determine index time source based on actual situation*/
Wentao MAeeffdb02022-06-27 16:34:35 +080098 loff_t guarded_segment_size; /**< Guarded segment size in bytes. Libdvr will be forcely stopped to write anymore if current segment reaches this size*/
Pengfei Liuc181a982020-01-07 19:27:13 +080099} DVR_RecordOpenParams_t;
100
Pengfei Liub4734232020-01-17 18:25:10 +0800101/**\brief DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800102typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +0800103 uint64_t segment_id; /**< Segment id*/
104 uint32_t nb_pids; /**< Number of pids*/
105 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids information*/
106 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids action*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800107} DVR_RecordSegmentStartParams_t;
108
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800109/**\brief DVR record encrypt function*/
110typedef DVR_Result_t (*DVR_RecordEncryptFunction_t) (uint8_t *p_in,
111 uint32_t in_len,
112 uint8_t *p_out,
113 uint32_t *p_out_len,
114 void *userdata);
115
Pengfei Liub4734232020-01-17 18:25:10 +0800116/**\brief DVR record current status*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800117typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +0800118 DVR_RecordState_t state; /**< DVR record state*/
119 DVR_RecordSegmentInfo_t info; /**< DVR record segment information*/
120} DVR_RecordStatus_t;
121
122/**\brief DVR record start parameters*/
123typedef struct {
124 char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/
125 DVR_RecordSegmentStartParams_t segment; /**< DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800126} DVR_RecordStartParams_t;
127
Pengfei Liuc181a982020-01-07 19:27:13 +0800128/**\brief Open a recording session for a target giving some open parameters
Gong Ke497c4c22020-03-20 10:15:42 +0800129 * \param[out] p_handle Return the handle of the newly created dvr session
130 * \param[in] params Open parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800131 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800132 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800133 */
134int dvr_record_open(DVR_RecordHandle_t *p_handle, DVR_RecordOpenParams_t *params);
135
136/**\brief Close a recording session
Gong Ke497c4c22020-03-20 10:15:42 +0800137 * \param[in] handle DVR recording session handle
Pengfei Liuc181a982020-01-07 19:27:13 +0800138 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800139 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800140 */
141int dvr_record_close(DVR_RecordHandle_t handle);
142
hualing chen03fd4942021-07-15 15:56:41 +0800143/**\brief pause recording on a segment
144 * \param[in] handle DVR recording session handle
145 * \return DVR_SUCCESS on success
146 * \return error code on failure
147 */
148int dvr_record_pause(DVR_RecordHandle_t handle);
149
150/**\brief resume recording on a segment
151 * \param[in] handle DVR recording session handle
152 * \return DVR_SUCCESS on success
153 * \return error code on failure
154 */
155int dvr_record_resume(DVR_RecordHandle_t handle);
156
Pengfei Liuc181a982020-01-07 19:27:13 +0800157/**\brief Start recording on a segment
Gong Ke497c4c22020-03-20 10:15:42 +0800158 * \param[in] handle DVR recording session handle
159 * \param[in] params DVR start parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800160 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800161 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800162 */
163int dvr_record_start_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params);
164
165/**\brief Stop the ongoing segment and start recording a new segment
Gong Ke497c4c22020-03-20 10:15:42 +0800166 * \param[in] handle DVR recording session handle
167 * \param[in] params DVR start parameters
168 * \param[out] p_info DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800169 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800170 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800171 */
172int dvr_record_next_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, DVR_RecordSegmentInfo_t *p_info);
173
174/**\brief Stop the ongoing segment
Gong Ke497c4c22020-03-20 10:15:42 +0800175 * \param[in] handle DVR recording session handle
176 * \param[out] p_info DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800177 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800178 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800179 */
180int dvr_record_stop_segment(DVR_RecordHandle_t handle, DVR_RecordSegmentInfo_t *p_info);
181
Pengfei Liub4734232020-01-17 18:25:10 +0800182/**\brief Resume the recording on a segment
Gong Ke497c4c22020-03-20 10:15:42 +0800183 * \param[in] handle DVR recording session handle
184 * \param[in] params DVR start parameters
185 * \param[inout] p_resume_size HAL propose a resume size as a input parameter and output is the real resume size
Pengfei Liub4734232020-01-17 18:25:10 +0800186 * \return DVR_SUCCESS on success
187 * \return error code on failure
188 */
189int dvr_record_resume_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, uint64_t *p_resume_size);
190
pengfei.liuab5a2262020-02-14 17:33:40 +0800191/**\brief DVR record write data, used for VOD mode
Gong Ke497c4c22020-03-20 10:15:42 +0800192 * \param[in] handle DVR recording session handle
Wentao MAe8ba5172022-08-09 11:18:17 +0800193 * \param[in] buffer The record data buffer
Gong Ke497c4c22020-03-20 10:15:42 +0800194 * \param[in] len The record data length
pengfei.liuab5a2262020-02-14 17:33:40 +0800195 * \return DVR_SUCCESS on success
196 * \return error code on failure
197 */
198int dvr_record_write(DVR_RecordHandle_t handle, void *buffer, uint32_t len);
199
200/**\brief DVR record get status
Gong Ke497c4c22020-03-20 10:15:42 +0800201 * \param[in] handle DVR recording session handle
202 * \param[out] p_status Return current DVR record status
pengfei.liuab5a2262020-02-14 17:33:40 +0800203 * \return DVR_SUCCESS on success
204 * \return error code on failure
205 */
206int dvr_record_get_status(DVR_RecordHandle_t handle, DVR_RecordStatus_t *p_status);
207
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800208/**\brief Set DVR record encrypt function
209 * \param[in] handle, DVR recording session handle
210 * \param[in] func, DVR recording encrypt function
211 * \param[in] userdata, DVR record userdata from the caller
212 * \return DVR_SUCCESS on success
213 * \return error code on failure
214 */
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800215int dvr_record_set_encrypt_callback(DVR_RecordHandle_t handle, DVR_CryptoFunction_t func, void *userdata);
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800216
217/**\brief Set DVR record secure buffer used for protect the secure content
218 * \param[in] handle, DVR recording session handle
219 * \param[in] p_secure_buf, Secure buffer address which can NOT access by ACPU
220 * \param[in] len, Secure buffer length
221 * \return DVR_SUCCESS on success
222 * \return error code on failure
223 */
224int dvr_record_set_secure_buffer(DVR_RecordHandle_t handle, uint8_t *p_secure_buf, uint32_t len);
225
hualing chen4fe3bee2020-10-23 13:58:52 +0800226/**
227 * check record mode is secure or free.
228 * \param handle The record session handle.
229 * \retval 1:secure 0: free mode.
230 * \return secure or free.
231 */
232int dvr_record_is_secure_mode(DVR_RecordHandle_t handle);
Wentao MAf4072032022-06-30 13:50:45 +0800233
234/**\brief Turn on/off recording data discarding
235 * \param[in] handle, DVR recording session handle
236 * \param[in] discard, 0: normal processing, 1: discard coming recording data
237 * \return DVR_SUCCESS on success
238 * \return error code on failure
239 */
240int dvr_record_discard_coming_data(DVR_RecordHandle_t handle, DVR_Bool_t discard);
241
Pengfei Liuc181a982020-01-07 19:27:13 +0800242#ifdef __cplusplus
243}
244#endif
245
246#endif /*END _DVR_RECORD_H_*/