* hb_ts_stream_decode *********************************************************************** * **********************************************************************/
| 4879 | * |
| 4880 | **********************************************************************/ |
| 4881 | hb_buffer_t * hb_ts_decode_pkt( hb_stream_t *stream, const uint8_t * pkt, |
| 4882 | int chapter, int discontinuity ) |
| 4883 | { |
| 4884 | /* |
| 4885 | * stash the output buffer pointer in our stream so we don't have to |
| 4886 | * pass it & its original value to everything we call. |
| 4887 | */ |
| 4888 | int video_index = ts_index_of_video(stream); |
| 4889 | int curstream; |
| 4890 | hb_buffer_t *buf = NULL; |
| 4891 | hb_buffer_list_t list; |
| 4892 | |
| 4893 | hb_buffer_list_clear(&list); |
| 4894 | |
| 4895 | if (chapter > 0) |
| 4896 | { |
| 4897 | stream->chapter = chapter; |
| 4898 | } |
| 4899 | if (discontinuity) |
| 4900 | { |
| 4901 | // If there is a discontinuity, flush all data |
| 4902 | buf = flush_ts_streams(stream); |
| 4903 | hb_buffer_list_append(&list, buf); |
| 4904 | |
| 4905 | stream->ts.discontinuity = 1; |
| 4906 | } |
| 4907 | |
| 4908 | /* This next section validates the packet */ |
| 4909 | |
| 4910 | // Get pid and use it to find stream state. |
| 4911 | int pid = ((pkt[1] & 0x1F) << 8) | pkt[2]; |
| 4912 | if ( ( curstream = index_of_pid( stream, pid ) ) < 0 ) |
| 4913 | { |
| 4914 | // Not a stream we care about |
| 4915 | return hb_buffer_list_clear(&list); |
| 4916 | } |
| 4917 | |
| 4918 | |
| 4919 | // Get error |
| 4920 | int errorbit = (pkt[1] & 0x80) != 0; |
| 4921 | if (errorbit) |
| 4922 | { |
| 4923 | ts_err( stream, curstream, "packet error bit set"); |
| 4924 | return hb_buffer_list_clear(&list); |
| 4925 | } |
| 4926 | |
| 4927 | // Get adaption header info |
| 4928 | int adaption = (pkt[3] & 0x30) >> 4; |
| 4929 | int adapt_len = 0; |
| 4930 | if (adaption == 0) |
| 4931 | { |
| 4932 | ts_err( stream, curstream, "adaptation code 0"); |
| 4933 | return hb_buffer_list_clear(&list); |
| 4934 | } |
| 4935 | else if (adaption == 0x2) |
| 4936 | adapt_len = 184; |
| 4937 | else if (adaption == 0x3) |
| 4938 | { |
no test coverage detected