blob: 51b5212004ca5b94ae8ecedf81d7a355d8c2d3c6 [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*/
83 DVR_RecordFlag_t flags; /**< DVR record flag*/
84 DVR_RecordEventFunction_t event_fn; /**< DVR record event callback function*/
85 void *event_userdata; /**< DVR event userdata*/
86 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*/
87 DVR_CryptoPeriod_t crypto_period; /**< DVR crypto period information*/
88 DVR_CryptoFunction_t crypto_fn; /**< DVR crypto callback function*/
89 void *crypto_userdata; /**< DVR crypto userdata*/
Pengfei Liuc181a982020-01-07 19:27:13 +080090} DVR_RecordOpenParams_t;
91
Pengfei Liub4734232020-01-17 18:25:10 +080092/**\brief DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +080093typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +080094 uint64_t segment_id; /**< Segment id*/
95 uint32_t nb_pids; /**< Number of pids*/
96 DVR_StreamPid_t pids[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids information*/
97 DVR_RecordPidAction_t pid_action[DVR_MAX_RECORD_PIDS_COUNT]; /**< Pids action*/
Pengfei Liuc181a982020-01-07 19:27:13 +080098} DVR_RecordSegmentStartParams_t;
99
Pengfei Liub4734232020-01-17 18:25:10 +0800100/**\brief DVR record current status*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800101typedef struct {
Pengfei Liub4734232020-01-17 18:25:10 +0800102 DVR_RecordState_t state; /**< DVR record state*/
103 DVR_RecordSegmentInfo_t info; /**< DVR record segment information*/
104} DVR_RecordStatus_t;
105
106/**\brief DVR record start parameters*/
107typedef struct {
108 char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/
109 DVR_RecordSegmentStartParams_t segment; /**< DVR record segment start parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +0800110} DVR_RecordStartParams_t;
111
Pengfei Liuc181a982020-01-07 19:27:13 +0800112/**\brief Open a recording session for a target giving some open parameters
Pengfei Liub4734232020-01-17 18:25:10 +0800113 * \param[out] p_handle, Return the handle of the newly created dvr session
114 * \param[in] params, Open parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800115 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800116 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800117 */
118int dvr_record_open(DVR_RecordHandle_t *p_handle, DVR_RecordOpenParams_t *params);
119
120/**\brief Close a recording session
Pengfei Liub4734232020-01-17 18:25:10 +0800121 * \param[in] handle, DVR recording session handle
Pengfei Liuc181a982020-01-07 19:27:13 +0800122 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800123 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800124 */
125int dvr_record_close(DVR_RecordHandle_t handle);
126
Pengfei Liuc181a982020-01-07 19:27:13 +0800127/**\brief Start recording on a segment
Pengfei Liub4734232020-01-17 18:25:10 +0800128 * \param[in] handle, DVR recording session handle
129 * \param[in] params, DVR start parameters
Pengfei Liuc181a982020-01-07 19:27:13 +0800130 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800131 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800132 */
133int dvr_record_start_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params);
134
135/**\brief Stop the ongoing segment and start recording a new segment
Pengfei Liub4734232020-01-17 18:25:10 +0800136 * \param[in] handle, DVR recording session handle
137 * \param[in] params, DVR start parameters
138 * \param[out] p_info, DVR record segment information
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_next_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, DVR_RecordSegmentInfo_t *p_info);
143
144/**\brief Stop the ongoing segment
Pengfei Liub4734232020-01-17 18:25:10 +0800145 * \param[in] handle, DVR recording session handle
146 * \param[out] p_info, DVR record segment information
Pengfei Liuc181a982020-01-07 19:27:13 +0800147 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +0800148 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +0800149 */
150int dvr_record_stop_segment(DVR_RecordHandle_t handle, DVR_RecordSegmentInfo_t *p_info);
151
Pengfei Liub4734232020-01-17 18:25:10 +0800152/**\brief Resume the recording on a segment
153 * \param[in] handle, DVR recording session handle
154 * \param[in] params, DVR start parameters
155 * \param[in/out] p_resume_size, HAL propose a resume size as a input parameter and output is the real resume size
156 * \return DVR_SUCCESS on success
157 * \return error code on failure
158 */
159int dvr_record_resume_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, uint64_t *p_resume_size);
160
Pengfei Liuc181a982020-01-07 19:27:13 +0800161#ifdef __cplusplus
162}
163#endif
164
165#endif /*END _DVR_RECORD_H_*/