Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * \file |
| 3 | * Record module |
| 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*/ |
| 25 | } DVR_RecordState_t; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 26 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 27 | /**\brief DVR record pid action*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 28 | typedef enum |
| 29 | { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 30 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 33 | } DVR_RecordPidAction_t; |
| 34 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 35 | /**\brief DVR record flag, used in push vod mode*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 36 | typedef enum { |
| 37 | DVR_RECORD_FLAG_SCRAMBLED = (1 << 0), |
| 38 | DVR_RECORD_FLAG_ACCURATE = (1 << 1), |
| 39 | } DVR_RecordFlag_t; |
| 40 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 41 | /**\brief DVR crypto parity flag*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 42 | typedef enum { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 43 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 46 | } DVR_CryptoParity_t; |
| 47 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 48 | /**\brief DVR crypto filter type*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 49 | typedef enum { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 50 | DVR_CRYPTO_FILTER_TYPE_AUDIO, /**< Indicate current notification concerns audio packets*/ |
| 51 | DVR_CRYPTO_FILTER_TYPE_VIDEO, /**< Indicate current notification concerns video packets*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 52 | } DVR_CryptoFilterType_t; |
| 53 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 54 | /**\brief DVR record event*/ |
| 55 | typedef 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 63 | typedef struct |
| 64 | { |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 65 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 69 | } DVR_CryptoPeriodInfo_t; |
| 70 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 71 | /**\brief DVR crypto period information*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 72 | typedef struct { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 73 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 76 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 77 | /**\brief DVR record event notify function*/ |
| 78 | typedef DVR_Result_t (*DVR_RecordEventFunction_t) (DVR_RecordEvent_t event, void *params, void *userdata); |
| 79 | |
| 80 | /**\brief DVR record open parameters*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 81 | typedef struct { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 82 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 90 | } DVR_RecordOpenParams_t; |
| 91 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 92 | /**\brief DVR record segment start parameters*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 93 | typedef struct { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 94 | 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 Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 98 | } DVR_RecordSegmentStartParams_t; |
| 99 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 100 | /**\brief DVR record current status*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 101 | typedef struct { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 102 | 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*/ |
| 107 | typedef struct { |
| 108 | char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/ |
| 109 | DVR_RecordSegmentStartParams_t segment; /**< DVR record segment start parameters*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 110 | } DVR_RecordStartParams_t; |
| 111 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 112 | /**\brief Open a recording session for a target giving some open parameters |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 113 | * \param[out] p_handle, Return the handle of the newly created dvr session |
| 114 | * \param[in] params, Open parameters |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 115 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 116 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 117 | */ |
| 118 | int dvr_record_open(DVR_RecordHandle_t *p_handle, DVR_RecordOpenParams_t *params); |
| 119 | |
| 120 | /**\brief Close a recording session |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 121 | * \param[in] handle, DVR recording session handle |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 122 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 123 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 124 | */ |
| 125 | int dvr_record_close(DVR_RecordHandle_t handle); |
| 126 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 127 | /**\brief Start recording on a segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 128 | * \param[in] handle, DVR recording session handle |
| 129 | * \param[in] params, DVR start parameters |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 130 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 131 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 132 | */ |
| 133 | int 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 Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 136 | * \param[in] handle, DVR recording session handle |
| 137 | * \param[in] params, DVR start parameters |
| 138 | * \param[out] p_info, DVR record segment information |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 139 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 140 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 141 | */ |
| 142 | int 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 Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 145 | * \param[in] handle, DVR recording session handle |
| 146 | * \param[out] p_info, DVR record segment information |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 147 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 148 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 149 | */ |
| 150 | int dvr_record_stop_segment(DVR_RecordHandle_t handle, DVR_RecordSegmentInfo_t *p_info); |
| 151 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 152 | /**\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 | */ |
| 159 | int dvr_record_resume_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, uint64_t *p_resume_size); |
| 160 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 161 | #ifdef __cplusplus |
| 162 | } |
| 163 | #endif |
| 164 | |
| 165 | #endif /*END _DVR_RECORD_H_*/ |