blob: f045fbabc80da7815ef58f2d44e7157bdf62e7eb [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),
Zhiqiang Han2f019af2023-08-31 11:12:02 +080040 DVR_RECORD_FLAG_DATAOUT = (1 << 2),
Pengfei Liuc181a982020-01-07 19:27:13 +080041} DVR_RecordFlag_t;
42
Pengfei Liub4734232020-01-17 18:25:10 +080043/**\brief DVR crypto parity flag*/
Pengfei Liuc181a982020-01-07 19:27:13 +080044typedef enum {
Pengfei Liu47ed6c92020-01-17 11:23:41 +080045 DVR_CRYPTO_PARITY_CLEAR, /**< Current period is clear*/
46 DVR_CRYPTO_PARITY_ODD, /**< Current period is ODD*/
47 DVR_CRYPTO_PARITY_EVEN, /**< Current period is EVEN*/
Pengfei Liuc181a982020-01-07 19:27:13 +080048} DVR_CryptoParity_t;
49
Pengfei Liub4734232020-01-17 18:25:10 +080050/**\brief DVR crypto filter type*/
Pengfei Liuc181a982020-01-07 19:27:13 +080051typedef enum {
Pengfei Liu47ed6c92020-01-17 11:23:41 +080052 DVR_CRYPTO_FILTER_TYPE_AUDIO, /**< Indicate current notification concerns audio packets*/
53 DVR_CRYPTO_FILTER_TYPE_VIDEO, /**< Indicate current notification concerns video packets*/
Pengfei Liuc181a982020-01-07 19:27:13 +080054} DVR_CryptoFilterType_t;
55
Pengfei Liub4734232020-01-17 18:25:10 +080056/**\brief DVR record event*/
57typedef enum {
58 DVR_RECORD_EVENT_ERROR = 0x1000, /**< Signal a critical DVR error*/
59 DVR_RECORD_EVENT_STATUS = 0x1001, /**< Signal the current record status which reach a certain size*/
60 DVR_RECORD_EVENT_SYNC_END = 0x1002, /**< Signal that data sync has ended*/
61 DVR_RECORD_EVENT_CRYPTO_STATUS = 0x2001, /**< Signal the current crypto status*/
hualing chen626204e2020-04-07 11:55:08 +080062 DVR_RECORD_EVENT_WRITE_ERROR = 0x9001, /**< Signal the current crypto status*/
Pengfei Liub4734232020-01-17 18:25:10 +080063} DVR_RecordEvent_t;
64
65/**\brief DVR crypto period information*/
Pengfei Liuc181a982020-01-07 19:27:13 +080066typedef struct
67{
Pengfei Liu47ed6c92020-01-17 11:23:41 +080068 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*/
69 DVR_CryptoParity_t parity; /**< The crypto parity at the ts_offset*/
Wentao MAe8ba5172022-08-09 11:18:17 +080070 loff_t ts_offset; /**< TS packet offset corresponding to this crypto period*/
Pengfei Liu47ed6c92020-01-17 11:23:41 +080071 DVR_CryptoFilterType_t filter_type; /**< Indicate this notification concerns audio or video*/
Pengfei Liuc181a982020-01-07 19:27:13 +080072} DVR_CryptoPeriodInfo_t;
73
Pengfei Liub4734232020-01-17 18:25:10 +080074/**\brief DVR crypto period information*/
Pengfei Liuc181a982020-01-07 19:27:13 +080075typedef struct {
Wentao MAe8ba5172022-08-09 11:18:17 +080076 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*/
77 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 +080078} DVR_CryptoPeriod_t;
Pengfei Liuc181a982020-01-07 19:27:13 +080079
Pengfei Liub4734232020-01-17 18:25:10 +080080/**\brief DVR record event notify function*/
81typedef DVR_Result_t (*DVR_RecordEventFunction_t) (DVR_RecordEvent_t event, void *params, void *userdata);
82
83/**\brief DVR record open parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +080084typedef struct {
Yahui Hance15e9c2020-12-08 18:08:32 +080085 int fend_dev_id; /**< Frontend device id */
Pengfei Liub4734232020-01-17 18:25:10 +080086 int dmx_dev_id; /**< Demux device id*/
pengfei.liuab5a2262020-02-14 17:33:40 +080087 int data_from_memory; /**< Indicate record data from demux or memory*/
Pengfei Liub4734232020-01-17 18:25:10 +080088 DVR_RecordFlag_t flags; /**< DVR record flag*/
pengfei.liu07ddc8a2020-03-24 23:36:53 +080089 int flush_size; /**< DVR record interrupt flush size*/
Pengfei Liub4734232020-01-17 18:25:10 +080090 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/
91 void *event_userdata; /**< DVR event userdata*/
Wentao MAe8ba5172022-08-09 11:18:17 +080092 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 +080093 uint8_t *clearkey; /**< key for encrypted PVR on FTA.*/
Wentao MAe8ba5172022-08-09 11:18:17 +080094 uint8_t *cleariv; /**< iv for encrypted PVR on FTA.*/
Yahui Han1fbf3292021-11-08 18:17:19 +080095 uint32_t keylen; /**< key/iv length.*/
hualing chen03fd4942021-07-15 15:56:41 +080096 int ringbuf_size; /**< DVR record ring buf size*/
Wentao MAe8ba5172022-08-09 11:18:17 +080097 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 +080098 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 +080099 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 +0800100} DVR_RecordOpenParams_t;
101
Pengfei Liub4734232020-01-17 18:25:10 +0800102/**\brief DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800103typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +0800104 uint64_t segment_id; /**< Segment id*/
105 uint32_t nb_pids; /**< Number of pids*/
106 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids information*/
107 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids action*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800108} DVR_RecordSegmentStartParams_t;
109
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800110/**\brief DVR record encrypt function*/
111typedef DVR_Result_t (*DVR_RecordEncryptFunction_t) (uint8_t *p_in,
112 uint32_t in_len,
113 uint8_t *p_out,
114 uint32_t *p_out_len,
115 void *userdata);
116
Pengfei Liub4734232020-01-17 18:25:10 +0800117/**\brief DVR record current status*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800118typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +0800119 DVR_RecordState_t state; /**< DVR record state*/
120 DVR_RecordSegmentInfo_t info; /**< DVR record segment information*/
121} DVR_RecordStatus_t;
122
123/**\brief DVR record start parameters*/
124typedef struct {
125 char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/
126 DVR_RecordSegmentStartParams_t segment; /**< DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800127} DVR_RecordStartParams_t;
128
Pengfei Liuc181a982020-01-07 19:27:13 +0800129/**\brief Open a recording session for a target giving some open parameters
Gong Ke497c4c22020-03-20 10:15:42 +0800130 * \param[out] p_handle Return the handle of the newly created dvr session
131 * \param[in] params Open parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800132 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800133 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800134 */
135int dvr_record_open(DVR_RecordHandle_t *p_handle, DVR_RecordOpenParams_t *params);
136
137/**\brief Close a recording session
Gong Ke497c4c22020-03-20 10:15:42 +0800138 * \param[in] handle DVR recording session handle
Pengfei Liuc181a982020-01-07 19:27:13 +0800139 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800140 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800141 */
142int dvr_record_close(DVR_RecordHandle_t handle);
143
hualing chen03fd4942021-07-15 15:56:41 +0800144/**\brief pause recording on a segment
145 * \param[in] handle DVR recording session handle
146 * \return DVR_SUCCESS on success
147 * \return error code on failure
148 */
149int dvr_record_pause(DVR_RecordHandle_t handle);
150
151/**\brief resume recording on a segment
152 * \param[in] handle DVR recording session handle
153 * \return DVR_SUCCESS on success
154 * \return error code on failure
155 */
156int dvr_record_resume(DVR_RecordHandle_t handle);
157
Pengfei Liuc181a982020-01-07 19:27:13 +0800158/**\brief Start recording on a segment
Gong Ke497c4c22020-03-20 10:15:42 +0800159 * \param[in] handle DVR recording session handle
160 * \param[in] params DVR start parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800161 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800162 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800163 */
164int dvr_record_start_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params);
165
166/**\brief Stop the ongoing segment and start recording a new segment
Gong Ke497c4c22020-03-20 10:15:42 +0800167 * \param[in] handle DVR recording session handle
168 * \param[in] params DVR start parameters
169 * \param[out] p_info DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800170 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800171 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800172 */
173int dvr_record_next_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, DVR_RecordSegmentInfo_t *p_info);
174
175/**\brief Stop the ongoing segment
Gong Ke497c4c22020-03-20 10:15:42 +0800176 * \param[in] handle DVR recording session handle
177 * \param[out] p_info DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800178 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800179 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800180 */
181int dvr_record_stop_segment(DVR_RecordHandle_t handle, DVR_RecordSegmentInfo_t *p_info);
182
Pengfei Liub4734232020-01-17 18:25:10 +0800183/**\brief Resume the recording on a segment
Gong Ke497c4c22020-03-20 10:15:42 +0800184 * \param[in] handle DVR recording session handle
185 * \param[in] params DVR start parameters
186 * \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 +0800187 * \return DVR_SUCCESS on success
188 * \return error code on failure
189 */
190int dvr_record_resume_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, uint64_t *p_resume_size);
191
pengfei.liuab5a2262020-02-14 17:33:40 +0800192/**\brief DVR record write data, used for VOD mode
Gong Ke497c4c22020-03-20 10:15:42 +0800193 * \param[in] handle DVR recording session handle
Wentao MAe8ba5172022-08-09 11:18:17 +0800194 * \param[in] buffer The record data buffer
Gong Ke497c4c22020-03-20 10:15:42 +0800195 * \param[in] len The record data length
pengfei.liuab5a2262020-02-14 17:33:40 +0800196 * \return DVR_SUCCESS on success
197 * \return error code on failure
198 */
199int dvr_record_write(DVR_RecordHandle_t handle, void *buffer, uint32_t len);
200
201/**\brief DVR record get status
Gong Ke497c4c22020-03-20 10:15:42 +0800202 * \param[in] handle DVR recording session handle
203 * \param[out] p_status Return current DVR record status
pengfei.liuab5a2262020-02-14 17:33:40 +0800204 * \return DVR_SUCCESS on success
205 * \return error code on failure
206 */
207int dvr_record_get_status(DVR_RecordHandle_t handle, DVR_RecordStatus_t *p_status);
208
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800209/**\brief Set DVR record encrypt function
210 * \param[in] handle, DVR recording session handle
211 * \param[in] func, DVR recording encrypt function
212 * \param[in] userdata, DVR record userdata from the caller
213 * \return DVR_SUCCESS on success
214 * \return error code on failure
215 */
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800216int dvr_record_set_encrypt_callback(DVR_RecordHandle_t handle, DVR_CryptoFunction_t func, void *userdata);
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800217
218/**\brief Set DVR record secure buffer used for protect the secure content
219 * \param[in] handle, DVR recording session handle
220 * \param[in] p_secure_buf, Secure buffer address which can NOT access by ACPU
221 * \param[in] len, Secure buffer length
222 * \return DVR_SUCCESS on success
223 * \return error code on failure
224 */
225int dvr_record_set_secure_buffer(DVR_RecordHandle_t handle, uint8_t *p_secure_buf, uint32_t len);
226
hualing chen4fe3bee2020-10-23 13:58:52 +0800227/**
228 * check record mode is secure or free.
229 * \param handle The record session handle.
230 * \retval 1:secure 0: free mode.
231 * \return secure or free.
232 */
233int dvr_record_is_secure_mode(DVR_RecordHandle_t handle);
Wentao MAf4072032022-06-30 13:50:45 +0800234
235/**\brief Turn on/off recording data discarding
236 * \param[in] handle, DVR recording session handle
237 * \param[in] discard, 0: normal processing, 1: discard coming recording data
238 * \return DVR_SUCCESS on success
239 * \return error code on failure
240 */
241int dvr_record_discard_coming_data(DVR_RecordHandle_t handle, DVR_Bool_t discard);
242
Zhiqiang Han2f019af2023-08-31 11:12:02 +0800243/**\brief control the recording logic
244 * \param[in] handle, DVR recording session handle
245 * \param[in] cmd, command
246 * \param[in/out] data, parameters
247 * \param[in/out] size, size of parameters
248 * \return DVR_SUCCESS on success
249 * \return error code on failure
250 */
251int dvr_record_ioctl(DVR_RecordHandle_t handle, unsigned int cmd, void *data, size_t size);
252
Pengfei Liuc181a982020-01-07 19:27:13 +0800253#ifdef __cplusplus
254}
255#endif
256
257#endif /*END _DVR_RECORD_H_*/