* ffmpeg.c: video decoder using ffmpeg library
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: ffmpeg.c,v 1.4 2002/08/10 20:05:21 fenrir Exp $
+ * $Id: ffmpeg.c,v 1.56 2003/10/27 17:50:54 gbazin Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
+ * Gildas Bazin <gbazin@netcourrier.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Preamble
*****************************************************************************/
#include <stdlib.h> /* malloc(), free() */
+#include <string.h>
#include <vlc/vlc.h>
#include <vlc/vout.h>
+#include <vlc/aout.h>
#include <vlc/decoder.h>
#include <vlc/input.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h> /* getpid() */
-#endif
-
-#include <errno.h>
-#include <string.h>
-
#ifdef HAVE_SYS_TIMES_H
# include <sys/times.h>
#endif
-#include "avcodec.h" /* ffmpeg */
+/* ffmpeg header */
+#ifdef HAVE_FFMPEG_AVCODEC_H
+# include <ffmpeg/avcodec.h>
+#else
+# include <avcodec.h>
+#endif
-#include "postprocessing/postprocessing.h"
+#if LIBAVCODEC_BUILD < 4655
+# error You must have a libavcodec >= 4655 (get CVS)
+#endif
#include "ffmpeg.h"
-/*
- * Local prototypes
- */
-static int OpenDecoder ( vlc_object_t * );
-static int RunDecoder ( decoder_fifo_t * );
-static int InitThread ( videodec_thread_t * );
-static void EndThread ( videodec_thread_t * );
-static void DecodeThread ( videodec_thread_t * );
+#ifdef LIBAVCODEC_PP
+# ifdef HAVE_POSTPROC_POSTPROCESS_H
+# include <postproc/postprocess.h>
+# else
+# include <libpostproc/postprocess.h>
+# endif
+#endif
+
+/*****************************************************************************
+ * decoder_sys_t: decoder descriptor
+ *****************************************************************************/
+struct decoder_sys_t
+{
+ /* Common part between video and audio decoder */
+ int i_cat;
+ int i_codec_id;
+ char *psz_namecodec;
+
+ AVCodecContext *p_context;
+ AVCodec *p_codec;
+};
+/****************************************************************************
+ * Local prototypes
+ ****************************************************************************/
+static int OpenDecoder( vlc_object_t * );
+static int InitDecoder( decoder_t * );
+static int EndDecoder( decoder_t * );
-static int b_ffmpeginit = 0;
+static int b_ffmpeginit = 0;
/*****************************************************************************
* Module descriptor
*****************************************************************************/
-
-#define ERROR_RESILIENCE_LONGTEXT \
- "ffmpeg can make errors resiliences. \n"\
- "Nevertheless, with buggy encoder (like ISO MPEG-4 encoder from M$) " \
- "this will produce a lot of errors.\n" \
- "Valid range is -1 to 99 (-1 disable all errors resiliences)."
-
-#define HURRY_UP_LONGTEXT \
- "Allow the decoder to partially decode or skip frame(s) " \
- "when there not enough time.\n It's usefull with low CPU power " \
- "but it could produce broken pictures."
-
-#define POSTPROCESSING_Q_LONGTEXT \
- "Quality of post processing\n"\
- "Valid range is 0 to 6\n" \
- "( Overridden by others setting)"
-
-#define POSTPROCESSING_AQ_LONGTEXT \
- "Post processing quality is selected upon time left" \
- "but no more than requested quality\n" \
- "Not yet implemented !"
-
vlc_module_begin();
- add_category_hint( N_("Miscellaneous"), NULL );
-#if LIBAVCODEC_BUILD >= 4611
- add_integer ( "ffmpeg-error-resilience", -1, NULL,
- "error resilience", ERROR_RESILIENCE_LONGTEXT );
- add_integer ( "ffmpeg-workaround-bugs", 0, NULL,
- "workaround bugs", "0-99, seems to be for msmpeg v3\n" );
-#endif
- add_bool( "ffmpeg-hurry-up", 0, NULL, "hurry up", HURRY_UP_LONGTEXT );
-
- add_category_hint( N_("Post processing"), NULL );
- add_module( "ffmpeg-pp", "postprocessing",NULL, NULL,
- N_( "ffmpeg postprocessing module" ), NULL );
- add_integer( "ffmpeg-pp-q", 0, NULL,
- "Post processing quality", POSTPROCESSING_Q_LONGTEXT );
- add_bool( "ffmpeg-pp-auto", 0, NULL,
- "Auto-level Post processing quality", POSTPROCESSING_AQ_LONGTEXT );
- add_bool( "ffmpeg-db-yv", 0, NULL,
- "force vertical luminance deblocking",
- "force vertical luminance deblocking (override other settings)" );
- add_bool( "ffmpeg-db-yh", 0, NULL,
- "force horizontal luminance deblocking",
- "force horizontal luminance deblocking (override other settings)" );
- add_bool( "ffmpeg-db-cv", 0, NULL,
- "force vertical chrominance deblocking",
- "force vertical chrominance deblocking (override other settings)" );
- add_bool( "ffmpeg-db-ch", 0, NULL,
- "force horizontal chrominance deblocking",
- "force horizontal chrominance deblocking (override other settings) " );
- add_bool( "ffmpeg-dr-y", 0, NULL,
- "force luminance deringing",
- "force luminance deringing (override other settings)" );
- add_bool( "ffmpeg-dr-c", 0, NULL,
- "force chrominance deringing",
- "force chrominance deringing (override other settings)" );
-
- set_description( _("ffmpeg video decoder((MS)MPEG4,SVQ1,H263)") );
+
+ /* decoder main module */
+ add_category_hint( N_("ffmpeg"), NULL, VLC_FALSE );
set_capability( "decoder", 70 );
set_callbacks( OpenDecoder, NULL );
+ set_description( _("ffmpeg audio/video decoder((MS)MPEG4,SVQ1,H263,WMV,WMA)") );
+
+ add_bool( "ffmpeg-dr", 1, NULL, DR_TEXT, DR_TEXT, VLC_TRUE );
+ add_integer ( "ffmpeg-error-resilience", -1, NULL, ERROR_TEXT,
+ ERROR_LONGTEXT, VLC_TRUE );
+ add_integer ( "ffmpeg-workaround-bugs", 1, NULL, BUGS_TEXT, BUGS_LONGTEXT,
+ VLC_FALSE );
+ add_bool( "ffmpeg-hurry-up", 0, NULL, HURRYUP_TEXT, HURRYUP_LONGTEXT,
+ VLC_FALSE );
+ add_integer( "ffmpeg-truncated", 0, NULL, TRUNC_TEXT, TRUNC_LONGTEXT,
+ VLC_FALSE );
+
+#ifdef LIBAVCODEC_PP
+ add_integer( "ffmpeg-pp-q", 0, NULL, PP_Q_TEXT, PP_Q_LONGTEXT, VLC_FALSE );
+ add_string( "ffmpeg-pp-name", "default", NULL, LIBAVCODEC_PP_TEXT,
+ LIBAVCODEC_PP_LONGTEXT, VLC_TRUE );
+#endif
+
+ /* chroma conversion submodule */
+ add_submodule();
+ set_capability( "chroma", 50 );
+ set_callbacks( E_(OpenChroma), NULL );
+ set_description( _("ffmpeg chroma conversion") );
+
+ /* video encoder submodule */
+ add_submodule();
+ set_description( _("ffmpeg video encoder") );
+ set_capability( "video encoder", 100 );
+ set_callbacks( E_(OpenVideoEncoder), E_(CloseVideoEncoder) );
+
+ /* audio encoder submodule */
+ add_submodule();
+ set_description( _("ffmpeg audio encoder") );
+ set_capability( "audio encoder", 10 );
+ set_callbacks( E_(OpenAudioEncoder), E_(CloseAudioEncoder) );
+
+ var_Create( p_module->p_libvlc, "avcodec", VLC_VAR_MUTEX );
vlc_module_end();
/*****************************************************************************
* OpenDecoder: probe the decoder and return score
- *****************************************************************************
- * Tries to launch a decoder and return score so that the interface is able
- * to chose.
*****************************************************************************/
static int OpenDecoder( vlc_object_t *p_this )
{
- decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
-
- if( ffmpeg_GetFfmpegCodec( p_fifo->i_fourcc, NULL, NULL ) )
- {
- p_fifo->pf_run = RunDecoder;
- return VLC_SUCCESS;
- }
-
- return VLC_EGENERIC;
-}
-
-/*****************************************************************************
- * RunDecoder: this function is called just after the thread is created
- *****************************************************************************/
-static int RunDecoder( decoder_fifo_t *p_fifo )
-{
- videodec_thread_t *p_vdec;
- int b_error;
+ decoder_t *p_dec = (decoder_t*) p_this;
+ int i_cat, i_codec_id;
+ char *psz_namecodec;
- if ( !(p_vdec = (videodec_thread_t*)malloc( sizeof(videodec_thread_t))) )
+ if( !E_(GetFfmpegCodec)( p_dec->p_fifo->i_fourcc, &i_cat, &i_codec_id,
+ &psz_namecodec ) )
{
- msg_Err( p_fifo, "out of memory" );
- DecoderError( p_fifo );
- return( -1 );
+ return VLC_EGENERIC;
}
- 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 );
- }
+ /* Initialization must be done before avcodec_find_decoder() */
+ E_(InitLibavcodec)(p_this);
- if( ( b_error = p_vdec->p_fifo->b_error ) )
+ if( !avcodec_find_decoder( i_codec_id ) )
{
- DecoderError( p_vdec->p_fifo );
+ msg_Err( p_dec, "codec not found (%s)", psz_namecodec );
+ return VLC_EGENERIC;
}
- EndThread( p_vdec );
-
- if( b_error )
- {
- return( -1 );
- }
-
- return( 0 );
-}
+ p_dec->pf_init = InitDecoder;
+ p_dec->pf_decode = (i_cat == VIDEO_ES) ? E_(DecodeVideo) : E_(DecodeAudio);
+ p_dec->pf_end = EndDecoder;
+ return VLC_SUCCESS;
+}
/*****************************************************************************
- * locales Functions
+ * InitDecoder: Initalize the decoder
*****************************************************************************/
-
-#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 ) )
-
-#define FREE( p ) if( p ) free( p ); p = NULL
-
-static void ffmpeg_ParseBitMapInfoHeader( bitmapinfoheader_t *p_bh,
- u8 *p_data )
-{
- p_bh->i_size = GetDWLE( p_data );
- p_bh->i_width = GetDWLE( p_data + 4 );
- p_bh->i_height = GetDWLE( p_data + 8 );
- p_bh->i_planes = GetWLE( p_data + 12 );
- p_bh->i_bitcount = GetWLE( p_data + 14 );
- p_bh->i_compression = GetDWLE( p_data + 16 );
- p_bh->i_sizeimage = GetDWLE( p_data + 20 );
- p_bh->i_xpelspermeter = GetDWLE( p_data + 24 );
- p_bh->i_ypelspermeter = GetDWLE( p_data + 28 );
- p_bh->i_clrused = GetDWLE( p_data + 32 );
- p_bh->i_clrimportant = GetDWLE( p_data + 36 );
-
- if( p_bh->i_size > 40 )
- {
- p_bh->i_data = p_bh->i_size - 40;
- if( ( p_bh->p_data = malloc( p_bh->i_data ) ) )
- {
- memcpy( p_bh->p_data, p_data + 40, p_bh->i_data );
- }
- else
- {
- p_bh->i_data = 0;
- }
- }
- else
- {
- p_bh->i_data = 0;
- p_bh->p_data = NULL;
- }
-
-}
-/* get the first pes from fifo */
-static pes_packet_t *__PES_GET( decoder_fifo_t *p_fifo )
+static int InitDecoder( decoder_t *p_dec )
{
- pes_packet_t *p_pes;
+ int i_cat, i_codec_id, i_result;
+ char *psz_namecodec;
+ AVCodecContext *p_context;
+ AVCodec *p_codec;
- vlc_mutex_lock( &p_fifo->data_lock );
+ /* *** determine codec type *** */
+ E_(GetFfmpegCodec)( p_dec->p_fifo->i_fourcc,
+ &i_cat, &i_codec_id, &psz_namecodec );
- /* if fifo is emty wait */
- while( !p_fifo->p_first )
+ /* *** ask ffmpeg for a decoder *** */
+ if( !( p_codec = avcodec_find_decoder( i_codec_id ) ) )
{
- if( p_fifo->b_die )
- {
- vlc_mutex_unlock( &p_fifo->data_lock );
- return( NULL );
- }
- vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
+ msg_Err( p_dec, "codec not found (%s)", psz_namecodec );
+ return VLC_EGENERIC;
}
- p_pes = p_fifo->p_first;
-
- vlc_mutex_unlock( &p_fifo->data_lock );
- return( p_pes );
-}
-
-/* free the first pes and go to next */
-static void __PES_NEXT( decoder_fifo_t *p_fifo )
-{
- pes_packet_t *p_next;
+ /* *** get a p_context *** */
+ p_context = avcodec_alloc_context();
- vlc_mutex_lock( &p_fifo->data_lock );
-
- p_next = p_fifo->p_first->p_next;
- p_fifo->p_first->p_next = NULL;
- input_DeletePES( p_fifo->p_packets_mgt, p_fifo->p_first );
- p_fifo->p_first = p_next;
- p_fifo->i_depth--;
-
- if( !p_fifo->p_first )
- {
- /* No PES in the fifo */
- /* pp_last no longer valid */
- p_fifo->pp_last = &p_fifo->p_first;
- while( !p_fifo->p_first )
- {
- vlc_cond_signal( &p_fifo->data_wait );
- vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
- }
- }
- vlc_mutex_unlock( &p_fifo->data_lock );
-}
-
-static inline void __GetFrame( videodec_thread_t *p_vdec )
-{
- pes_packet_t *p_pes;
- data_packet_t *p_data;
- byte_t *p_buffer;
-
- p_pes = __PES_GET( p_vdec->p_fifo );
- p_vdec->i_pts = p_pes->i_pts;
-
- while( ( !p_pes->i_nb_data )||( !p_pes->i_pes_size ) )
- {
- __PES_NEXT( p_vdec->p_fifo );
- p_pes = __PES_GET( p_vdec->p_fifo );
- }
- p_vdec->i_framesize = p_pes->i_pes_size;
- if( p_pes->i_nb_data == 1 )
+ switch( i_cat )
{
- p_vdec->p_framedata = p_pes->p_first->p_payload_start;
- return;
+ case VIDEO_ES:
+ i_result = E_( InitVideoDec )( p_dec, p_context, p_codec,
+ i_codec_id, psz_namecodec );
+ p_dec->pf_decode = E_(DecodeVideo);
+ break;
+ case AUDIO_ES:
+ i_result = E_( InitAudioDec )( p_dec, p_context, p_codec,
+ i_codec_id, psz_namecodec );
+ p_dec->pf_decode = E_(DecodeAudio);
+ break;
+ default:
+ i_result = VLC_EGENERIC;
}
- /* get a buffer and gather all data packet */
- if( p_vdec->i_buffer_size < p_pes->i_pes_size )
- {
- if( p_vdec->p_buffer )
- {
- p_vdec->p_buffer = realloc( p_vdec->p_buffer,
- p_pes->i_pes_size );
- }
- else
- {
- p_vdec->p_buffer = malloc( p_pes->i_pes_size );
- }
- p_vdec->i_buffer_size = p_pes->i_pes_size;
- }
-
- p_buffer = p_vdec->p_framedata = p_vdec->p_buffer;
- p_data = p_pes->p_first;
- do
- {
- p_vdec->p_fifo->p_vlc->pf_memcpy( p_buffer, p_data->p_payload_start,
- p_data->p_payload_end - p_data->p_payload_start );
- p_buffer += p_data->p_payload_end - p_data->p_payload_start;
- p_data = p_data->p_next;
- } while( p_data );
-}
-static inline void __NextFrame( videodec_thread_t *p_vdec )
-{
- __PES_NEXT( p_vdec->p_fifo );
-}
+ p_dec->p_sys->i_cat = i_cat;
-
-/* Check if we have a Vout with good parameters */
-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 )
- {
- /* we will try to make conversion */
- i_chroma = VLC_FOURCC('I','4','2','0');
- }
-
- 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 ) ) )
- {
- return( 0 );
- }
- else
- {
- return( 1 );
- }
+ return i_result;
}
-
-/* Return a Vout */
-
-static vout_thread_t *ffmpeg_CreateVout( videodec_thread_t *p_vdec,
- int i_width,
- int i_height,
- int i_aspect,
- int i_chroma )
+
+/*****************************************************************************
+ * EndDecoder: decoder destruction
+ *****************************************************************************/
+static int EndDecoder( decoder_t *p_dec )
{
- vout_thread_t *p_vout;
-
- if( (!i_width)||(!i_height) )
- {
- return( NULL ); /* Can't create a new vout without display size */
- }
-
- if( !i_chroma )
- {
- /* we make conversion if possible*/
- i_chroma = VLC_FOURCC('I','4','2','0');
- 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 );
- }
+ decoder_sys_t *p_sys = p_dec->p_sys;
- if( p_vout )
+ if( !p_sys->p_context )
{
- 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 );
- }
- }
+ if( p_sys->p_context->extradata )
+ free( p_sys->p_context->extradata );
- 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 );
+ avcodec_close( p_sys->p_context );
+ msg_Dbg( p_dec, "ffmpeg codec (%s) stopped", p_sys->psz_namecodec );
+ free( p_sys->p_context );
}
-
- return( p_vout );
-}
-/* FIXME FIXME FIXME this is a big shit
- does someone want to rewrite this function ?
- or said to me how write a better thing
- FIXME FIXME FIXME
-*/
-static void ffmpeg_ConvertPictureI410toI420( picture_t *p_pic,
- AVPicture *p_avpicture,
- videodec_thread_t *p_vdec )
-{
- u8 *p_src, *p_dst;
- u8 *p_plane[3];
- int i_plane;
-
- int i_stride, i_lines;
- int i_height, i_width;
- int i_y, i_x;
-
- i_height = p_vdec->p_context->height;
- i_width = p_vdec->p_context->width;
-
- p_dst = p_pic->p[0].p_pixels;
- p_src = p_avpicture->data[0];
-
- /* copy first plane */
- for( i_y = 0; i_y < i_height; i_y++ )
+ switch( p_sys->i_cat )
{
- p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, i_width);
- p_dst += p_pic->p[0].i_pitch;
- p_src += p_avpicture->linesize[0];
- }
-
- /* process each plane in a temporary buffer */
- for( i_plane = 1; i_plane < 3; i_plane++ )
- {
- i_stride = p_avpicture->linesize[i_plane];
- i_lines = i_height / 4;
-
- p_dst = p_plane[i_plane] = malloc( i_lines * i_stride * 2 * 2 );
- p_src = p_avpicture->data[i_plane];
-
- /* for each source line */
- for( i_y = 0; i_y < i_lines; i_y++ )
- {
- for( i_x = 0; i_x < i_stride - 1; i_x++ )
- {
- p_dst[2 * i_x ] = p_src[i_x];
- p_dst[2 * i_x + 1] = ( p_src[i_x] + p_src[i_x + 1]) / 2;
-
- }
- p_dst[2 * i_stride - 2] = p_src[i_x];
- p_dst[2 * i_stride - 1] = p_src[i_x];
-
- p_dst += 4 * i_stride; /* process the next even lines */
- p_src += i_stride;
- }
-
-
- }
-
- for( i_plane = 1; i_plane < 3; i_plane++ )
- {
- i_stride = p_avpicture->linesize[i_plane];
- i_lines = i_height / 4;
-
- p_dst = p_plane[i_plane] + 2*i_stride;
- p_src = p_plane[i_plane];
-
- for( i_y = 0; i_y < i_lines - 1; i_y++ )
- {
- for( i_x = 0; i_x < 2 * i_stride ; i_x++ )
- {
- p_dst[i_x] = ( p_src[i_x] + p_src[i_x + 4*i_stride])/2;
- }
-
- p_dst += 4 * i_stride; /* process the next odd lines */
- p_src += 4 * i_stride;
- }
- /* last line */
- p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, 2*i_stride );
- }
- /* copy to p_pic, by block
- if I do pixel per pixel it segfault. It's why I use
- temporaries buffers */
- for( i_plane = 1; i_plane < 3; i_plane++ )
- {
-
- int i_size;
- p_src = p_plane[i_plane];
- p_dst = p_pic->p[i_plane].p_pixels;
-
- i_size = __MIN( 2*i_stride, p_pic->p[i_plane].i_pitch);
- for( i_y = 0; i_y < __MIN(p_pic->p[i_plane].i_lines, 2 * i_lines); i_y++ )
- {
- p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, i_size );
- p_src += 2 * i_stride;
- p_dst += p_pic->p[i_plane].i_pitch;
- }
- free( p_plane[i_plane] );
+ case AUDIO_ES:
+ E_( EndAudioDec )( p_dec );
+ break;
+ case VIDEO_ES:
+ E_( EndVideoDec )( p_dec );
+ break;
}
+ free( p_sys );
+ return VLC_SUCCESS;
}
-
-static void ffmpeg_GetPicture( picture_t *p_pic,
- AVPicture *p_avpicture,
- videodec_thread_t *p_vdec )
-{
- int i_plane;
- int i_size;
- int i_line;
-
- u8 *p_dst;
- u8 *p_src;
- int i_src_stride;
- int i_dst_stride;
-
- if( ffmpeg_PixFmtToChroma( p_vdec->p_context->pix_fmt ) )
- {
- for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
- {
- p_src = p_avpicture->data[i_plane];
- p_dst = p_pic->p[i_plane].p_pixels;
- i_src_stride = p_avpicture->linesize[i_plane];
- i_dst_stride = p_pic->p[i_plane].i_pitch;
-
- i_size = __MIN( i_src_stride, i_dst_stride );
- for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
- {
- p_vdec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, i_size );
- p_src += i_src_stride;
- p_dst += i_dst_stride;
- }
- }
- if( ( p_vdec->i_pp_mode )&&
- ( ( p_vdec->p_vout->render.i_chroma ==
- VLC_FOURCC( 'I','4','2','0' ) )||
- ( p_vdec->p_vout->render.i_chroma ==
- VLC_FOURCC( 'Y','V','1','2' ) ) ) )
- {
- /* Make postproc */
-#if LIBAVCODEC_BUILD > 4313
- p_vdec->p_pp->pf_postprocess( p_pic,
- p_vdec->p_context->quant_store,
- p_vdec->p_context->qstride,
- p_vdec->i_pp_mode );
-#endif
- }
- }
- else
- {
- /* we need to convert to I420 */
- switch( p_vdec->p_context->pix_fmt )
- {
-#if LIBAVCODEC_BUILD >= 4615
- case( PIX_FMT_YUV410P ):
- ffmpeg_ConvertPictureI410toI420( p_pic, p_avpicture, p_vdec );
- break;
-#endif
- default:
- p_vdec->p_fifo->b_error = 1;
- break;
- }
-
- }
-}
-
-
-
/*****************************************************************************
- *
- * Functions that initialize, decode and end the decoding process
- *
- *****************************************************************************/
-
-/*****************************************************************************
- * InitThread: initialize vdec output thread
- *****************************************************************************
- * This function is called from decoder_Run and performs the second step
- * of the initialization. It returns 0 on success. Note that the thread's
- * flag are not modified inside this function.
- *
- * ffmpeg codec will be open, some memory allocated. But Vout is not yet
- * open (done after the first decoded frame)
+ * local Functions
*****************************************************************************/
-static int InitThread( videodec_thread_t *p_vdec )
+int E_(GetFfmpegCodec)( vlc_fourcc_t i_fourcc, int *pi_cat,
+ int *pi_ffmpeg_codec, char **ppsz_name )
{
- int i_ffmpeg_codec;
- int i_tmp;
-
- if( p_vdec->p_fifo->p_demux_data )
- {
- ffmpeg_ParseBitMapInfoHeader( &p_vdec->format,
- (u8*)p_vdec->p_fifo->p_demux_data );
- }
- else
- {
- msg_Warn( p_vdec->p_fifo, "display informations missing" );
- }
-
- /* **** init ffmpeg library (libavcodec) ***** */
- if( !b_ffmpeginit )
- {
- avcodec_init();
- avcodec_register_all();
- b_ffmpeginit = 1;
- msg_Dbg( p_vdec->p_fifo, "library ffmpeg initialized" );
- }
- else
- {
- msg_Dbg( p_vdec->p_fifo, "library ffmpeg already initialized" );
- }
-
- /* ***** Search for codec ***** */
- ffmpeg_GetFfmpegCodec( p_vdec->p_fifo->i_fourcc,
- &i_ffmpeg_codec,
- &p_vdec->psz_namecodec );
- p_vdec->p_codec =
- avcodec_find_decoder( i_ffmpeg_codec );
-
- if( !p_vdec->p_codec )
- {
- msg_Err( p_vdec->p_fifo, "codec not found (%s)",
- p_vdec->psz_namecodec );
- return( -1 );
- }
-
- /* ***** Fill p_context with init values ***** */
- p_vdec->p_context = &p_vdec->context;
- memset( p_vdec->p_context, 0, sizeof( AVCodecContext ) );
-
- p_vdec->p_context->width = p_vdec->format.i_width;
- p_vdec->p_context->height = p_vdec->format.i_height;
-
- /* ***** Get configuration of ffmpeg plugin ***** */
-#if LIBAVCODEC_BUILD >= 4611
- i_tmp = config_GetInt( p_vdec->p_fifo, "ffmpeg-workaround-bugs" );
- p_vdec->p_context->workaround_bugs = __MAX( __MIN( i_tmp, 99 ), 0 );
+ int i_cat;
+ int i_codec;
+ char *psz_name;
+
+ switch( i_fourcc )
+ {
+
+ /*
+ * Video Codecs
+ */
+
+ /* MPEG-1 Video */
+ case VLC_FOURCC('m','p','1','v'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MPEG1VIDEO;
+ psz_name = "MPEG-1/2 Video";
+ break;
+
+ /* MPEG-2 Video */
+ case VLC_FOURCC('m','p','2','v'):
+ case VLC_FOURCC('m','p','g','v'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MPEG2VIDEO;
+ psz_name = "MPEG-2 Video";
+ break;
+
+ /* MPEG-4 Video */
+ case VLC_FOURCC('D','I','V','X'):
+ case VLC_FOURCC('d','i','v','x'):
+ case VLC_FOURCC('M','P','4','S'):
+ case VLC_FOURCC('m','p','4','s'):
+ case VLC_FOURCC('M','4','S','2'):
+ case VLC_FOURCC('m','4','s','2'):
+ case VLC_FOURCC('x','v','i','d'):
+ case VLC_FOURCC('X','V','I','D'):
+ case VLC_FOURCC('X','v','i','D'):
+ case VLC_FOURCC('D','X','5','0'):
+ case VLC_FOURCC('m','p','4','v'):
+ case VLC_FOURCC( 4, 0, 0, 0 ):
+ case VLC_FOURCC('m','4','c','c'):
+ case VLC_FOURCC('M','4','C','C'):
+ /* 3ivx delta 3.5 Unsupported
+ * putting it here gives extreme distorted images
+ case VLC_FOURCC('3','I','V','1'):
+ case VLC_FOURCC('3','i','v','1'): */
+ /* 3ivx delta 4 */
+ case VLC_FOURCC('3','I','V','2'):
+ case VLC_FOURCC('3','i','v','2'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MPEG4;
+ psz_name = "MPEG-4";
+ break;
+
+ /* MSMPEG4 v1 */
+ case VLC_FOURCC('D','I','V','1'):
+ case VLC_FOURCC('d','i','v','1'):
+ case VLC_FOURCC('M','P','G','4'):
+ case VLC_FOURCC('m','p','g','4'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MSMPEG4V1;
+ psz_name = "MS MPEG-4 v1";
+ break;
+
+ /* MSMPEG4 v2 */
+ case VLC_FOURCC('D','I','V','2'):
+ case VLC_FOURCC('d','i','v','2'):
+ case VLC_FOURCC('M','P','4','2'):
+ case VLC_FOURCC('m','p','4','2'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MSMPEG4V2;
+ psz_name = "MS MPEG-4 v2";
+ break;
+
+ /* MSMPEG4 v3 / M$ mpeg4 v3 */
+ case VLC_FOURCC('M','P','G','3'):
+ case VLC_FOURCC('m','p','g','3'):
+ case VLC_FOURCC('d','i','v','3'):
+ case VLC_FOURCC('M','P','4','3'):
+ case VLC_FOURCC('m','p','4','3'):
+ /* DivX 3.20 */
+ case VLC_FOURCC('D','I','V','3'):
+ case VLC_FOURCC('D','I','V','4'):
+ case VLC_FOURCC('d','i','v','4'):
+ case VLC_FOURCC('D','I','V','5'):
+ case VLC_FOURCC('d','i','v','5'):
+ case VLC_FOURCC('D','I','V','6'):
+ case VLC_FOURCC('d','i','v','6'):
+ /* AngelPotion stuff */
+ case VLC_FOURCC('A','P','4','1'):
+ /* 3ivx doctered divx files */
+ case VLC_FOURCC('3','I','V','D'):
+ case VLC_FOURCC('3','i','v','d'):
+ /* who knows? */
+ case VLC_FOURCC('3','V','I','D'):
+ case VLC_FOURCC('3','v','i','d'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MSMPEG4V3;
+ psz_name = "MS MPEG-4 v3";
+ break;
+
+ /* Sorenson v1 */
+ case VLC_FOURCC('S','V','Q','1'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_SVQ1;
+ psz_name = "SVQ-1 (Sorenson Video v1)";
+ break;
+
+ /* Sorenson v3 */
+ case VLC_FOURCC('S','V','Q','3'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_SVQ3;
+ psz_name = "SVQ-3 (Sorenson Video v3)";
+ break;
+
+/* H263 and H263i */
+/* H263(+) is also known as Real Video 1.0 */
+
+/* FIXME FOURCC_H263P exist but what fourcc ? */
+
+ /* H263 */
+ case VLC_FOURCC('H','2','6','3'):
+ case VLC_FOURCC('h','2','6','3'):
+ case VLC_FOURCC('U','2','6','3'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_H263;
+ psz_name = "H263";
+ break;
+
+ /* H263i */
+ case VLC_FOURCC('I','2','6','3'):
+ case VLC_FOURCC('i','2','6','3'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_H263I;
+ psz_name = "I263.I";
+ break;
+
+#if LIBAVCODEC_BUILD >= 4669
+ /* Flash (H263) variant */
+ case VLC_FOURCC('F','L','V','1'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_FLV1;
+ psz_name = "Flash Video";
+ break;
+#endif
- i_tmp = config_GetInt( p_vdec->p_fifo, "ffmpeg-error-resilience" );
- p_vdec->p_context->error_resilience = __MAX( __MIN( i_tmp, 99 ), -1 );
+ /* MJPEG */
+ case VLC_FOURCC( 'M', 'J', 'P', 'G' ):
+ case VLC_FOURCC( 'm', 'j', 'p', 'g' ):
+ case VLC_FOURCC( 'm', 'j', 'p', 'a' ): /* for mov file */
+ case VLC_FOURCC( 'j', 'p', 'e', 'g' ):
+ case VLC_FOURCC( 'J', 'P', 'E', 'G' ):
+ case VLC_FOURCC( 'J', 'F', 'I', 'F' ):
+ case VLC_FOURCC( 'J', 'P', 'G', 'L' ):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MJPEG;
+ psz_name = "Motion JPEG";
+ break;
+ case VLC_FOURCC( 'm', 'j', 'p', 'b' ): /* for mov file */
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MJPEGB;
+ psz_name = "Motion JPEG B";
+ break;
+
+ /* DV */
+ case VLC_FOURCC('d','v','s','l'):
+ case VLC_FOURCC('d','v','s','d'):
+ case VLC_FOURCC('D','V','S','D'):
+ case VLC_FOURCC('d','v','h','d'):
+ case VLC_FOURCC('d','v','c',' '):
+ case VLC_FOURCC('d','v','p',' '):
+ case VLC_FOURCC('C','D','V','C'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_DVVIDEO;
+ psz_name = "DV video";
+ break;
+
+ /* Windows Media Video */
+ case VLC_FOURCC('W','M','V','1'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_WMV1;
+ psz_name ="Windows Media Video 1";
+ break;
+ case VLC_FOURCC('W','M','V','2'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_WMV2;
+ psz_name ="Windows Media Video 2";
+ break;
+
+#if LIBAVCODEC_BUILD >= 4683
+ /* Microsoft Video 1 */
+ case VLC_FOURCC('M','S','V','C'):
+ case VLC_FOURCC('m','s','v','c'):
+ case VLC_FOURCC('C','R','A','M'):
+ case VLC_FOURCC('c','r','a','m'):
+ case VLC_FOURCC('W','H','A','M'):
+ case VLC_FOURCC('w','h','a','m'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MSVIDEO1;
+ psz_name = "Microsoft Video 1";
+ break;
+
+ /* Microsoft RLE */
+ case VLC_FOURCC('m','r','l','e'):
+ case VLC_FOURCC(0x1,0x0,0x0,0x0):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_MSRLE;
+ psz_name = "Microsoft RLE";
+ break;
#endif
-#if LIBAVCODEC_BUILD >= 4614
- if( config_GetInt( p_vdec->p_fifo, "grayscale" ) )
- {
- p_vdec->p_context->flags|= CODEC_FLAG_GRAY;
- }
+
+#if( ( LIBAVCODEC_BUILD >= 4663 ) && ( !defined( WORDS_BIGENDIAN ) ) )
+ /* Indeo Video Codecs (Quality of this decoder on ppc is not good) */
+ case VLC_FOURCC('I','V','3','1'):
+ case VLC_FOURCC('i','v','3','1'):
+ case VLC_FOURCC('I','V','3','2'):
+ case VLC_FOURCC('i','v','3','2'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_INDEO3;
+ psz_name = "Indeo v3";
+ break;
#endif
- p_vdec->b_hurry_up = config_GetInt(p_vdec->p_fifo, "ffmpeg-hurry-up");
-
- /* ***** Open the codec ***** */
- if (avcodec_open(p_vdec->p_context, p_vdec->p_codec) < 0)
- {
- msg_Err( p_vdec->p_fifo, "cannot open codec (%s)",
- p_vdec->psz_namecodec );
- return( -1 );
- }
- else
- {
- msg_Dbg( p_vdec->p_fifo, "ffmpeg codec (%s) started",
- p_vdec->psz_namecodec );
- }
+ /* Huff YUV */
+ case VLC_FOURCC('H','F','Y','U'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_HUFFYUV;
+ psz_name ="Huff YUV";
+ break;
+
+ /* Creative YUV */
+ case VLC_FOURCC('C','Y','U','V'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_CYUV;
+ psz_name ="Creative YUV";
+ break;
+
+#if LIBAVCODEC_BUILD >= 4668
+ /* On2 VP3 Video Codecs */
+ case VLC_FOURCC('V','P','3','1'):
+ case VLC_FOURCC('v','p','3','1'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_VP3;
+ psz_name = "On2's VP3 Video";
+ break;
+#endif
- /* ***** init this codec with special data(up to now MPEG4 only) ***** */
- if( p_vdec->format.i_data )
- {
- AVPicture avpicture;
- int b_gotpicture;
-
- switch( i_ffmpeg_codec )
- {
- case( CODEC_ID_MPEG4 ):
- avcodec_decode_video( p_vdec->p_context, &avpicture,
- &b_gotpicture,
- p_vdec->format.p_data,
- p_vdec->format.i_data );
- break;
- default:
- break;
- }
- }
-
- /* ***** Load post processing ***** */
-
- /* get overridding settings */
- p_vdec->i_pp_mode = 0;
- if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-yv" ) )
- p_vdec->i_pp_mode |= PP_DEBLOCK_Y_V;
- if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-yh" ) )
- p_vdec->i_pp_mode |= PP_DEBLOCK_Y_H;
- if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-cv" ) )
- p_vdec->i_pp_mode |= PP_DEBLOCK_C_V;
- if( config_GetInt( p_vdec->p_fifo, "ffmpeg-db-ch" ) )
- p_vdec->i_pp_mode |= PP_DEBLOCK_C_H;
- if( config_GetInt( p_vdec->p_fifo, "ffmpeg-dr-y" ) )
- p_vdec->i_pp_mode |= PP_DERING_Y;
- if( config_GetInt( p_vdec->p_fifo, "ffmpeg-dr-c" ) )
- p_vdec->i_pp_mode |= PP_DERING_C;
-
- if( ( config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-q" ) > 0 )||
- ( config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-auto" ) )||
- ( p_vdec->i_pp_mode != 0 ) )
- {
- /* check if the codec support postproc. */
- switch( i_ffmpeg_codec )
- {
-#if LIBAVCODEC_BUILD > 4608
- case( CODEC_ID_MSMPEG4V1 ):
- case( CODEC_ID_MSMPEG4V2 ):
- case( CODEC_ID_MSMPEG4V3 ):
-#else
- case( CODEC_ID_MSMPEG4 ):
+#if ( !defined( WORDS_BIGENDIAN ) )
+#if LIBAVCODEC_BUILD >= 4668
+ /* Asus Video (Another thing that doesn't work on PPC) */
+ case VLC_FOURCC('A','S','V','1'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_ASV1;
+ psz_name = "Asus V1";
+ break;
+#endif
+#if LIBAVCODEC_BUILD >= 4677
+ case VLC_FOURCC('A','S','V','2'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_ASV2;
+ psz_name = "Asus V2";
+ break;
#endif
- case( CODEC_ID_MPEG4 ):
- case( CODEC_ID_H263 ):
-// case( CODEC_ID_H263P ): I don't use it up to now
- case( CODEC_ID_H263I ):
- /* Ok we can make postprocessing :)) */
- /* first try to get a postprocess module */
-#if LIBAVCODEC_BUILD > 4613
- p_vdec->p_pp = vlc_object_create( p_vdec->p_fifo,
- sizeof( postprocessing_t ) );
- p_vdec->p_pp->psz_object_name = "postprocessing";
- p_vdec->p_pp->p_module =
- module_Need( p_vdec->p_pp, "postprocessing", "$ffmpeg-pp" );
-
- if( !p_vdec->p_pp->p_module )
- {
- msg_Warn( p_vdec->p_fifo,
- "no suitable postprocessing module" );
- vlc_object_destroy( p_vdec->p_pp );
- p_vdec->p_pp = NULL;
- p_vdec->i_pp_mode = 0;
- }
- else
- {
- /* get mode upon quality */
- p_vdec->i_pp_mode |=
- p_vdec->p_pp->pf_getmode(
- config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-q" ),
- config_GetInt( p_vdec->p_fifo, "ffmpeg-pp-auto" )
- );
-
- /* allocate table for postprocess */
- p_vdec->p_context->quant_store =
- malloc( sizeof( int ) * ( MBR + 1 ) * ( MBC + 1 ) );
- p_vdec->p_context->qstride = MBC + 1;
- }
-#else
- p_vdec->i_pp_mode = 0;
- msg_Warn( p_vdec->p_fifo,
- "post-processing not supported, upgrade ffmpeg" );
#endif
- break;
- default:
- p_vdec->i_pp_mode = 0;
- msg_Warn( p_vdec->p_fifo,
- "Post processing unsupported for this codec" );
- break;
- }
-
- }
-// memset( &p_vdec->statistic, 0, sizeof( statistic_t ) );
-
- return( 0 );
-}
-/*****************************************************************************
- * DecodeThread: Called for decode one frame
- *****************************************************************************/
-static void DecodeThread( videodec_thread_t *p_vdec )
-{
- int i_status;
- int b_drawpicture;
- int b_gotpicture;
- AVPicture avpicture; /* ffmpeg picture */
- picture_t *p_pic; /* videolan picture */
- /* we have to get a frame stored in a pes
- give it to ffmpeg decoder
- and send the image to the output */
-
- /* TODO implement it in a better way */
- /* A good idea could be to decode all I pictures and see for the other */
- if( ( p_vdec->b_hurry_up )&&
- ( p_vdec->i_frame_late > 4 ) )
- {
-#if LIBAVCODEC_BUILD > 4603
- b_drawpicture = 0;
- if( p_vdec->i_frame_late < 8 )
- {
- p_vdec->p_context->hurry_up = 2;
- }
- else
- {
- /* too much late picture, won't decode
- but break picture until a new I, and for mpeg4 ...*/
- p_vdec->i_frame_late--; /* needed else it will never be decrease */
- __PES_NEXT( p_vdec->p_fifo );
- return;
- }
-#else
- if( p_vdec->i_frame_late < 8 )
- {
- b_drawpicture = 0; /* not really good but .. UPGRADE FFMPEG !! */
- }
- else
- {
- /* too much late picture, won't decode
- but break picture until a new I, and for mpeg4 ...*/
- p_vdec->i_frame_late--; /* needed else it will never be decrease */
- __PES_NEXT( p_vdec->p_fifo );
- return;
- }
+#if LIBAVCODEC_BUILD >= 4668
+ /* FFMPEG Video 1 (lossless codec) */
+ case VLC_FOURCC('F','F','V','1'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_FFV1;
+ psz_name = "FFMpeg Video 1";
+ break;
#endif
- }
- else
- {
- b_drawpicture = 1;
-#if LIBAVCODEC_BUILD > 4603
- p_vdec->p_context->hurry_up = 0;
+
+#if LIBAVCODEC_BUILD >= 4669
+ /* ATI VCR1 */
+ case VLC_FOURCC('V','C','R','1'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_VCR1;
+ psz_name = "ATI VCR1";
+ break;
#endif
- }
- __GetFrame( p_vdec );
+#if LIBAVCODEC_BUILD >= 4672
+ /* Cirrus Logic AccuPak */
+ case VLC_FOURCC('C','L','J','R'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_CLJR;
+ psz_name = "Creative Logic AccuPak";
+ break;
+#endif
- i_status = avcodec_decode_video( p_vdec->p_context,
- &avpicture,
- &b_gotpicture,
- p_vdec->p_framedata,
- p_vdec->i_framesize);
+#if LIBAVCODEC_BUILD >= 4683
+ /* Apple Video */
+ case VLC_FOURCC('r','p','z','a'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_RPZA;
+ psz_name = "Apple Video";
+ break;
+#endif
- __NextFrame( p_vdec );
+#if LIBAVCODEC_BUILD >= 4683
+ /* Cinepak */
+ case VLC_FOURCC('c','v','i','d'):
+ i_cat = VIDEO_ES;
+ i_codec = CODEC_ID_CINEPAK;
+ psz_name = "Cinepak";
+ break;
+#endif
- if( i_status < 0 )
- {
- msg_Warn( p_vdec->p_fifo, "cannot decode one frame (%d bytes)",
- p_vdec->i_framesize );
- p_vdec->i_frame_error++;
- return;
- }
- /* Update frame late count*/
- /* I don't make statistic on decoding time */
- if( p_vdec->i_pts <= mdate())
- {
- p_vdec->i_frame_late++;
- }
- else
- {
- p_vdec->i_frame_late = 0;
- }
+ /*
+ * Audio Codecs
+ */
+
+ /* Windows Media Audio 1 */
+ case VLC_FOURCC('W','M','A','1'):
+ case VLC_FOURCC('w','m','a','1'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_WMAV1;
+ psz_name ="Windows Media Audio 1";
+ break;
+
+ /* Windows Media Audio 2 */
+ case VLC_FOURCC('W','M','A','2'):
+ case VLC_FOURCC('w','m','a','2'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_WMAV2;
+ psz_name ="Windows Media Audio 2";
+ break;
+
+ /* DV Audio */
+ case VLC_FOURCC('d','v','a','u'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_DVAUDIO;
+ psz_name = "DV audio";
+ break;
+
+ /* MACE-3 Audio */
+ case VLC_FOURCC('M','A','C','3'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_MACE3;
+ psz_name = "MACE-3 audio";
+ break;
+
+ /* MACE-6 Audio */
+ case VLC_FOURCC('M','A','C','6'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_MACE6;
+ psz_name = "MACE-6 audio";
+ break;
+
+#if LIBAVCODEC_BUILD >= 4668
+ /* RealAudio 1.0 */
+ case VLC_FOURCC('1','4','_','4'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_RA_144;
+ psz_name = "RealAudio 1.0";
+ break;
+
+ /* RealAudio 2.0 */
+ case VLC_FOURCC('2','8','_','8'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_RA_288;
+ psz_name = "RealAudio 2.0";
+ break;
+#endif
- if( !b_gotpicture || avpicture.linesize[0] == 0 || !b_drawpicture)
- {
- return;
- }
-
- /* Check our vout */
- if( !ffmpeg_CheckVout( p_vdec->p_vout,
- p_vdec->p_context->width,
- p_vdec->p_context->height,
- p_vdec->p_context->aspect_ratio_info,
- ffmpeg_PixFmtToChroma(p_vdec->p_context->pix_fmt)) )
- {
- p_vdec->p_vout =
- ffmpeg_CreateVout( p_vdec,
- p_vdec->p_context->width,
- p_vdec->p_context->height,
- p_vdec->p_context->aspect_ratio_info,
- ffmpeg_PixFmtToChroma(p_vdec->p_context->pix_fmt));
- if( !p_vdec->p_vout )
- {
- msg_Err( p_vdec->p_fifo, "cannot create vout" );
- p_vdec->p_fifo->b_error = 1; /* abort */
- return;
- }
- }
+ /* MPEG Audio layer 1/2/3 */
+ case VLC_FOURCC('m','p','g','a'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_MP2;
+ psz_name = "MPEG Audio layer 1/2";
+ break;
+ case VLC_FOURCC('m','p','3',' '):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_MP3;
+ psz_name = "MPEG Audio layer 1/2/3";
+ break;
+
+ /* A52 Audio (aka AC3) */
+ case VLC_FOURCC('a','5','2',' '):
+ case VLC_FOURCC('a','5','2','b'): /* VLC specific hack */
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_AC3;
+ psz_name = "A52 Audio (aka AC3)";
+ break;
+
+ /* AAC audio */
+ case VLC_FOURCC('m','p','4','a'):
+ i_cat = AUDIO_ES;
+ i_codec = CODEC_ID_AAC;
+ psz_name = "MPEG AAC Audio";
+ break;
+
+ default:
+ i_cat = UNKNOWN_ES;
+ i_codec = CODEC_ID_NONE;
+ psz_name = NULL;
+ break;
+ }
+
+ if( i_codec != CODEC_ID_NONE )
+ {
+ if( pi_cat ) *pi_cat = i_cat;
+ if( pi_ffmpeg_codec ) *pi_ffmpeg_codec = i_codec;
+ if( ppsz_name ) *ppsz_name = psz_name;
+ return VLC_TRUE;
+ }
+
+ return VLC_FALSE;
+}
- /* Get a new picture */
- while( !(p_pic = vout_CreatePicture( p_vdec->p_vout, 0, 0, 0 ) ) )
- {
- if( p_vdec->p_fifo->b_die || p_vdec->p_fifo->b_error )
- {
- return;
- }
- msleep( VOUT_OUTMEM_SLEEP );
+int E_(GetFfmpegChroma)( vlc_fourcc_t i_chroma )
+{
+ switch( i_chroma )
+ {
+ case VLC_FOURCC( 'I', '4', '2', '0' ):
+ return PIX_FMT_YUV420P;
+ case VLC_FOURCC( 'I', '4', '2', '2' ):
+ return PIX_FMT_YUV422P;
+ case VLC_FOURCC( 'I', '4', '4', '4' ):
+ return PIX_FMT_YUV444P;
+ case VLC_FOURCC( 'R', 'V', '1', '5' ):
+ return PIX_FMT_RGB555;
+ case VLC_FOURCC( 'R', 'V', '1', '6' ):
+ return PIX_FMT_RGB565;
+ case VLC_FOURCC( 'R', 'V', '2', '4' ):
+ return PIX_FMT_RGB24;
+ case VLC_FOURCC( 'R', 'V', '3', '2' ):
+ return PIX_FMT_RGBA32;
+ case VLC_FOURCC( 'G', 'R', 'E', 'Y' ):
+ return PIX_FMT_GRAY8;
+ case VLC_FOURCC( 'Y', 'U', 'Y', '2' ):
+ return PIX_FMT_YUV422;
+ default:
+ return 0;
}
- /* fill p_picture_t from avpicture, do I410->I420 if needed
- and do post-processing if requested */
- ffmpeg_GetPicture( p_pic, &avpicture, p_vdec );
-
- /* FIXME correct avi and use i_dts */
-
- /* Send decoded frame to vout */
- vout_DatePicture( p_vdec->p_vout, p_pic, p_vdec->i_pts);
- vout_DisplayPicture( p_vdec->p_vout, p_pic );
-
- return;
}
-
-/*****************************************************************************
- * EndThread: thread destruction
- *****************************************************************************
- * This function is called when the thread ends after a sucessful
- * initialization.
- *****************************************************************************/
-static void EndThread( videodec_thread_t *p_vdec )
+void E_(InitLibavcodec)( vlc_object_t *p_object )
{
-
- if( !p_vdec )
- {
- return;
- }
- if( p_vdec->p_pp )
- {
- /* release postprocessing module */
- module_Unneed( p_vdec->p_pp, p_vdec->p_pp->p_module );
- vlc_object_destroy( p_vdec->p_pp );
- p_vdec->p_pp = NULL;
- }
+ vlc_value_t lockval;
+
+ var_Get( p_object->p_libvlc, "avcodec", &lockval );
+ vlc_mutex_lock( lockval.p_address );
- if( p_vdec->p_context != NULL)
+ /* *** init ffmpeg library (libavcodec) *** */
+ if( !b_ffmpeginit )
{
- FREE( p_vdec->p_context->quant_store );
- avcodec_close( p_vdec->p_context );
- msg_Dbg( p_vdec->p_fifo, "ffmpeg codec (%s) stopped",
- p_vdec->psz_namecodec );
- }
+ avcodec_init();
+ avcodec_register_all();
+ b_ffmpeginit = 1;
- if( p_vdec->p_vout != NULL )
+ msg_Dbg( p_object, "libavcodec initialized (interface %d )",
+ LIBAVCODEC_BUILD );
+ }
+ else
{
- /* We are about to die. Reattach video output to p_vlc. */
- vlc_object_detach( p_vdec->p_vout, p_vdec->p_fifo );
- vlc_object_attach( p_vdec->p_vout, p_vdec->p_fifo->p_vlc );
+ msg_Dbg( p_object, "libavcodec already initialized" );
}
- FREE( p_vdec->format.p_data );
- FREE( p_vdec->p_buffer );
-
- free( p_vdec );
+ vlc_mutex_unlock( lockval.p_address );
}
-