blob: 9d3a3a144a3f5057c34a14a9dbc88728f27eb6a3 [file] [log] [blame]
Pengfei Liub4734232020-01-17 18:25:10 +08001/*
2 * \file
3 * Record module
4 */
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*/
25} DVR_RecordState_t;
Pengfei Liuc181a982020-01-07 19:27:13 +080026
Pengfei Liub4734232020-01-17 18:25:10 +080027/**\brief DVR record pid action*/
Pengfei Liuc181a982020-01-07 19:27:13 +080028typedef enum
29{
Pengfei Liu47ed6c92020-01-17 11:23:41 +080030 DVR_RECORD_PID_CREATE, /**< Create a new pid used to record*/
31 DVR_RECORD_PID_KEEP, /**< Indicate this pid keep last state*/
32 DVR_RECORD_PID_CLOSE /**< Close this pid record*/
Pengfei Liuc181a982020-01-07 19:27:13 +080033} DVR_RecordPidAction_t;
34
Pengfei Liub4734232020-01-17 18:25:10 +080035/**\brief DVR record flag, used in push vod mode*/
Pengfei Liuc181a982020-01-07 19:27:13 +080036typedef enum {
37 DVR_RECORD_FLAG_SCRAMBLED = (1 << 0),
38 DVR_RECORD_FLAG_ACCURATE = (1 << 1),
39} DVR_RecordFlag_t;
40
Pengfei Liub4734232020-01-17 18:25:10 +080041/**\brief DVR crypto parity flag*/
Pengfei Liuc181a982020-01-07 19:27:13 +080042typedef enum {
Pengfei Liu47ed6c92020-01-17 11:23:41 +080043 DVR_CRYPTO_PARITY_CLEAR, /**< Current period is clear*/
44 DVR_CRYPTO_PARITY_ODD, /**< Current period is ODD*/
45 DVR_CRYPTO_PARITY_EVEN, /**< Current period is EVEN*/
Pengfei Liuc181a982020-01-07 19:27:13 +080046} DVR_CryptoParity_t;
47
Pengfei Liub4734232020-01-17 18:25:10 +080048/**\brief DVR crypto filter type*/
Pengfei Liuc181a982020-01-07 19:27:13 +080049typedef enum {
Pengfei Liu47ed6c92020-01-17 11:23:41 +080050 DVR_CRYPTO_FILTER_TYPE_AUDIO, /**< Indicate current notification concerns audio packets*/
51 DVR_CRYPTO_FILTER_TYPE_VIDEO, /**< Indicate current notification concerns video packets*/
Pengfei Liuc181a982020-01-07 19:27:13 +080052} DVR_CryptoFilterType_t;
53
Pengfei Liub4734232020-01-17 18:25:10 +080054/**\brief DVR record event*/
55typedef enum {
56 DVR_RECORD_EVENT_ERROR = 0x1000, /**< Signal a critical DVR error*/
57 DVR_RECORD_EVENT_STATUS = 0x1001, /**< Signal the current record status which reach a certain size*/
58 DVR_RECORD_EVENT_SYNC_END = 0x1002, /**< Signal that data sync has ended*/
59 DVR_RECORD_EVENT_CRYPTO_STATUS = 0x2001, /**< Signal the current crypto status*/
60} DVR_RecordEvent_t;
61
62/**\brief DVR crypto period information*/
Pengfei Liuc181a982020-01-07 19:27:13 +080063typedef struct
64{
Pengfei Liu47ed6c92020-01-17 11:23:41 +080065 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*/
66 DVR_CryptoParity_t parity; /**< The crypto parity at the ts_offset*/
67 loff_t ts_offset; /**< TS packet offset correspongding to this crypto period*/
68 DVR_CryptoFilterType_t filter_type; /**< Indicate this notification concerns audio or video*/
Pengfei Liuc181a982020-01-07 19:27:13 +080069} DVR_CryptoPeriodInfo_t;
70
Pengfei Liub4734232020-01-17 18:25:10 +080071/**\brief DVR crypto period information*/
Pengfei Liuc181a982020-01-07 19:27:13 +080072typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +080073 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*/
74 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*/
75} DVR_CryptoPeriod_t;
Pengfei Liuc181a982020-01-07 19:27:13 +080076
Pengfei Liub4734232020-01-17 18:25:10 +080077/**\brief DVR record event notify function*/
78typedef DVR_Result_t (*DVR_RecordEventFunction_t) (DVR_RecordEvent_t event, void *params, void *userdata);
79
80/**\brief DVR record open parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +080081typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +080082 int dmx_dev_id; /**< Demux device id*/
pengfei.liuab5a2262020-02-14 17:33:40 +080083 int data_from_memory; /**< Indicate record data from demux or memory*/
Pengfei Liub4734232020-01-17 18:25:10 +080084 DVR_RecordFlag_t flags; /**< DVR record flag*/
85 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/
86 void *event_userdata; /**< DVR event userdata*/
87 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*/
88 DVR_CryptoPeriod_t crypto_period; /**< DVR crypto period information*/
89 DVR_CryptoFunction_t crypto_fn; /**< DVR crypto callback function*/
90 void *crypto_userdata; /**< DVR crypto userdata*/
Pengfei Liuc181a982020-01-07 19:27:13 +080091} DVR_RecordOpenParams_t;
92
Pengfei Liub4734232020-01-17 18:25:10 +080093/**\brief DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +080094typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +080095 uint64_t segment_id; /**< Segment id*/
96 uint32_t nb_pids; /**< Number of pids*/
97 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids information*/
98 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids action*/
Pengfei Liuc181a982020-01-07 19:27:13 +080099} DVR_RecordSegmentStartParams_t;
100
Pengfei Liub4734232020-01-17 18:25:10 +0800101/**\brief DVR record current status*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800102typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +0800103 DVR_RecordState_t state; /**< DVR record state*/
104 DVR_RecordSegmentInfo_t info; /**< DVR record segment information*/
105} DVR_RecordStatus_t;
106
107/**\brief DVR record start parameters*/
108typedef struct {
109 char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/
110 DVR_RecordSegmentStartParams_t segment; /**< DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800111} DVR_RecordStartParams_t;
112
Pengfei Liuc181a982020-01-07 19:27:13 +0800113/**\brief Open a recording session for a target giving some open parameters
Pengfei Liub4734232020-01-17 18:25:10 +0800114 * \param[out] p_handle, Return the handle of the newly created dvr session
115 * \param[in] params, Open parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800116 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800117 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800118 */
119int dvr_record_open(DVR_RecordHandle_t *p_handle, DVR_RecordOpenParams_t *params);
120
121/**\brief Close a recording session
Pengfei Liub4734232020-01-17 18:25:10 +0800122 * \param[in] handle, DVR recording session handle
Pengfei Liuc181a982020-01-07 19:27:13 +0800123 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800124 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800125 */
126int dvr_record_close(DVR_RecordHandle_t handle);
127
Pengfei Liuc181a982020-01-07 19:27:13 +0800128/**\brief Start recording on a segment
Pengfei Liub4734232020-01-17 18:25:10 +0800129 * \param[in] handle, DVR recording session handle
130 * \param[in] params, DVR start 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_start_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params);
135
136/**\brief Stop the ongoing segment and start recording a new segment
Pengfei Liub4734232020-01-17 18:25:10 +0800137 * \param[in] handle, DVR recording session handle
138 * \param[in] params, DVR start parameters
139 * \param[out] p_info, DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800140 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800141 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800142 */
143int dvr_record_next_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, DVR_RecordSegmentInfo_t *p_info);
144
145/**\brief Stop the ongoing segment
Pengfei Liub4734232020-01-17 18:25:10 +0800146 * \param[in] handle, DVR recording session handle
147 * \param[out] p_info, DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800148 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800149 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800150 */
151int dvr_record_stop_segment(DVR_RecordHandle_t handle, DVR_RecordSegmentInfo_t *p_info);
152
Pengfei Liub4734232020-01-17 18:25:10 +0800153/**\brief Resume the recording on a segment
154 * \param[in] handle, DVR recording session handle
155 * \param[in] params, DVR start parameters
156 * \param[in/out] p_resume_size, HAL propose a resume size as a input parameter and output is the real resume size
157 * \return DVR_SUCCESS on success
158 * \return error code on failure
159 */
160int dvr_record_resume_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, uint64_t *p_resume_size);
161
pengfei.liuab5a2262020-02-14 17:33:40 +0800162/**\brief DVR record write data, used for VOD mode
163 * \param[in] handle, DVR recording session handle
164 * \param[in] buffer, The redcord data buffer
165 * \param[in] len, The record data length
166 * \return DVR_SUCCESS on success
167 * \return error code on failure
168 */
169int dvr_record_write(DVR_RecordHandle_t handle, void *buffer, uint32_t len);
170
171/**\brief DVR record get status
172 * \param[in] handle, DVR recording session handle
173 * \param[out] p_status, Return current DVR record status
174 * \return DVR_SUCCESS on success
175 * \return error code on failure
176 */
177int dvr_record_get_status(DVR_RecordHandle_t handle, DVR_RecordStatus_t *p_status);
178
Pengfei Liuc181a982020-01-07 19:27:13 +0800179#ifdef __cplusplus
180}
181#endif
182
183#endif /*END _DVR_RECORD_H_*/