-
-static int mms_ReceivePacket( input_thread_t *p_input )
-{
- access_t *p_access = (access_t*)p_input->p_access_data;
- uint8_t preheader[8];
- int i_read;
-
- if( p_access->i_proto == MMS_PROTO_UDP )
- {
- return( -1 );
- }
- else
- {
- for( ;; )
- {
- i_read = NetRead( p_input, &p_access->socket_server, preheader, 8 );
- if( i_read < 8 )
- {
- msg_Warn( p_input, "cannot read preheader" );
- return( -1 );
- }
- /* preheader format :
- * u32 i_sequence_number
- * u8 i_packet_id
- * u8 i_udp_sequence/i_tcp_flags
- * u16 i_length
- */
- if( preheader[4] == p_access->i_header_packet_id_type ||
- preheader[4] == p_access->i_media_packet_id_type ||
- preheader[4] == 0xff )// udp timing pair
- {
- int i_packet_seq_num;
- int i_packet_length;
- int i_packet_id;
-
- uint8_t *p_packet;
-
- i_packet_seq_num = GetDWLE( preheader );
- i_packet_length = GetWLE( preheader + 6 );
- i_packet_id = preheader[4];
-
- /* *** read complete packet *** */
- if( i_packet_length <= 8 )
- {
- msg_Err( p_input,
- "empty or broken packet" );
- return( -1 );
- }
- p_packet = malloc( i_packet_length - 8 );
- if( mms_ReadData( p_input,
- p_packet,
- i_packet_length - 8 ) < 0 )
- {
- msg_Err( p_input,
- "cannot read data" );
- }
-
-
- if( i_packet_id == 0xff )
- {
- msg_Warn( p_input,
- "receive MMS UDP pair timing" );
- free( p_packet );
- return( MMS_PACKET_UDP_TIMING );
- }
- else
- {
- if( i_packet_seq_num != p_access->i_packet_seq_num )
- {
- // FIXME for udp could be just wrong order ?
- msg_Warn( p_input,
- "detected packet lost (%d != %d)",
- i_packet_seq_num,
- p_access->i_packet_seq_num );
- p_access->i_packet_seq_num = i_packet_seq_num;
- }
- p_access->i_packet_seq_num++;
-
- if( i_packet_id == p_access->i_header_packet_id_type )
- {
- FREE( p_access->p_header );
- p_access->p_header = p_packet;
- p_access->i_header = i_packet_length - 8;
- return( MMS_PACKET_HEADER );
- }
- else
- {
- FREE( p_access->p_media );
- p_access->p_media = p_packet;
- p_access->i_media = i_packet_length - 8;
- p_access->i_media_used = 0;
- return( MMS_PACKET_MEDIA );
- }
- }
- }
- else
- {
- int i_packet_length;
- // command ?
- if( GetDWLE( preheader + 4 ) != 0xb00bface )
- {
- msg_Err( p_input,
- "incorrect command header (0x%x)",
- GetDWLE( preheader + 4 ) );
- }
- memcpy( p_access->p_cmd, preheader, 8 );
- if( mms_ReadData( p_input,
- p_access->p_cmd + 8,
- 8 ) < 0 )
- {
- msg_Err( p_input,
- "cannot read data" );
- }
- p_access->i_cmd = 16;
- i_packet_length = GetDWLE( p_access->p_cmd + 8 );
- if( mms_ReadData( p_input,
- p_access->p_cmd + 16,
- i_packet_length ) < 0 )
- {
- msg_Err( p_input,
- "cannot read data" );
- }
- p_access->i_cmd += i_packet_length;
- p_access->i_command = GetDWLE( p_access->p_cmd + 36 ) & 0xffff;
- if( p_access->i_command == 0x1b )
- {
- mms_CommandSend( p_input, 0x1b, 0, 0, NULL, 0 );
- }
- else
- {
- return( MMS_PACKET_CMD );
- }
-
- }
- }
- }
-}
-
-