Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 1 | /** |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 2 | * \file |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 3 | * \brief Record module |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 6 | #ifndef _DVR_RECORD_H_ |
| 7 | #define _DVR_RECORD_H_ |
| 8 | |
| 9 | #ifdef __cplusplus |
| 10 | extern "C" { |
| 11 | #endif |
| 12 | |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 13 | #include "dvr_types.h" |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 14 | #include "dvr_crypto.h" |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 15 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 16 | /**\brief DVR record handle*/ |
Gong Ke | 3489c0f | 2020-01-16 18:11:44 +0800 | [diff] [blame] | 17 | typedef void* DVR_RecordHandle_t; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 18 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 19 | /**\brief DVR record state*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 20 | typedef enum { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 21 | 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 chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 25 | DVR_RECORD_STATE_PAUSE, /**< Record state is pause*/ |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 26 | } DVR_RecordState_t; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 27 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 28 | /**\brief DVR record pid action*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 29 | typedef enum |
| 30 | { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 31 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 34 | } DVR_RecordPidAction_t; |
| 35 | |
Yahui Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame^] | 36 | /**\brief DVR record flag*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 37 | typedef enum { |
| 38 | DVR_RECORD_FLAG_SCRAMBLED = (1 << 0), |
| 39 | DVR_RECORD_FLAG_ACCURATE = (1 << 1), |
| 40 | } DVR_RecordFlag_t; |
| 41 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 42 | /**\brief DVR crypto parity flag*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 43 | typedef enum { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 44 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 47 | } DVR_CryptoParity_t; |
| 48 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 49 | /**\brief DVR crypto filter type*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 50 | typedef enum { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 51 | DVR_CRYPTO_FILTER_TYPE_AUDIO, /**< Indicate current notification concerns audio packets*/ |
| 52 | DVR_CRYPTO_FILTER_TYPE_VIDEO, /**< Indicate current notification concerns video packets*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 53 | } DVR_CryptoFilterType_t; |
| 54 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 55 | /**\brief DVR record event*/ |
| 56 | typedef 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 chen | 626204e | 2020-04-07 11:55:08 +0800 | [diff] [blame] | 61 | DVR_RECORD_EVENT_WRITE_ERROR = 0x9001, /**< Signal the current crypto status*/ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 62 | } DVR_RecordEvent_t; |
| 63 | |
| 64 | /**\brief DVR crypto period information*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 65 | typedef struct |
| 66 | { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 67 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 71 | } DVR_CryptoPeriodInfo_t; |
| 72 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 73 | /**\brief DVR crypto period information*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 74 | typedef struct { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 75 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 78 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 79 | /**\brief DVR record event notify function*/ |
| 80 | typedef DVR_Result_t (*DVR_RecordEventFunction_t) (DVR_RecordEvent_t event, void *params, void *userdata); |
| 81 | |
| 82 | /**\brief DVR record open parameters*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 83 | typedef struct { |
Yahui Han | ce15e9c | 2020-12-08 18:08:32 +0800 | [diff] [blame] | 84 | int fend_dev_id; /**< Frontend device id */ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 85 | int dmx_dev_id; /**< Demux device id*/ |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 86 | int data_from_memory; /**< Indicate record data from demux or memory*/ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 87 | DVR_RecordFlag_t flags; /**< DVR record flag*/ |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 88 | int flush_size; /**< DVR record interrupt flush size*/ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 89 | 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 Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame^] | 92 | 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 chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 95 | int ringbuf_size; /**< DVR record ring buf size*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 96 | } DVR_RecordOpenParams_t; |
| 97 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 98 | /**\brief DVR record segment start parameters*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 99 | typedef struct { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 100 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 104 | } DVR_RecordSegmentStartParams_t; |
| 105 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 106 | /**\brief DVR record encrypt function*/ |
| 107 | typedef 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 Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 113 | /**\brief DVR record current status*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 114 | typedef struct { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 115 | 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*/ |
| 120 | typedef struct { |
| 121 | char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/ |
| 122 | DVR_RecordSegmentStartParams_t segment; /**< DVR record segment start parameters*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 123 | } DVR_RecordStartParams_t; |
| 124 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 125 | /**\brief Open a recording session for a target giving some open parameters |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 126 | * \param[out] p_handle Return the handle of the newly created dvr session |
| 127 | * \param[in] params Open parameters |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 128 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 129 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 130 | */ |
| 131 | int dvr_record_open(DVR_RecordHandle_t *p_handle, DVR_RecordOpenParams_t *params); |
| 132 | |
| 133 | /**\brief Close a recording session |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 134 | * \param[in] handle DVR recording session handle |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 135 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 136 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 137 | */ |
| 138 | int dvr_record_close(DVR_RecordHandle_t handle); |
| 139 | |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 140 | /**\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 | */ |
| 145 | int 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 | */ |
| 152 | int dvr_record_resume(DVR_RecordHandle_t handle); |
| 153 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 154 | /**\brief Start recording on a segment |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 155 | * \param[in] handle DVR recording session handle |
| 156 | * \param[in] params DVR start parameters |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 157 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 158 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 159 | */ |
| 160 | int 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 Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 163 | * \param[in] handle DVR recording session handle |
| 164 | * \param[in] params DVR start parameters |
| 165 | * \param[out] p_info DVR record segment information |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 166 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 167 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 168 | */ |
| 169 | int 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 Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 172 | * \param[in] handle DVR recording session handle |
| 173 | * \param[out] p_info DVR record segment information |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 174 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 175 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 176 | */ |
| 177 | int dvr_record_stop_segment(DVR_RecordHandle_t handle, DVR_RecordSegmentInfo_t *p_info); |
| 178 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 179 | /**\brief Resume the recording on a segment |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 180 | * \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 Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 183 | * \return DVR_SUCCESS on success |
| 184 | * \return error code on failure |
| 185 | */ |
| 186 | int dvr_record_resume_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, uint64_t *p_resume_size); |
| 187 | |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 188 | /**\brief DVR record write data, used for VOD mode |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 189 | * \param[in] handle DVR recording session handle |
| 190 | * \param[in] buffer The redcord data buffer |
| 191 | * \param[in] len The record data length |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 192 | * \return DVR_SUCCESS on success |
| 193 | * \return error code on failure |
| 194 | */ |
| 195 | int dvr_record_write(DVR_RecordHandle_t handle, void *buffer, uint32_t len); |
| 196 | |
| 197 | /**\brief DVR record get status |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 198 | * \param[in] handle DVR recording session handle |
| 199 | * \param[out] p_status Return current DVR record status |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 200 | * \return DVR_SUCCESS on success |
| 201 | * \return error code on failure |
| 202 | */ |
| 203 | int dvr_record_get_status(DVR_RecordHandle_t handle, DVR_RecordStatus_t *p_status); |
| 204 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 205 | /**\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.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 212 | int dvr_record_set_encrypt_callback(DVR_RecordHandle_t handle, DVR_CryptoFunction_t func, void *userdata); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 213 | |
| 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 | */ |
| 221 | int dvr_record_set_secure_buffer(DVR_RecordHandle_t handle, uint8_t *p_secure_buf, uint32_t len); |
| 222 | |
hualing chen | 4fe3bee | 2020-10-23 13:58:52 +0800 | [diff] [blame] | 223 | /** |
| 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 | */ |
| 229 | int dvr_record_is_secure_mode(DVR_RecordHandle_t handle); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 230 | #ifdef __cplusplus |
| 231 | } |
| 232 | #endif |
| 233 | |
| 234 | #endif /*END _DVR_RECORD_H_*/ |