Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 2 | #include <unistd.h> |
| 3 | #include <stdlib.h> |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 4 | #include <pthread.h> |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 5 | #include <string.h> |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 6 | #include "dvr_types.h" |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 7 | #include "dvr_record.h" |
| 8 | #include "dvr_crypto.h" |
| 9 | #include "record_device.h" |
| 10 | #include "segment.h" |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 11 | |
| 12 | #define MAX_DVR_RECORD_SESSION_COUNT 2 |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 13 | |
| 14 | /**\brief DVR index file type*/ |
| 15 | typedef enum { |
| 16 | DVR_INDEX_TYPE_PCR, /**< DVR index file use pcr*/ |
| 17 | DVR_INDEX_TYPE_LOCAL_CLOCK, /**< DVR index file use local clock*/ |
| 18 | DVR_INDEX_TYPE_INVALID /**< DVR index file type invalid type*/ |
| 19 | } DVR_IndexType_t; |
| 20 | |
| 21 | /**\brief DVR VOD context*/ |
| 22 | typedef struct { |
| 23 | pthread_mutex_t mutex; /**< VOD mutex lock*/ |
| 24 | pthread_cond_t cond; /**< VOD condition*/ |
| 25 | void *buffer; /**< VOD buffer*/ |
| 26 | uint32_t buf_len; /**< VOD buffer len*/ |
| 27 | } DVR_VodContext_t; |
| 28 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 29 | /**\brief DVR record context*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 30 | typedef struct { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 31 | pthread_t thread; /**< DVR thread handle*/ |
| 32 | Record_DeviceHandle_t dev_handle; /**< DVR device handle*/ |
| 33 | Segment_Handle_t segment_handle; /**< DVR segment handle*/ |
| 34 | DVR_RecordState_t state; /**< DVR record state*/ |
| 35 | char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/ |
| 36 | DVR_RecordSegmentStartParams_t segment_params; /**< DVR record start parameters*/ |
| 37 | DVR_RecordSegmentInfo_t segment_info; /**< DVR record current segment info*/ |
| 38 | size_t notification_size; /**< DVR record nogification size*/ |
| 39 | DVR_RecordEventFunction_t event_notify_fn; /**< DVR record event notify function*/ |
| 40 | void *event_userdata; /**< DVR record event userdata*/ |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 41 | //DVR_VodContext_t vod; /**< DVR record vod context*/ |
| 42 | int is_vod; /**< Indicate current mode is VOD record mode*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 43 | } DVR_RecordContext_t; |
| 44 | |
| 45 | static DVR_RecordContext_t record_ctx[MAX_DVR_RECORD_SESSION_COUNT] = { |
| 46 | { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 47 | .state = DVR_RECORD_STATE_CLOSED |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 48 | }, |
| 49 | { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 50 | .state = DVR_RECORD_STATE_CLOSED |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 51 | } |
| 52 | }; |
| 53 | |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 54 | //#define USE_TEST_DATA |
| 55 | #ifdef USE_TEST_DATA |
| 56 | static int test_data_read(uint8_t *buf, int len) |
| 57 | { |
| 58 | int i; |
| 59 | for (i = 0; i < len; i++) { |
| 60 | buf[i] = i % 0xff; |
| 61 | } |
| 62 | usleep(50*1000); |
| 63 | return len; |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | static int record_save_pcr(DVR_RecordContext_t *p_ctx, uint8_t *buf, loff_t pos) |
| 68 | { |
| 69 | uint8_t *p = buf; |
| 70 | int len; |
| 71 | uint8_t afc; |
| 72 | uint64_t pcr = 0; |
| 73 | int has_pcr = 0; |
| 74 | int pid; |
| 75 | int adp_field_len; |
| 76 | |
| 77 | pid = ((p[1] & 0x1f) << 8) | p[2]; |
| 78 | if (pid == 0x1fff) |
| 79 | return has_pcr; |
| 80 | |
| 81 | //scramble = p[3] >> 6; |
| 82 | //cc = p[3] & 0x0f; |
| 83 | afc = (p[3] >> 4) & 0x03; |
| 84 | |
| 85 | p += 4; |
| 86 | len = 184; |
| 87 | |
| 88 | if (afc & 2) { |
| 89 | adp_field_len = p[0]; |
| 90 | /* Skip adaptation len */ |
| 91 | p++; |
| 92 | len--; |
| 93 | /* Parse pcr field, see 13818 spec table I-2-6,adaptation_field */ |
| 94 | if (p[0] & 0x10 && len >= 6) { |
| 95 | /* get pcr value,pcr is 33bit value */ |
| 96 | pcr = (((uint64_t)(p[1])) << 25) |
| 97 | | (((uint64_t)p[2]) << 17) |
| 98 | | (((uint64_t)(p[3])) << 9) |
| 99 | | (((uint64_t)p[4]) << 1) |
| 100 | | ((((uint64_t)p[5]) & 0x80) >> 7); |
| 101 | has_pcr = 1; |
| 102 | } |
| 103 | |
| 104 | p += adp_field_len; |
| 105 | len -= adp_field_len; |
| 106 | |
| 107 | if (len < 0) { |
| 108 | DVR_DEBUG(1, "parser pcr: illegal adaptation field length"); |
| 109 | return 0; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (has_pcr) { |
| 114 | segment_update_pts(p_ctx->segment_handle, pcr/90, pos); |
| 115 | } |
| 116 | return has_pcr; |
| 117 | } |
| 118 | |
| 119 | static int record_do_pcr_index(DVR_RecordContext_t *p_ctx, uint8_t *buf, int len) |
| 120 | { |
| 121 | uint8_t *p = buf; |
| 122 | int left = len; |
| 123 | loff_t pos; |
| 124 | int has_pcr = 0; |
| 125 | |
| 126 | pos = segment_tell_position(p_ctx->segment_handle); |
| 127 | while (left >= 188) { |
| 128 | if (*p == 0x47) { |
| 129 | has_pcr |= record_save_pcr(p_ctx, p, pos); |
| 130 | p += 188; |
| 131 | left -= 188; |
| 132 | pos += 188; |
| 133 | } else { |
| 134 | p++; |
| 135 | left --; |
| 136 | pos++; |
| 137 | } |
| 138 | } |
| 139 | return has_pcr; |
| 140 | } |
| 141 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 142 | void *record_thread(void *arg) |
| 143 | { |
| 144 | DVR_RecordContext_t *p_ctx = (DVR_RecordContext_t *)arg; |
| 145 | ssize_t len; |
| 146 | uint8_t *buf; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 147 | int block_size = 256*1024; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 148 | loff_t pos = 0; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 149 | int ret; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 150 | struct timespec start_ts, end_ts; |
| 151 | DVR_RecordStatus_t record_status; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 152 | int has_pcr; |
| 153 | int index_type = DVR_INDEX_TYPE_INVALID; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 154 | time_t pre_time = 0; |
| 155 | #define DVR_STORE_INFO_TIME (1000) |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 156 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 157 | buf = (uint8_t *)malloc(block_size); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 158 | if (!buf) { |
| 159 | DVR_DEBUG(1, "%s, malloc failed", __func__); |
| 160 | return NULL; |
| 161 | } |
| 162 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 163 | clock_gettime(CLOCK_MONOTONIC, &start_ts); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 164 | while (p_ctx->state == DVR_RECORD_STATE_STARTED) { |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 165 | /* data from dmx, normal dvr case */ |
| 166 | #ifdef USE_TEST_DATA |
| 167 | len = test_data_read(buf, block_size); |
| 168 | #else |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 169 | len = record_device_read(p_ctx->dev_handle, buf, block_size, 1000); |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 170 | #endif |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 171 | if (len == DVR_FAILURE) { |
| 172 | usleep(10*1000); |
| 173 | continue; |
| 174 | } |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 175 | /* got data from device, record it */ |
| 176 | pos = segment_tell_position(p_ctx->segment_handle); |
| 177 | has_pcr = record_do_pcr_index(p_ctx, buf, len); |
| 178 | if (has_pcr == 0 && index_type == DVR_INDEX_TYPE_INVALID) { |
| 179 | clock_gettime(CLOCK_MONOTONIC, &end_ts); |
| 180 | if ((end_ts.tv_sec*1000 + end_ts.tv_nsec/1000000) - |
| 181 | (start_ts.tv_sec*1000 + start_ts.tv_nsec/1000000) > 40) { |
| 182 | /* PCR interval threshlod > 40 ms*/ |
| 183 | DVR_DEBUG(1, "%s use local clock time index", __func__); |
| 184 | index_type = DVR_INDEX_TYPE_LOCAL_CLOCK; |
| 185 | } |
| 186 | } else if (has_pcr && index_type == DVR_INDEX_TYPE_INVALID){ |
| 187 | DVR_DEBUG(1, "%s use pcr time index", __func__); |
| 188 | index_type = DVR_INDEX_TYPE_PCR; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 189 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 190 | ret = segment_write(p_ctx->segment_handle, buf, len); |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 191 | |
| 192 | /* Update segment info */ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 193 | p_ctx->segment_info.size += len; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 194 | /*Duration need use pcr to calculate, todo...*/ |
| 195 | if (index_type == DVR_INDEX_TYPE_PCR) { |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 196 | p_ctx->segment_info.duration = segment_tell_total_time(p_ctx->segment_handle); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 197 | if (pre_time == 0) |
| 198 | pre_time = p_ctx->segment_info.duration; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 199 | } else if (index_type == DVR_INDEX_TYPE_LOCAL_CLOCK) { |
| 200 | clock_gettime(CLOCK_MONOTONIC, &end_ts); |
| 201 | p_ctx->segment_info.duration = (end_ts.tv_sec*1000 + end_ts.tv_nsec/1000000) - |
| 202 | (start_ts.tv_sec*1000 + start_ts.tv_nsec/1000000); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 203 | if (pre_time == 0) |
| 204 | pre_time = p_ctx->segment_info.duration; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 205 | segment_update_pts(p_ctx->segment_handle, p_ctx->segment_info.duration, pos); |
| 206 | } else { |
| 207 | DVR_DEBUG(1, "%s can NOT do time index", __func__); |
| 208 | } |
| 209 | p_ctx->segment_info.nb_packets = p_ctx->segment_info.size/188; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 210 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 211 | if (p_ctx->segment_info.duration - pre_time > DVR_STORE_INFO_TIME) { |
| 212 | pre_time = p_ctx->segment_info.duration + DVR_STORE_INFO_TIME; |
| 213 | segment_store_info(p_ctx->segment_handle, &(p_ctx->segment_info)); |
| 214 | } |
| 215 | /*Event notification*/ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 216 | if (p_ctx->notification_size && |
| 217 | p_ctx->event_notify_fn && |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 218 | !(p_ctx->segment_info.size % p_ctx->notification_size) && |
| 219 | p_ctx->segment_info.duration > 0) { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 220 | memset(&record_status, 0, sizeof(record_status)); |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 221 | //clock_gettime(CLOCK_MONOTONIC, &end_ts); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 222 | |
| 223 | record_status.state = p_ctx->state; |
| 224 | record_status.info.id = p_ctx->segment_info.id; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 225 | record_status.info.duration = p_ctx->segment_info.duration; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 226 | record_status.info.size = p_ctx->segment_info.size; |
| 227 | record_status.info.nb_packets = p_ctx->segment_info.size/188; |
| 228 | p_ctx->event_notify_fn(DVR_RECORD_EVENT_STATUS, &record_status, p_ctx->event_userdata); |
| 229 | DVR_DEBUG(1, "%s notify record status, state:%d, id:%lld, duration:%ld ms, size:%zu", |
| 230 | __func__, record_status.state, record_status.info.id, record_status.info.duration, record_status.info.size); |
| 231 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 232 | } |
| 233 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 234 | free((void *)buf); |
| 235 | DVR_DEBUG(1, "exit %s", __func__); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | int dvr_record_open(DVR_RecordHandle_t *p_handle, DVR_RecordOpenParams_t *params) |
| 240 | { |
| 241 | DVR_RecordContext_t *p_ctx; |
| 242 | Record_DeviceOpenParams_t dev_open_params; |
| 243 | int ret; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 244 | uint32_t i; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 245 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 246 | DVR_RETURN_IF_FALSE(p_handle); |
| 247 | DVR_RETURN_IF_FALSE(params); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 248 | |
| 249 | for (i = 0; i < MAX_DVR_RECORD_SESSION_COUNT; i++) { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 250 | if (record_ctx[i].state == DVR_RECORD_STATE_CLOSED) { |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 251 | break; |
| 252 | } |
| 253 | } |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 254 | DVR_RETURN_IF_FALSE(record_ctx[i].state == DVR_RECORD_STATE_CLOSED); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 255 | p_ctx = &record_ctx[i]; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 256 | DVR_DEBUG(1, "%s , current state:%d, dmx_id:%d, notification_size:%zu", __func__, |
| 257 | p_ctx->state, params->dmx_dev_id, params->notification_size); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 258 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 259 | /*Process event params*/ |
| 260 | p_ctx->notification_size = params->notification_size; |
| 261 | p_ctx->event_notify_fn = params->event_fn; |
| 262 | p_ctx->event_userdata = params->event_userdata; |
| 263 | /*Process crypto params, todo*/ |
| 264 | #if 0 |
| 265 | DVR_CryptoPeriod_t crypto_period; /**< DVR crypto period information*/ |
| 266 | DVR_CryptoFunction_t crypto_fn; /**< DVR crypto callback function*/ |
| 267 | void *crypto_data; /**< DVR crypto userdata*/ |
| 268 | #endif |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 269 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 270 | memset((void *)&dev_open_params, 0, sizeof(dev_open_params)); |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 271 | if (params->data_from_memory) { |
| 272 | /* data from memory, VOD case */ |
| 273 | p_ctx->is_vod = 1; |
| 274 | } else { |
| 275 | p_ctx->is_vod = 0; |
| 276 | /* data from dmx, normal dvr case */ |
hualing chen | 958fe4c | 2020-03-24 17:35:07 +0800 | [diff] [blame] | 277 | dev_open_params.dmx_dev_id = params->dmx_dev_id; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 278 | dev_open_params.buf_size = 256*1024; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 279 | |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 280 | ret = record_device_open(&p_ctx->dev_handle, &dev_open_params); |
| 281 | if (ret != DVR_SUCCESS) { |
| 282 | DVR_DEBUG(1, "%s, open record devices failed", __func__); |
| 283 | return DVR_FAILURE; |
| 284 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | p_ctx->state = DVR_RECORD_STATE_OPENED; |
| 288 | |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 289 | *p_handle = p_ctx; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 290 | return DVR_SUCCESS; |
| 291 | } |
| 292 | |
| 293 | int dvr_record_close(DVR_RecordHandle_t handle) |
| 294 | { |
| 295 | DVR_RecordContext_t *p_ctx; |
| 296 | int ret; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 297 | uint32_t i; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 298 | |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 299 | p_ctx = (DVR_RecordContext_t *)handle; |
| 300 | for (i = 0; i < MAX_DVR_RECORD_SESSION_COUNT; i++) { |
| 301 | if (p_ctx == &record_ctx[i]) |
| 302 | break; |
| 303 | } |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 304 | DVR_RETURN_IF_FALSE(p_ctx == &record_ctx[i]); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 305 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 306 | DVR_DEBUG(1, "%s , current state:%d", __func__, p_ctx->state); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 307 | DVR_RETURN_IF_FALSE(p_ctx->state != DVR_RECORD_STATE_CLOSED); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 308 | |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 309 | if (p_ctx->is_vod) { |
| 310 | ret = DVR_SUCCESS; |
| 311 | } else { |
| 312 | ret = record_device_close(p_ctx->dev_handle); |
| 313 | if (ret != DVR_SUCCESS) { |
| 314 | DVR_DEBUG(1, "%s, failed", __func__); |
| 315 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 316 | } |
| 317 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 318 | p_ctx->state = DVR_RECORD_STATE_CLOSED; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 319 | return ret; |
| 320 | } |
| 321 | |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 322 | #if 0 |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 323 | int dvr_record_register_encryption(DVR_RecordHandle_t handle, |
| 324 | DVR_CryptoFunction_t cb, |
| 325 | DVR_CryptoParams_t params, |
| 326 | void *userdata) |
| 327 | { |
| 328 | return DVR_SUCCESS; |
| 329 | } |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 330 | #endif |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 331 | |
| 332 | int dvr_record_start_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params) |
| 333 | { |
| 334 | DVR_RecordContext_t *p_ctx; |
| 335 | Segment_OpenParams_t open_params; |
| 336 | int ret; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 337 | uint32_t i; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 338 | |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 339 | p_ctx = (DVR_RecordContext_t *)handle; |
| 340 | for (i = 0; i < MAX_DVR_RECORD_SESSION_COUNT; i++) { |
| 341 | if (p_ctx == &record_ctx[i]) |
| 342 | break; |
| 343 | } |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 344 | DVR_RETURN_IF_FALSE(p_ctx == &record_ctx[i]); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 345 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 346 | DVR_DEBUG(1, "%s , current state:%d", __func__, p_ctx->state); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 347 | DVR_RETURN_IF_FALSE(p_ctx->state != DVR_RECORD_STATE_STARTED); |
| 348 | DVR_RETURN_IF_FALSE(p_ctx->state != DVR_RECORD_STATE_CLOSED); |
| 349 | DVR_RETURN_IF_FALSE(params); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 350 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 351 | DVR_RETURN_IF_FALSE(strlen((const char *)params->location) < DVR_MAX_LOCATION_SIZE); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 352 | memset(&open_params, 0, sizeof(open_params)); |
| 353 | memcpy(open_params.location, params->location, strlen(params->location)); |
| 354 | open_params.segment_id = params->segment.segment_id; |
| 355 | open_params.mode = SEGMENT_MODE_WRITE; |
| 356 | |
| 357 | ret = segment_open(&open_params, &p_ctx->segment_handle); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 358 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 359 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 360 | /*process params*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 361 | { |
| 362 | memcpy(p_ctx->location, params->location, strlen(params->location)); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 363 | //need all params?? |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 364 | memcpy(&p_ctx->segment_params, ¶ms->segment, sizeof(params->segment)); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 365 | /*save current segment info*/ |
| 366 | memset(&p_ctx->segment_info, 0, sizeof(p_ctx->segment_info)); |
| 367 | p_ctx->segment_info.id = params->segment.segment_id; |
| 368 | p_ctx->segment_info.nb_pids = params->segment.nb_pids; |
| 369 | memcpy(p_ctx->segment_info.pids, params->segment.pids, params->segment.nb_pids*sizeof(DVR_StreamPid_t)); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 370 | } |
| 371 | |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 372 | if (!p_ctx->is_vod) { |
| 373 | /* normal dvr case */ |
| 374 | for (i = 0; i < params->segment.nb_pids; i++) { |
| 375 | ret = record_device_add_pid(p_ctx->dev_handle, params->segment.pids[i].pid); |
| 376 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
| 377 | } |
| 378 | ret = record_device_start(p_ctx->dev_handle); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 379 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 380 | } |
| 381 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 382 | p_ctx->state = DVR_RECORD_STATE_STARTED; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 383 | if (!p_ctx->is_vod) |
| 384 | pthread_create(&p_ctx->thread, NULL, record_thread, p_ctx); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 385 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 386 | return DVR_SUCCESS; |
| 387 | } |
| 388 | |
| 389 | int dvr_record_next_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, DVR_RecordSegmentInfo_t *p_info) |
| 390 | { |
| 391 | DVR_RecordContext_t *p_ctx; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 392 | Segment_OpenParams_t open_params; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 393 | int ret; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 394 | uint32_t i; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 395 | |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 396 | p_ctx = (DVR_RecordContext_t *)handle; |
| 397 | for (i = 0; i < MAX_DVR_RECORD_SESSION_COUNT; i++) { |
| 398 | if (p_ctx == &record_ctx[i]) |
| 399 | break; |
| 400 | } |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 401 | DVR_RETURN_IF_FALSE(p_ctx == &record_ctx[i]); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 402 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 403 | DVR_DEBUG(1, "%s , current state:%d", __func__, p_ctx->state); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 404 | DVR_RETURN_IF_FALSE(p_ctx->state == DVR_RECORD_STATE_STARTED); |
| 405 | //DVR_RETURN_IF_FALSE(p_ctx->state != DVR_RECORD_STATE_CLOSED); |
| 406 | DVR_RETURN_IF_FALSE(params); |
| 407 | DVR_RETURN_IF_FALSE(p_info); |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 408 | DVR_RETURN_IF_FALSE(!p_ctx->is_vod); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 409 | |
| 410 | /*Stop the on going record segment*/ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 411 | //ret = record_device_stop(p_ctx->dev_handle); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 412 | //DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 413 | |
| 414 | p_ctx->state = DVR_RECORD_STATE_STOPPED; |
| 415 | pthread_join(p_ctx->thread, NULL); |
| 416 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 417 | /*Update segment info*/ |
| 418 | memcpy(p_info, &p_ctx->segment_info, sizeof(p_ctx->segment_info)); |
| 419 | |
| 420 | ret = segment_store_info(p_ctx->segment_handle, p_info); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 421 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 422 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame^] | 423 | DVR_DEBUG(1, "%s dump segment info, id:%lld, nb_pids:%d, duration:%ld ms, size:%zu, nb_packets:%d params->segment.nb_pids:%d", |
| 424 | __func__, p_info->id, p_info->nb_pids, p_info->duration, p_info->size, p_info->nb_packets, params->segment.nb_pids); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 425 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 426 | /*Close current segment*/ |
| 427 | ret = segment_close(p_ctx->segment_handle); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 428 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 429 | /*Open the new record segment*/ |
| 430 | memset(&open_params, 0, sizeof(open_params)); |
| 431 | memcpy(open_params.location, p_ctx->location, strlen(p_ctx->location)); |
| 432 | open_params.segment_id = params->segment.segment_id; |
| 433 | open_params.mode = SEGMENT_MODE_WRITE; |
| 434 | |
| 435 | ret = segment_open(&open_params, &p_ctx->segment_handle); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 436 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 437 | /*process params*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 438 | { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 439 | //need all params?? |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 440 | memcpy(&p_ctx->segment_params, ¶ms->segment, sizeof(params->segment)); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 441 | /*save current segment info*/ |
| 442 | memset(&p_ctx->segment_info, 0, sizeof(p_ctx->segment_info)); |
| 443 | p_ctx->segment_info.id = params->segment.segment_id; |
| 444 | memcpy(p_ctx->segment_info.pids, params->segment.pids, params->segment.nb_pids*sizeof(DVR_StreamPid_t)); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 445 | } |
| 446 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 447 | p_ctx->segment_info.nb_pids = 0; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 448 | for (i = 0; i < params->segment.nb_pids; i++) { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 449 | switch (params->segment.pid_action[i]) { |
| 450 | case DVR_RECORD_PID_CREATE: |
| 451 | DVR_DEBUG(1, "%s create pid:%d", __func__, params->segment.pids[i].pid); |
| 452 | ret = record_device_add_pid(p_ctx->dev_handle, params->segment.pids[i].pid); |
| 453 | p_ctx->segment_info.nb_pids++; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 454 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 455 | break; |
| 456 | case DVR_RECORD_PID_KEEP: |
| 457 | DVR_DEBUG(1, "%s keep pid:%d", __func__, params->segment.pids[i].pid); |
| 458 | p_ctx->segment_info.nb_pids++; |
| 459 | break; |
| 460 | case DVR_RECORD_PID_CLOSE: |
| 461 | DVR_DEBUG(1, "%s close pid:%d", __func__, params->segment.pids[i].pid); |
| 462 | ret = record_device_remove_pid(p_ctx->dev_handle, params->segment.pids[i].pid); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 463 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 464 | break; |
| 465 | default: |
| 466 | DVR_DEBUG(1, "%s wrong action pid:%d", __func__, params->segment.pids[i].pid); |
| 467 | return DVR_FAILURE; |
| 468 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 469 | } |
| 470 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 471 | //ret = record_device_start(p_ctx->dev_handle); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 472 | //DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 473 | |
| 474 | pthread_create(&p_ctx->thread, NULL, record_thread, p_ctx); |
| 475 | p_ctx->state = DVR_RECORD_STATE_STARTED; |
| 476 | return DVR_SUCCESS; |
| 477 | } |
| 478 | |
| 479 | int dvr_record_stop_segment(DVR_RecordHandle_t handle, DVR_RecordSegmentInfo_t *p_info) |
| 480 | { |
| 481 | DVR_RecordContext_t *p_ctx; |
| 482 | int ret; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 483 | uint32_t i; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 484 | |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 485 | p_ctx = (DVR_RecordContext_t *)handle; |
| 486 | for (i = 0; i < MAX_DVR_RECORD_SESSION_COUNT; i++) { |
| 487 | if (p_ctx == &record_ctx[i]) |
| 488 | break; |
| 489 | } |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 490 | DVR_RETURN_IF_FALSE(p_ctx == &record_ctx[i]); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 491 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 492 | DVR_DEBUG(1, "%s , current state:%d", __func__, p_ctx->state); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 493 | DVR_RETURN_IF_FALSE(p_ctx->state != DVR_RECORD_STATE_STOPPED); |
| 494 | DVR_RETURN_IF_FALSE(p_ctx->state != DVR_RECORD_STATE_CLOSED); |
| 495 | DVR_RETURN_IF_FALSE(p_info); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 496 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 497 | p_ctx->state = DVR_RECORD_STATE_STOPPED; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 498 | if (p_ctx->is_vod) { |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 499 | p_ctx->segment_info.duration = segment_tell_total_time(p_ctx->segment_handle); |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 500 | p_ctx->segment_info.duration = 10*1000; //debug, should delete it |
| 501 | } else { |
| 502 | ret = record_device_stop(p_ctx->dev_handle); |
| 503 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
| 504 | //p_ctx->state = DVR_RECORD_STATE_STOPPED; |
| 505 | pthread_join(p_ctx->thread, NULL); |
| 506 | } |
| 507 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 508 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 509 | /*Update segment info*/ |
| 510 | memcpy(p_info, &p_ctx->segment_info, sizeof(p_ctx->segment_info)); |
| 511 | |
| 512 | ret = segment_store_info(p_ctx->segment_handle, p_info); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 513 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 514 | |
| 515 | DVR_DEBUG(1, "%s dump segment info, id:%lld, nb_pids:%d, duration:%ld ms, size:%zu, nb_packets:%d", |
| 516 | __func__, p_info->id, p_info->nb_pids, p_info->duration, p_info->size, p_info->nb_packets); |
| 517 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 518 | ret = segment_close(p_ctx->segment_handle); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 519 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 520 | return DVR_SUCCESS; |
| 521 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 522 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 523 | int dvr_record_resume_segment(DVR_RecordHandle_t handle, DVR_RecordStartParams_t *params, uint64_t *p_resume_size) |
| 524 | { |
| 525 | DVR_RecordContext_t *p_ctx; |
| 526 | uint32_t i; |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 527 | int ret; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 528 | |
| 529 | p_ctx = (DVR_RecordContext_t *)handle; |
| 530 | for (i = 0; i < MAX_DVR_RECORD_SESSION_COUNT; i++) { |
| 531 | if (p_ctx == &record_ctx[i]) |
| 532 | break; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 533 | } |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 534 | DVR_RETURN_IF_FALSE(p_ctx == &record_ctx[i]); |
| 535 | DVR_RETURN_IF_FALSE(params); |
| 536 | DVR_RETURN_IF_FALSE(p_resume_size); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 537 | |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 538 | DVR_DEBUG(1, "%s , current state:%d, resume size:%lld", __func__, p_ctx->state, *p_resume_size); |
| 539 | ret = dvr_record_start_segment(handle, params); |
| 540 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
| 541 | |
| 542 | p_ctx->segment_info.size = *p_resume_size; |
| 543 | |
| 544 | return DVR_SUCCESS; |
| 545 | } |
| 546 | |
| 547 | int dvr_record_get_status(DVR_RecordHandle_t handle, DVR_RecordStatus_t *p_status) |
| 548 | { |
| 549 | DVR_RecordContext_t *p_ctx; |
| 550 | int i; |
| 551 | |
| 552 | p_ctx = (DVR_RecordContext_t *)handle; |
| 553 | for (i = 0; i < MAX_DVR_RECORD_SESSION_COUNT; i++) { |
| 554 | if (p_ctx == &record_ctx[i]) |
| 555 | break; |
| 556 | } |
| 557 | DVR_RETURN_IF_FALSE(p_ctx == &record_ctx[i]); |
| 558 | DVR_RETURN_IF_FALSE(p_status); |
| 559 | |
| 560 | //lock |
| 561 | p_status->state = p_ctx->state; |
| 562 | p_status->info.id = p_ctx->segment_info.id; |
| 563 | p_status->info.duration = p_ctx->segment_info.duration; |
| 564 | p_status->info.size = p_ctx->segment_info.size; |
| 565 | p_status->info.nb_packets = p_ctx->segment_info.size/188; |
| 566 | |
| 567 | return DVR_SUCCESS; |
| 568 | } |
| 569 | |
| 570 | int dvr_record_write(DVR_RecordHandle_t handle, void *buffer, uint32_t len) |
| 571 | { |
| 572 | DVR_RecordContext_t *p_ctx; |
| 573 | uint32_t i; |
| 574 | off_t pos = 0; |
| 575 | int ret; |
| 576 | int has_pcr; |
| 577 | |
| 578 | p_ctx = (DVR_RecordContext_t *)handle; |
| 579 | for (i = 0; i < MAX_DVR_RECORD_SESSION_COUNT; i++) { |
| 580 | if (p_ctx == &record_ctx[i]) |
| 581 | break; |
| 582 | } |
| 583 | DVR_RETURN_IF_FALSE(p_ctx == &record_ctx[i]); |
| 584 | DVR_RETURN_IF_FALSE(buffer); |
| 585 | DVR_RETURN_IF_FALSE(len); |
| 586 | |
| 587 | pos = segment_tell_position(p_ctx->segment_handle); |
| 588 | has_pcr = record_do_pcr_index(p_ctx, buffer, len); |
| 589 | if (has_pcr == 0) { |
| 590 | /* Pull VOD record shoud use PCR time index */ |
| 591 | DVR_DEBUG(1, "%s has no pcr, can NOT do time index", __func__); |
| 592 | } |
| 593 | ret = segment_write(p_ctx->segment_handle, buffer, len); |
| 594 | p_ctx->segment_info.size += len; |
| 595 | p_ctx->segment_info.nb_packets = p_ctx->segment_info.size/188; |
| 596 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 597 | return DVR_SUCCESS; |
| 598 | } |