1374 {
1377 }
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1397 long byterate = file_size / duration;
1398
1400 double scan_span = 1;
1401
1402 if (seek_time > duration) {
1403 seek_time = duration;
1404 }
1405 else if (seek_time < 0) {
1406 seek_time = 0;
1407 }
1409
1410 for (int retry = 0; retry < 32; retry++) {
1411 int found_packet_with_pts =
FALSE;
1412 int found_packet_in_range =
FALSE;
1413 long last_valid_packet_start = -1;
1415
1417
1418
1419 long offset = (seek_time - cur_time - scan_span) * byterate;
1420 long seek_pos = cur_pos +
offset;
1421 if (seek_pos < 0) {
1422 seek_pos = 0;
1423 }
1424 else if (seek_pos > file_size - 256) {
1425 seek_pos = file_size - 256;
1426 }
1427
1429
1430
1431
1435
1436
1438 continue;
1439 }
1440
1441
1442
1443
1444
1445 if (packet->pts > seek_time || packet->pts < seek_time - scan_span) {
1446 found_packet_with_pts =
TRUE;
1447 byterate = (seek_pos - cur_pos) / (packet->pts - cur_time);
1448 cur_time = packet->pts;
1449 break;
1450 }
1451
1452
1453
1454
1455
1456
1457 if (!found_packet_in_range) {
1458 found_packet_in_range =
TRUE;
1459 first_packet_time = packet->pts;
1460 }
1461
1462
1463
1464
1465
1466 if (force_intra) {
1467 for (size_t i = 0; i < packet->length - 6; i++) {
1468
1469 if (
1470 packet->data[i] == 0x00 &&
1471 packet->data[i + 1] == 0x00 &&
1472 packet->data[i + 2] == 0x01 &&
1473 packet->data[i + 3] == 0x00
1474 ) {
1475
1476
1477 if ((packet->data[i + 5] & 0x38) == 8) {
1478 last_valid_packet_start = packet_start;
1479 }
1480 break;
1481 }
1482 }
1483 }
1484
1485
1486 else {
1487 last_valid_packet_start = packet_start;
1488 }
1489 }
1490
1491
1492
1493 if (last_valid_packet_start != -1) {
1496 }
1497
1498
1499
1500
1501 else if (found_packet_in_range) {
1502 scan_span *= 2;
1503 seek_time = first_packet_time;
1504 }
1505
1506
1507
1508 else if (!found_packet_with_pts) {
1509 byterate = (seek_pos - cur_pos) / (duration - cur_time);
1510 cur_time = duration;
1511 }
1512 }
1513
1515}
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
void plm_demux_buffer_seek(plm_demux_t *self, size_t pos) FL_NOEXCEPT
size_t plm_buffer_get_size(plm_buffer_t *self) FL_NOEXCEPT
double plm_demux_get_duration(plm_demux_t *self, int type) FL_NOEXCEPT
int plm_buffer_find_start_code(plm_buffer_t *self, int code) FL_NOEXCEPT
plm_packet_t * plm_demux_decode_packet(plm_demux_t *self, int type) FL_NOEXCEPT
int plm_demux_has_headers(plm_demux_t *self) FL_NOEXCEPT
size_t plm_buffer_tell(plm_buffer_t *self) FL_NOEXCEPT
#define PLM_PACKET_INVALID_TS