blob: ab7fb9f5ef3274462086cc43bba84e2dfba77fb1 [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*/
69 loff_t ts_offset; /**< TS packet offset correspongding to this crypto period*/
70 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 {
Pengfei Liub4734232020-01-17 18:25:10 +080075 uint64_t interval_bytes; /**< The inteval 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; /**< Inticate 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*/
77} 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*/
91 size_t notification_size; /**< DVR record notification size, record moudle would send a notifaction 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.*/
93 uint8_t *cleariv; /**< iv for encrpted PVR on FTA.*/
94 uint32_t keylen; /**< key/iv length.*/
hualing chen03fd4942021-07-15 15:56:41 +080095 int ringbuf_size; /**< DVR record ring buf size*/
Pengfei Liuc181a982020-01-07 19:27:13 +080096} DVR_RecordOpenParams_t;
97
Pengfei Liub4734232020-01-17 18:25:10 +080098/**\brief DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +080099typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +0800100 uint64_t segment_id; /**< Segment id*/
101 uint32_t nb_pids; /**< Number of pids*/
102 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids information*/
103 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids action*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800104} DVR_RecordSegmentStartParams_t;
105
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800106/**\brief DVR record encrypt function*/
107typedef DVR_Result_t (*DVR_RecordEncryptFunction_t) (uint8_t *p_in,
108 uint32_t in_len,
109 uint8_t *p_out,
110 uint32_t *p_out_len,
111 void *userdata);
112
Pengfei Liub4734232020-01-17 18:25:10 +0800113/**\brief DVR record current status*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800114typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +0800115 DVR_RecordState_t state; /**< DVR record state*/
116 DVR_RecordSegmentInfo_t info; /**< DVR record segment information*/
117} DVR_RecordStatus_t;
118
119/**\brief DVR record start parameters*/
120typedef struct {
121 char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/
122 DVR_RecordSegmentStartParams_t segment; /**< DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800123} DVR_RecordStartParams_t;
124
Pengfei Liuc181a982020-01-07 19:27:13 +0800125/**\brief Open a recording session for a target giving some open parameters
Gong Ke497c4c22020-03-20 10:15:42 +0800126 * \param[out] p_handle Return the handle of the newly created dvr session
127 * \param[in] params Open parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800128 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800129 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800130 */
131int dvr_record_open(DVR_RecordHandle_t *p_handle, DVR_RecordOpenParams_t *params);
132
133/**\brief Close a recording session
Gong Ke497c4c22020-03-20 10:15:42 +0800134 * \param[in] handle DVR recording session handle
Pengfei Liuc181a982020-01-07 19:27:13 +0800135 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800136 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800137 */
138int dvr_record_close(DVR_RecordHandle_t handle);
139
hualing chen03fd4942021-07-15 15:56:41 +0800140/**\brief pause recording on a segment
141 * \param[in] handle DVR recording session handle
142 * \return DVR_SUCCESS on success
143 * \return error code on failure
144 */
145int dvr_record_pause(DVR_RecordHandle_t handle);
146
147/**\brief resume recording on a segment
148 * \param[in] handle DVR recording session handle
149 * \return DVR_SUCCESS on success
150 * \return error code on failure
151 */
152int dvr_record_resume(DVR_RecordHandle_t handle);
153
Pengfei Liuc181a982020-01-07 19:27:13 +0800154/**\brief Start recording on a segment
Gong Ke497c4c22020-03-20 10:15:42 +0800155 * \param[in] handle DVR recording session handle
156 * \param[in] params DVR start parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800157 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800158 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800159 */
160int dvr_record_start_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params);
161
162/**\brief Stop the ongoing segment and start recording a new segment
Gong Ke497c4c22020-03-20 10:15:42 +0800163 * \param[in] handle DVR recording session handle
164 * \param[in] params DVR start parameters
165 * \param[out] p_info DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800166 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800167 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800168 */
169int dvr_record_next_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, DVR_RecordSegmentInfo_t *p_info);
170
171/**\brief Stop the ongoing segment
Gong Ke497c4c22020-03-20 10:15:42 +0800172 * \param[in] handle DVR recording session handle
173 * \param[out] p_info DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800174 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800175 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800176 */
177int dvr_record_stop_segment(DVR_RecordHandle_t handle, DVR_RecordSegmentInfo_t *p_info);
178
Pengfei Liub4734232020-01-17 18:25:10 +0800179/**\brief Resume the recording on a segment
Gong Ke497c4c22020-03-20 10:15:42 +0800180 * \param[in] handle DVR recording session handle
181 * \param[in] params DVR start parameters
182 * \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 +0800183 * \return DVR_SUCCESS on success
184 * \return error code on failure
185 */
186int dvr_record_resume_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, uint64_t *p_resume_size);
187
pengfei.liuab5a2262020-02-14 17:33:40 +0800188/**\brief DVR record write data, used for VOD mode
Gong Ke497c4c22020-03-20 10:15:42 +0800189 * \param[in] handle DVR recording session handle
190 * \param[in] buffer The redcord data buffer
191 * \param[in] len The record data length
pengfei.liuab5a2262020-02-14 17:33:40 +0800192 * \return DVR_SUCCESS on success
193 * \return error code on failure
194 */
195int dvr_record_write(DVR_RecordHandle_t handle, void *buffer, uint32_t len);
196
197/**\brief DVR record get status
Gong Ke497c4c22020-03-20 10:15:42 +0800198 * \param[in] handle DVR recording session handle
199 * \param[out] p_status Return current DVR record status
pengfei.liuab5a2262020-02-14 17:33:40 +0800200 * \return DVR_SUCCESS on success
201 * \return error code on failure
202 */
203int dvr_record_get_status(DVR_RecordHandle_t handle, DVR_RecordStatus_t *p_status);
204
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800205/**\brief Set DVR record encrypt function
206 * \param[in] handle, DVR recording session handle
207 * \param[in] func, DVR recording encrypt function
208 * \param[in] userdata, DVR record userdata from the caller
209 * \return DVR_SUCCESS on success
210 * \return error code on failure
211 */
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800212int dvr_record_set_encrypt_callback(DVR_RecordHandle_t handle, DVR_CryptoFunction_t func, void *userdata);
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800213
214/**\brief Set DVR record secure buffer used for protect the secure content
215 * \param[in] handle, DVR recording session handle
216 * \param[in] p_secure_buf, Secure buffer address which can NOT access by ACPU
217 * \param[in] len, Secure buffer length
218 * \return DVR_SUCCESS on success
219 * \return error code on failure
220 */
221int dvr_record_set_secure_buffer(DVR_RecordHandle_t handle, uint8_t *p_secure_buf, uint32_t len);
222
hualing chen4fe3bee2020-10-23 13:58:52 +0800223/**
224 * check record mode is secure or free.
225 * \param handle The record session handle.
226 * \retval 1:secure 0: free mode.
227 * \return secure or free.
228 */
229int dvr_record_is_secure_mode(DVR_RecordHandle_t handle);
Pengfei Liuc181a982020-01-07 19:27:13 +0800230#ifdef __cplusplus
231}
232#endif
233
234#endif /*END _DVR_RECORD_H_*/