Commit fc4a4577 authored by Rafaël Carré's avatar Rafaël Carré

avformat demux: use new IO API

- Use AVIOContext instead of ByteIOContext
- Use avformat_open_input instead of av_open_input_stream
- Use avio_alloc_context instead of init_put_byte, allocate context on the heap
- Use AVIOContext.seekable

print avformat_open_input errors

avformat_open_input is the most recent and is documented as available since
libavformat 53.2.0 (other changes happened in 52.105)
avformat_open_input was introduced in 52.94 in FFmpeg
(cherry picked from commit 4c3037ac)
Signed-off-by: default avatarKO Myung-Hun <komh@chollian.net>
Signed-off-by: default avatarRafaël Carré <funman@videolan.org>
parent ece5edec
...@@ -67,7 +67,10 @@ ...@@ -67,7 +67,10 @@
*****************************************************************************/ *****************************************************************************/
struct demux_sys_t struct demux_sys_t
{ {
#if LIBAVFORMAT_VERSION_INT < ((53<<16)+(2<<8)+0)
ByteIOContext io; ByteIOContext io;
#endif
int io_buffer_size; int io_buffer_size;
uint8_t *io_buffer; uint8_t *io_buffer;
...@@ -132,6 +135,7 @@ int OpenDemux( vlc_object_t *p_this ) ...@@ -132,6 +135,7 @@ int OpenDemux( vlc_object_t *p_this )
msg_Warn( p_demux, "cannot peek" ); msg_Warn( p_demux, "cannot peek" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_can_seek );
vlc_avcodec_lock(); vlc_avcodec_lock();
av_register_all(); /* Can be called several times */ av_register_all(); /* Can be called several times */
...@@ -220,35 +224,36 @@ int OpenDemux( vlc_object_t *p_this ) ...@@ -220,35 +224,36 @@ int OpenDemux( vlc_object_t *p_this )
/* Create I/O wrapper */ /* Create I/O wrapper */
p_sys->io_buffer_size = 32768; /* FIXME */ p_sys->io_buffer_size = 32768; /* FIXME */
p_sys->io_buffer = malloc( p_sys->io_buffer_size ); p_sys->io_buffer = malloc( p_sys->io_buffer_size );
init_put_byte( &p_sys->io, p_sys->io_buffer, p_sys->io_buffer_size,
0, p_demux, IORead, NULL, IOSeek );
stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_can_seek ); #if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(2<<8)+0)
if( !b_can_seek ) AVIOContext *io = avio_alloc_context( p_sys->io_buffer,
{ p_sys->io_buffer_size, 0, p_demux, IORead, NULL, IOSeek );
/* Tell avformat that input is stream, so it doesn't get stuck io->seekable = b_can_seek ? AVIO_SEEKABLE_NORMAL : 0;
when trying av_find_stream_info() trying to seek all the wrong places error = avformat_open_input(&p_sys->ic, psz_url, p_sys->fmt, NULL);
init_put_byte defaults io.is_streamed=0, so thats why we set them after it if (error == 0)
*/ {
p_sys->io.is_streamed = 1; p_sys->ic->flags |= AVFMT_FLAG_CUSTOM_IO;
#if defined(AVIO_SEEKABLE_NORMAL) p_sys->ic->pb = io;
p_sys->io.seekable = 0;
#endif
} }
#else
init_put_byte( &p_sys->io, p_sys->io_buffer, p_sys->io_buffer_size, 0,
p_demux, IORead, NULL, IOSeek );
p_sys->io.is_streamed = !b_can_seek;
# if defined(AVIO_SEEKABLE_NORMAL)
p_sys->io.seekable = !!b_can_seek;
# endif
error = av_open_input_stream(&p_sys->ic, &p_sys->io, psz_url, p_sys->fmt, NULL);
#endif
free( psz_url );
/* Open it */ if( error < 0 )
if( av_open_input_stream( &p_sys->ic, &p_sys->io, psz_url,
p_sys->fmt, NULL ) )
{ {
msg_Err( p_demux, "av_open_input_stream failed" ); errno = AVUNERROR(error);
msg_Err( p_demux, "Could not open %s: %m", psz_url );
p_sys->ic = NULL; p_sys->ic = NULL;
free( psz_url );
CloseDemux( p_this ); CloseDemux( p_this );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
free( psz_url );
psz_url = NULL;
vlc_avcodec_lock(); /* avformat calls avcodec behind our back!!! */ vlc_avcodec_lock(); /* avformat calls avcodec behind our back!!! */
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(26<<8)+0) #if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(26<<8)+0)
...@@ -537,11 +542,16 @@ void CloseDemux( vlc_object_t *p_this ) ...@@ -537,11 +542,16 @@ void CloseDemux( vlc_object_t *p_this )
free( p_sys->tk_pcr ); free( p_sys->tk_pcr );
if( p_sys->ic ) if( p_sys->ic )
{
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(2<<8)+0)
av_free( p_sys->ic->pb );
#endif
#if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(26<<8)+0) #if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(26<<8)+0)
avformat_close_input( &p_sys->ic ); avformat_close_input( &p_sys->ic );
#else #else
av_close_input_stream( p_sys->ic ); av_close_input_stream( p_sys->ic );
#endif #endif
}
for( int i = 0; i < p_sys->i_attachments; i++ ) for( int i = 0; i < p_sys->i_attachments; i++ )
free( p_sys->attachments[i] ); free( p_sys->attachments[i] );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment