1370 |
1370 |
}
|
1371 |
1371 |
}
|
1372 |
1372 |
|
1373 |
|
int av_add_index_entry(AVStream *st,
|
1374 |
|
int64_t pos, int64_t timestamp, int size, int distance, int flags)
|
|
1373 |
int ff_add_index_entry(AVIndexEntry **index_entries,
|
|
1374 |
int *nb_index_entries,
|
|
1375 |
unsigned int *index_entries_allocated_size,
|
|
1376 |
int64_t pos, int64_t timestamp, int size, int distance, int flags)
|
1375 |
1377 |
{
|
1376 |
1378 |
AVIndexEntry *entries, *ie;
|
1377 |
1379 |
int index;
|
1378 |
1380 |
|
1379 |
|
if((unsigned)st->nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry))
|
|
1381 |
if((unsigned)*nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry))
|
1380 |
1382 |
return -1;
|
1381 |
1383 |
|
1382 |
|
entries = av_fast_realloc(st->index_entries,
|
1383 |
|
&st->index_entries_allocated_size,
|
1384 |
|
(st->nb_index_entries + 1) *
|
|
1384 |
entries = av_fast_realloc(*index_entries,
|
|
1385 |
index_entries_allocated_size,
|
|
1386 |
(*nb_index_entries + 1) *
|
1385 |
1387 |
sizeof(AVIndexEntry));
|
1386 |
1388 |
if(!entries)
|
1387 |
1389 |
return -1;
|
1388 |
1390 |
|
1389 |
|
st->index_entries= entries;
|
|
1391 |
*index_entries= entries;
|
1390 |
1392 |
|
1391 |
|
index= av_index_search_timestamp(st, timestamp, AVSEEK_FLAG_ANY);
|
|
1393 |
index= ff_index_search_timestamp(*index_entries, *nb_index_entries, timestamp, AVSEEK_FLAG_ANY);
|
1392 |
1394 |
|
1393 |
1395 |
if(index<0){
|
1394 |
|
index= st->nb_index_entries++;
|
|
1396 |
index= (*nb_index_entries)++;
|
1395 |
1397 |
ie= &entries[index];
|
1396 |
1398 |
assert(index==0 || ie[-1].timestamp < timestamp);
|
1397 |
1399 |
}else{
|
... | ... | |
1399 |
1401 |
if(ie->timestamp != timestamp){
|
1400 |
1402 |
if(ie->timestamp <= timestamp)
|
1401 |
1403 |
return -1;
|
1402 |
|
memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index));
|
1403 |
|
st->nb_index_entries++;
|
|
1404 |
memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(*nb_index_entries - index));
|
|
1405 |
(*nb_index_entries)++;
|
1404 |
1406 |
}else if(ie->pos == pos && distance < ie->min_distance) //do not reduce the distance
|
1405 |
1407 |
distance= ie->min_distance;
|
1406 |
1408 |
}
|
... | ... | |
1414 |
1416 |
return index;
|
1415 |
1417 |
}
|
1416 |
1418 |
|
1417 |
|
int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp,
|
1418 |
|
int flags)
|
|
1419 |
int av_add_index_entry(AVStream *st,
|
|
1420 |
int64_t pos, int64_t timestamp, int size, int distance, int flags)
|
|
1421 |
{
|
|
1422 |
return ff_add_index_entry(&st->index_entries, &st->nb_index_entries,
|
|
1423 |
&st->index_entries_allocated_size, pos,
|
|
1424 |
timestamp, size, distance, flags);
|
|
1425 |
}
|
|
1426 |
|
|
1427 |
int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries,
|
|
1428 |
int64_t wanted_timestamp, int flags)
|
1419 |
1429 |
{
|
1420 |
|
AVIndexEntry *entries= st->index_entries;
|
1421 |
|
int nb_entries= st->nb_index_entries;
|
1422 |
1430 |
int a, b, m;
|
1423 |
1431 |
int64_t timestamp;
|
1424 |
1432 |
|
... | ... | |
1450 |
1458 |
return m;
|
1451 |
1459 |
}
|
1452 |
1460 |
|
|
1461 |
int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp,
|
|
1462 |
int flags)
|
|
1463 |
{
|
|
1464 |
return ff_index_search_timestamp(st->index_entries, st->nb_index_entries,
|
|
1465 |
wanted_timestamp, flags);
|
|
1466 |
}
|
|
1467 |
|
1453 |
1468 |
#define DEBUG_SEEK
|
1454 |
1469 |
|
1455 |
1470 |
int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
|