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

Function decode_PAT

libhb/stream.c:2899–3007  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2897}
2898
2899static int decode_PAT(const uint8_t *buf, hb_stream_t *stream)
2900{
2901 unsigned char tablebuf[1024];
2902 unsigned int tablepos = 0;
2903
2904 int reading = 0;
2905
2906
2907 // Get adaption header info
2908 int adapt_len = 0;
2909 int adaption = (buf[3] & 0x30) >> 4;
2910 if (adaption == 0)
2911 return 0;
2912 else if (adaption == 0x2)
2913 adapt_len = 184;
2914 else if (adaption == 0x3)
2915 adapt_len = buf[4] + 1;
2916 if (adapt_len > 184)
2917 return 0;
2918
2919 // Get pointer length
2920 int pointer_len = buf[4 + adapt_len] + 1;
2921
2922 // Get payload start indicator
2923 int start;
2924 start = (buf[1] & 0x40) != 0;
2925
2926 if (start)
2927 reading = 1;
2928
2929 // Add the payload for this packet to the current buffer
2930 if (reading && (184 - adapt_len) > 0)
2931 {
2932 if (tablepos + 184 - adapt_len - pointer_len > 1024)
2933 {
2934 hb_log("decode_PAT - Bad program section length (> 1024)");
2935 return 0;
2936 }
2937 memcpy(tablebuf + tablepos, buf + 4 + adapt_len + pointer_len, 184 - adapt_len - pointer_len);
2938 tablepos += 184 - adapt_len - pointer_len;
2939 }
2940
2941 if (start && reading)
2942 {
2943 memcpy(tablebuf + tablepos, buf + 4 + adapt_len + 1, pointer_len - 1);
2944
2945
2946 unsigned int pos = 0;
2947 //while (pos < tablepos)
2948 {
2949 bitbuf_t bb;
2950 bits_init(&bb, tablebuf + pos, tablepos - pos, 0);
2951
2952 unsigned char section_id = bits_get(&bb, 8);
2953 bits_get(&bb, 4);
2954 unsigned int section_len = bits_get(&bb, 12);
2955 bits_get(&bb, 16); // transport_id
2956 bits_get(&bb, 2);

Callers 1

hb_ts_stream_find_pidsFunction · 0.85

Calls 3

hb_logFunction · 0.85
bits_initFunction · 0.85
bits_getFunction · 0.85

Tested by

no test coverage detected