/***************************************************************************** * NewUDPPacket: allocate a new UDP packet of size p_sys->i_mtu *****************************************************************************/ static block_t *NewUDPPacket( sout_access_out_t *p_access, mtime_t i_dts) { sout_access_out_sys_t *p_sys = p_access->p_sys; block_t *p_buffer; while ( block_FifoCount( p_sys->p_empty_blocks ) > MAX_EMPTY_BLOCKS ) { p_buffer = block_FifoGet( p_sys->p_empty_blocks ); block_Release( p_buffer ); } if( block_FifoCount( p_sys->p_empty_blocks ) == 0 ) { p_buffer = block_Alloc( p_sys->i_mtu ); } else { p_buffer = block_FifoGet(p_sys->p_empty_blocks ); p_buffer->i_flags = 0; p_buffer = block_Realloc( p_buffer, 0, p_sys->i_mtu ); } p_buffer->i_dts = i_dts; p_buffer->i_buffer = 0; return p_buffer; }
/***************************************************************************** * sout_MuxGetStream: find stream to be muxed *****************************************************************************/ int sout_MuxGetStream( sout_mux_t *p_mux, unsigned i_blocks, mtime_t *pi_dts ) { mtime_t i_dts = 0; int i_stream = -1; assert( i_blocks > 0 ); for( int i = 0; i < p_mux->i_nb_inputs; i++ ) { sout_input_t *p_input = p_mux->pp_inputs[i]; block_t *p_data; if( block_FifoCount( p_input->p_fifo ) < i_blocks ) { if( (!p_mux->b_add_stream_any_time) && (p_input->p_fmt->i_cat != SPU_ES ) ) { return -1; } /* FIXME: SPU muxing */ continue; } p_data = block_FifoShow( p_input->p_fifo ); if( i_stream < 0 || p_data->i_dts < i_dts ) { i_stream = i; i_dts = p_data->i_dts; } } if( pi_dts ) *pi_dts = i_dts; return i_stream; }
/***************************************************************************** * sout_MuxDeleteStream: *****************************************************************************/ void sout_MuxDeleteStream( sout_mux_t *p_mux, sout_input_t *p_input ) { int i_index; if( p_mux->b_waiting_stream && block_FifoCount( p_input->p_fifo ) > 0 ) { /* We stop waiting, and call the muxer for taking care of the data * before we remove this es */ p_mux->b_waiting_stream = false; p_mux->pf_mux( p_mux ); } TAB_FIND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input, i_index ); if( i_index >= 0 ) { p_mux->pf_delstream( p_mux, p_input ); /* remove the entry */ TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input ); if( p_mux->i_nb_inputs == 0 ) { msg_Warn( p_mux, "no more input streams for this mux" ); } block_FifoRelease( p_input->p_fifo ); es_format_Clean( &p_input->fmt ); free( p_input ); } }
/***************************************************************************** * Close: *****************************************************************************/ void CloseVoD( vlc_object_t * p_this ) { vod_t *p_vod = (vod_t *)p_this; vod_sys_t *p_sys = p_vod->p_sys; /* Stop command thread */ vlc_cancel( p_sys->thread ); vlc_join( p_sys->thread, NULL ); while( block_FifoCount( p_sys->p_fifo_cmd ) > 0 ) { rtsp_cmd_t cmd; block_t *p_block_cmd = block_FifoGet( p_sys->p_fifo_cmd ); memcpy( &cmd, p_block_cmd->p_buffer, sizeof(cmd) ); block_Release( p_block_cmd ); if ( cmd.i_type == RTSP_CMD_TYPE_DEL ) MediaDel(p_vod, cmd.p_media); free( cmd.psz_arg ); } block_FifoRelease( p_sys->p_fifo_cmd ); free( p_sys->psz_rtsp_path ); free( p_sys ); }
/* We split/pack PCM blocks to a fixed size: pcm_chunk_size bytes */ static block_t *GetPCM( encoder_t *p_enc, aout_buffer_t *p_block ) { encoder_sys_t *p_sys = p_enc->p_sys; block_t *p_pcm_block; if( !p_block ) goto buffered; /* just return a block if we can */ /* Put the PCM samples sent by VLC in the Fifo */ while( p_sys->i_buffer + p_block->i_buffer >= pcm_chunk_size ) { unsigned int i_buffer = 0; p_pcm_block = block_New( p_enc, pcm_chunk_size ); if( !p_pcm_block ) break; if( p_sys->i_buffer ) { vlc_memcpy( p_pcm_block->p_buffer, p_sys->p_buffer, p_sys->i_buffer ); i_buffer = p_sys->i_buffer; p_sys->i_buffer = 0; free( p_sys->p_buffer ); } vlc_memcpy( p_pcm_block->p_buffer + i_buffer, p_block->p_buffer, pcm_chunk_size - i_buffer ); p_block->p_buffer += pcm_chunk_size - i_buffer; p_block->i_buffer -= pcm_chunk_size - i_buffer; block_FifoPut( p_sys->p_fifo, p_pcm_block ); } /* We hadn't enough data to make a block, put it in standby */ if( p_block->i_buffer ) { uint8_t *p_tmp; if( p_sys->i_buffer > 0 ) p_tmp = realloc( p_sys->p_buffer, p_block->i_buffer + p_sys->i_buffer ); else p_tmp = malloc( p_block->i_buffer ); if( !p_tmp ) { p_sys->i_buffer = 0; free( p_sys->p_buffer ); p_sys->p_buffer = NULL; return NULL; } p_sys->p_buffer = p_tmp; vlc_memcpy( p_sys->p_buffer + p_sys->i_buffer, p_block->p_buffer, p_block->i_buffer ); p_sys->i_buffer += p_block->i_buffer; p_block->i_buffer = 0; } buffered: /* and finally get a block back */ return block_FifoCount( p_sys->p_fifo ) > 0 ? block_FifoGet( p_sys->p_fifo ) : NULL; }