| 196 | } |
| 197 | |
| 198 | static void adjust_write_index(AVFormatContext *s) |
| 199 | { |
| 200 | FFMContext *ffm = s->priv_data; |
| 201 | ByteIOContext *pb = s->pb; |
| 202 | int64_t pts; |
| 203 | //int64_t orig_write_index = ffm->write_index; |
| 204 | int64_t pos_min, pos_max; |
| 205 | int64_t pts_start; |
| 206 | int64_t ptr = url_ftell(pb); |
| 207 | |
| 208 | |
| 209 | pos_min = 0; |
| 210 | pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE; |
| 211 | |
| 212 | pts_start = get_dts(s, pos_min); |
| 213 | |
| 214 | pts = get_dts(s, pos_max); |
| 215 | |
| 216 | if (pts - 100000 > pts_start) |
| 217 | goto end; |
| 218 | |
| 219 | ffm->write_index = FFM_PACKET_SIZE; |
| 220 | |
| 221 | pts_start = get_dts(s, pos_min); |
| 222 | |
| 223 | pts = get_dts(s, pos_max); |
| 224 | |
| 225 | if (pts - 100000 <= pts_start) { |
| 226 | while (1) { |
| 227 | int64_t newpos; |
| 228 | int64_t newpts; |
| 229 | |
| 230 | newpos = ((pos_max + pos_min) / (2 * FFM_PACKET_SIZE)) * FFM_PACKET_SIZE; |
| 231 | |
| 232 | if (newpos == pos_min) |
| 233 | break; |
| 234 | |
| 235 | newpts = get_dts(s, newpos); |
| 236 | |
| 237 | if (newpts - 100000 <= pts) { |
| 238 | pos_max = newpos; |
| 239 | pts = newpts; |
| 240 | } else { |
| 241 | pos_min = newpos; |
| 242 | } |
| 243 | } |
| 244 | ffm->write_index += pos_max; |
| 245 | } |
| 246 | |
| 247 | //printf("Adjusted write index from %"PRId64" to %"PRId64": pts=%0.6f\n", orig_write_index, ffm->write_index, pts / 1000000.); |
| 248 | //printf("pts range %0.6f - %0.6f\n", get_dts(s, 0) / 1000000. , get_dts(s, ffm->file_size - 2 * FFM_PACKET_SIZE) / 1000000. ); |
| 249 | |
| 250 | end: |
| 251 | url_fseek(pb, ptr, SEEK_SET); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) |
no test coverage detected