blob: cd3f16fe741a5f3e675d0c4e7d58ddb03aaea4bb [file] [log] [blame]
Pengfei Liuc181a982020-01-07 19:27:13 +08001#include <stdio.h>
Pengfei Liub038b6a2020-01-14 15:57:01 +08002#include <unistd.h>
Pengfei Liuc181a982020-01-07 19:27:13 +08003#include <sys/types.h>
4#include <sys/stat.h>
5#include <fcntl.h>
6#include <string.h>
Pengfei Liub038b6a2020-01-14 15:57:01 +08007#include <stdlib.h>
Pengfei Liuc181a982020-01-07 19:27:13 +08008#include <errno.h>
Pengfei Liu47ed6c92020-01-17 11:23:41 +08009#include "dvr_types.h"
Pengfei Liuc181a982020-01-07 19:27:13 +080010#include "segment.h"
11
12#define MAX_SEGMENT_FD_COUNT (128)
13#define MAX_SEGMENT_PATH_SIZE (DVR_MAX_LOCATION_SIZE + 32)
Pengfei Liub038b6a2020-01-14 15:57:01 +080014#define MAX_PTS_THRESHOLD (10*1000)
hualing chen06209692020-11-05 14:51:46 +080015#define PCR_RECORD_INTERVAL_MS (300)
hualing chen2932d372020-04-29 13:44:00 +080016#define PTS_DISCONTINE_DEVIATION (40)
17#define PTS_HEAD_DEVIATION (40)
18
19
Pengfei Liub4734232020-01-17 18:25:10 +080020/**\brief Segment context*/
Pengfei Liuc181a982020-01-07 19:27:13 +080021typedef struct {
Pengfei Liu3b1a8202020-02-12 23:04:21 +080022 int ts_fd; /**< Segment ts file fd*/
Pengfei Liub4734232020-01-17 18:25:10 +080023 FILE *index_fp; /**< Time index file fd*/
24 FILE *dat_fp; /**< Information file fd*/
pengfei.liu567d6d82020-04-17 16:48:59 +080025 FILE *ongoing_fp; /**< Ongoing file fd, used to verify timedhift mode*/
Pengfei Liub4734232020-01-17 18:25:10 +080026 uint64_t first_pts; /**< First pts value, use for write mode*/
pengfei.liu567d6d82020-04-17 16:48:59 +080027 uint64_t last_pts; /**< Last input pts value, use for write mode*/
28 uint64_t last_record_pts; /**< Last record pts value, use for write mode*/
pengfei.liuab5a2262020-02-14 17:33:40 +080029 uint64_t cur_time; /**< Current time save in index file */
pengfei.liu567d6d82020-04-17 16:48:59 +080030 uint64_t segment_id; /**< Current segment ID */
31 char location[MAX_SEGMENT_PATH_SIZE]; /**< Current time save in index file */
Pengfei Liuc181a982020-01-07 19:27:13 +080032} Segment_Context_t;
33
Pengfei Liub4734232020-01-17 18:25:10 +080034/**\brief Segment file type*/
Pengfei Liuc181a982020-01-07 19:27:13 +080035typedef enum {
Pengfei Liub4734232020-01-17 18:25:10 +080036 SEGMENT_FILE_TYPE_TS, /**< Used for store TS data*/
37 SEGMENT_FILE_TYPE_INDEX, /**< Used for store index data*/
38 SEGMENT_FILE_TYPE_DAT, /**< Used for store information data, such as duration etc*/
pengfei.liu567d6d82020-04-17 16:48:59 +080039 SEGMENT_FILE_TYPE_ONGOING, /**< Used for store information data, such as duration etc*/
Pengfei Liuc181a982020-01-07 19:27:13 +080040} Segment_FileType_t;
41
42static void segment_get_fname(char fname[MAX_SEGMENT_PATH_SIZE],
Pengfei Liub4734232020-01-17 18:25:10 +080043 const char location[DVR_MAX_LOCATION_SIZE],
Pengfei Liuc181a982020-01-07 19:27:13 +080044 uint64_t segment_id,
45 Segment_FileType_t type)
46{
47 int offset;
48
49 memset(fname, 0, MAX_SEGMENT_PATH_SIZE);
50 strncpy(fname, location, strlen(location));
51 offset = strlen(location);
52 strncpy(fname + offset, "-", 1);
53 offset += 1;
54 sprintf(fname + offset, "%04llu", segment_id);
55 offset += 4;
56 if (type == SEGMENT_FILE_TYPE_TS)
57 strncpy(fname + offset, ".ts", 3);
58 else if (type == SEGMENT_FILE_TYPE_INDEX)
59 strncpy(fname + offset, ".idx", 4);
Pengfei Liub4734232020-01-17 18:25:10 +080060 else if (type == SEGMENT_FILE_TYPE_DAT)
61 strncpy(fname + offset, ".dat", 4);
hualing chen87072a82020-03-12 16:20:12 +080062 else if (type == SEGMENT_FILE_TYPE_ONGOING)
63 strncpy(fname + offset, ".going", 6);
Pengfei Liuc181a982020-01-07 19:27:13 +080064}
65
Pengfei Liu3b1a8202020-02-12 23:04:21 +080066static void segment_get_dirname(char dir_name[MAX_SEGMENT_PATH_SIZE],
67 const char location[DVR_MAX_LOCATION_SIZE])
68{
69 char *p;
70 int i;
71 int found = 0;
72
73 for (i = 0; i < (int)strlen(location); i++) {
74 if (location[i] == '/') {
75 p = (char *)location + i;
76 found = 1;
77 }
78 }
79 if (found)
80 memcpy(dir_name, location, p - location);
81}
82
Pengfei Liuc181a982020-01-07 19:27:13 +080083int segment_open(Segment_OpenParams_t *params, Segment_Handle_t *p_handle)
84{
85 Segment_Context_t *p_ctx;
86 char ts_fname[MAX_SEGMENT_PATH_SIZE];
87 char index_fname[MAX_SEGMENT_PATH_SIZE];
Pengfei Liub4734232020-01-17 18:25:10 +080088 char dat_fname[MAX_SEGMENT_PATH_SIZE];
Pengfei Liu3b1a8202020-02-12 23:04:21 +080089 char dir_name[MAX_SEGMENT_PATH_SIZE];
hualing chen87072a82020-03-12 16:20:12 +080090 char going_name[MAX_SEGMENT_PATH_SIZE];
Pengfei Liuc181a982020-01-07 19:27:13 +080091
Pengfei Liu3b1a8202020-02-12 23:04:21 +080092 DVR_RETURN_IF_FALSE(params);
93 DVR_RETURN_IF_FALSE(p_handle);
Pengfei Liuc181a982020-01-07 19:27:13 +080094
hualing chena540a7e2020-03-27 16:44:05 +080095 //DVR_DEBUG(1, "%s, location:%s, id:%llu", __func__, params->location, params->segment_id);
Pengfei Liuc181a982020-01-07 19:27:13 +080096
Pengfei Liub038b6a2020-01-14 15:57:01 +080097 p_ctx = (void*)malloc(sizeof(Segment_Context_t));
Pengfei Liu3b1a8202020-02-12 23:04:21 +080098 DVR_RETURN_IF_FALSE(p_ctx);
Pengfei Liub4734232020-01-17 18:25:10 +080099 memset(p_ctx, 0, sizeof(Segment_Context_t));
Pengfei Liuc181a982020-01-07 19:27:13 +0800100
101 memset(ts_fname, 0, sizeof(ts_fname));
102 segment_get_fname(ts_fname, params->location, params->segment_id, SEGMENT_FILE_TYPE_TS);
103
104 memset(index_fname, 0, sizeof(index_fname));
105 segment_get_fname(index_fname, params->location, params->segment_id, SEGMENT_FILE_TYPE_INDEX);
106
Pengfei Liub4734232020-01-17 18:25:10 +0800107 memset(dat_fname, 0, sizeof(dat_fname));
108 segment_get_fname(dat_fname, params->location, params->segment_id, SEGMENT_FILE_TYPE_DAT);
109
hualing chen87072a82020-03-12 16:20:12 +0800110 memset(going_name, 0, sizeof(going_name));
111 segment_get_fname(going_name, params->location, params->segment_id, SEGMENT_FILE_TYPE_ONGOING);
112
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800113 memset(dir_name, 0, sizeof(dir_name));
114 segment_get_dirname(dir_name, params->location);
115 if (access(dir_name, F_OK) == -1) {
116 DVR_DEBUG(1, "%s dir %s is not exist, create it", __func__, dir_name);
117 mkdir(dir_name, 0666);
118 }
119
Pengfei Liuc181a982020-01-07 19:27:13 +0800120 if (params->mode == SEGMENT_MODE_READ) {
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800121 p_ctx->ts_fd = open(ts_fname, O_RDONLY);
Pengfei Liuc181a982020-01-07 19:27:13 +0800122 p_ctx->index_fp = fopen(index_fname, "r");
Pengfei Liub4734232020-01-17 18:25:10 +0800123 p_ctx->dat_fp = fopen(dat_fname, "r");
hualing chen87072a82020-03-12 16:20:12 +0800124 p_ctx->ongoing_fp = NULL;
Pengfei Liuc181a982020-01-07 19:27:13 +0800125 } else if (params->mode == SEGMENT_MODE_WRITE) {
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800126 p_ctx->ts_fd = open(ts_fname, O_CREAT | O_RDWR | O_TRUNC, 0644);
Pengfei Liuc181a982020-01-07 19:27:13 +0800127 p_ctx->index_fp = fopen(index_fname, "w+");
Pengfei Liub4734232020-01-17 18:25:10 +0800128 p_ctx->dat_fp = fopen(dat_fname, "w+");
hualing chen87072a82020-03-12 16:20:12 +0800129 p_ctx->ongoing_fp = fopen(going_name, "w+");
Pengfei Liub038b6a2020-01-14 15:57:01 +0800130 p_ctx->first_pts = ULLONG_MAX;
131 p_ctx->last_pts = ULLONG_MAX;
pengfei.liu567d6d82020-04-17 16:48:59 +0800132 p_ctx->last_record_pts = ULLONG_MAX;
Pengfei Liuc181a982020-01-07 19:27:13 +0800133 } else {
134 DVR_DEBUG(1, "%s, unknow mode use default", __func__);
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800135 p_ctx->ts_fd = open(ts_fname, O_RDONLY);
Pengfei Liuc181a982020-01-07 19:27:13 +0800136 p_ctx->index_fp = fopen(index_fname, "r");
Pengfei Liub4734232020-01-17 18:25:10 +0800137 p_ctx->dat_fp = fopen(dat_fname, "r");
hualing chen87072a82020-03-12 16:20:12 +0800138 p_ctx->ongoing_fp = NULL;
Pengfei Liuc181a982020-01-07 19:27:13 +0800139 }
140
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800141 if (p_ctx->ts_fd == -1 || !p_ctx->index_fp || !p_ctx->dat_fp) {
Pengfei Liub4734232020-01-17 18:25:10 +0800142 DVR_DEBUG(1, "%s open file failed [%s, %s, %s], reason:%s", __func__,
143 ts_fname, index_fname, dat_fname, strerror(errno));
Zhiqiang Han5c805cf2020-05-09 16:51:08 +0800144 if (p_ctx->ts_fd != -1)
145 close(p_ctx->ts_fd);
146 if (p_ctx->index_fp)
147 fclose(p_ctx->index_fp);
148 if (p_ctx->dat_fp)
149 fclose(p_ctx->dat_fp);
150 if (p_ctx->ongoing_fp)
151 fclose(p_ctx->ongoing_fp);
Pengfei Liuc181a982020-01-07 19:27:13 +0800152 free(p_ctx);
Pengfei Liub038b6a2020-01-14 15:57:01 +0800153 *p_handle = NULL;
Pengfei Liuc181a982020-01-07 19:27:13 +0800154 return DVR_FAILURE;
155 }
hualing chen87072a82020-03-12 16:20:12 +0800156 p_ctx->segment_id = params->segment_id;
157 strncpy(p_ctx->location, params->location, strlen(params->location));
Pengfei Liub4734232020-01-17 18:25:10 +0800158
hualing chen7a56cba2020-04-14 14:09:27 +0800159 //DVR_DEBUG(1, "%s, open file success p_ctx->location [%s]", __func__, p_ctx->location, params->mode);
Pengfei Liub038b6a2020-01-14 15:57:01 +0800160 *p_handle = (Segment_Handle_t)p_ctx;
Pengfei Liuc181a982020-01-07 19:27:13 +0800161 return DVR_SUCCESS;
162}
163
164int segment_close(Segment_Handle_t handle)
165{
166 Segment_Context_t *p_ctx;
167
Pengfei Liub038b6a2020-01-14 15:57:01 +0800168 p_ctx = (void *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800169 DVR_RETURN_IF_FALSE(p_ctx);
Pengfei Liuc181a982020-01-07 19:27:13 +0800170
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800171 if (p_ctx->ts_fd != -1) {
172 close(p_ctx->ts_fd);
Pengfei Liuc181a982020-01-07 19:27:13 +0800173 }
174
175 if (p_ctx->index_fp) {
176 fclose(p_ctx->index_fp);
177 }
178
Pengfei Liub4734232020-01-17 18:25:10 +0800179 if (p_ctx->dat_fp) {
180 fclose(p_ctx->dat_fp);
181 }
182
hualing chen87072a82020-03-12 16:20:12 +0800183 if (p_ctx->ongoing_fp != NULL) {
184 fclose(p_ctx->ongoing_fp);
185 char going_name[MAX_SEGMENT_PATH_SIZE];
186 memset(going_name, 0, sizeof(going_name));
187 segment_get_fname(going_name, p_ctx->location, p_ctx->segment_id, SEGMENT_FILE_TYPE_ONGOING);
188 DVR_DEBUG(1, "segment close del [%s]", going_name);
189 unlink(going_name);
190 }
191
Pengfei Liuc181a982020-01-07 19:27:13 +0800192 free(p_ctx);
193 return 0;
194}
195
196ssize_t segment_read(Segment_Handle_t handle, void *buf, size_t count)
197{
198 Segment_Context_t *p_ctx;
199
200 p_ctx = (Segment_Context_t *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800201 DVR_RETURN_IF_FALSE(p_ctx);
202 DVR_RETURN_IF_FALSE(buf);
203 DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1);
Pengfei Liuc181a982020-01-07 19:27:13 +0800204
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800205 return read(p_ctx->ts_fd, buf, count);
Pengfei Liuc181a982020-01-07 19:27:13 +0800206}
207
208ssize_t segment_write(Segment_Handle_t handle, void *buf, size_t count)
209{
210 Segment_Context_t *p_ctx;
Chuanzhi Wangccecb8d2020-12-02 11:22:54 +0800211 ssize_t len;
Pengfei Liuc181a982020-01-07 19:27:13 +0800212 p_ctx = (Segment_Context_t *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800213 DVR_RETURN_IF_FALSE(p_ctx);
214 DVR_RETURN_IF_FALSE(buf);
215 DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1);
Chuanzhi Wangccecb8d2020-12-02 11:22:54 +0800216 len = write(p_ctx->ts_fd, buf, count);
217 fsync(p_ctx->ts_fd);
218 return len;
Pengfei Liuc181a982020-01-07 19:27:13 +0800219}
220
hualing chen2932d372020-04-29 13:44:00 +0800221int segment_update_pts_force(Segment_Handle_t handle, uint64_t pts, loff_t offset)
Pengfei Liuc181a982020-01-07 19:27:13 +0800222{
223 Segment_Context_t *p_ctx;
224 char buf[256];
pengfei.liu567d6d82020-04-17 16:48:59 +0800225 int record_diff = 0;
Pengfei Liuc181a982020-01-07 19:27:13 +0800226
227 p_ctx = (Segment_Context_t *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800228 DVR_RETURN_IF_FALSE(p_ctx);
229 DVR_RETURN_IF_FALSE(p_ctx->index_fp);
Pengfei Liuc181a982020-01-07 19:27:13 +0800230
Pengfei Liub038b6a2020-01-14 15:57:01 +0800231 if (p_ctx->first_pts == ULLONG_MAX) {
pengfei.liuab5a2262020-02-14 17:33:40 +0800232 DVR_DEBUG(1, "%s first pcr:%llu", __func__, pts);
Pengfei Liub038b6a2020-01-14 15:57:01 +0800233 p_ctx->first_pts = pts;
234 }
Pengfei Liuc181a982020-01-07 19:27:13 +0800235 memset(buf, 0, sizeof(buf));
Pengfei Liub038b6a2020-01-14 15:57:01 +0800236 if (p_ctx->last_pts == ULLONG_MAX) {
237 /*Last pts is init value*/
hualing chen2aba4022020-03-02 13:49:55 +0800238 sprintf(buf, "{time=%llu, offset=%lld}", pts - p_ctx->first_pts, offset);
pengfei.liuab5a2262020-02-14 17:33:40 +0800239 p_ctx->cur_time = pts - p_ctx->first_pts;
hualing chen2932d372020-04-29 13:44:00 +0800240 DVR_DEBUG(1, "%s force pcr:%llu -1", __func__, pts);
241 } else {
242 /*Last pts has valid value*/
243 int diff = pts - p_ctx->last_pts;
244 if ((diff > MAX_PTS_THRESHOLD) || (diff < 0)) {
245 /*Current pts has a transition*/
246 DVR_DEBUG(1, "[%s]force update Current pts has a transition, [%llu, %llu, %llu]",__func__,
247 p_ctx->first_pts, p_ctx->last_pts, pts);
248 sprintf(buf, "\n{time=%llu, offset=%lld}", p_ctx->cur_time, offset);
249 } else {
250 /*This is a normal pts, record it*/
251 p_ctx->cur_time += diff;
252 DVR_DEBUG(1, "%s force pcr:%llu -1 diff [%d]", __func__, pts, diff);
253 sprintf(buf, "\n{time=%llu, offset=%lld}", p_ctx->cur_time, offset);
254 }
255 }
256
257 record_diff = pts - p_ctx->last_record_pts;
258 if (strlen(buf) > 0) {
259 DVR_DEBUG(1, "%s force pcr:%llu buf:%s", __func__, pts, buf);
260 fputs(buf, p_ctx->index_fp);
261 fflush(p_ctx->index_fp);
262 fsync(fileno(p_ctx->index_fp));
263 p_ctx->last_record_pts = pts;
264 }
265 p_ctx->last_pts = pts;
266
267 return DVR_SUCCESS;
268}
269
270int segment_update_pts(Segment_Handle_t handle, uint64_t pts, loff_t offset)
271{
272 Segment_Context_t *p_ctx;
273 char buf[256];
274 int record_diff = 0;
275
276 p_ctx = (Segment_Context_t *)handle;
277 DVR_RETURN_IF_FALSE(p_ctx);
278 DVR_RETURN_IF_FALSE(p_ctx->index_fp);
279
280 if (p_ctx->first_pts == ULLONG_MAX) {
281 DVR_DEBUG(1, "%s first pcr:%llu", __func__, pts);
282 p_ctx->first_pts = pts;
283 //p_ctx->cur_time = p_ctx->cur_time + PTS_HEAD_DEVIATION;
284 }
285 memset(buf, 0, sizeof(buf));
286 if (p_ctx->last_pts == ULLONG_MAX) {
287 /*Last pts is init value*/
288 sprintf(buf, "{time=%llu, offset=%lld}", pts - p_ctx->first_pts, offset);
289 p_ctx->cur_time = pts - p_ctx->first_pts;
Pengfei Liub038b6a2020-01-14 15:57:01 +0800290 } else {
291 /*Last pts has valid value*/
pengfei.liu567d6d82020-04-17 16:48:59 +0800292 int diff = pts - p_ctx->last_pts;
hualing chen4b7c15d2020-04-07 16:13:48 +0800293 if ((diff > MAX_PTS_THRESHOLD) || (diff < 0)) {
Pengfei Liub038b6a2020-01-14 15:57:01 +0800294 /*Current pts has a transition*/
pengfei.liuab5a2262020-02-14 17:33:40 +0800295 DVR_DEBUG(1, "Current pts has a transition, [%llu, %llu, %llu]",
296 p_ctx->first_pts, p_ctx->last_pts, pts);
pengfei.liu567d6d82020-04-17 16:48:59 +0800297 p_ctx->last_record_pts = pts;
hualing chen2932d372020-04-29 13:44:00 +0800298 //p_ctx->cur_time = p_ctx->cur_time + PTS_DISCONTINE_DEVIATION;
Pengfei Liub038b6a2020-01-14 15:57:01 +0800299 } else {
300 /*This is a normal pts, record it*/
hualing chen4b7c15d2020-04-07 16:13:48 +0800301 p_ctx->cur_time += diff;
hualing chen2aba4022020-03-02 13:49:55 +0800302 sprintf(buf, "\n{time=%llu, offset=%lld}", p_ctx->cur_time, offset);
Pengfei Liub038b6a2020-01-14 15:57:01 +0800303 }
304 }
pengfei.liu567d6d82020-04-17 16:48:59 +0800305
306 record_diff = pts - p_ctx->last_record_pts;
307 if (strlen(buf) > 0 &&
308 (record_diff > PCR_RECORD_INTERVAL_MS || p_ctx->last_record_pts == ULLONG_MAX)){
hualing chen4b7c15d2020-04-07 16:13:48 +0800309 fputs(buf, p_ctx->index_fp);
pengfei.liu567d6d82020-04-17 16:48:59 +0800310 fflush(p_ctx->index_fp);
hualing chen47c34bc2020-05-11 09:15:47 +0800311 fsync(fileno(p_ctx->index_fp));
pengfei.liu567d6d82020-04-17 16:48:59 +0800312 p_ctx->last_record_pts = pts;
313 }
Pengfei Liub038b6a2020-01-14 15:57:01 +0800314 p_ctx->last_pts = pts;
Pengfei Liub4734232020-01-17 18:25:10 +0800315
Pengfei Liuc181a982020-01-07 19:27:13 +0800316 return DVR_SUCCESS;
317}
318
hualing chen266b9502020-04-04 17:39:39 +0800319loff_t segment_seek(Segment_Handle_t handle, uint64_t time, int block_size)
Pengfei Liuc181a982020-01-07 19:27:13 +0800320{
321 Segment_Context_t *p_ctx;
322 char buf[256];
323 char value[256];
hualing chen2aba4022020-03-02 13:49:55 +0800324 uint64_t pts = 0L;
325 loff_t offset = 0;
Pengfei Liuc181a982020-01-07 19:27:13 +0800326 char *p1, *p2;
327
328 p_ctx = (Segment_Context_t *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800329 DVR_RETURN_IF_FALSE(p_ctx);
330 DVR_RETURN_IF_FALSE(p_ctx->index_fp);
331 DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1);
Pengfei Liuc181a982020-01-07 19:27:13 +0800332
hualing chen266b9502020-04-04 17:39:39 +0800333 if (time == 0) {
334 offset = 0;
hualing chen92f3a142020-07-08 20:59:33 +0800335 //DVR_DEBUG(1, "seek time=%llu, offset=%lld time--%llu\n", pts, offset, time);
hualing chen266b9502020-04-04 17:39:39 +0800336 DVR_RETURN_IF_FALSE(lseek64(p_ctx->ts_fd, offset, SEEK_SET) != -1);
337 return offset;
338 }
339
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800340 memset(buf, 0, sizeof(buf));
341 DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, 0, SEEK_SET) != -1);
hualing chen2aba4022020-03-02 13:49:55 +0800342 int line = 0;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800343 while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) {
hualing chen2aba4022020-03-02 13:49:55 +0800344 line++;
Pengfei Liuc181a982020-01-07 19:27:13 +0800345 memset(value, 0, sizeof(value));
Pengfei Liub038b6a2020-01-14 15:57:01 +0800346 if ((p1 = strstr(buf, "time="))) {
hualing chencc91e1c2020-02-28 13:26:17 +0800347 p1 += 5;
Pengfei Liuc181a982020-01-07 19:27:13 +0800348 if ((p2 = strstr(buf, ","))) {
349 memcpy(value, p1, p2 - p1);
350 }
351 pts = strtoull(value, NULL, 10);
352 }
353
354 memset(value, 0, sizeof(value));
355 if ((p1 = strstr(buf, "offset="))) {
356 p1 += 7;
357 if ((p2 = strstr(buf, "}"))) {
358 memcpy(value, p1, p2 - p1);
359 }
360 offset = strtoull(value, NULL, 10);
361 }
hualing chen2aba4022020-03-02 13:49:55 +0800362 if (0)
363 {
364 DVR_DEBUG(1, "seek buf[%s]", buf);
365 DVR_DEBUG(1, "seek time=%llu, offset=%lld\n", pts, offset);
366 }
Pengfei Liuc181a982020-01-07 19:27:13 +0800367 memset(buf, 0, sizeof(buf));
hualing chencc91e1c2020-02-28 13:26:17 +0800368 //DVR_DEBUG(1, "seek time=%llu, offset=%lld\n", pts, offset);
369 if (time <= pts) {
hualing chen266b9502020-04-04 17:39:39 +0800370 if (block_size > 0) {
371 offset = offset - offset%block_size;
372 }
hualing chen2aba4022020-03-02 13:49:55 +0800373 DVR_DEBUG(1, "seek time=%llu, offset=%lld time--%llu line %d\n", pts, offset, time, line);
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800374 DVR_RETURN_IF_FALSE(lseek64(p_ctx->ts_fd, offset, SEEK_SET) != -1);
Pengfei Liuc181a982020-01-07 19:27:13 +0800375 return offset;
376 }
hualing chen2aba4022020-03-02 13:49:55 +0800377 }
hualing chen2932d372020-04-29 13:44:00 +0800378 if (time > pts) {
379 if (block_size > 0) {
380 offset = offset - offset%block_size;
381 }
382 DVR_DEBUG(1, "seek time=%llu, offset=%lld time--%llu line %d end\n", pts, offset, time, line);
383 DVR_RETURN_IF_FALSE(lseek64(p_ctx->ts_fd, offset, SEEK_SET) != -1);
384 return offset;
385 }
hualing chen2aba4022020-03-02 13:49:55 +0800386 DVR_DEBUG(1, "seek error line [%d]", line);
Pengfei Liuc181a982020-01-07 19:27:13 +0800387 return DVR_FAILURE;
388}
389
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800390loff_t segment_tell_position(Segment_Handle_t handle)
Pengfei Liuc181a982020-01-07 19:27:13 +0800391{
392 Segment_Context_t *p_ctx;
393
394 p_ctx = (Segment_Context_t *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800395 DVR_RETURN_IF_FALSE(p_ctx);
396 DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1);
Pengfei Liuc181a982020-01-07 19:27:13 +0800397
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800398 return lseek64(p_ctx->ts_fd, 0, SEEK_CUR);
399}
400
hualing chen5605eed2020-05-26 18:18:06 +0800401uint64_t segment_tell_position_time(Segment_Handle_t handle, loff_t position)
402{
403 Segment_Context_t *p_ctx;
404 char buf[256];
405 char value[256];
406 uint64_t pts = 0L;
407 loff_t offset = 0;
408 char *p1, *p2;
409
410 p_ctx = (Segment_Context_t *)handle;
411 DVR_RETURN_IF_FALSE(p_ctx);
412 DVR_RETURN_IF_FALSE(p_ctx->index_fp);
413 DVR_RETURN_IF_FALSE(p_ctx->ts_fd);
414
415 memset(buf, 0, sizeof(buf));
416 DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, 0, SEEK_SET) != -1);
417 DVR_RETURN_IF_FALSE(position != -1);
418
419 while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) {
420 memset(value, 0, sizeof(value));
421 if ((p1 = strstr(buf, "time="))) {
422 p1 += 5;
423 if ((p2 = strstr(buf, ","))) {
424 memcpy(value, p1, p2 - p1);
425 }
426 pts = strtoull(value, NULL, 10);
427 }
428
429 memset(value, 0, sizeof(value));
430 if ((p1 = strstr(buf, "offset="))) {
431 p1 += 7;
432 if ((p2 = strstr(buf, "}"))) {
433 memcpy(value, p1, p2 - p1);
434 }
435 offset = strtoull(value, NULL, 10);
436 }
437
438 memset(buf, 0, sizeof(buf));
439 //DVR_DEBUG(1, "tell cur time=%llu, offset=%lld, position=%lld\n", pts, offset, position);
440 if (position <= offset) {
441 return pts;
442 }
443 }
444 //DVR_DEBUG(1, "tell cur time=%llu, offset=%lld, position=%lld\n", pts, offset, position);
445 return pts;
446}
447
448
pengfei.liu8b563292020-02-26 15:49:02 +0800449uint64_t segment_tell_current_time(Segment_Handle_t handle)
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800450{
451 Segment_Context_t *p_ctx;
452 char buf[256];
453 char value[256];
hualing chen2aba4022020-03-02 13:49:55 +0800454 uint64_t pts = 0L;
455 loff_t offset = 0, position = 0;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800456 char *p1, *p2;
457
458 p_ctx = (Segment_Context_t *)handle;
459 DVR_RETURN_IF_FALSE(p_ctx);
460 DVR_RETURN_IF_FALSE(p_ctx->index_fp);
461 DVR_RETURN_IF_FALSE(p_ctx->ts_fd);
462
463 memset(buf, 0, sizeof(buf));
464 DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, 0, SEEK_SET) != -1);
465 position = lseek64(p_ctx->ts_fd, 0, SEEK_CUR);
466 DVR_RETURN_IF_FALSE(position != -1);
467
468 while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) {
469 memset(value, 0, sizeof(value));
470 if ((p1 = strstr(buf, "time="))) {
hualing chencc91e1c2020-02-28 13:26:17 +0800471 p1 += 5;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800472 if ((p2 = strstr(buf, ","))) {
473 memcpy(value, p1, p2 - p1);
474 }
475 pts = strtoull(value, NULL, 10);
476 }
477
478 memset(value, 0, sizeof(value));
479 if ((p1 = strstr(buf, "offset="))) {
480 p1 += 7;
481 if ((p2 = strstr(buf, "}"))) {
482 memcpy(value, p1, p2 - p1);
483 }
484 offset = strtoull(value, NULL, 10);
485 }
486
487 memset(buf, 0, sizeof(buf));
hualing chencc91e1c2020-02-28 13:26:17 +0800488 //DVR_DEBUG(1, "tell cur time=%llu, offset=%lld, position=%lld\n", pts, offset, position);
hualing chen2aba4022020-03-02 13:49:55 +0800489 if (position <= offset) {
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800490 return pts;
491 }
492 }
hualing chena540a7e2020-03-27 16:44:05 +0800493 //DVR_DEBUG(1, "tell cur time=%llu, offset=%lld, position=%lld\n", pts, offset, position);
hualing chen2aba4022020-03-02 13:49:55 +0800494 return pts;
Pengfei Liuc181a982020-01-07 19:27:13 +0800495}
Pengfei Liub038b6a2020-01-14 15:57:01 +0800496
pengfei.liu8b563292020-02-26 15:49:02 +0800497uint64_t segment_tell_total_time(Segment_Handle_t handle)
498{
499 Segment_Context_t *p_ctx;
500 char buf[256];
501 char last_buf[256];
502 char value[256];
503 uint64_t pts = ULLONG_MAX;
504 loff_t offset = 0, position = 0;
505 char *p1, *p2;
506 int line = 0;
507
508 p_ctx = (Segment_Context_t *)handle;
509 DVR_RETURN_IF_FALSE(p_ctx);
510 DVR_RETURN_IF_FALSE(p_ctx->index_fp);
511 DVR_RETURN_IF_FALSE(p_ctx->ts_fd);
512
513 memset(buf, 0, sizeof(buf));
514 memset(last_buf, 0, sizeof(last_buf));
515 position = lseek64(p_ctx->ts_fd, 0, SEEK_CUR);
516 DVR_RETURN_IF_FALSE(position != -1);
517
hualing chen041c4092020-04-05 15:11:50 +0800518 //DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, -1000L, SEEK_END) != -1);
519 //if seek error.we need seek 0 pos.
520 if (fseek(p_ctx->index_fp, -1000L, SEEK_END) == -1) {
521 fseek(p_ctx->index_fp, 0L, SEEK_SET);
522 }
pengfei.liu8b563292020-02-26 15:49:02 +0800523 /* Save last line buffer */
524 while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) {
hualing chen2aba4022020-03-02 13:49:55 +0800525 if (strlen(buf) <= 0) {
hualing chen87072a82020-03-12 16:20:12 +0800526 DVR_DEBUG(1, "read index buf is len 0");
hualing chen2aba4022020-03-02 13:49:55 +0800527 continue;
528 }
pengfei.liu8b563292020-02-26 15:49:02 +0800529 memset(last_buf, 0, sizeof(last_buf));
530 memcpy(last_buf, buf, strlen(buf));
531 memset(buf, 0, sizeof(buf));
532 line++;
533 }
534
535 /* Extract time value */
536 memset(value, 0, sizeof(value));
537 if ((p1 = strstr(last_buf, "time="))) {
538 p1 += 5;
539 if ((p2 = strstr(last_buf, ","))) {
540 memcpy(value, p1, p2 - p1);
541 }
542 pts = strtoull(value, NULL, 10);
543 }
544
545 memset(value, 0, sizeof(value));
546 if ((p1 = strstr(last_buf, "offset="))) {
547 p1 += 7;
548 if ((p2 = strstr(last_buf, "}"))) {
549 memcpy(value, p1, p2 - p1);
550 }
551 offset = strtoull(value, NULL, 10);
552 }
hualing chen87072a82020-03-12 16:20:12 +0800553 //if (line < 2)
554 //DVR_DEBUG(1, "totle time=%llu, offset=%lld, position=%lld, line:%d\n", pts, offset, position, line);
pengfei.liu8b563292020-02-26 15:49:02 +0800555 return (pts == ULLONG_MAX ? DVR_FAILURE : pts);
556}
557
pengfei.liuab5a2262020-02-14 17:33:40 +0800558/* Should consider the case of cut power, todo... */
Pengfei Liub4734232020-01-17 18:25:10 +0800559int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info)
560{
561 Segment_Context_t *p_ctx;
562 char buf[256];
563 uint32_t i;
564
565 p_ctx = (Segment_Context_t *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800566 DVR_RETURN_IF_FALSE(p_ctx);
567 DVR_RETURN_IF_FALSE(p_ctx->dat_fp);
568 DVR_RETURN_IF_FALSE(p_info);
hualing chen87072a82020-03-12 16:20:12 +0800569 //seek 0, rewrite info
570 DVR_RETURN_IF_FALSE(fseek(p_ctx->dat_fp, 0, SEEK_SET) != -1);
Pengfei Liub4734232020-01-17 18:25:10 +0800571
572 /*Save segment id*/
573 memset(buf, 0, sizeof(buf));
574 sprintf(buf, "id=%lld\n", p_info->id);
575 fputs(buf, p_ctx->dat_fp);
576
577 /*Save number of pids*/
578 memset(buf, 0, sizeof(buf));
579 sprintf(buf, "nb_pids=%d\n", p_info->nb_pids);
580 fputs(buf, p_ctx->dat_fp);
581
582 /*Save pid information*/
583 for (i = 0; i < p_info->nb_pids; i++) {
584 memset(buf, 0, sizeof(buf));
585 sprintf(buf, "{pid=%d, type=%d}\n", p_info->pids[i].pid, p_info->pids[i].type);
586 fputs(buf, p_ctx->dat_fp);
587 }
588
589 /*Save segment duration*/
590 memset(buf, 0, sizeof(buf));
hualing chen87072a82020-03-12 16:20:12 +0800591 DVR_DEBUG(1, "duration store:[%ld]", p_info->duration);
Pengfei Liub4734232020-01-17 18:25:10 +0800592 sprintf(buf, "duration=%ld\n", p_info->duration);
593 fputs(buf, p_ctx->dat_fp);
594
595 /*Save segment size*/
596 memset(buf, 0, sizeof(buf));
597 sprintf(buf, "size=%zu\n", p_info->size);
598 fputs(buf, p_ctx->dat_fp);
599
600 /*Save number of packets*/
601 memset(buf, 0, sizeof(buf));
602 sprintf(buf, "nb_packets=%d\n", p_info->nb_packets);
603 fputs(buf, p_ctx->dat_fp);
604
605 fflush(p_ctx->dat_fp);
hualing chen47c34bc2020-05-11 09:15:47 +0800606 fsync(fileno(p_ctx->dat_fp));
Pengfei Liub4734232020-01-17 18:25:10 +0800607 return DVR_SUCCESS;
608}
609
pengfei.liuab5a2262020-02-14 17:33:40 +0800610/* Should consider the case of cut power, todo... */
Pengfei Liub4734232020-01-17 18:25:10 +0800611int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info)
612{
613 Segment_Context_t *p_ctx;
614 uint32_t i;
615 char buf[256];
616 char value[256];
617 char *p1, *p2;
618
619 p_ctx = (Segment_Context_t *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800620 DVR_RETURN_IF_FALSE(p_ctx);
621 DVR_RETURN_IF_FALSE(p_info);
Pengfei Liub4734232020-01-17 18:25:10 +0800622
623 /*Load segment id*/
624 p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp);
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800625 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800626 p1 = strstr(buf, "id=");
hualing chen2aba4022020-03-02 13:49:55 +0800627 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800628 p_info->id = strtoull(p1 + 3, NULL, 10);
629
630 /*Save number of pids*/
631 p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp);
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800632 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800633 p1 = strstr(buf, "nb_pids=");
hualing chen2aba4022020-03-02 13:49:55 +0800634 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800635 p_info->nb_pids = strtoull(p1 + 8, NULL, 10);
636
637 /*Save pid information*/
638 for (i = 0; i < p_info->nb_pids; i++) {
639 p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp);
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800640 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800641 memset(value, 0, sizeof(value));
642 if ((p1 = strstr(buf, "pid="))) {
hualing chen2aba4022020-03-02 13:49:55 +0800643 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800644 p1 += 4;
645 if ((p2 = strstr(buf, ","))) {
hualing chen2aba4022020-03-02 13:49:55 +0800646 DVR_RETURN_IF_FALSE(p2);
Pengfei Liub4734232020-01-17 18:25:10 +0800647 memcpy(value, p1, p2 - p1);
648 }
649 p_info->pids[i].pid = strtoull(value, NULL, 10);
650 }
651
652 memset(value, 0, sizeof(value));
653 if ((p1 = strstr(buf, "type="))) {
hualing chen2aba4022020-03-02 13:49:55 +0800654 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800655 p1 += 5;
656 if ((p2 = strstr(buf, "}"))) {
hualing chen2aba4022020-03-02 13:49:55 +0800657 DVR_RETURN_IF_FALSE(p2);
Pengfei Liub4734232020-01-17 18:25:10 +0800658 memcpy(value, p1, p2 - p1);
659 }
660 p_info->pids[i].type = strtoull(value, NULL, 10);
661 }
662 }
663
664 /*Save segment duration*/
665 p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp);
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800666 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800667 p1 = strstr(buf, "duration=");
hualing chen2aba4022020-03-02 13:49:55 +0800668 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800669 p_info->duration = strtoull(p1 + 9, NULL, 10);
hualing chena540a7e2020-03-27 16:44:05 +0800670 //DVR_DEBUG(1, "load info p_info->duration:%lld", p_info->duration);
Pengfei Liub4734232020-01-17 18:25:10 +0800671
672 /*Save segment size*/
673 p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp);
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800674 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800675 p1 = strstr(buf, "size=");
hualing chen2aba4022020-03-02 13:49:55 +0800676 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800677 p_info->size = strtoull(p1 + 5, NULL, 10);
678
679 /*Save number of packets*/
680 p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp);
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800681 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800682 p1 = strstr(buf, "nb_packets=");
hualing chen2aba4022020-03-02 13:49:55 +0800683 DVR_RETURN_IF_FALSE(p1);
Pengfei Liub4734232020-01-17 18:25:10 +0800684 p_info->nb_packets = strtoull(p1 + 11, NULL, 10);
685
686 return DVR_SUCCESS;
687}
688
689int segment_delete(const char *location, uint64_t segment_id)
690{
691 char fname[MAX_SEGMENT_PATH_SIZE];
692 int ret;
693
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800694 DVR_RETURN_IF_FALSE(location);
Pengfei Liub4734232020-01-17 18:25:10 +0800695
696 /*delete ts file*/
697 memset(fname, 0, sizeof(fname));
698 segment_get_fname(fname, location, segment_id, SEGMENT_FILE_TYPE_TS);
699 ret = unlink(fname);
700 DVR_DEBUG(1, "%s, [%s] return:%s", __func__, fname, strerror(errno));
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800701 DVR_RETURN_IF_FALSE(ret == 0);
Pengfei Liub4734232020-01-17 18:25:10 +0800702
703 /*delete index file*/
704 memset(fname, 0, sizeof(fname));
705 segment_get_fname(fname, location, segment_id, SEGMENT_FILE_TYPE_INDEX);
706 unlink(fname);
707 DVR_DEBUG(1, "%s, [%s] return:%s", __func__, fname, strerror(errno));
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800708 DVR_RETURN_IF_FALSE(ret == 0);
Pengfei Liub4734232020-01-17 18:25:10 +0800709
710 /*delete store information file*/
711 memset(fname, 0, sizeof(fname));
712 segment_get_fname(fname, location, segment_id, SEGMENT_FILE_TYPE_DAT);
713 unlink(fname);
714 DVR_DEBUG(1, "%s, [%s] return:%s", __func__, fname, strerror(errno));
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800715 DVR_RETURN_IF_FALSE(ret == 0);
Pengfei Liub4734232020-01-17 18:25:10 +0800716
717 return DVR_SUCCESS;
718}
719
hualing chen87072a82020-03-12 16:20:12 +0800720int segment_ongoing(Segment_Handle_t handle)
721{
722 Segment_Context_t *p_ctx;
723 p_ctx = (Segment_Context_t *)handle;
724 struct stat mstat;
725
726 char going_name[MAX_SEGMENT_PATH_SIZE];
727 memset(going_name, 0, sizeof(going_name));
728 segment_get_fname(going_name, p_ctx->location, p_ctx->segment_id, SEGMENT_FILE_TYPE_ONGOING);
729 int ret = stat(going_name, &mstat);
730 DVR_DEBUG(1, "segment check ongoing [%s] ret [%d]", going_name, ret);
731 if (ret != 0) {
732 return DVR_FAILURE;
733 }
734 return DVR_SUCCESS;
735}
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800736loff_t segment_dump_pts(Segment_Handle_t handle)
Pengfei Liub038b6a2020-01-14 15:57:01 +0800737{
738 Segment_Context_t *p_ctx;
739 char buf[256];
740 char value[256];
741 uint64_t pts;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800742 loff_t offset;
Pengfei Liub038b6a2020-01-14 15:57:01 +0800743 char *p1, *p2;
744
745 p_ctx = (Segment_Context_t *)handle;
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800746 DVR_RETURN_IF_FALSE(p_ctx);
747 DVR_RETURN_IF_FALSE(p_ctx->index_fp);
748 DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1);
Pengfei Liub038b6a2020-01-14 15:57:01 +0800749
750 memset(buf, 0, sizeof(buf));
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800751 DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, 0, SEEK_SET) != -1);
Pengfei Liub038b6a2020-01-14 15:57:01 +0800752 printf("start gets pts\n");
753 while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) {
754 printf("buf[%s]\n", buf);
755 memset(value, 0, sizeof(value));
756 if ((p1 = strstr(buf, "time="))) {
hualing chencc91e1c2020-02-28 13:26:17 +0800757 p1 += 5;
Pengfei Liub038b6a2020-01-14 15:57:01 +0800758 if ((p2 = strstr(buf, ","))) {
759 memcpy(value, p1, p2 - p1);
760 }
761 pts = strtoull(value, NULL, 10);
762 }
763
764 memset(value, 0, sizeof(value));
765 if ((p1 = strstr(buf, "offset="))) {
766 p1 += 7;
767 if ((p2 = strstr(buf, "}"))) {
768 memcpy(value, p1, p2 - p1);
769 }
770 offset = strtoull(value, NULL, 10);
771 }
772
773 memset(buf, 0, sizeof(buf));
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800774 printf("pts=%llu, offset=%lld\n", pts, offset);
Pengfei Liub038b6a2020-01-14 15:57:01 +0800775 }
776
777 return 0;
778}