Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 2 | #include <unistd.h> |
| 3 | #include <stdlib.h> |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 4 | #include <string.h> |
Zhiqiang Han | e0a1c38 | 2021-06-08 11:28:05 +0800 | [diff] [blame] | 5 | #include <errno.h> |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 6 | #include <pthread.h> |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 7 | #include "dvr_segment.h" |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 8 | #include <segment.h> |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 9 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 10 | /**\brief DVR segment file information*/ |
| 11 | typedef struct { |
| 12 | char location[DVR_MAX_LOCATION_SIZE]; /**< DVR record file location*/ |
| 13 | uint64_t id; /**< DVR Segment id*/ |
| 14 | } DVR_SegmentFile_t; |
| 15 | |
| 16 | void *dvr_segment_thread(void *arg) |
| 17 | { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 18 | int ret; |
hualing chen | e83bf81 | 2020-04-23 13:42:37 +0800 | [diff] [blame] | 19 | DVR_SegmentFile_t *segment_file = (DVR_SegmentFile_t*)arg; |
Wentao MA | 16f870e | 2022-09-09 11:00:22 +0800 | [diff] [blame^] | 20 | if (segment_file == NULL) { |
| 21 | DVR_ERROR("Invalid segment_file pointer"); |
| 22 | return NULL; |
| 23 | } |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 24 | |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 25 | pthread_detach(pthread_self()); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 26 | DVR_INFO("%s try to delete [%s-%lld]", __func__, segment_file->location, segment_file->id); |
hualing chen | e83bf81 | 2020-04-23 13:42:37 +0800 | [diff] [blame] | 27 | ret = segment_delete(segment_file->location, segment_file->id); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 28 | DVR_INFO("%s delete segment [%s-%lld] %s", __func__, segment_file->location, segment_file->id, |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 29 | ret == DVR_SUCCESS ? "success" : "failed"); |
hualing chen | e83bf81 | 2020-04-23 13:42:37 +0800 | [diff] [blame] | 30 | if (segment_file != NULL) { |
| 31 | //malloc at delete api.free at this |
| 32 | free(segment_file); |
| 33 | segment_file = NULL; |
| 34 | } |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 35 | return NULL; |
| 36 | } |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 37 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 38 | int dvr_segment_delete(const char *location, uint64_t segment_id) |
| 39 | { |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 40 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 41 | pthread_t thread; |
hualing chen | e83bf81 | 2020-04-23 13:42:37 +0800 | [diff] [blame] | 42 | DVR_SegmentFile_t *segment; |
| 43 | //this segment will be free at del thread when used end.if thread |
| 44 | //creat error.will be free now. |
| 45 | segment = (DVR_SegmentFile_t *)malloc(sizeof(DVR_SegmentFile_t)); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 46 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 47 | DVR_INFO("%s in, %s,id:%lld", __func__, location, segment_id); |
hualing chen | e83bf81 | 2020-04-23 13:42:37 +0800 | [diff] [blame] | 48 | DVR_RETURN_IF_FALSE(segment); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 49 | DVR_RETURN_IF_FALSE(location); |
| 50 | DVR_RETURN_IF_FALSE(strlen(location) < DVR_MAX_LOCATION_SIZE); |
hualing chen | e83bf81 | 2020-04-23 13:42:37 +0800 | [diff] [blame] | 51 | memset(segment->location, 0, sizeof(segment->location)); |
| 52 | memcpy(segment->location, location, strlen(location)); |
| 53 | segment->id = segment_id; |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 54 | |
hualing chen | e83bf81 | 2020-04-23 13:42:37 +0800 | [diff] [blame] | 55 | int ret = pthread_create(&thread, NULL, dvr_segment_thread, segment); |
| 56 | if (ret != 0) { |
| 57 | //creat thread error,need free segment |
| 58 | if (segment != NULL) { |
| 59 | free(segment); |
| 60 | segment = NULL; |
| 61 | } |
| 62 | } |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 63 | return DVR_SUCCESS; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 64 | } |
| 65 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 66 | int dvr_segment_del_by_location(const char *location) |
| 67 | { |
| 68 | FILE *fp; |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 69 | char cmd[DVR_MAX_LOCATION_SIZE + 64]; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 70 | |
| 71 | DVR_RETURN_IF_FALSE(location); |
| 72 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 73 | DVR_INFO("%s location:%s", __func__, location); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 74 | { |
| 75 | /* del file */ |
| 76 | memset(cmd, 0, sizeof(cmd)); |
hualing chen | 926a8ec | 2021-12-20 20:38:24 +0800 | [diff] [blame] | 77 | sprintf(cmd, "rm %s-* %s.list %s.stats %s.odb %s.dat", location, location, location, location, location); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 78 | fp = popen(cmd, "r"); |
| 79 | DVR_RETURN_IF_FALSE(fp); |
| 80 | } |
Zhiqiang Han | 5c805cf | 2020-05-09 16:51:08 +0800 | [diff] [blame] | 81 | pclose(fp); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 82 | DVR_INFO("%s location:%s end", __func__, location); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 83 | return DVR_SUCCESS; |
| 84 | } |
| 85 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 86 | int dvr_segment_get_list(const char *location, uint32_t *p_segment_nb, uint64_t **pp_segment_ids) |
| 87 | { |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 88 | FILE *fp; |
| 89 | char fpath[DVR_MAX_LOCATION_SIZE]; |
Zhiqiang Han | ee5ac41 | 2020-05-07 20:54:32 +0800 | [diff] [blame] | 90 | uint32_t i = 0, j = 0, n = 0; |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 91 | char buf[DVR_MAX_LOCATION_SIZE + 10]; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 92 | uint64_t *p = NULL; |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 93 | char cmd[DVR_MAX_LOCATION_SIZE + 64]; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 94 | |
| 95 | DVR_RETURN_IF_FALSE(location); |
| 96 | DVR_RETURN_IF_FALSE(p_segment_nb); |
| 97 | DVR_RETURN_IF_FALSE(pp_segment_ids); |
| 98 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 99 | //DVR_INFO("%s location:%s", __func__, location); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 100 | memset(fpath, 0, sizeof(fpath)); |
| 101 | sprintf(fpath, "%s.list", location); |
| 102 | |
| 103 | if (access(fpath, 0) != -1) { |
| 104 | /*the list file is exist*/ |
| 105 | fp = fopen(fpath, "r"); |
| 106 | DVR_RETURN_IF_FALSE(fp); |
| 107 | /*get segment numbers*/ |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 108 | while (fgets(buf, sizeof(buf), fp) != NULL) { |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 109 | i++; |
| 110 | } |
| 111 | *p_segment_nb = i; |
| 112 | rewind(fp); |
| 113 | /*malloc*/ |
| 114 | p = malloc(i * sizeof(uint64_t)); |
| 115 | i = 0; |
| 116 | /*set value*/ |
| 117 | memset(buf, 0, sizeof(buf)); |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 118 | while (fgets(buf, sizeof(buf), fp) != NULL) { |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 119 | p[i++] = strtoull(buf, NULL, 10); |
| 120 | memset(buf, 0, sizeof(buf)); |
| 121 | } |
| 122 | *pp_segment_ids = p; |
| 123 | fclose(fp); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 124 | DVR_INFO("%s location:%s segments:%d", __func__, location, i); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 125 | } else { |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 126 | uint32_t id = 0; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 127 | /*the list file does not exist*/ |
| 128 | memset(cmd, 0, sizeof(cmd)); |
Zhiqiang Han | ade34ff | 2020-04-17 16:50:59 +0800 | [diff] [blame] | 129 | sprintf(cmd, "ls -l %s-*.ts | wc -l", location); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 130 | fp = popen(cmd, "r"); |
| 131 | DVR_RETURN_IF_FALSE(fp); |
| 132 | memset(buf, 0, sizeof(buf)); |
| 133 | if (fgets(buf, sizeof(buf), fp) != NULL) { |
| 134 | i = strtoull(buf, NULL, 10); |
| 135 | pclose(fp); |
| 136 | } else { |
| 137 | pclose(fp); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 138 | DVR_INFO("%s location:%s get null", __func__, location); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 139 | return DVR_FAILURE; |
| 140 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 141 | //DVR_INFO("%s location:%s i: %d ls buf:%s", __func__, location, i, buf); |
Zhiqiang Han | ee5ac41 | 2020-05-07 20:54:32 +0800 | [diff] [blame] | 142 | n = i; |
| 143 | p = malloc(n * sizeof(uint64_t)); |
Zhiqiang Han | 8dd08b3 | 2020-05-13 16:50:04 +0800 | [diff] [blame] | 144 | /*try to get the 1st segment id*/ |
| 145 | memset(cmd, 0, sizeof(cmd)); |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 146 | sprintf(cmd, "ls %s-*.ts", location); |
Zhiqiang Han | 8dd08b3 | 2020-05-13 16:50:04 +0800 | [diff] [blame] | 147 | fp = popen(cmd, "r"); |
| 148 | DVR_RETURN_IF_FALSE(fp); |
| 149 | memset(buf, 0, sizeof(buf)); |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 150 | j = 0; |
| 151 | snprintf(fpath, sizeof(fpath), "%s-%%d.ts", location); |
| 152 | while (fgets(buf, sizeof(buf), fp) != NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 153 | //DVR_INFO("%s buf:%s", __func__, buf); |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 154 | if (sscanf(buf, fpath, &id) != 1) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 155 | DVR_INFO("%s location:%s buf:%s not get id", __func__, location, buf); |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 156 | id = 0; |
| 157 | n = n -1; |
| 158 | } else { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 159 | //DVR_INFO("%s location:%s buf:%s get id:%d", __func__, location, buf, id); |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 160 | p[j++] = id; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 161 | } |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 162 | memset(buf, 0, sizeof(buf)); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 163 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 164 | DVR_DEBUG("%s location:%s n=%d j=%d end", __func__, location, n, j); |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 165 | pclose(fp); |
| 166 | *p_segment_nb = n; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 167 | *pp_segment_ids = p; |
| 168 | } |
Pengfei Liu | faf38e4 | 2020-05-22 00:28:02 +0800 | [diff] [blame] | 169 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 170 | return DVR_SUCCESS; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 171 | } |
| 172 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 173 | int dvr_segment_get_info(const char *location, uint64_t segment_id, DVR_RecordSegmentInfo_t *p_info) |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 174 | { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 175 | int ret; |
| 176 | Segment_OpenParams_t open_params; |
| 177 | Segment_Handle_t segment_handle; |
| 178 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 179 | DVR_RETURN_IF_FALSE(location); |
| 180 | DVR_RETURN_IF_FALSE(p_info); |
| 181 | DVR_RETURN_IF_FALSE(strlen((const char *)location) < DVR_MAX_LOCATION_SIZE); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 182 | |
| 183 | memset(&open_params, 0, sizeof(open_params)); |
| 184 | memcpy(open_params.location, location, strlen(location)); |
| 185 | open_params.segment_id = segment_id; |
| 186 | open_params.mode = SEGMENT_MODE_READ; |
| 187 | ret = segment_open(&open_params, &segment_handle); |
Zhiqiang Han | 5c805cf | 2020-05-09 16:51:08 +0800 | [diff] [blame] | 188 | if (ret == DVR_SUCCESS) { |
| 189 | ret = segment_load_info(segment_handle, p_info); |
| 190 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 191 | DVR_DEBUG("%s, id:%lld, nb_pids:%d, duration:%ld ms, size:%zu, nb_packets:%d", |
hualing chen | 926a8ec | 2021-12-20 20:38:24 +0800 | [diff] [blame] | 192 | __func__, p_info->id, p_info->nb_pids, p_info->duration, p_info->size, p_info->nb_packets); |
hualing chen | b224235 | 2021-05-18 17:16:16 +0800 | [diff] [blame] | 193 | //DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 194 | ret = segment_close(segment_handle); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 195 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 196 | |
| 197 | return DVR_SUCCESS; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 198 | } |
| 199 | |
hualing chen | b9a0292 | 2021-12-14 11:29:47 +0800 | [diff] [blame] | 200 | int dvr_segment_get_allInfo(const char *location, struct list_head *list) |
| 201 | { |
| 202 | int ret; |
| 203 | Segment_OpenParams_t open_params; |
| 204 | Segment_Handle_t segment_handle; |
| 205 | |
| 206 | DVR_RETURN_IF_FALSE(location); |
| 207 | DVR_RETURN_IF_FALSE(list); |
| 208 | DVR_RETURN_IF_FALSE(strlen((const char *)location) < DVR_MAX_LOCATION_SIZE); |
| 209 | |
| 210 | memset(&open_params, 0, sizeof(open_params)); |
| 211 | memcpy(open_params.location, location, strlen(location)); |
| 212 | open_params.segment_id = 0; |
| 213 | open_params.mode = SEGMENT_MODE_READ; |
| 214 | ret = segment_open(&open_params, &segment_handle); |
| 215 | if (ret == DVR_SUCCESS) { |
| 216 | ret = segment_load_allInfo(segment_handle, list); |
hualing chen | 926a8ec | 2021-12-20 20:38:24 +0800 | [diff] [blame] | 217 | if (ret == DVR_FAILURE) { |
| 218 | segment_close(segment_handle); |
| 219 | return DVR_FAILURE; |
| 220 | } |
hualing chen | b9a0292 | 2021-12-14 11:29:47 +0800 | [diff] [blame] | 221 | } |
| 222 | ret = segment_close(segment_handle); |
| 223 | DVR_RETURN_IF_FALSE(ret == DVR_SUCCESS); |
| 224 | |
| 225 | return DVR_SUCCESS; |
| 226 | } |
| 227 | |
| 228 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 229 | int dvr_segment_link(const char *location, uint32_t nb_segments, uint64_t *p_segment_ids) |
| 230 | { |
Wentao MA | e8ba517 | 2022-08-09 11:18:17 +0800 | [diff] [blame] | 231 | return dvr_segment_link_op(location, nb_segments, p_segment_ids, SEGMENT_OP_NEW); |
Zhiqiang Han | e0a1c38 | 2021-06-08 11:28:05 +0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | int dvr_segment_link_op(const char *location, uint32_t nb_segments, uint64_t *p_segment_ids, int op) |
| 235 | { |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 236 | FILE *fp; |
| 237 | char fpath[DVR_MAX_LOCATION_SIZE]; |
| 238 | uint32_t i; |
hualing chen | b270cfa | 2020-08-19 15:04:35 +0800 | [diff] [blame] | 239 | char buf[DVR_MAX_LOCATION_SIZE + 64]; |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 240 | |
| 241 | DVR_RETURN_IF_FALSE(location); |
| 242 | DVR_RETURN_IF_FALSE(p_segment_ids); |
| 243 | DVR_RETURN_IF_FALSE(strlen((const char *)location) < DVR_MAX_LOCATION_SIZE); |
| 244 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 245 | DVR_INFO("%s op[%d] location:%s, nb_segments:%d", __func__, op, location, nb_segments); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 246 | memset(fpath, 0, sizeof(fpath)); |
| 247 | sprintf(fpath, "%s.list", location); |
Wentao MA | e8ba517 | 2022-08-09 11:18:17 +0800 | [diff] [blame] | 248 | fp = fopen(fpath, (op == SEGMENT_OP_ADD) ? "a+" : "w+"); |
Zhiqiang Han | e0a1c38 | 2021-06-08 11:28:05 +0800 | [diff] [blame] | 249 | if (!fp) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 250 | DVR_INFO("failed to open list file, err:%d:%s", errno, strerror(errno)); |
Zhiqiang Han | e0a1c38 | 2021-06-08 11:28:05 +0800 | [diff] [blame] | 251 | return DVR_FAILURE; |
| 252 | } |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 253 | for (i = 0; i< nb_segments; i++) { |
| 254 | memset(buf, 0, sizeof(buf)); |
Zhiqiang Han | e0a1c38 | 2021-06-08 11:28:05 +0800 | [diff] [blame] | 255 | sprintf(buf, "%lld\n", p_segment_ids[i]); |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 256 | fwrite(buf, 1, strlen(buf), fp); |
| 257 | } |
| 258 | |
| 259 | fflush(fp); |
| 260 | fsync(fileno(fp)); |
| 261 | fclose(fp); |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 262 | return DVR_SUCCESS; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 263 | } |