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

Function align_to_next_packet

libhb/bd.c:1038–1104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1036#define MAX_HOLE 192*80
1037
1038static uint64_t align_to_next_packet(BLURAY *bd, uint8_t *pkt)
1039{
1040 int result;
1041 uint8_t buf[MAX_HOLE];
1042 uint64_t pos = 0;
1043 uint64_t start = bd_tell(bd);
1044 uint64_t orig;
1045 uint64_t off = 192;
1046
1047 memcpy(buf, pkt, 192);
1048 if ( start >= 192 ) {
1049 start -= 192;
1050 }
1051 orig = start;
1052
1053 while (1)
1054 {
1055 result = bd_read(bd, buf + off, sizeof(buf) - off);
1056 if (result == sizeof(buf) - off)
1057 {
1058 const uint8_t *bp = buf;
1059 int i;
1060
1061 for ( i = sizeof(buf) - 8 * 192; --i >= 0; ++bp )
1062 {
1063 if ( have_ts_sync( bp, 192 ) )
1064 {
1065 break;
1066 }
1067 }
1068 if ( i >= 0 )
1069 {
1070 pos = ( bp - buf );
1071 break;
1072 }
1073 off = 8 * 192;
1074 memcpy(buf, buf + sizeof(buf) - off, off);
1075 start += sizeof(buf) - off;
1076 }
1077 else if (result < 0)
1078 {
1079 return -1;
1080 }
1081 else
1082 {
1083 return 0;
1084 }
1085 }
1086 off = start + pos - 4;
1087 // bd_seek seeks to the nearest access unit *before* the requested position
1088 // we don't want to seek backwards, so we need to read until we get
1089 // past that position.
1090 bd_seek(bd, off);
1091 while (off > bd_tell(bd))
1092 {
1093 result = bd_read(bd, buf, 192);
1094 if (result < 0)
1095 {

Callers 1

next_packetFunction · 0.70

Calls 1

have_ts_syncFunction · 0.70

Tested by

no test coverage detected