Commit 1943b8df authored by Laurent Aimar's avatar Laurent Aimar

* avi.c : quick hack to read file created by ffmpeg. I think it should

work.
 * all   : add support for some others codecs provided by ffmpeg, but some of them aren't tested.
parent 07828972
......@@ -2,7 +2,7 @@
* input_ext-dec.h: structures exported to the VideoLAN decoders
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: input_ext-dec.h,v 1.60 2002/06/01 12:31:57 sam Exp $
* $Id: input_ext-dec.h,v 1.61 2002/07/15 19:33:02 fenrir Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Michel Kaempf <maxx@via.ecp.fr>
......@@ -38,6 +38,9 @@
#define MSMPEG4v2_VIDEO_ES 0x41
#define MSMPEG4v3_VIDEO_ES 0x42
#define MPEG4_VIDEO_ES 0x50
#define H263_VIDEO_ES 0x60
#define I263_VIDEO_ES 0x61
#define SVQ1_VIDEO_ES 0x62
#define UNKNOWN_ES 0xFF
......
......@@ -4,7 +4,7 @@
* includes all common video types and constants.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: video.h,v 1.53 2002/06/01 12:31:58 sam Exp $
* $Id: video.h,v 1.54 2002/07/15 19:33:02 fenrir Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
*
......@@ -220,6 +220,13 @@ struct picture_heap_s
/* ?? */
#define FOURCC_3IV1 VLC_FOURCC('3','I','V','1')
/* H263 and H263i */
#define FOURCC_H263 VLC_FOURCC('H','2','6','3')
#define FOURCC_h263 VLC_FOURCC('h','2','6','3')
#define FOURCC_U263 VLC_FOURCC('U','2','6','3')
#define FOURCC_I263 VLC_FOURCC('I','2','6','3')
#define FOURCC_i263 VLC_FOURCC('i','2','6','3')
/* Packed RGB for 8bpp */
#define FOURCC_BI_RGB VLC_FOURCC( 0 , 0 , 0 , 0 )
......
......@@ -2,7 +2,7 @@
* avi.c : AVI file Stream input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: avi.c,v 1.30 2002/07/09 22:18:23 fenrir Exp $
* $Id: avi.c,v 1.31 2002/07/15 19:33:02 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
......@@ -195,56 +195,7 @@ static int AVI_AudioGetType( u32 i_type )
return( 0 );
}
}
static int AVI_VideoGetType( u32 i_type )
{
switch( i_type )
{
case( FOURCC_DIV1 ): /* FIXME it is for msmpeg4v1 or old mpeg4 ?? */
case( FOURCC_div1 ):
case( FOURCC_MPG4 ):
case( FOURCC_mpg4 ):
return( MSMPEG4v1_VIDEO_ES );
case( FOURCC_DIV2 ):
case( FOURCC_div2 ):
case( FOURCC_MP42 ):
case( FOURCC_mp42 ):
return( MSMPEG4v2_VIDEO_ES );
case( FOURCC_MPG3 ):
case( FOURCC_mpg3 ):
case( FOURCC_div3 ):
case( FOURCC_MP43 ):
case( FOURCC_mp43 ):
case( FOURCC_DIV3 ):
case( FOURCC_DIV4 ):
case( FOURCC_div4 ):
case( FOURCC_DIV5 ):
case( FOURCC_div5 ):
case( FOURCC_DIV6 ):
case( FOURCC_div6 ):
case( FOURCC_AP41 ):
case( FOURCC_3IV1 ):
return( MSMPEG4v3_VIDEO_ES );
case( FOURCC_DIVX ):
case( FOURCC_divx ):
case( FOURCC_MP4S ):
case( FOURCC_mp4s ):
case( FOURCC_M4S2 ):
case( FOURCC_m4s2 ):
case( FOURCC_xvid ):
case( FOURCC_XVID ):
case( FOURCC_XviD ):
case( FOURCC_DX50 ):
case( FOURCC_mp4v ):
case( FOURCC_4 ):
return( MPEG4_VIDEO_ES );
default:
return( 0 );
}
}
/* Test if it seems that it's a key frame */
static int AVI_GetKeyFlag( int i_type, u8 *p_byte )
{
......@@ -606,8 +557,8 @@ static int AVIInit( input_thread_t *p_input )
riffchunk_t *p_strl,*p_strh,*p_strf;
demux_data_avi_file_t *p_avi_demux;
es_descriptor_t *p_es = NULL; /* for not warning */
int i;
char *name;
int i, i_codec;
if( !( p_input->p_demux_data =
p_avi_demux = malloc( sizeof(demux_data_avi_file_t) ) ) )
......@@ -781,15 +732,21 @@ static int AVIInit( input_thread_t *p_input )
p_es->i_cat = VIDEO_ES;
AVI_Parse_BitMapInfoHeader( &p_info->video_format,
p_strf->p_data->p_payload_start );
/* XXX quick hack for playing ffmpeg video, I don't know
who is doing something wrong */
p_info->header.i_samplesize = 0;
p_es->b_audio = 0;
p_es->i_type =
AVI_VideoGetType( p_info->video_format.i_compression );
if( !p_es->i_type )
if( !AVI_GetVideoCodec( p_info->video_format.i_compression,
&i_codec,
&name ) )
{
msg_Warn( p_input, "stream(%d,%4.4s) not supported", i,
(char*)&p_info->video_format.i_compression);
p_es->i_cat = UNKNOWN_ES;
}
p_es->i_type = i_codec;
break;
default:
msg_Err( p_input, "unknown stream(%d) type", i );
......@@ -827,8 +784,7 @@ static int AVIInit( input_thread_t *p_input )
p_avi_demux->p_movi = p_movi;
/* get index XXX need to have p_movi */
if( ( p_avi_demux->b_seekable )
&&( p_avi_demux->avih.i_flags&AVIF_HASINDEX ) )
if( p_avi_demux->b_seekable )
{
/* get index */
__AVI_GetIndex( p_input );
......@@ -864,6 +820,7 @@ static int AVIInit( input_thread_t *p_input )
switch( p_info->p_es->i_cat )
{
case( VIDEO_ES ):
msg_Dbg( p_input, "video(%4.4s) %dx%d %dbpp %ffps",
(char*)&p_info->video_format.i_compression,
p_info->video_format.i_width,
......@@ -2258,6 +2215,7 @@ static int AVIDemux( input_thread_t *p_input )
p_avi_demux->i_rate = p_input->stream.control.i_rate;
}
vlc_mutex_unlock( &p_input->stream.stream_lock );
p_avi_demux->i_rate = DEFAULT_RATE;
if( p_avi_demux->i_rate != DEFAULT_RATE )
{
p_info_slave = NULL;
......
......@@ -2,7 +2,7 @@
* avi.h : AVI file Stream input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: avi.h,v 1.8 2002/06/30 15:07:57 fenrir Exp $
* $Id: avi.h,v 1.9 2002/07/15 19:33:02 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
......@@ -182,4 +182,82 @@ typedef struct demux_data_avi_file_s
AVIStreamInfo_t *p_info_audio;
} demux_data_avi_file_t;
/* current codec */
static struct
{
int i_fourcc;
int i_vlc_codec;
char *psz_name;
} AVI_VideoCodecs [] = {
{ FOURCC_DIV1, MSMPEG4v1_VIDEO_ES, "MS MPEG-4 v1" },
{ FOURCC_div1, MSMPEG4v1_VIDEO_ES, "MS MPEG-4 v1" },
{ FOURCC_MPG4, MSMPEG4v1_VIDEO_ES, "MS MPEG-4 v1" },
{ FOURCC_mpg4, MSMPEG4v1_VIDEO_ES, "MS MPEG-4 v1" },
{ FOURCC_DIV2, MSMPEG4v2_VIDEO_ES, "MS MPEG-4 v2" },
{ FOURCC_div2, MSMPEG4v2_VIDEO_ES, "MS MPEG-4 v2" },
{ FOURCC_MP42, MSMPEG4v2_VIDEO_ES, "MS MPEG-4 v2" },
{ FOURCC_mp42, MSMPEG4v2_VIDEO_ES, "MS MPEG-4 v2" },
{ FOURCC_MPG3, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_mpg3, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_div3, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_MP43, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_mp43, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_DIV3, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_DIV4, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_div4, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_DIV5, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_div5, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_DIV6, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_div6, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_AP41, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" },
{ FOURCC_3IV1, MSMPEG4v3_VIDEO_ES, "MS MPEG-4 v3" }, /* wrong */
{ FOURCC_DIVX, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_divx, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_MP4S, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_mp4s, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_M4S2, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_m4s2, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_xvid, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_XVID, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_XviD, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_DX50, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_mp4v, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_4, MPEG4_VIDEO_ES, "MPEG-4" },
{ FOURCC_H263, H263_VIDEO_ES, "H263" },
{ FOURCC_h263, H263_VIDEO_ES, "H263" },
{ FOURCC_U263, H263_VIDEO_ES, "H263" },
{ FOURCC_I263, I263_VIDEO_ES, "H263.I" },
{ FOURCC_i263, I263_VIDEO_ES, "H263.I" },
{ 0, UNKNOWN_ES, "Unknown" }
};
static int AVI_GetVideoCodec( int i_fourcc,
int *pi_vlc_codec,
char **ppsz_name )
{
int i_codec;
for( i_codec = 0; ; i_codec++ )
{
if( ( AVI_VideoCodecs[i_codec].i_fourcc == i_fourcc )||
( AVI_VideoCodecs[i_codec].i_fourcc == 0 ) )
{
break;
}
}
if( pi_vlc_codec )
*pi_vlc_codec = AVI_VideoCodecs[i_codec].i_vlc_codec;
if( ppsz_name )
*ppsz_name = AVI_VideoCodecs[i_codec].psz_name;
return( AVI_VideoCodecs[i_codec].i_fourcc == 0 ? 0 : 1 );
}
......@@ -2,7 +2,7 @@
* ffmpeg.c: video decoder using ffmpeg library
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: ffmpeg.c,v 1.13 2002/06/07 14:30:40 sam Exp $
* $Id: ffmpeg.c,v 1.14 2002/07/15 19:33:02 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -75,7 +75,7 @@ MODULE_CONFIG_START
MODULE_CONFIG_STOP
MODULE_INIT_START
SET_DESCRIPTION( "ffmpeg video decoder (MSMPEG4v123,MPEG4)" )
SET_DESCRIPTION( "ffmpeg video decoder (MS-MPEG4,MPEG4,SVQ1,H263,H263.I)" )
ADD_CAPABILITY( DECODER, 70 )
MODULE_INIT_STOP
......@@ -87,20 +87,6 @@ MODULE_DEACTIVATE_START
MODULE_DEACTIVATE_STOP
static inline u16 __GetWordLittleEndianFromBuff( byte_t *p_buff )
{
u16 i;
i = (*p_buff) + ( *(p_buff + 1) <<8 );
return ( i );
}
static inline u32 __GetDoubleWordLittleEndianFromBuff( byte_t *p_buff )
{
u32 i;
i = (*p_buff) + ( *(p_buff + 1) <<8 ) +
( *(p_buff + 2) <<16 ) + ( *(p_buff + 3) <<24 );
return ( i );
}
/*****************************************************************************
* decoder_Probe: probe the decoder and return score
......@@ -110,37 +96,78 @@ static inline u32 __GetDoubleWordLittleEndianFromBuff( byte_t *p_buff )
*****************************************************************************/
static int decoder_Probe( u8 *pi_type )
{
switch( *pi_type )
return( ffmpeg_GetFfmpegCodec( *pi_type, NULL, NULL ) ? 0 : -1 );
}
/*****************************************************************************
* decoder_Run: this function is called just after the thread is created
*****************************************************************************/
static int decoder_Run ( decoder_fifo_t * p_fifo )
{
videodec_thread_t *p_vdec;
int b_error;
if ( !(p_vdec = (videodec_thread_t*)malloc( sizeof(videodec_thread_t))) )
{
#if LIBAVCODEC_BUILD >= 4608
case( MSMPEG4v1_VIDEO_ES):
case( MSMPEG4v2_VIDEO_ES):
#endif
case( MSMPEG4v3_VIDEO_ES):
case( MPEG4_VIDEO_ES ):
return( 0 );
default:
return( -1 );
msg_Err( p_fifo, "out of memory" );
DecoderError( p_fifo );
return( -1 );
}
memset( p_vdec, 0, sizeof( videodec_thread_t ) );
p_vdec->p_fifo = p_fifo;
if( InitThread( p_vdec ) != 0 )
{
DecoderError( p_fifo );
return( -1 );
}
while( (!p_vdec->p_fifo->b_die) && (!p_vdec->p_fifo->b_error) )
{
DecodeThread( p_vdec );
}
if( ( b_error = p_vdec->p_fifo->b_error ) )
{
DecoderError( p_vdec->p_fifo );
}
}
EndThread( p_vdec );
if( b_error )
{
return( -1 );
}
return( 0 );
}
/*****************************************************************************
* Functions locales
* locales Functions
*****************************************************************************/
#define GetWLE( p ) \
( *(u8*)(p) + ( *((u8*)(p)+1) << 8 ) )
#define GetDWLE( p ) \
( *(u8*)(p) + ( *((u8*)(p)+1) << 8 ) + \
( *((u8*)(p)+2) << 16 ) + ( *((u8*)(p)+3) << 24 ) )
static void __ParseBitMapInfoHeader( bitmapinfoheader_t *h, byte_t *p_data )
{
h->i_size = __GetDoubleWordLittleEndianFromBuff( p_data );
h->i_width = __GetDoubleWordLittleEndianFromBuff( p_data + 4 );
h->i_height = __GetDoubleWordLittleEndianFromBuff( p_data + 8 );
h->i_planes = __GetWordLittleEndianFromBuff( p_data + 12 );
h->i_bitcount = __GetWordLittleEndianFromBuff( p_data + 14 );
h->i_compression = __GetDoubleWordLittleEndianFromBuff( p_data + 16 );
h->i_sizeimage = __GetDoubleWordLittleEndianFromBuff( p_data + 20 );
h->i_xpelspermeter = __GetDoubleWordLittleEndianFromBuff( p_data + 24 );
h->i_ypelspermeter = __GetDoubleWordLittleEndianFromBuff( p_data + 28 );
h->i_clrused = __GetDoubleWordLittleEndianFromBuff( p_data + 32 );
h->i_clrimportant = __GetDoubleWordLittleEndianFromBuff( p_data + 36 );
h->i_size = GetDWLE( p_data );
h->i_width = GetDWLE( p_data + 4 );
h->i_height = GetDWLE( p_data + 8 );
h->i_planes = GetWLE( p_data + 12 );
h->i_bitcount = GetWLE( p_data + 14 );
h->i_compression = GetDWLE( p_data + 16 );
h->i_sizeimage = GetDWLE( p_data + 20 );
h->i_xpelspermeter = GetDWLE( p_data + 24 );
h->i_ypelspermeter = GetDWLE( p_data + 28 );
h->i_clrused = GetDWLE( p_data + 32 );
h->i_clrimportant = GetDWLE( p_data + 36 );
}
/* get the first pes from fifo */
static pes_packet_t *__PES_GET( decoder_fifo_t *p_fifo )
......@@ -165,6 +192,7 @@ static pes_packet_t *__PES_GET( decoder_fifo_t *p_fifo )
return( p_pes );
}
/* free the first pes and go to next */
static void __PES_NEXT( decoder_fifo_t *p_fifo )
{
......@@ -236,53 +264,383 @@ static inline void __NextFrame( videodec_thread_t *p_vdec )
__PES_NEXT( p_vdec->p_fifo );
}
/* FIXME FIXME some of them may be wrong */
static int i_ffmpeg_PixFmtToChroma[] =
{
/* PIX_FMT_ANY = -1,PIX_FMT_YUV420P, PIX_FMT_YUV422,
PIX_FMT_RGB24, PIX_FMT_BGR24, PIX_FMT_YUV422P,
PIX_FMT_YUV444P, PIX_FMT_YUV410P */
0, FOURCC_I420, FOURCC_I420,
FOURCC_RV24, 0, FOURCC_Y422,
FOURCC_I444, 0
};
/*****************************************************************************
* decoder_Run: this function is called just after the thread is created
*****************************************************************************/
static int decoder_Run ( decoder_fifo_t * p_fifo )
static inline u32 ffmpeg_PixFmtToChroma( int i_ffmpegchroma )
{
videodec_thread_t *p_vdec;
int b_error;
if( ++i_ffmpegchroma > 7 )
{
return( 0 );
}
else
{
return( i_ffmpeg_PixFmtToChroma[i_ffmpegchroma] );
}
}
static inline int ffmpeg_FfAspect( int i_width, int i_height, int i_ffaspect )
{
switch( i_ffaspect )
{
case( FF_ASPECT_4_3_625 ):
case( FF_ASPECT_4_3_525 ):
return( VOUT_ASPECT_FACTOR * 4 / 3);
case( FF_ASPECT_16_9_625 ):
case( FF_ASPECT_16_9_525 ):
return( VOUT_ASPECT_FACTOR * 16 / 9 );
case( FF_ASPECT_SQUARE ):
default:
return( VOUT_ASPECT_FACTOR * i_width / i_height );
}
}
static int ffmpeg_CheckVout( vout_thread_t *p_vout,
int i_width,
int i_height,
int i_aspect,
int i_chroma )
{
if( !p_vout )
{
return( 0 );
}
if( !i_chroma )
{
i_chroma = FOURCC_I420; /* we will try to make conversion */
}
if ( (p_vdec = (videodec_thread_t*)malloc( sizeof(videodec_thread_t)))
== NULL )
if( ( p_vout->render.i_width != i_width )||
( p_vout->render.i_height != i_height )||
( p_vout->render.i_chroma != i_chroma )||
( p_vout->render.i_aspect !=
ffmpeg_FfAspect( i_width, i_height, i_aspect ) ) )
{
msg_Err( p_fifo, "out of memory" );
DecoderError( p_fifo );
return( -1 );
return( 0 );
}
memset( p_vdec, 0, sizeof( videodec_thread_t ) );
else
{
return( 1 );
}
}
p_vdec->p_fifo = p_fifo;
/* Return a Vout */
if( InitThread( p_vdec ) != 0 )
static vout_thread_t *ffmpeg_CreateVout( videodec_thread_t *p_vdec,
int i_width,
int i_height,
int i_aspect,
int i_chroma )
{
vout_thread_t *p_vout;
if( (!i_width)||(!i_height) )
{
DecoderError( p_fifo );
return( -1 );
return( NULL ); /* Can't create a new vout without display size */
}
while( (!p_vdec->p_fifo->b_die) && (!p_vdec->p_fifo->b_error) )
if( !i_chroma )
{
/* decode a picture */
DecodeThread( p_vdec );
i_chroma = FOURCC_I420; /* we make conversion if possible*/
msg_Warn( p_vdec->p_fifo, "Internal chroma conversion (FIXME)");
/* It's mainly for I410 -> I420 conversion that I've made,
it's buggy and very slow */
}
i_aspect = ffmpeg_FfAspect( i_width, i_height, i_aspect );
/* Spawn a video output if there is none. First we look for our children,
* then we look for any other vout that might be available. */
p_vout = vlc_object_find( p_vdec->p_fifo, VLC_OBJECT_VOUT,
FIND_CHILD );
if( !p_vout )
{
p_vout = vlc_object_find( p_vdec->p_fifo, VLC_OBJECT_VOUT,
FIND_ANYWHERE );
}
if( ( b_error = p_vdec->p_fifo->b_error ) )
if( p_vout )
{
DecoderError( p_vdec->p_fifo );
if( !ffmpeg_CheckVout( p_vout,
i_width, i_height, i_aspect,i_chroma ) )
{
/* We are not interested in this format, close this vout */
vlc_object_detach_all( p_vout );
vlc_object_release( p_vout );
vout_DestroyThread( p_vout );
p_vout = NULL;
}
else
{
/* This video output is cool! Hijack it. */
vlc_object_detach_all( p_vout );
vlc_object_attach( p_vout, p_vdec->p_fifo );
vlc_object_release( p_vout );
}
}
EndThread( p_vdec );
if( p_vout == NULL )
{
msg_Dbg( p_vdec->p_fifo, "no vout present, spawning one" );
p_vout = vout_CreateThread( p_vdec->p_fifo,
i_width,
i_height,
i_chroma,
i_aspect );
}
if( b_error )
return( p_vout );
}
#if 0
/* segfault some^Wevery times*/
static void ffmpeg_ConvertPictureI410toI420( picture_t *p_pic,
AVPicture *p_avpicture,
videodec_thread_t *p_vdec )
{
int i_plane;
int i_x, i_y;
int i_x_max, i_y_max;
int i_width;
int i_height;
int i_dst_stride;
int i_src_stride;
u8 *p_dest;
u8 *p_src;
i_width = p_vdec->p_context->width;
i_height= p_vdec->p_context->height;
p_dest = p_pic->p[0].p_pixels;
p_src = p_avpicture->data[0];
i_src_stride = p_avpicture->linesize[0];
i_dst_stride = p_pic->p[0].i_pitch;
if( i_src_stride == i_dst_stride )
{
return( -1 );
p_vdec->p_fifo->p_vlc->pf_memcpy( p_dest, p_src, i_src_stride * i_height );
}
return( 0 );
}
else
{
for( i_y = 0; i_y < i_height; i_y++ )
{
p_vdec->p_fifo->p_vlc->pf_memcpy( p_dest, p_src, i_width );
p_dest += i_dst_stride;
p_src += i_src_stride;
}
}
for( i_plane = 1; i_plane < 3; i_plane++ )
{
i_y_max = p_pic->p[i_plane].i_lines;
p_src = p_avpicture->data[i_plane];
p_dest = p_pic->p[i_plane].p_pixels;
i_dst_stride = p_pic->p[i_plane].i_pitch;