/*****************************************************************************
* video_parser.c : video parser thread
*****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
- * $Id: video_parser.c,v 1.2 2001/11/15 17:39:12 sam Exp $
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: video_parser.c,v 1.27 2002/07/31 20:56:52 sam Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Samuel Hocevar <sam@via.ecp.fr>
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-#define MODULE_NAME mpeg_vdec
-#include "modules_inner.h"
-
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include "defs.h"
-
#include <stdlib.h> /* malloc(), free() */
+#include <vlc/vlc.h>
+#include <vlc/vout.h>
+#include <vlc/decoder.h>
+
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* getpid() */
#endif
# include <sys/times.h>
#endif
-#include "config.h"
-#include "common.h"
-#include "threads.h"
-#include "mtime.h"
-#include "modules.h"
-#include "intf_msg.h"
-
-#include "main.h"
-
-#include "video.h"
-#include "video_output.h"
-
-#include "modules_export.h"
-#include "stream_control.h"
-#include "input_ext-dec.h"
-
-
#include "vdec_ext-plugins.h"
+#include "video_decoder.h"
#include "vpar_pool.h"
#include "video_parser.h"
-
/*
* Local prototypes
*/
-static int mpeg_vdec_Probe ( probedata_t * );
-static int mpeg_vdec_Run ( decoder_config_t * );
-static int mpeg_vdec_Init ( vpar_thread_t * );
-static void mpeg_vdec_ErrorThread ( vpar_thread_t * );
-static void mpeg_vdec_EndThread ( vpar_thread_t * );
-static void BitstreamCallback ( bit_stream_t *, boolean_t );
-
-/*****************************************************************************
- * Capabilities
- *****************************************************************************/
-void _M( vdec_getfunctions )( function_list_t * p_function_list )
-{
- p_function_list->pf_probe = mpeg_vdec_Probe;
- p_function_list->functions.dec.pf_RunThread = mpeg_vdec_Run;
-}
+static int OpenDecoder ( vlc_object_t * );
+static int RunDecoder ( decoder_fifo_t * );
+static int InitThread ( vpar_thread_t * );
+static void EndThread ( vpar_thread_t * );
+static void BitstreamCallback ( bit_stream_t *, vlc_bool_t );
/*****************************************************************************
- * Build configuration tree.
+ * Module descriptor
*****************************************************************************/
-MODULE_CONFIG_START
-ADD_WINDOW( "Configuration for MPEG video decoder module" )
- ADD_COMMENT( "Nothing to configure" )
-MODULE_CONFIG_STOP
-
-MODULE_INIT_START
- p_module->i_capabilities = MODULE_CAPABILITY_DEC;
- p_module->psz_longname = "MPEG I/II video decoder module";
-MODULE_INIT_STOP
-
-MODULE_ACTIVATE_START
- _M( vdec_getfunctions )( &p_module->p_functions->dec );
-MODULE_ACTIVATE_STOP
-
-MODULE_DEACTIVATE_START
-MODULE_DEACTIVATE_STOP
-
+#define VDEC_IDCT_TEXT N_("IDCT module")
+#define VDEC_IDCT_LONGTEXT N_( \
+ "This option allows you to select the IDCT module used by this video " \
+ "decoder. The default behavior is to automatically select the best " \
+ "module available.")
+
+#define VDEC_MOTION_TEXT N_("motion compensation module")
+#define VDEC_MOTION_LONGTEXT N_( \
+ "This option allows you to select the motion compensation module used by "\
+ "this video decoder. The default behavior is to automatically select the "\
+ "best module available.")
+
+#define VDEC_SMP_TEXT N_("use additional processors")
+#define VDEC_SMP_LONGTEXT N_( \
+ "This video decoder can benefit from a multiprocessor computer. If you " \
+ "have one, you can specify the number of processors here.")
+
+#define VPAR_SYNCHRO_TEXT N_("force synchro algorithm {I|I+|IP|IP+|IPB}")
+#define VPAR_SYNCHRO_LONGTEXT N_( \
+ "This allows you to force the synchro algorithm, by directly selecting " \
+ "the types of picture you want to decode. Please bear in mind that if " \
+ "you select more pictures than what your CPU is capable to decode, " \
+ "you won't get anything.")
+
+vlc_module_begin();
+ add_category_hint( N_("Miscellaneous"), NULL );
+ add_module ( "mpeg-idct", "idct", NULL, NULL,
+ VDEC_IDCT_TEXT, VDEC_IDCT_LONGTEXT );
+ add_module ( "mpeg-motion", "motion", NULL, NULL,
+ VDEC_MOTION_TEXT, VDEC_IDCT_LONGTEXT );
+ add_integer ( "vdec-smp", 0, NULL, VDEC_SMP_TEXT, VDEC_SMP_LONGTEXT );
+ add_string ( "vpar-synchro", NULL, NULL, VPAR_SYNCHRO_TEXT,
+ VPAR_SYNCHRO_LONGTEXT );
+ set_description( _("MPEG I/II video decoder module") );
+ set_capability( "decoder", 50 );
+ set_callbacks( OpenDecoder, NULL );
+vlc_module_end();
/*****************************************************************************
- * mpeg_vdec_Probe: probe the decoder and return score
+ * 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 mpeg_vdec_Probe( probedata_t *p_data )
+static int OpenDecoder( vlc_object_t *p_this )
{
- if( p_data->i_type == MPEG1_VIDEO_ES || p_data->i_type == MPEG2_VIDEO_ES )
- return( 50 );
- else
- return( 0 );
+ decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
+
+ if( p_fifo->i_fourcc == VLC_FOURCC('m','p','g','v') )
+ {
+ p_fifo->pf_run = RunDecoder;
+ return VLC_SUCCESS;
+ }
+
+ return VLC_EGENERIC;
}
/*****************************************************************************
- * mpeg_vdec_Run: this function is called just after the thread is created
+ * RunDecoder: this function is called just after the thread is created
*****************************************************************************/
-static int mpeg_vdec_Run ( decoder_config_t * p_config )
+static int RunDecoder ( decoder_fifo_t * p_fifo )
{
vpar_thread_t * p_vpar;
-
- intf_DbgMsg( "vpar debug: video parser thread created. Initializing..." );
+ vlc_bool_t b_error;
/* Allocate the memory needed to store the thread's structure */
if ( (p_vpar = (vpar_thread_t *)malloc( sizeof(vpar_thread_t) )) == NULL )
{
- intf_ErrMsg( "vpar error: not enough memory "
- "for vpar_CreateThread() to create the new thread");
+ msg_Err( p_fifo, "out of memory" );
+ DecoderError( p_fifo );
return( -1 );
}
/*
* Initialize the thread properties
*/
- p_vpar->p_fifo = p_config->p_decoder_fifo;
- p_vpar->p_config = p_config;
+ p_vpar->p_fifo = p_fifo;
p_vpar->p_vout = NULL;
/*
* Initialize thread
*/
- p_vpar->p_fifo->b_error = mpeg_vdec_Init( p_vpar );
+ p_vpar->p_fifo->b_error = InitThread( p_vpar );
/*
* Main loop - it is not executed if an error occured during
/*
* Error loop
*/
- if( p_vpar->p_fifo->b_error )
+ if( ( b_error = p_vpar->p_fifo->b_error ) )
{
- mpeg_vdec_ErrorThread( p_vpar );
+ DecoderError( p_vpar->p_fifo );
}
/* End of thread */
- mpeg_vdec_EndThread( p_vpar );
+ EndThread( p_vpar );
- if( p_vpar->p_fifo->b_error )
+ if( b_error )
{
return( -1 );
}
}
/*****************************************************************************
- * mpeg_vdec_Init: initialize vpar output thread
+ * InitThread: initialize vpar output thread
*****************************************************************************
- * This function is called from mpeg_vdec_Run and performs the second step
+ * This function is called from 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.
*****************************************************************************/
-static int mpeg_vdec_Init( vpar_thread_t *p_vpar )
+static int InitThread( vpar_thread_t *p_vpar )
{
+ char *psz_name;
+
/*
* Choose the best motion compensation module
*/
- p_vpar->p_motion_module = module_Need( MODULE_CAPABILITY_MOTION, NULL );
+ psz_name = config_GetPsz( p_vpar->p_fifo, "mpeg-motion" );
+ p_vpar->p_motion =
+ module_Need( p_vpar->p_fifo, "motion compensation", psz_name );
+ if( psz_name ) free( psz_name );
- if( p_vpar->p_motion_module == NULL )
+ if( p_vpar->p_motion == NULL )
{
- intf_ErrMsg( "vpar error: no suitable motion compensation module" );
+ msg_Err( p_vpar->p_fifo, "no suitable motion compensation module" );
free( p_vpar );
return( -1 );
}
-#define f ( p_vpar->p_motion_module->p_functions->motion.functions.motion )
- memcpy( p_vpar->pool.ppppf_motion, f.ppppf_motion, sizeof(void *) * 16 );
-#undef f
+ memcpy( p_vpar->pool.ppppf_motion,
+ p_vpar->p_fifo->p_private, sizeof(void *) * 16 );
/*
* Choose the best IDCT module
*/
- p_vpar->p_idct_module = module_Need( MODULE_CAPABILITY_IDCT, NULL );
+ psz_name = config_GetPsz( p_vpar->p_fifo, "mpeg-idct" );
+ p_vpar->p_idct = module_Need( p_vpar->p_fifo, "idct", psz_name );
+ if( psz_name ) free( psz_name );
- if( p_vpar->p_idct_module == NULL )
+ if( p_vpar->p_idct == NULL )
{
- intf_ErrMsg( "vpar error: no suitable IDCT module" );
- module_Unneed( p_vpar->p_motion_module );
+ msg_Err( p_vpar->p_fifo, "no suitable IDCT module" );
+ module_Unneed( p_vpar->p_fifo, p_vpar->p_motion );
free( p_vpar );
return( -1 );
}
-#define f p_vpar->p_idct_module->p_functions->idct.functions.idct
- p_vpar->pool.pf_idct_init = f.pf_idct_init;
- p_vpar->pf_sparse_idct_add = f.pf_sparse_idct_add;
- p_vpar->pf_idct_add = f.pf_idct_add;
- p_vpar->pf_sparse_idct_copy = f.pf_sparse_idct_copy;
- p_vpar->pf_idct_copy = f.pf_idct_copy;
- p_vpar->pf_norm_scan = f.pf_norm_scan;
-#undef f
+ p_vpar->pool.pf_idct_init = ((void**)p_vpar->p_fifo->p_private)[0];
+ p_vpar->pf_norm_scan = ((void**)p_vpar->p_fifo->p_private)[1];
+ p_vpar->pf_sparse_idct_add = ((void**)p_vpar->p_fifo->p_private)[2];
+ p_vpar->pf_sparse_idct_copy = ((void**)p_vpar->p_fifo->p_private)[3];
+ p_vpar->pf_idct_add = ((void**)p_vpar->p_fifo->p_private)[4];
+ p_vpar->pf_idct_copy = ((void**)p_vpar->p_fifo->p_private)[5];
/* Initialize input bitstream */
- p_vpar->p_config->pf_init_bit_stream( &p_vpar->bit_stream,
- p_vpar->p_config->p_decoder_fifo, BitstreamCallback,
- (void *)p_vpar );
+ InitBitstream( &p_vpar->bit_stream, p_vpar->p_fifo,
+ BitstreamCallback, (void *)p_vpar );
/* Initialize parsing data */
p_vpar->sequence.p_forward = NULL;
p_vpar->sequence.next_pts = p_vpar->sequence.next_dts = 0;
p_vpar->sequence.b_expect_discontinuity = 0;
+ p_vpar->sequence.i_width = 0;
+ p_vpar->sequence.i_height = 0;
+ p_vpar->sequence.i_frame_rate = 0;
+ p_vpar->sequence.i_scalable_mode = 0;
+ p_vpar->sequence.i_matrix_coefficients = 0;
+ p_vpar->sequence.b_mpeg2 = 0;
+ p_vpar->sequence.b_progressive = 0;
+
/* Initialize copyright information */
p_vpar->sequence.b_copyright_flag = 0;
p_vpar->sequence.b_original = 0;
vpar_InitPool( p_vpar );
/* Mark thread as running and return */
- intf_DbgMsg("vpar debug: mpeg_vdec_Init(%p) succeeded", p_vpar);
return( 0 );
}
/*****************************************************************************
- * mpeg_vdec_ErrorThread: RunThread() error loop
+ * EndThread: thread destruction
*****************************************************************************
- * This function is called when an error occured during thread main's loop. The
- * thread can still receive feed, but must be ready to terminate as soon as
- * possible.
+ * This function is called when the thread ends after a sucessful
+ * initialization.
*****************************************************************************/
-static void mpeg_vdec_ErrorThread( vpar_thread_t *p_vpar )
+static void EndThread( vpar_thread_t *p_vpar )
{
- /* We take the lock, because we are going to read/write the start/end
- * indexes of the decoder fifo */
- vlc_mutex_lock( &p_vpar->p_fifo->data_lock );
+#ifdef HAVE_SYS_TIMES_H
+ struct tms cpu_usage;
+ times( &cpu_usage );
+#endif
- /* Wait until a `die' order is sent */
- while( !p_vpar->p_fifo->b_die )
+ if( p_vpar->p_vout != NULL )
{
- /* Trash all received PES packets */
- while( !DECODER_FIFO_ISEMPTY(*p_vpar->p_fifo) )
+ /* Release used video buffers. */
+ if( p_vpar->sequence.p_forward != NULL )
{
- p_vpar->p_fifo->pf_delete_pes( p_vpar->p_fifo->p_packets_mgt,
- DECODER_FIFO_START(*p_vpar->p_fifo) );
- DECODER_FIFO_INCSTART( *p_vpar->p_fifo );
+ vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_forward );
+ }
+ if( p_vpar->sequence.p_backward != NULL )
+ {
+ vout_DatePicture( p_vpar->p_vout, p_vpar->sequence.p_backward,
+ vpar_SynchroDate( p_vpar ) );
+ vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_backward );
+ }
+ if( p_vpar->picture.p_picture != NULL )
+ {
+ vout_DestroyPicture( p_vpar->p_vout, p_vpar->picture.p_picture );
}
- /* Waiting for the input thread to put new PES packets in the fifo */
- vlc_cond_wait( &p_vpar->p_fifo->data_wait, &p_vpar->p_fifo->data_lock );
- }
-
- /* We can release the lock before leaving */
- vlc_mutex_unlock( &p_vpar->p_fifo->data_lock );
-}
-
-/*****************************************************************************
- * mpeg_vdec_EndThread: thread destruction
- *****************************************************************************
- * This function is called when the thread ends after a sucessful
- * initialization.
- *****************************************************************************/
-static void mpeg_vdec_EndThread( vpar_thread_t *p_vpar )
-{
- intf_DbgMsg("vpar debug: destroying video parser thread %p", p_vpar);
-
- /* Release used video buffers. */
- if( p_vpar->sequence.p_forward != NULL )
- {
- vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_forward );
- }
- if( p_vpar->sequence.p_backward != NULL )
- {
- vout_DatePicture( p_vpar->p_vout, p_vpar->sequence.p_backward,
- vpar_SynchroDate( p_vpar ) );
- vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_backward );
+ /* We are about to die. Reattach video output to p_vlc. */
+ vlc_object_detach( p_vpar->p_vout, p_vpar->p_fifo );
+ vlc_object_attach( p_vpar->p_vout, p_vpar->p_fifo->p_vlc );
}
- if( p_vpar->picture.p_picture != NULL )
- {
- vout_DestroyPicture( p_vpar->p_vout, p_vpar->picture.p_picture );
- }
-
- if( p_main->b_stats )
- {
-#ifdef HAVE_SYS_TIMES_H
- struct tms cpu_usage;
- times( &cpu_usage );
-#endif
- intf_StatMsg( "vpar stats: %d loops among %d sequence(s)",
- p_vpar->c_loops, p_vpar->c_sequences );
+ msg_Dbg( p_vpar->p_fifo, "%d loops among %d sequence(s)",
+ p_vpar->c_loops, p_vpar->c_sequences );
#ifdef HAVE_SYS_TIMES_H
- intf_StatMsg( "vpar stats: cpu usage (user: %d, system: %d)",
- cpu_usage.tms_utime, cpu_usage.tms_stime );
+ msg_Dbg( p_vpar->p_fifo, "cpu usage (user: %d, system: %d)",
+ cpu_usage.tms_utime, cpu_usage.tms_stime );
#endif
- intf_StatMsg( "vpar stats: Read %d frames/fields (I %d/P %d/B %d)",
- p_vpar->pc_pictures[I_CODING_TYPE]
- + p_vpar->pc_pictures[P_CODING_TYPE]
- + p_vpar->pc_pictures[B_CODING_TYPE],
- p_vpar->pc_pictures[I_CODING_TYPE],
- p_vpar->pc_pictures[P_CODING_TYPE],
- p_vpar->pc_pictures[B_CODING_TYPE] );
- intf_StatMsg( "vpar stats: Decoded %d frames/fields (I %d/P %d/B %d)",
- p_vpar->pc_decoded_pictures[I_CODING_TYPE]
- + p_vpar->pc_decoded_pictures[P_CODING_TYPE]
- + p_vpar->pc_decoded_pictures[B_CODING_TYPE],
- p_vpar->pc_decoded_pictures[I_CODING_TYPE],
- p_vpar->pc_decoded_pictures[P_CODING_TYPE],
- p_vpar->pc_decoded_pictures[B_CODING_TYPE] );
- intf_StatMsg( "vpar stats: Read %d malformed frames/fields (I %d/P %d/B %d)",
- p_vpar->pc_malformed_pictures[I_CODING_TYPE]
- + p_vpar->pc_malformed_pictures[P_CODING_TYPE]
- + p_vpar->pc_malformed_pictures[B_CODING_TYPE],
- p_vpar->pc_malformed_pictures[I_CODING_TYPE],
- p_vpar->pc_malformed_pictures[P_CODING_TYPE],
- p_vpar->pc_malformed_pictures[B_CODING_TYPE] );
+ msg_Dbg( p_vpar->p_fifo, "read %d frames/fields (I %d/P %d/B %d)",
+ p_vpar->pc_pictures[I_CODING_TYPE]
+ + p_vpar->pc_pictures[P_CODING_TYPE]
+ + p_vpar->pc_pictures[B_CODING_TYPE],
+ p_vpar->pc_pictures[I_CODING_TYPE],
+ p_vpar->pc_pictures[P_CODING_TYPE],
+ p_vpar->pc_pictures[B_CODING_TYPE] );
+ msg_Dbg( p_vpar->p_fifo, "decoded %d frames/fields (I %d/P %d/B %d)",
+ p_vpar->pc_decoded_pictures[I_CODING_TYPE]
+ + p_vpar->pc_decoded_pictures[P_CODING_TYPE]
+ + p_vpar->pc_decoded_pictures[B_CODING_TYPE],
+ p_vpar->pc_decoded_pictures[I_CODING_TYPE],
+ p_vpar->pc_decoded_pictures[P_CODING_TYPE],
+ p_vpar->pc_decoded_pictures[B_CODING_TYPE] );
+ msg_Dbg( p_vpar->p_fifo,
+ "read %d malformed frames/fields (I %d/P %d/B %d)",
+ p_vpar->pc_malformed_pictures[I_CODING_TYPE]
+ + p_vpar->pc_malformed_pictures[P_CODING_TYPE]
+ + p_vpar->pc_malformed_pictures[B_CODING_TYPE],
+ p_vpar->pc_malformed_pictures[I_CODING_TYPE],
+ p_vpar->pc_malformed_pictures[P_CODING_TYPE],
+ p_vpar->pc_malformed_pictures[B_CODING_TYPE] );
#define S p_vpar->sequence
- intf_StatMsg( "vpar info: %s stream (%dx%d), %d.%d pi/s",
- S.b_mpeg2 ? "MPEG-2" : "MPEG-1",
- S.i_width, S.i_height, S.i_frame_rate/1001,
- S.i_frame_rate % 1001 );
- intf_StatMsg( "vpar info: %s, %s, matrix_coeff: %d",
- S.b_progressive ? "Progressive" : "Non-progressive",
- S.i_scalable_mode ? "scalable" : "non-scalable",
- S.i_matrix_coefficients );
+ msg_Dbg( p_vpar->p_fifo, "%s stream (%dx%d), %d.%d pi/s",
+ S.b_mpeg2 ? "MPEG-2" : "MPEG-1",
+ S.i_width, S.i_height, S.i_frame_rate/1001,
+ S.i_frame_rate % 1001 );
+ msg_Dbg( p_vpar->p_fifo, "%s, %s, matrix_coeff: %d",
+ S.b_progressive ? "Progressive" : "Non-progressive",
+ S.i_scalable_mode ? "scalable" : "non-scalable",
+ S.i_matrix_coefficients );
#undef S
- }
/* Dispose of matrices if they have been allocated. */
if( p_vpar->sequence.intra_quant.b_allocated )
vpar_EndPool( p_vpar );
- module_Unneed( p_vpar->p_idct_module );
- module_Unneed( p_vpar->p_motion_module );
+ module_Unneed( p_vpar->p_fifo, p_vpar->p_idct );
+ module_Unneed( p_vpar->p_fifo, p_vpar->p_motion );
free( p_vpar );
-
- intf_DbgMsg("vpar debug: EndThread(%p)", p_vpar);
}
/*****************************************************************************
* This function is called by input's NextDataPacket.
*****************************************************************************/
static void BitstreamCallback ( bit_stream_t * p_bit_stream,
- boolean_t b_new_pes )
+ vlc_bool_t b_new_pes )
{
vpar_thread_t * p_vpar = (vpar_thread_t *)p_bit_stream->p_callback_arg;
if( b_new_pes )
{
- p_vpar->sequence.next_pts =
- DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->i_pts;
- p_vpar->sequence.next_dts =
- DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->i_dts;
p_vpar->sequence.i_current_rate =
- DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->i_rate;
+ p_bit_stream->p_decoder_fifo->p_first->i_rate;
- if( DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->b_discontinuity )
+ if( p_bit_stream->p_decoder_fifo->p_first->b_discontinuity )
{
-#ifdef TRACE_VPAR
- intf_DbgMsg( "Discontinuity in BitstreamCallback" );
-#endif
/* Escape the current picture and reset the picture predictors. */
p_vpar->sequence.b_expect_discontinuity = 1;
p_vpar->picture.b_error = 1;
if( p_bit_stream->p_data->b_discard_payload )
{
-#ifdef TRACE_VPAR
- intf_DbgMsg( "Discard payload in BitstreamCallback" );
-#endif
/* 1 packet messed up, trash the slice. */
p_vpar->picture.b_error = 1;
}