- /* If this is a PCR_PID, and this TS packet contains a PCR,
- we pass it along to the PCR decoder. */
- if( (p_es_descriptor->b_pcr) && (p[5] & 0x10) )
- {
- /* There should be a PCR field in the packet, check if the
- adaption field is long enough to carry it */
- if( p[4] >= 7 )
- {
- /* Call the PCR decoder */
- input_PcrDecode( p_input, p_es_descriptor, &p[6] );
- }
- }
- }
- }
- }
-
- /* Check the continuity of the stream. */
- i_dummy = ((p[3] & 0x0f) - p_es_descriptor->i_continuity_counter) & 0x0f;
- if( i_dummy == 1 )
- {
- /* Everything is ok, just increase our counter */
- p_es_descriptor->i_continuity_counter++;
- }
- else
- {
- if( !b_payload && i_dummy == 0 )
- {
- /* This is a packet without payload, this is allowed by the draft
- As there is nothing interesting in this packet (except PCR that
- have already been handled), we can trash the packet. */
- intf_DbgMsg("Packet without payload received by TS demux\n");
- b_trash = 1;
- }
- else if( i_dummy <= 0 )
- {
- /* Duplicate packet: mark it as being to be trashed. */
- intf_DbgMsg("Duplicate packet received by TS demux\n");
- b_trash = 1;
- }
- else if( p_es_descriptor->i_continuity_counter == 0xFF )
- {
- /* This means that the packet is the first one we receive for this
- ES since the continuity counter ranges between 0 and 0x0F
- excepts when it has been initialized by the input: Init the
- counter to the correct value. */
- intf_DbgMsg("First packet for PID %d received by TS demux\n",
- p_es_descriptor->i_id);
- p_es_descriptor->i_continuity_counter = (p[3] & 0x0f);
- }
- else
- {
- /* This can indicate that we missed a packet or that the
- continuity_counter wrapped and we received a dup packet: as we
- don't know, do as if we missed a packet to be sure to recover
- from this situation */
- intf_DbgMsg("Packet lost by TS demux: current %d, packet %d\n",
- p_es_descriptor->i_continuity_counter & 0x0f,
- p[3] & 0x0f);
- b_lost = 1;
- p_es_descriptor->i_continuity_counter = p[3] & 0x0f;
- }
- }
-
- /* Trash the packet if it has no payload or if it is bad */
- if( b_trash )
- {
- input_NetlistFreeTS( p_input, p_ts_packet );
-#ifdef STATS
- p_input->c_packets_trashed++;
-#endif
- }
- else
- {
- if( p_es_descriptor->b_psi )
- {
- /* The payload contains PSI tables */
- input_DemuxPSI( p_input, p_ts_packet, p_es_descriptor,
- b_unit_start, b_lost );
- }
- else
- {
- /* The payload carries a PES stream */
- input_DemuxPES( p_input, p_ts_packet, p_es_descriptor,
- b_unit_start, b_lost );
- }
- }
-
-#undef p