Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 2 | #include <unistd.h> |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 3 | #include <sys/types.h> |
| 4 | #include <sys/stat.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <string.h> |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 7 | #include <stdlib.h> |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 8 | #include <errno.h> |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 9 | #include "dvr_types.h" |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 10 | #include "segment.h" |
| 11 | |
| 12 | #define MAX_SEGMENT_FD_COUNT (128) |
| 13 | #define MAX_SEGMENT_PATH_SIZE (DVR_MAX_LOCATION_SIZE + 32) |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 14 | #define MAX_PTS_THRESHOLD (10*1000) |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 15 | /**\brief Segment context*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 16 | typedef struct { |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 17 | int ts_fd; /**< Segment ts file fd*/ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 18 | FILE *index_fp; /**< Time index file fd*/ |
| 19 | FILE *dat_fp; /**< Information file fd*/ |
| 20 | uint64_t first_pts; /**< First pts value, use for write mode*/ |
| 21 | uint64_t last_pts; /**< Last pts value, use for write mode*/ |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 22 | uint64_t cur_time; /**< Current time save in index file */ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 23 | } Segment_Context_t; |
| 24 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 25 | /**\brief Segment file type*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 26 | typedef enum { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 27 | SEGMENT_FILE_TYPE_TS, /**< Used for store TS data*/ |
| 28 | SEGMENT_FILE_TYPE_INDEX, /**< Used for store index data*/ |
| 29 | SEGMENT_FILE_TYPE_DAT, /**< Used for store information data, such as duration etc*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 30 | } Segment_FileType_t; |
| 31 | |
| 32 | static void segment_get_fname(char fname[MAX_SEGMENT_PATH_SIZE], |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 33 | const char location[DVR_MAX_LOCATION_SIZE], |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 34 | uint64_t segment_id, |
| 35 | Segment_FileType_t type) |
| 36 | { |
| 37 | int offset; |
| 38 | |
| 39 | memset(fname, 0, MAX_SEGMENT_PATH_SIZE); |
| 40 | strncpy(fname, location, strlen(location)); |
| 41 | offset = strlen(location); |
| 42 | strncpy(fname + offset, "-", 1); |
| 43 | offset += 1; |
| 44 | sprintf(fname + offset, "%04llu", segment_id); |
| 45 | offset += 4; |
| 46 | if (type == SEGMENT_FILE_TYPE_TS) |
| 47 | strncpy(fname + offset, ".ts", 3); |
| 48 | else if (type == SEGMENT_FILE_TYPE_INDEX) |
| 49 | strncpy(fname + offset, ".idx", 4); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 50 | else if (type == SEGMENT_FILE_TYPE_DAT) |
| 51 | strncpy(fname + offset, ".dat", 4); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 52 | } |
| 53 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 54 | static void segment_get_dirname(char dir_name[MAX_SEGMENT_PATH_SIZE], |
| 55 | const char location[DVR_MAX_LOCATION_SIZE]) |
| 56 | { |
| 57 | char *p; |
| 58 | int i; |
| 59 | int found = 0; |
| 60 | |
| 61 | for (i = 0; i < (int)strlen(location); i++) { |
| 62 | if (location[i] == '/') { |
| 63 | p = (char *)location + i; |
| 64 | found = 1; |
| 65 | } |
| 66 | } |
| 67 | if (found) |
| 68 | memcpy(dir_name, location, p - location); |
| 69 | } |
| 70 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 71 | int segment_open(Segment_OpenParams_t *params, Segment_Handle_t *p_handle) |
| 72 | { |
| 73 | Segment_Context_t *p_ctx; |
| 74 | char ts_fname[MAX_SEGMENT_PATH_SIZE]; |
| 75 | char index_fname[MAX_SEGMENT_PATH_SIZE]; |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 76 | char dat_fname[MAX_SEGMENT_PATH_SIZE]; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 77 | char dir_name[MAX_SEGMENT_PATH_SIZE]; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 78 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 79 | DVR_RETURN_IF_FALSE(params); |
| 80 | DVR_RETURN_IF_FALSE(p_handle); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 81 | |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 82 | DVR_DEBUG(1, "%s, location:%s, id:%llu", __func__, params->location, params->segment_id); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 83 | |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 84 | p_ctx = (void*)malloc(sizeof(Segment_Context_t)); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 85 | DVR_RETURN_IF_FALSE(p_ctx); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 86 | memset(p_ctx, 0, sizeof(Segment_Context_t)); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 87 | |
| 88 | memset(ts_fname, 0, sizeof(ts_fname)); |
| 89 | segment_get_fname(ts_fname, params->location, params->segment_id, SEGMENT_FILE_TYPE_TS); |
| 90 | |
| 91 | memset(index_fname, 0, sizeof(index_fname)); |
| 92 | segment_get_fname(index_fname, params->location, params->segment_id, SEGMENT_FILE_TYPE_INDEX); |
| 93 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 94 | memset(dat_fname, 0, sizeof(dat_fname)); |
| 95 | segment_get_fname(dat_fname, params->location, params->segment_id, SEGMENT_FILE_TYPE_DAT); |
| 96 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 97 | memset(dir_name, 0, sizeof(dir_name)); |
| 98 | segment_get_dirname(dir_name, params->location); |
| 99 | if (access(dir_name, F_OK) == -1) { |
| 100 | DVR_DEBUG(1, "%s dir %s is not exist, create it", __func__, dir_name); |
| 101 | mkdir(dir_name, 0666); |
| 102 | } |
| 103 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 104 | if (params->mode == SEGMENT_MODE_READ) { |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 105 | p_ctx->ts_fd = open(ts_fname, O_RDONLY); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 106 | p_ctx->index_fp = fopen(index_fname, "r"); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 107 | p_ctx->dat_fp = fopen(dat_fname, "r"); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 108 | } else if (params->mode == SEGMENT_MODE_WRITE) { |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 109 | p_ctx->ts_fd = open(ts_fname, O_CREAT | O_RDWR | O_TRUNC, 0644); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 110 | p_ctx->index_fp = fopen(index_fname, "w+"); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 111 | p_ctx->dat_fp = fopen(dat_fname, "w+"); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 112 | p_ctx->first_pts = ULLONG_MAX; |
| 113 | p_ctx->last_pts = ULLONG_MAX; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 114 | } else { |
| 115 | DVR_DEBUG(1, "%s, unknow mode use default", __func__); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 116 | p_ctx->ts_fd = open(ts_fname, O_RDONLY); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 117 | p_ctx->index_fp = fopen(index_fname, "r"); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 118 | p_ctx->dat_fp = fopen(dat_fname, "r"); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 119 | } |
| 120 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 121 | if (p_ctx->ts_fd == -1 || !p_ctx->index_fp || !p_ctx->dat_fp) { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 122 | DVR_DEBUG(1, "%s open file failed [%s, %s, %s], reason:%s", __func__, |
| 123 | ts_fname, index_fname, dat_fname, strerror(errno)); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 124 | free(p_ctx); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 125 | *p_handle = NULL; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 126 | return DVR_FAILURE; |
| 127 | } |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 128 | |
| 129 | DVR_DEBUG(1, "%s, open file success", __func__); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 130 | *p_handle = (Segment_Handle_t)p_ctx; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 131 | return DVR_SUCCESS; |
| 132 | } |
| 133 | |
| 134 | int segment_close(Segment_Handle_t handle) |
| 135 | { |
| 136 | Segment_Context_t *p_ctx; |
| 137 | |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 138 | p_ctx = (void *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 139 | DVR_RETURN_IF_FALSE(p_ctx); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 140 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 141 | if (p_ctx->ts_fd != -1) { |
| 142 | close(p_ctx->ts_fd); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | if (p_ctx->index_fp) { |
| 146 | fclose(p_ctx->index_fp); |
| 147 | } |
| 148 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 149 | if (p_ctx->dat_fp) { |
| 150 | fclose(p_ctx->dat_fp); |
| 151 | } |
| 152 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 153 | free(p_ctx); |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | ssize_t segment_read(Segment_Handle_t handle, void *buf, size_t count) |
| 158 | { |
| 159 | Segment_Context_t *p_ctx; |
| 160 | |
| 161 | p_ctx = (Segment_Context_t *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 162 | DVR_RETURN_IF_FALSE(p_ctx); |
| 163 | DVR_RETURN_IF_FALSE(buf); |
| 164 | DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 165 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 166 | return read(p_ctx->ts_fd, buf, count); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | ssize_t segment_write(Segment_Handle_t handle, void *buf, size_t count) |
| 170 | { |
| 171 | Segment_Context_t *p_ctx; |
| 172 | |
| 173 | p_ctx = (Segment_Context_t *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 174 | DVR_RETURN_IF_FALSE(p_ctx); |
| 175 | DVR_RETURN_IF_FALSE(buf); |
| 176 | DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 177 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 178 | return write(p_ctx->ts_fd, buf, count); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 179 | } |
| 180 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 181 | int segment_update_pts(Segment_Handle_t handle, uint64_t pts, loff_t offset) |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 182 | { |
| 183 | Segment_Context_t *p_ctx; |
| 184 | char buf[256]; |
| 185 | |
| 186 | p_ctx = (Segment_Context_t *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 187 | DVR_RETURN_IF_FALSE(p_ctx); |
| 188 | DVR_RETURN_IF_FALSE(p_ctx->index_fp); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 189 | |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 190 | if (p_ctx->first_pts == ULLONG_MAX) { |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 191 | DVR_DEBUG(1, "%s first pcr:%llu", __func__, pts); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 192 | p_ctx->first_pts = pts; |
| 193 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 194 | memset(buf, 0, sizeof(buf)); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 195 | if (p_ctx->last_pts == ULLONG_MAX) { |
| 196 | /*Last pts is init value*/ |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 197 | sprintf(buf, "{time=%llu, offset=%lld}", pts - p_ctx->first_pts, offset); |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 198 | p_ctx->cur_time = pts - p_ctx->first_pts; |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 199 | } else { |
| 200 | /*Last pts has valid value*/ |
| 201 | if (pts - p_ctx->last_pts > MAX_PTS_THRESHOLD) { |
| 202 | /*Current pts has a transition*/ |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 203 | DVR_DEBUG(1, "Current pts has a transition, [%llu, %llu, %llu]", |
| 204 | p_ctx->first_pts, p_ctx->last_pts, pts); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 205 | } else { |
| 206 | /*This is a normal pts, record it*/ |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 207 | p_ctx->cur_time += (pts - p_ctx->last_pts); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 208 | sprintf(buf, "\n{time=%llu, offset=%lld}", p_ctx->cur_time, offset); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 209 | } |
| 210 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 211 | |
| 212 | fputs(buf, p_ctx->index_fp); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 213 | p_ctx->last_pts = pts; |
| 214 | fflush(p_ctx->index_fp); |
| 215 | fsync(fileno(p_ctx->index_fp)); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 216 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 217 | return DVR_SUCCESS; |
| 218 | } |
| 219 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 220 | loff_t segment_seek(Segment_Handle_t handle, uint64_t time) |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 221 | { |
| 222 | Segment_Context_t *p_ctx; |
| 223 | char buf[256]; |
| 224 | char value[256]; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 225 | uint64_t pts = 0L; |
| 226 | loff_t offset = 0; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 227 | char *p1, *p2; |
| 228 | |
| 229 | p_ctx = (Segment_Context_t *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 230 | DVR_RETURN_IF_FALSE(p_ctx); |
| 231 | DVR_RETURN_IF_FALSE(p_ctx->index_fp); |
| 232 | DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 233 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 234 | memset(buf, 0, sizeof(buf)); |
| 235 | DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, 0, SEEK_SET) != -1); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 236 | int line = 0; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 237 | while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 238 | line++; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 239 | memset(value, 0, sizeof(value)); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 240 | if ((p1 = strstr(buf, "time="))) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 241 | p1 += 5; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 242 | if ((p2 = strstr(buf, ","))) { |
| 243 | memcpy(value, p1, p2 - p1); |
| 244 | } |
| 245 | pts = strtoull(value, NULL, 10); |
| 246 | } |
| 247 | |
| 248 | memset(value, 0, sizeof(value)); |
| 249 | if ((p1 = strstr(buf, "offset="))) { |
| 250 | p1 += 7; |
| 251 | if ((p2 = strstr(buf, "}"))) { |
| 252 | memcpy(value, p1, p2 - p1); |
| 253 | } |
| 254 | offset = strtoull(value, NULL, 10); |
| 255 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 256 | if (0) |
| 257 | { |
| 258 | DVR_DEBUG(1, "seek buf[%s]", buf); |
| 259 | DVR_DEBUG(1, "seek time=%llu, offset=%lld\n", pts, offset); |
| 260 | } |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 261 | memset(buf, 0, sizeof(buf)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 262 | //DVR_DEBUG(1, "seek time=%llu, offset=%lld\n", pts, offset); |
| 263 | if (time <= pts) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 264 | DVR_DEBUG(1, "seek time=%llu, offset=%lld time--%llu line %d\n", pts, offset, time, line); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 265 | DVR_RETURN_IF_FALSE(lseek64(p_ctx->ts_fd, offset, SEEK_SET) != -1); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 266 | return offset; |
| 267 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 268 | } |
| 269 | DVR_DEBUG(1, "seek error line [%d]", line); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 270 | return DVR_FAILURE; |
| 271 | } |
| 272 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 273 | loff_t segment_tell_position(Segment_Handle_t handle) |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 274 | { |
| 275 | Segment_Context_t *p_ctx; |
| 276 | |
| 277 | p_ctx = (Segment_Context_t *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 278 | DVR_RETURN_IF_FALSE(p_ctx); |
| 279 | DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 280 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 281 | return lseek64(p_ctx->ts_fd, 0, SEEK_CUR); |
| 282 | } |
| 283 | |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 284 | uint64_t segment_tell_current_time(Segment_Handle_t handle) |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 285 | { |
| 286 | Segment_Context_t *p_ctx; |
| 287 | char buf[256]; |
| 288 | char value[256]; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 289 | uint64_t pts = 0L; |
| 290 | loff_t offset = 0, position = 0; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 291 | char *p1, *p2; |
| 292 | |
| 293 | p_ctx = (Segment_Context_t *)handle; |
| 294 | DVR_RETURN_IF_FALSE(p_ctx); |
| 295 | DVR_RETURN_IF_FALSE(p_ctx->index_fp); |
| 296 | DVR_RETURN_IF_FALSE(p_ctx->ts_fd); |
| 297 | |
| 298 | memset(buf, 0, sizeof(buf)); |
| 299 | DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, 0, SEEK_SET) != -1); |
| 300 | position = lseek64(p_ctx->ts_fd, 0, SEEK_CUR); |
| 301 | DVR_RETURN_IF_FALSE(position != -1); |
| 302 | |
| 303 | while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) { |
| 304 | memset(value, 0, sizeof(value)); |
| 305 | if ((p1 = strstr(buf, "time="))) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 306 | p1 += 5; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 307 | if ((p2 = strstr(buf, ","))) { |
| 308 | memcpy(value, p1, p2 - p1); |
| 309 | } |
| 310 | pts = strtoull(value, NULL, 10); |
| 311 | } |
| 312 | |
| 313 | memset(value, 0, sizeof(value)); |
| 314 | if ((p1 = strstr(buf, "offset="))) { |
| 315 | p1 += 7; |
| 316 | if ((p2 = strstr(buf, "}"))) { |
| 317 | memcpy(value, p1, p2 - p1); |
| 318 | } |
| 319 | offset = strtoull(value, NULL, 10); |
| 320 | } |
| 321 | |
| 322 | memset(buf, 0, sizeof(buf)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 323 | //DVR_DEBUG(1, "tell cur time=%llu, offset=%lld, position=%lld\n", pts, offset, position); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 324 | if (position <= offset) { |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 325 | return pts; |
| 326 | } |
| 327 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 328 | DVR_DEBUG(1, "tell cur time=%llu, offset=%lld, position=%lld\n", pts, offset, position); |
| 329 | return pts; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 330 | } |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 331 | |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 332 | uint64_t segment_tell_total_time(Segment_Handle_t handle) |
| 333 | { |
| 334 | Segment_Context_t *p_ctx; |
| 335 | char buf[256]; |
| 336 | char last_buf[256]; |
| 337 | char value[256]; |
| 338 | uint64_t pts = ULLONG_MAX; |
| 339 | loff_t offset = 0, position = 0; |
| 340 | char *p1, *p2; |
| 341 | int line = 0; |
| 342 | |
| 343 | p_ctx = (Segment_Context_t *)handle; |
| 344 | DVR_RETURN_IF_FALSE(p_ctx); |
| 345 | DVR_RETURN_IF_FALSE(p_ctx->index_fp); |
| 346 | DVR_RETURN_IF_FALSE(p_ctx->ts_fd); |
| 347 | |
| 348 | memset(buf, 0, sizeof(buf)); |
| 349 | memset(last_buf, 0, sizeof(last_buf)); |
| 350 | position = lseek64(p_ctx->ts_fd, 0, SEEK_CUR); |
| 351 | DVR_RETURN_IF_FALSE(position != -1); |
| 352 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 353 | //DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, -1000L, SEEK_END) != -1); |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 354 | /* Save last line buffer */ |
| 355 | while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 356 | if (strlen(buf) <= 0) { |
| 357 | continue; |
| 358 | } |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 359 | memset(last_buf, 0, sizeof(last_buf)); |
| 360 | memcpy(last_buf, buf, strlen(buf)); |
| 361 | memset(buf, 0, sizeof(buf)); |
| 362 | line++; |
| 363 | } |
| 364 | |
| 365 | /* Extract time value */ |
| 366 | memset(value, 0, sizeof(value)); |
| 367 | if ((p1 = strstr(last_buf, "time="))) { |
| 368 | p1 += 5; |
| 369 | if ((p2 = strstr(last_buf, ","))) { |
| 370 | memcpy(value, p1, p2 - p1); |
| 371 | } |
| 372 | pts = strtoull(value, NULL, 10); |
| 373 | } |
| 374 | |
| 375 | memset(value, 0, sizeof(value)); |
| 376 | if ((p1 = strstr(last_buf, "offset="))) { |
| 377 | p1 += 7; |
| 378 | if ((p2 = strstr(last_buf, "}"))) { |
| 379 | memcpy(value, p1, p2 - p1); |
| 380 | } |
| 381 | offset = strtoull(value, NULL, 10); |
| 382 | } |
| 383 | if (line < 2) |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 384 | DVR_DEBUG(1, "totle time=%llu, offset=%lld, position=%lld, line:%d\n", pts, offset, position, line); |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 385 | |
| 386 | return (pts == ULLONG_MAX ? DVR_FAILURE : pts); |
| 387 | } |
| 388 | |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 389 | /* Should consider the case of cut power, todo... */ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 390 | int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info) |
| 391 | { |
| 392 | Segment_Context_t *p_ctx; |
| 393 | char buf[256]; |
| 394 | uint32_t i; |
| 395 | |
| 396 | p_ctx = (Segment_Context_t *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 397 | DVR_RETURN_IF_FALSE(p_ctx); |
| 398 | DVR_RETURN_IF_FALSE(p_ctx->dat_fp); |
| 399 | DVR_RETURN_IF_FALSE(p_info); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 400 | |
| 401 | /*Save segment id*/ |
| 402 | memset(buf, 0, sizeof(buf)); |
| 403 | sprintf(buf, "id=%lld\n", p_info->id); |
| 404 | fputs(buf, p_ctx->dat_fp); |
| 405 | |
| 406 | /*Save number of pids*/ |
| 407 | memset(buf, 0, sizeof(buf)); |
| 408 | sprintf(buf, "nb_pids=%d\n", p_info->nb_pids); |
| 409 | fputs(buf, p_ctx->dat_fp); |
| 410 | |
| 411 | /*Save pid information*/ |
| 412 | for (i = 0; i < p_info->nb_pids; i++) { |
| 413 | memset(buf, 0, sizeof(buf)); |
| 414 | sprintf(buf, "{pid=%d, type=%d}\n", p_info->pids[i].pid, p_info->pids[i].type); |
| 415 | fputs(buf, p_ctx->dat_fp); |
| 416 | } |
| 417 | |
| 418 | /*Save segment duration*/ |
| 419 | memset(buf, 0, sizeof(buf)); |
| 420 | sprintf(buf, "duration=%ld\n", p_info->duration); |
| 421 | fputs(buf, p_ctx->dat_fp); |
| 422 | |
| 423 | /*Save segment size*/ |
| 424 | memset(buf, 0, sizeof(buf)); |
| 425 | sprintf(buf, "size=%zu\n", p_info->size); |
| 426 | fputs(buf, p_ctx->dat_fp); |
| 427 | |
| 428 | /*Save number of packets*/ |
| 429 | memset(buf, 0, sizeof(buf)); |
| 430 | sprintf(buf, "nb_packets=%d\n", p_info->nb_packets); |
| 431 | fputs(buf, p_ctx->dat_fp); |
| 432 | |
| 433 | fflush(p_ctx->dat_fp); |
| 434 | fsync(fileno(p_ctx->dat_fp)); |
| 435 | return DVR_SUCCESS; |
| 436 | } |
| 437 | |
pengfei.liu | ab5a226 | 2020-02-14 17:33:40 +0800 | [diff] [blame] | 438 | /* Should consider the case of cut power, todo... */ |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 439 | int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info) |
| 440 | { |
| 441 | Segment_Context_t *p_ctx; |
| 442 | uint32_t i; |
| 443 | char buf[256]; |
| 444 | char value[256]; |
| 445 | char *p1, *p2; |
| 446 | |
| 447 | p_ctx = (Segment_Context_t *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 448 | DVR_RETURN_IF_FALSE(p_ctx); |
| 449 | DVR_RETURN_IF_FALSE(p_info); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 450 | |
| 451 | /*Load segment id*/ |
| 452 | p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 453 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 454 | p1 = strstr(buf, "id="); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 455 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 456 | p_info->id = strtoull(p1 + 3, NULL, 10); |
| 457 | |
| 458 | /*Save number of pids*/ |
| 459 | p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 460 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 461 | p1 = strstr(buf, "nb_pids="); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 462 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 463 | p_info->nb_pids = strtoull(p1 + 8, NULL, 10); |
| 464 | |
| 465 | /*Save pid information*/ |
| 466 | for (i = 0; i < p_info->nb_pids; i++) { |
| 467 | p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 468 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 469 | memset(value, 0, sizeof(value)); |
| 470 | if ((p1 = strstr(buf, "pid="))) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 471 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 472 | p1 += 4; |
| 473 | if ((p2 = strstr(buf, ","))) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 474 | DVR_RETURN_IF_FALSE(p2); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 475 | memcpy(value, p1, p2 - p1); |
| 476 | } |
| 477 | p_info->pids[i].pid = strtoull(value, NULL, 10); |
| 478 | } |
| 479 | |
| 480 | memset(value, 0, sizeof(value)); |
| 481 | if ((p1 = strstr(buf, "type="))) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 482 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 483 | p1 += 5; |
| 484 | if ((p2 = strstr(buf, "}"))) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 485 | DVR_RETURN_IF_FALSE(p2); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 486 | memcpy(value, p1, p2 - p1); |
| 487 | } |
| 488 | p_info->pids[i].type = strtoull(value, NULL, 10); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /*Save segment duration*/ |
| 493 | p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 494 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 495 | p1 = strstr(buf, "duration="); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 496 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 497 | p_info->duration = strtoull(p1 + 9, NULL, 10); |
| 498 | |
| 499 | /*Save segment size*/ |
| 500 | p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 501 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 502 | p1 = strstr(buf, "size="); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 503 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 504 | p_info->size = strtoull(p1 + 5, NULL, 10); |
| 505 | |
| 506 | /*Save number of packets*/ |
| 507 | p1 = fgets(buf, sizeof(buf), p_ctx->dat_fp); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 508 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 509 | p1 = strstr(buf, "nb_packets="); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame^] | 510 | DVR_RETURN_IF_FALSE(p1); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 511 | p_info->nb_packets = strtoull(p1 + 11, NULL, 10); |
| 512 | |
| 513 | return DVR_SUCCESS; |
| 514 | } |
| 515 | |
| 516 | int segment_delete(const char *location, uint64_t segment_id) |
| 517 | { |
| 518 | char fname[MAX_SEGMENT_PATH_SIZE]; |
| 519 | int ret; |
| 520 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 521 | DVR_RETURN_IF_FALSE(location); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 522 | |
| 523 | /*delete ts file*/ |
| 524 | memset(fname, 0, sizeof(fname)); |
| 525 | segment_get_fname(fname, location, segment_id, SEGMENT_FILE_TYPE_TS); |
| 526 | ret = unlink(fname); |
| 527 | DVR_DEBUG(1, "%s, [%s] return:%s", __func__, fname, strerror(errno)); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 528 | DVR_RETURN_IF_FALSE(ret == 0); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 529 | |
| 530 | /*delete index file*/ |
| 531 | memset(fname, 0, sizeof(fname)); |
| 532 | segment_get_fname(fname, location, segment_id, SEGMENT_FILE_TYPE_INDEX); |
| 533 | unlink(fname); |
| 534 | DVR_DEBUG(1, "%s, [%s] return:%s", __func__, fname, strerror(errno)); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 535 | DVR_RETURN_IF_FALSE(ret == 0); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 536 | |
| 537 | /*delete store information file*/ |
| 538 | memset(fname, 0, sizeof(fname)); |
| 539 | segment_get_fname(fname, location, segment_id, SEGMENT_FILE_TYPE_DAT); |
| 540 | unlink(fname); |
| 541 | DVR_DEBUG(1, "%s, [%s] return:%s", __func__, fname, strerror(errno)); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 542 | DVR_RETURN_IF_FALSE(ret == 0); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 543 | |
| 544 | return DVR_SUCCESS; |
| 545 | } |
| 546 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 547 | loff_t segment_dump_pts(Segment_Handle_t handle) |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 548 | { |
| 549 | Segment_Context_t *p_ctx; |
| 550 | char buf[256]; |
| 551 | char value[256]; |
| 552 | uint64_t pts; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 553 | loff_t offset; |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 554 | char *p1, *p2; |
| 555 | |
| 556 | p_ctx = (Segment_Context_t *)handle; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 557 | DVR_RETURN_IF_FALSE(p_ctx); |
| 558 | DVR_RETURN_IF_FALSE(p_ctx->index_fp); |
| 559 | DVR_RETURN_IF_FALSE(p_ctx->ts_fd != -1); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 560 | |
| 561 | memset(buf, 0, sizeof(buf)); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 562 | DVR_RETURN_IF_FALSE(fseek(p_ctx->index_fp, 0, SEEK_SET) != -1); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 563 | printf("start gets pts\n"); |
| 564 | while (fgets(buf, sizeof(buf), p_ctx->index_fp) != NULL) { |
| 565 | printf("buf[%s]\n", buf); |
| 566 | memset(value, 0, sizeof(value)); |
| 567 | if ((p1 = strstr(buf, "time="))) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 568 | p1 += 5; |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 569 | if ((p2 = strstr(buf, ","))) { |
| 570 | memcpy(value, p1, p2 - p1); |
| 571 | } |
| 572 | pts = strtoull(value, NULL, 10); |
| 573 | } |
| 574 | |
| 575 | memset(value, 0, sizeof(value)); |
| 576 | if ((p1 = strstr(buf, "offset="))) { |
| 577 | p1 += 7; |
| 578 | if ((p2 = strstr(buf, "}"))) { |
| 579 | memcpy(value, p1, p2 - p1); |
| 580 | } |
| 581 | offset = strtoull(value, NULL, 10); |
| 582 | } |
| 583 | |
| 584 | memset(buf, 0, sizeof(buf)); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 585 | printf("pts=%llu, offset=%lld\n", pts, offset); |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | return 0; |
| 589 | } |