- /* Return the packet without the RTP header. */
- i_ret -= ( RTP_HEADER_LEN + 4 * i_CSRC_count );
-
- if ( (size_t)i_ret > i_len )
- {
- /* This should NOT happen. */
- msg_Warn( p_input, "RTP input trashing %d bytes", i_ret - i_len );
- i_ret = i_len;
- }
-
- p_input->p_vlc->pf_memcpy( p_buffer,
- p_tmp_buffer + RTP_HEADER_LEN + 4 * i_CSRC_count,
- i_ret );
-
- return i_ret;
-}
-
-/*****************************************************************************
- * RTPChoose : read from the network, and decide whether it's UDP or RTP
- *****************************************************************************/
-static ssize_t RTPChoose( input_thread_t * p_input, byte_t * p_buffer,
- size_t i_len )
-{
- int i_rtp_version;
- int i_CSRC_count;
- int i_payload_type;
-
- byte_t * p_tmp_buffer = alloca( p_input->i_mtu );
-
- /* Get the raw data from the socket.
- * We first assume that RTP header size is the classic RTP_HEADER_LEN. */
- ssize_t i_ret = Read( p_input, p_tmp_buffer, p_input->i_mtu );
-
- if ( i_ret <= 0 ) return 0; /* i_ret is at least 1 */
-
- /* Check that it's not TS. */
- if ( p_tmp_buffer[0] == 0x47 )
- {
- msg_Dbg( p_input, "detected TS over raw UDP" );
- p_input->pf_read = Read;
- p_input->p_vlc->pf_memcpy( p_buffer, p_tmp_buffer, i_ret );
- return i_ret;
- }
-
- /* Parse the header and make some verifications.
- * See RFC 1889 & RFC 2250. */
-
- i_rtp_version = ( p_tmp_buffer[0] & 0xC0 ) >> 6;
- i_CSRC_count = ( p_tmp_buffer[0] & 0x0F );
- i_payload_type = ( p_tmp_buffer[1] & 0x7F );
-
- if ( i_rtp_version != 2 )
- {
- msg_Dbg( p_input, "no supported RTP header detected" );
- p_input->pf_read = Read;
- p_input->p_vlc->pf_memcpy( p_buffer, p_tmp_buffer, i_ret );
- return i_ret;
- }
-
- switch ( i_payload_type )
- {
- case 33:
- msg_Dbg( p_input, "detected TS over RTP" );
- break;
-
- case 14:
- msg_Dbg( p_input, "detected MPEG audio over RTP" );
- break;
-
- case 32:
- msg_Dbg( p_input, "detected MPEG video over RTP" );
- break;
-
- default:
- msg_Dbg( p_input, "no RTP header detected" );
- p_input->pf_read = Read;
- p_input->p_vlc->pf_memcpy( p_buffer, p_tmp_buffer, i_ret );
- return i_ret;
- }
-
- p_input->pf_read = RTPRead;
-
- /* A CSRC extension field is 32 bits in size (4 bytes) */
- if ( i_ret < (RTP_HEADER_LEN + 4*i_CSRC_count) )
- {
- /* Packet is not big enough to hold the complete RTP_HEADER with
- * CSRC extensions.
- */
- msg_Warn( p_input, "RTP input trashing %d bytes", i_ret - i_len );
- return 0;
- }
-
- /* Return the packet without the RTP header. */
- i_ret -= ( RTP_HEADER_LEN + 4 * i_CSRC_count );
-
- if ( (size_t)i_ret > i_len )
- {
- /* This should NOT happen. */
- msg_Warn( p_input, "RTP input trashing %d bytes", i_ret - i_len );
- i_ret = i_len;
- }
-
- p_input->p_vlc->pf_memcpy( p_buffer,
- p_tmp_buffer + RTP_HEADER_LEN + 4 * i_CSRC_count,
- i_ret );
-
- return i_ret;