+
+ case STATE_GET_DATA:
+ /* Make sure we have enough data.
+ * (Not useful if we went through NEXT_SYNC) */
+ if( block_WaitBytes( &p_sys->bytestream,
+ p_sys->i_frame_size ) != VLC_SUCCESS )
+ {
+ /* Need more data */
+ return NULL;
+ }
+ p_sys->i_state = STATE_SEND_DATA;
+
+ case STATE_SEND_DATA:
+ if( !(p_buf = GetOutBuffer( p_dec, &p_out_buffer )) )
+ {
+ //p_dec->b_error = true;
+ return NULL;
+ }
+
+ /* Free bitrate only */
+ if( p_sys->i_bit_rate == 0 )
+ {
+ p_sys->i_free_frame_size = p_sys->i_frame_size;
+ }
+
+ /* Copy the whole frame into the buffer. When we reach this point
+ * we already know we have enough data available. */
+ block_GetBytes( &p_sys->bytestream,
+ p_buf, __MIN( (unsigned)p_sys->i_frame_size, p_out_buffer->i_buffer ) );
+
+ /* Get beginning of next frame for libmad */
+ if( !p_sys->b_packetizer )
+ {
+ assert( p_out_buffer->i_buffer >= (unsigned)p_sys->i_frame_size + MAD_BUFFER_GUARD );
+ memcpy( p_buf + p_sys->i_frame_size,
+ p_header, MAD_BUFFER_GUARD );
+ }
+
+ p_sys->i_state = STATE_NOSYNC;
+
+ /* Make sure we don't reuse the same pts twice */
+ if( p_sys->i_pts == p_sys->bytestream.p_block->i_pts )
+ p_sys->i_pts = p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID;
+
+ /* So p_block doesn't get re-added several times */
+ *pp_block = block_BytestreamPop( &p_sys->bytestream );
+
+ return p_out_buffer;