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

Function next_packet

libhb/stream.c:1151–1183  ·  view source on GitHub ↗

* read the next transport stream packet from 'stream'. Return NULL if * we hit eof & a pointer to the sync byte otherwise. */

Source from the content-addressed store, hash-verified

1149 * we hit eof & a pointer to the sync byte otherwise.
1150 */
1151static const uint8_t *next_packet( hb_stream_t *stream )
1152{
1153 uint8_t *buf = stream->ts.packet + stream->packetsize - 188;
1154
1155 while ( 1 )
1156 {
1157 if ( fread(stream->ts.packet, 1, stream->packetsize, stream->file_handle) !=
1158 stream->packetsize )
1159 {
1160 int err;
1161 if ((err = ferror(stream->file_handle)) != 0)
1162 {
1163 hb_error("next_packet: error (%d)", err);
1164 hb_set_work_error(stream->h, HB_ERROR_READ);
1165 }
1166 return NULL;
1167 }
1168 if (buf[0] == 0x47)
1169 {
1170 return buf;
1171 }
1172 // lost sync - back up to where we started then try to re-establish.
1173 off_t pos = ftello(stream->file_handle) - stream->packetsize;
1174 off_t pos2 = align_to_next_packet(stream);
1175 if ( pos2 == 0 )
1176 {
1177 hb_log( "next_packet: eof while re-establishing sync @ %"PRId64, pos );
1178 return NULL;
1179 }
1180 ts_warn( stream, "next_packet: sync lost @ %"PRId64", regained after %"PRId64" bytes",
1181 pos, pos2 );
1182 }
1183}
1184
1185/*
1186 * skip to the start of the next PACK header in program stream src_stream.

Callers 3

hb_ts_stream_getPEStypeFunction · 0.70
hb_ts_stream_find_pidsFunction · 0.70
hb_ts_stream_decodeFunction · 0.70

Calls 5

hb_errorFunction · 0.85
hb_set_work_errorFunction · 0.85
hb_logFunction · 0.85
ts_warnFunction · 0.85
align_to_next_packetFunction · 0.70

Tested by

no test coverage detected