| 2897 | } |
| 2898 | |
| 2899 | static 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); |
no test coverage detected