MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / align_to_next_packet

Function align_to_next_packet

libhb/stream.c:2484–2532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2482#define MAX_HOLE 208*80
2483
2484static off_t align_to_next_packet(hb_stream_t *stream)
2485{
2486 uint8_t buf[MAX_HOLE];
2487 off_t pos = 0;
2488 off_t start = ftello(stream->file_handle);
2489 off_t orig;
2490
2491 if ( start >= stream->packetsize ) {
2492 start -= stream->packetsize;
2493 fseeko(stream->file_handle, start, SEEK_SET);
2494 }
2495 orig = start;
2496
2497 while (1)
2498 {
2499 if (fread(buf, sizeof(buf), 1, stream->file_handle) == 1)
2500 {
2501 const uint8_t *bp = buf;
2502 int i;
2503
2504 for ( i = sizeof(buf) - 8 * stream->packetsize; --i >= 0; ++bp )
2505 {
2506 if ( have_ts_sync( bp, stream->packetsize, 8 ) )
2507 {
2508 break;
2509 }
2510 }
2511 if ( i >= 0 )
2512 {
2513 pos = ( bp - buf ) - stream->packetsize + 188;
2514 break;
2515 }
2516 fseeko(stream->file_handle, -8 * stream->packetsize, SEEK_CUR);
2517 start = ftello(stream->file_handle);
2518 }
2519 else
2520 {
2521 int err;
2522 if ((err = ferror(stream->file_handle)) != 0)
2523 {
2524 hb_error("align_to_next_packet: error (%d)", err);
2525 hb_set_work_error(stream->h, HB_ERROR_READ);
2526 }
2527 return 0;
2528 }
2529 }
2530 fseeko(stream->file_handle, start+pos, SEEK_SET);
2531 return start - orig + pos;
2532}
2533
2534static const unsigned int bitmask[] = {
2535 0x0,0x1,0x3,0x7,0xf,0x1f,0x3f,0x7f,0xff,

Callers 4

next_packetFunction · 0.70
hb_sample_ptsFunction · 0.70
hb_stream_seekFunction · 0.70
hb_ts_stream_find_pidsFunction · 0.70

Calls 3

hb_errorFunction · 0.85
hb_set_work_errorFunction · 0.85
have_ts_syncFunction · 0.70

Tested by

no test coverage detected