* read the next transport stream packet from 'stream'. Return NULL if * we hit eof & a pointer to the sync byte otherwise. */
| 1149 | * we hit eof & a pointer to the sync byte otherwise. |
| 1150 | */ |
| 1151 | static 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. |
no test coverage detected