]> git.sesse.net Git - vlc/blobdiff - src/input/input_dec.c
* ALL: experimental code for stream (dvd) navigation through object variables.
[vlc] / src / input / input_dec.c
index 36ff2245f0a3eefaa67b9c50dc0a2d4fc0732cca..7489d7aa7c07ded49a53f3485ba8cd8738e28772 100644 (file)
@@ -2,7 +2,7 @@
  * input_dec.c: Functions for the management of decoders
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: input_dec.c,v 1.48 2002/10/27 16:58:12 gbazin Exp $
+ * $Id: input_dec.c,v 1.59 2003/03/04 13:21:19 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -10,7 +10,7 @@
  * 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
@@ -26,7 +26,6 @@
  *****************************************************************************/
 #include <stdlib.h>
 #include <string.h>                                    /* memcpy(), memset() */
-#include <sys/types.h>                                              /* off_t */
 
 #include <vlc/vlc.h>
 
@@ -45,6 +44,7 @@ static void             DeleteDecoderFifo( decoder_fifo_t * );
 decoder_fifo_t * input_RunDecoder( input_thread_t * p_input,
                                    es_descriptor_t * p_es )
 {
+    char           *psz_sout;
     decoder_fifo_t *p_fifo;
     int i_priority;
 
@@ -57,11 +57,70 @@ decoder_fifo_t * input_RunDecoder( input_thread_t * p_input,
         return NULL;
     }
 
-    /* Get a suitable module */
-    p_fifo->p_module = module_Need( p_fifo, "decoder", "$codec" );
+    p_fifo->p_module = NULL;
+    /* If we are in sout mode, search first for packetizer module then
+     * codec to do transcoding */
+    psz_sout = config_GetPsz( p_input, "sout" );
+    if( psz_sout != NULL && *psz_sout != 0 )
+    {
+        vlc_bool_t b_sout = VLC_TRUE;
+
+        if( p_es->i_cat == AUDIO_ES )
+        {
+            b_sout = config_GetInt( p_input, "sout-audio" );
+        }
+        else if( p_es->i_cat == VIDEO_ES )
+        {
+            b_sout = config_GetInt( p_input, "sout-video" );
+        }
+
+        if( b_sout )
+        {
+            vlc_bool_t b_reencode = VLC_FALSE;
+
+            if( p_es->i_cat == AUDIO_ES )
+            {
+                char *psz_sout_acodec = config_GetPsz( p_input, "sout-acodec" );
+                if( psz_sout_acodec != NULL && *psz_sout_acodec != '\0' )
+                {
+                    msg_Dbg( p_input, "audio reencoding requested -> unsupported" );
+                    b_reencode = VLC_TRUE;
+                }
+            }
+            else if( p_es->i_cat == VIDEO_ES )
+            {
+                char *psz_sout_vcodec = config_GetPsz( p_input, "sout-vcodec" );
+                if( psz_sout_vcodec != NULL && *psz_sout_vcodec != '\0' )
+                {
+                    msg_Dbg( p_input, "video reencoding requested" );
+                    /* force encoder video output */
+                    config_PutPsz( p_input, "vout", "encoder" );
+                    b_reencode = VLC_TRUE;
+                }
+            }
+
+            if( !b_reencode )
+            {
+                /* we don't want to reencode so search for a packetizer */
+                p_fifo->p_module =
+                    module_Need( p_fifo, "packetizer", "$packetizer" );
+            }
+            else
+            {
+                /* get a suitable decoder module to do reencoding*/
+                p_fifo->p_module = module_Need( p_fifo, "decoder", "$codec" );
+            }
+        }
+    }
+    else
+    {
+        /* default Get a suitable decoder module */
+        p_fifo->p_module = module_Need( p_fifo, "decoder", "$codec" );
+    }
+
     if( p_fifo->p_module == NULL )
     {
-        msg_Err( p_fifo, "no suitable decoder module for fourcc `%4.4s'",
+        msg_Err( p_fifo, "no suitable decoder module for fourcc `%4.4s'.\nVLC probably does not support this sound or video format.",
                        (char*)&p_fifo->i_fourcc );
         DeleteDecoderFifo( p_fifo );
         vlc_object_destroy( p_fifo );
@@ -155,74 +214,49 @@ void input_DecodePES( decoder_fifo_t * p_decoder_fifo, pes_packet_t * p_pes )
     vlc_mutex_unlock( &p_decoder_fifo->data_lock );
 }
 
-/****************************************************************************
- * input_ExtractPES
- *****************************************************************************
- * Extract a PES from the fifo. If pp_pes is NULL then the PES is just
- * deleted, otherwise *pp_pes will point to this PES.
- ****************************************************************************/
-void input_ExtractPES( decoder_fifo_t *p_fifo, pes_packet_t **pp_pes )
+/*****************************************************************************
+ * Create a NULL packet for padding in case of a data loss
+ *****************************************************************************/
+void input_NullPacket( input_thread_t * p_input,
+                       es_descriptor_t * p_es )
 {
-    pes_packet_t *p_pes;
-
-    vlc_mutex_lock( &p_fifo->data_lock );
+    data_packet_t *             p_pad_data;
+    pes_packet_t *              p_pes;
 
-    if( p_fifo->p_first == NULL )
+    if( (p_pad_data = input_NewPacketForce( p_input->p_method_data,
+                    PADDING_PACKET_SIZE)) == NULL )
     {
-        if( p_fifo->b_die )
-        {
-            vlc_mutex_unlock( &p_fifo->data_lock );
-            if( pp_pes ) *pp_pes = NULL;
-            return;
-        }
-
-        /* Signal the input thread we're waiting. This is only
-         * needed in case of slave clock (ES plug-in) but it won't
-         * harm. */
-        vlc_cond_signal( &p_fifo->data_wait );
-
-        /* Wait for the input to tell us when we received a packet. */
-        vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
+        msg_Err( p_input, "no new packet" );
+        p_input->b_error = 1;
+        return;
     }
 
-    p_pes = p_fifo->p_first;
-    p_fifo->p_first = p_pes->p_next;
-    p_pes->p_next = NULL;
-    p_fifo->i_depth--;
+    memset( p_pad_data->p_payload_start, 0, PADDING_PACKET_SIZE );
+    p_pad_data->b_discard_payload = 1;
+    p_pes = p_es->p_pes;
 
-    if( !p_fifo->p_first )
+    if( p_pes != NULL )
     {
-        /* No PES in the FIFO. p_last is no longer valid. */
-        p_fifo->pp_last = &p_fifo->p_first;
+        p_pes->b_discontinuity = 1;
+        p_pes->p_last->p_next = p_pad_data;
+        p_pes->p_last = p_pad_data;
+        p_pes->i_nb_data++;
     }
-
-    vlc_mutex_unlock( &p_fifo->data_lock );
-
-    if( pp_pes )
-        *pp_pes = p_pes;
     else
-        input_DeletePES( p_fifo->p_packets_mgt, p_pes );
-}
-
-/****************************************************************************
- * input_FlushPESFifo
- *****************************************************************************
- * Empties the PES fifo of the decoder.
- ****************************************************************************/
-void input_FlushPESFifo( decoder_fifo_t *p_fifo )
-{
-    pes_packet_t * p_pes;
-
-    vlc_mutex_lock( &p_fifo->data_lock );
-    while( p_fifo->p_first )
     {
-        p_pes = p_fifo->p_first;
-        p_fifo->p_first = p_fifo->p_first->p_next;
-        input_DeletePES( p_fifo->p_packets_mgt, p_pes );
+        if( (p_pes = input_NewPES( p_input->p_method_data )) == NULL )
+        {
+            msg_Err( p_input, "no PES packet" );
+            p_input->b_error = 1;
+            return;
+        }
+
+        p_pes->i_rate = p_input->stream.control.i_rate;
+        p_pes->p_first = p_pes->p_last = p_pad_data;
+        p_pes->i_nb_data = 1;
+        p_pes->b_discontinuity = 1;
+        input_DecodePES( p_es->p_decoder_fifo, p_pes );
     }
-    /* No PES in the FIFO. p_last is no longer valid. */
-    p_fifo->pp_last = &p_fifo->p_first;
-    vlc_mutex_unlock( &p_fifo->data_lock );
 }
 
 /*****************************************************************************
@@ -230,7 +264,7 @@ void input_FlushPESFifo( decoder_fifo_t *p_fifo )
  *****************************************************************************/
 void input_EscapeDiscontinuity( input_thread_t * p_input )
 {
-    int     i_es, i;
+    unsigned int i_es, i;
 
     for( i_es = 0; i_es < p_input->stream.i_selected_es_number; i_es++ )
     {
@@ -251,7 +285,7 @@ void input_EscapeDiscontinuity( input_thread_t * p_input )
  *****************************************************************************/
 void input_EscapeAudioDiscontinuity( input_thread_t * p_input )
 {
-    int     i_es, i;
+    unsigned int i_es, i;
 
     for( i_es = 0; i_es < p_input->stream.i_selected_es_number; i_es++ )
     {
@@ -284,20 +318,10 @@ static decoder_fifo_t * CreateDecoderFifo( input_thread_t * p_input,
     }
 
     /* Select a new ES */
-    p_input->stream.i_selected_es_number++;
-    p_input->stream.pp_selected_es = realloc(
-                                          p_input->stream.pp_selected_es,
-                                          p_input->stream.i_selected_es_number
-                                           * sizeof(es_descriptor_t *) );
-    if( p_input->stream.pp_selected_es == NULL )
-    {
-        msg_Err( p_input, "out of memory" );
-        vlc_object_destroy( p_fifo );
-        return NULL;
-    }
-
-    p_input->stream.pp_selected_es[p_input->stream.i_selected_es_number - 1]
-            = p_es;
+    INSERT_ELEM( p_input->stream.pp_selected_es,
+                 p_input->stream.i_selected_es_number,
+                 p_input->stream.i_selected_es_number,
+                 p_es );
 
     /* Initialize the p_fifo structure */
     vlc_mutex_init( p_input, &p_fifo->data_lock );
@@ -306,8 +330,9 @@ static decoder_fifo_t * CreateDecoderFifo( input_thread_t * p_input,
 
     p_fifo->i_id = p_es->i_id;
     p_fifo->i_fourcc = p_es->i_fourcc;
-    p_fifo->p_demux_data = p_es->p_demux_data;
-    
+    p_fifo->p_demux_data   = p_es->p_demux_data;
+    p_fifo->p_waveformatex = p_es->p_waveformatex;
+    p_fifo->p_bitmapinfoheader = p_es->p_bitmapinfoheader;
     p_fifo->p_stream_ctrl = &p_input->stream.control;
     p_fifo->p_sout = p_input->stream.p_sout;