X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Favformat%2Fmux.c;h=af69662b8ad735407ef986819f16df197e2c904e;hb=41b8c2e1f660c767ee7a96ab69204b94b1470ca8;hp=14b19cef1488d79b18f8d424982b2a2e4413139c;hpb=f7d5f3e7cab176a0d68b736e05dece392d611161;p=vlc diff --git a/modules/demux/avformat/mux.c b/modules/demux/avformat/mux.c index 14b19cef14..af69662b8a 100644 --- a/modules/demux/avformat/mux.c +++ b/modules/demux/avformat/mux.c @@ -41,7 +41,7 @@ #endif #include "avformat.h" -#include "../../codec/avcodec/fourcc.h" +#include "../../codec/avcodec/avcodec.h" #include "../../codec/avcodec/avutil.h" //#define AVFORMAT_DEBUG 1 @@ -78,7 +78,7 @@ static int DelStream( sout_mux_t *, sout_input_t * ); static int Mux ( sout_mux_t * ); static int IOWrite( void *opaque, uint8_t *buf, int buf_size ); -static offset_t IOSeek( void *opaque, offset_t offset, int whence ); +static int64_t IOSeek( void *opaque, int64_t offset, int whence ); /***************************************************************************** * Open @@ -135,7 +135,7 @@ int OpenMux( vlc_object_t *p_this ) p_sys->url.prot->url_write = (int (*) (URLContext *, unsigned char *, int))IOWrite; p_sys->url.prot->url_seek = - (offset_t (*) (URLContext *, offset_t, int))IOSeek; + (int64_t (*) (URLContext *, int64_t, int))IOSeek; p_sys->url.prot->url_close = 0; p_sys->url.prot->next = 0; init_put_byte( &p_sys->io, p_sys->io_buffer, p_sys->io_buffer_size, @@ -151,11 +151,7 @@ int OpenMux( vlc_object_t *p_this ) return VLC_EGENERIC; } -#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(0<<8)+0) p_sys->oc->pb = &p_sys->io; -#else - p_sys->oc->pb = p_sys->io; -#endif p_sys->oc->nb_streams = 0; p_sys->b_write_header = true; @@ -174,7 +170,7 @@ void CloseMux( vlc_object_t *p_this ) sout_mux_sys_t *p_sys = p_mux->p_sys; unsigned int i; - if( av_write_trailer( p_sys->oc ) < 0 ) + if( !p_sys->b_write_header && av_write_trailer( p_sys->oc ) < 0 ) { msg_Err( p_mux, "could not write trailer" ); } @@ -200,7 +196,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) sout_mux_sys_t *p_sys = p_mux->p_sys; AVCodecContext *codec; AVStream *stream; - int i_codec_id, i_aspect_num, i_aspect_den; + int i_codec_id; msg_Dbg( p_mux, "adding input" ); @@ -214,6 +210,12 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) p_input->p_sys = malloc( sizeof( int ) ); *((int *)p_input->p_sys) = p_sys->oc->nb_streams; + if( p_input->p_fmt->i_cat != VIDEO_ES && p_input->p_fmt->i_cat != AUDIO_ES) + { + msg_Warn( p_mux, "Unhandled ES category" ); + return VLC_EGENERIC; + } + stream = av_new_stream( p_sys->oc, p_sys->oc->nb_streams); if( !stream ) { @@ -232,6 +234,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) codec->channels = p_input->p_fmt->audio.i_channels; codec->sample_rate = p_input->p_fmt->audio.i_rate; codec->time_base = (AVRational){1, codec->sample_rate}; + codec->frame_size = p_input->p_fmt->audio.i_frame_length; break; case VIDEO_ES: @@ -245,19 +248,18 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) codec->codec_type = CODEC_TYPE_VIDEO; codec->width = p_input->p_fmt->video.i_width; codec->height = p_input->p_fmt->video.i_height; - av_reduce( &i_aspect_num, &i_aspect_den, - p_input->p_fmt->video.i_aspect, - VOUT_ASPECT_FACTOR, 1 << 30 /* something big */ ); av_reduce( &codec->sample_aspect_ratio.num, &codec->sample_aspect_ratio.den, - i_aspect_num * (int64_t)codec->height, - i_aspect_den * (int64_t)codec->width, 1 << 30 ); + p_input->p_fmt->video.i_sar_num, + p_input->p_fmt->video.i_sar_den, 1 << 30 /* something big */ ); +#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(21<<8)+0) + stream->sample_aspect_ratio.num = codec->sample_aspect_ratio.num; + stream->sample_aspect_ratio.den = codec->sample_aspect_ratio.den; +#endif codec->time_base.den = p_input->p_fmt->video.i_frame_rate; codec->time_base.num = p_input->p_fmt->video.i_frame_rate_base; break; - default: - msg_Warn( p_mux, "Unhandled ES category" ); } codec->bit_rate = p_input->p_fmt->i_bitrate; @@ -274,7 +276,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) /* This is a hack */ if( i_codec_id == CODEC_ID_MP2 ) i_codec_id = CODEC_ID_MP3; - codec->codec_tag = p_input->p_fmt->i_codec; + codec->codec_tag = p_input->p_fmt->i_original_fourcc ?: p_input->p_fmt->i_codec; #endif codec->codec_id = i_codec_id; @@ -299,44 +301,6 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input ) return VLC_SUCCESS; } -/* - * TODO move this function to src/stream_output.c (used by nearly all muxers) - */ -static int MuxGetStream( sout_mux_t *p_mux, int *pi_stream, mtime_t *pi_dts ) -{ - mtime_t i_dts; - int i_stream, i; - - for( i = 0, i_dts = 0, i_stream = -1; i < p_mux->i_nb_inputs; i++ ) - { - block_fifo_t *p_fifo; - - p_fifo = p_mux->pp_inputs[i]->p_fifo; - - /* We don't really need to have anything in the SPU fifo */ - if( p_mux->pp_inputs[i]->p_fmt->i_cat == SPU_ES && - block_FifoCount( p_fifo ) == 0 ) continue; - - if( block_FifoCount( p_fifo ) ) - { - block_t *p_buf; - - p_buf = block_FifoShow( p_fifo ); - if( i_stream < 0 || p_buf->i_dts < i_dts ) - { - i_dts = p_buf->i_dts; - i_stream = i; - } - } - else return -1; - - } - if( pi_stream ) *pi_stream = i_stream; - if( pi_dts ) *pi_dts = i_dts; - if( !p_mux->p_sys->i_initial_dts ) p_mux->p_sys->i_initial_dts = i_dts; - return i_stream; -} - static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input ) { sout_mux_sys_t *p_sys = p_mux->p_sys; @@ -388,7 +352,6 @@ static int MuxBlock( sout_mux_t *p_mux, sout_input_t *p_input ) static int Mux( sout_mux_t *p_mux ) { sout_mux_sys_t *p_sys = p_mux->p_sys; - int i_stream; if( p_sys->b_error ) return VLC_EGENERIC; @@ -414,7 +377,15 @@ static int Mux( sout_mux_t *p_mux ) for( ;; ) { - if( MuxGetStream( p_mux, &i_stream, 0 ) < 0 ) return VLC_SUCCESS; + mtime_t i_dts; + + int i_stream = sout_MuxGetStream( p_mux, 1, &i_dts ); + if( i_stream < 0 ) + return VLC_SUCCESS; + + if( !p_mux->p_sys->i_initial_dts ) + p_mux->p_sys->i_initial_dts = i_dts; + MuxBlock( p_mux, p_mux->pp_inputs[i_stream] ); } @@ -475,11 +446,10 @@ static int IOWrite( void *opaque, uint8_t *buf, int buf_size ) return i_ret ? i_ret : -1; } -static offset_t IOSeek( void *opaque, offset_t offset, int whence ) +static int64_t IOSeek( void *opaque, int64_t offset, int whence ) { URLContext *p_url = opaque; sout_mux_t *p_mux = p_url->priv_data; - int64_t i_absolute; #ifdef AVFORMAT_DEBUG msg_Dbg( p_mux, "IOSeek offset: %"PRId64", whence: %i", offset, whence ); @@ -488,18 +458,10 @@ static offset_t IOSeek( void *opaque, offset_t offset, int whence ) switch( whence ) { case SEEK_SET: - i_absolute = offset; - break; + return sout_AccessOutSeek( p_mux->p_access, offset ); case SEEK_CUR: case SEEK_END: default: return -1; } - - if( sout_AccessOutSeek( p_mux->p_access, i_absolute ) ) - { - return -1; - } - - return 0; }