- if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ||
- tk->fmt.i_codec == VLC_FOURCC( 'a', 't', 'r', 'c') ||
- tk->fmt.i_codec == VLC_FOURCC( 's', 'i', 'p', 'r') ||
- tk->fmt.i_codec == VLC_FOURCC( '2', '8', '_', '8') )
- {
- uint8_t *p_buf = p_sys->buffer;
- int y = tk->i_subpacket / ( tk->i_frame_size /tk->i_subpacket_size);
- int i_index, i;
-
- /* Sanity check */
- if( i_flags & 2 || ( p_sys->b_seek ) )
- {
- y = tk->i_subpacket = 0;
- tk->i_out_subpacket = 0;
- p_sys->b_seek = 0;
- }
-
- if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ||
- tk->fmt.i_codec == VLC_FOURCC( 'a', 't', 'r', 'c' ))
- {
- int num = tk->i_frame_size / tk->i_subpacket_size;
- for( i = 0; i < num; i++ )
- {
- block_t *p_block = block_New( p_demux, tk->i_subpacket_size );
- memcpy( p_block->p_buffer, p_buf, tk->i_subpacket_size );
- p_buf += tk->i_subpacket_size;
-
- i_index = tk->i_subpacket_h * i +
- ((tk->i_subpacket_h + 1) / 2) * (y&1) + (y>>1);
-
- if ( tk->p_subpackets[i_index] != NULL )
- {
- msg_Dbg(p_demux, "p_subpackets[ %d ] not null!", i_index );
- free( tk->p_subpackets[i_index] );
- }
-
- tk->p_subpackets[i_index] = p_block;
- tk->i_subpacket++;
- p_block->i_dts = p_block->i_pts = 0;
- }
- tk->p_subpackets_timecode[tk->i_subpacket - num] = i_pts;
- }
-
- if( tk->fmt.i_codec == VLC_FOURCC( '2', '8', '_', '8' ) ||
- tk->fmt.i_codec == VLC_FOURCC( 's', 'i', 'p', 'r' ) )
- for( i = 0; i < tk->i_subpacket_h / 2; i++ )
- {
- block_t *p_block = block_New( p_demux, tk->i_coded_frame_size);
- memcpy( p_block->p_buffer, p_buf, tk->i_coded_frame_size );
- p_buf += tk->i_coded_frame_size;
-
- i_index = (i * 2 * tk->i_frame_size) /
- tk->i_coded_frame_size + y;
-
- p_block->i_dts = p_block->i_pts = i_pts;
- tk->p_subpackets[i_index] = p_block;
- tk->i_subpacket++;
- }
-
- while( tk->i_out_subpacket != tk->i_subpackets &&
- tk->p_subpackets[tk->i_out_subpacket] )
- {
- /* Set the PCR */
-#if 0
- if (tk->i_out_subpacket == 0)
- {
- p_sys->i_pcr = tk->p_subpackets[tk->i_out_subpacket]->i_dts;
- es_out_Control( p_demux->out, ES_OUT_SET_PCR,
- (int64_t)p_sys->i_pcr );
- }
-
- block_t *p_block = tk->p_subpackets[tk->i_out_subpacket];
- tk->p_subpackets[tk->i_out_subpacket] = 0;
-
- if( tk->i_out_subpacket ) p_block->i_dts = p_block->i_pts = 0;
-#endif
-
- block_t *p_block = tk->p_subpackets[tk->i_out_subpacket];
- tk->p_subpackets[tk->i_out_subpacket] = 0;
- if ( tk->p_subpackets_timecode[tk->i_out_subpacket] )
- {
- p_block->i_dts = p_block->i_pts =
- tk->p_subpackets_timecode[tk->i_out_subpacket];
- tk->p_subpackets_timecode[tk->i_out_subpacket] = 0;
-
- p_sys->i_pcr = p_block->i_dts;
- es_out_Control( p_demux->out, ES_OUT_SET_PCR,
- (int64_t)p_sys->i_pcr );
- }
- es_out_Send( p_demux->out, tk->p_es, p_block );
-
- tk->i_out_subpacket++;
- }
-
- if( tk->i_subpacket == tk->i_subpackets &&
- tk->i_out_subpacket != tk->i_subpackets )
- {
- msg_Warn( p_demux, "i_subpacket != i_out_subpacket, "
- "this shouldn't happen" );
- }
-
- if( tk->i_subpacket == tk->i_subpackets )
- {
- tk->i_subpacket = 0;
- tk->i_out_subpacket = 0;
- }
- }
- else
- {
- /* Set PCR */
- if( p_sys->i_pcr < i_pts )
- {
- p_sys->i_pcr = i_pts;
- es_out_Control( p_demux->out, ES_OUT_SET_PCR,
- (int64_t)p_sys->i_pcr );
- }
-
- if( tk->fmt.i_codec == VLC_FOURCC( 'm','p','4','a' ) )
- {
- int i_sub = (p_sys->buffer[1] >> 4)&0x0f;
- uint8_t *p_sub = &p_sys->buffer[2+2*i_sub];
-
- int i;
- for( i = 0; i < i_sub; i++ )
- {
- int i_sub_size = GetWBE( &p_sys->buffer[2+i*2]);
- block_t *p_block = block_New( p_demux, i_sub_size );
- if( p_block )
- {
- memcpy( p_block->p_buffer, p_sub, i_sub_size );
- p_sub += i_sub_size;
-
- p_block->i_dts =
- p_block->i_pts = ( i == 0 ? i_pts : 0 );
-
- es_out_Send( p_demux->out, tk->p_es, p_block );
- }
- }
- }
- else
- {
- block_t *p_block = block_New( p_demux, i_size );
-
- if( tk->fmt.i_codec == VLC_FOURCC( 'a', '5', '2', ' ' ) )
- {
- uint8_t *src = p_sys->buffer;
- uint8_t *dst = p_block->p_buffer;
-
- /* byte swap data */
- while( dst < &p_block->p_buffer[i_size- 1])
- {
- *dst++ = src[1];
- *dst++ = src[0];
-
- src += 2;
- }
- }
- else
- {
- memcpy( p_block->p_buffer, p_sys->buffer, i_size );
- }
- p_block->i_dts = p_block->i_pts = i_pts;
- es_out_Send( p_demux->out, tk->p_es, p_block );
- }
- }