]> git.sesse.net Git - vlc/blobdiff - src/lpcm_decoder/lpcm_decoder_thread.c
* Mandatory step for video output IV and the audio output quality
[vlc] / src / lpcm_decoder / lpcm_decoder_thread.c
index 6feeea23e5af6a6b7ac71a8a176014730b29f615..9a3c3d260c988bf5f699b7bcbfed187cfd2bcccd 100644 (file)
@@ -2,9 +2,9 @@
  * lpcm_decoder_thread.c: lpcm decoder thread
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: lpcm_decoder_thread.c,v 1.6 2000/12/22 13:04:45 sam Exp $
+ * $Id: lpcm_decoder_thread.c,v 1.14 2001/05/01 04:18:18 sam Exp $
  *
- * Authors:
+ * Authors: Samuel Hocevar <sam@zoy.org>
  *
  * 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
 #include <unistd.h>                                              /* getpid() */
 
 #include <stdio.h>                                           /* "intf_msg.h" */
+#include <string.h>                                    /* memcpy(), memset() */
 #include <stdlib.h>                                      /* malloc(), free() */
-#include <sys/types.h>                        /* on BSD, uio.h needs types.h */
-#include <sys/uio.h>                                            /* "input.h" */
 
 #include "config.h"
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
-#include "plugins.h"
-#include "debug.h"                                      /* "input_netlist.h" */
 
 #include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
 
@@ -50,7 +47,7 @@
 #include "lpcm_decoder.h"
 #include "lpcm_decoder_thread.h"
 
-#define LPCMDEC_FRAME_SIZE (2*1536)                    /* May not be usefull */
+#define LPCMDEC_FRAME_SIZE (2*1536)                        /* May be useless */
 
 /*****************************************************************************
  * Local prototypes
@@ -66,11 +63,11 @@ static void     EndThread               (lpcmdec_thread_t * p_adec);
 vlc_thread_t lpcmdec_CreateThread (adec_config_t * p_config)
 {
     lpcmdec_thread_t *   p_lpcmdec;
-    intf_DbgMsg ( "LPCM Debug: creating lpcm decoder thread" );
+    intf_DbgMsg ( "lpcm: creating lpcm decoder thread" );
 
     /* Allocate the memory needed to store the thread's structure */
     if ((p_lpcmdec = (lpcmdec_thread_t *)malloc (sizeof(lpcmdec_thread_t))) == NULL) {
-        intf_ErrMsg ( "LPCM Error: not enough memory for lpcmdec_CreateThread() to create the new thread" );
+        intf_ErrMsg ( "lpcm error: cannot create lpcmdec_thread_t" );
         return 0;
     }
 
@@ -87,12 +84,11 @@ vlc_thread_t lpcmdec_CreateThread (adec_config_t * p_config)
     /*
      * Initialize the output properties
      */
-    p_lpcmdec->p_aout = p_config->p_aout;
     p_lpcmdec->p_aout_fifo = NULL;
 
     /* Spawn the lpcm decoder thread */
     if (vlc_thread_create(&p_lpcmdec->thread_id, "lpcm decoder", (vlc_thread_func_t)RunThread, (void *)p_lpcmdec)) {
-        intf_ErrMsg  ( "LPCM Error: can't spawn lpcm decoder thread" );
+        intf_ErrMsg  ( "lpcm error: cannot spawn thread" );
         free (p_lpcmdec);
         return 0;
     }
@@ -108,7 +104,6 @@ vlc_thread_t lpcmdec_CreateThread (adec_config_t * p_config)
  *****************************************************************************/
 static int InitThread (lpcmdec_thread_t * p_lpcmdec)
 {
-    aout_fifo_t         aout_fifo;
     lpcm_byte_stream_t * byte_stream;
 
     intf_DbgMsg ( "LPCM Debug: initializing lpcm decoder thread %p", p_lpcmdec );
@@ -130,14 +125,11 @@ static int InitThread (lpcmdec_thread_t * p_lpcmdec)
     byte_stream->info = p_lpcmdec;
     vlc_mutex_unlock (&p_lpcmdec->p_fifo->data_lock);
 
-    aout_fifo.i_type = AOUT_ADEC_STEREO_FIFO;
-    aout_fifo.i_channels = 2;
-    aout_fifo.b_stereo = 1;
-
-    aout_fifo.l_frame_size = LPCMDEC_FRAME_SIZE;
-
     /* Creating the audio output fifo */
-    if ((p_lpcmdec->p_aout_fifo = aout_CreateFifo(p_lpcmdec->p_aout, &aout_fifo)) == NULL) {
+    p_lpcmdec->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO, 2, 0, 0,
+                                              LPCMDEC_FRAME_SIZE, NULL  );
+    if ( p_lpcmdec->p_aout_fifo == NULL )
+    {
         return -1;
     }
 
@@ -171,41 +163,43 @@ static void RunThread (lpcmdec_thread_t * p_lpcmdec)
    
     while ((!p_lpcmdec->p_fifo->b_die) && (!p_lpcmdec->p_fifo->b_error))
     {
-           s16 * buffer;
-           lpcm_sync_info_t sync_info;
+        s16 * buffer;
+        lpcm_sync_info_t sync_info;
 
-           if (!sync)
+        if (!sync)
         {
             /* have to find a synchro point */
         }
     
-        if (DECODER_FIFO_START(*p_lpcmdec->p_fifo)->b_has_pts)
+        if (DECODER_FIFO_START(*p_lpcmdec->p_fifo)->i_pts)
         {
-               p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame] = DECODER_FIFO_START(*p_lpcmdec->p_fifo)->i_pts;
-               DECODER_FIFO_START(*p_lpcmdec->p_fifo)->b_has_pts = 0;
+            p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame] = DECODER_FIFO_START(*p_lpcmdec->p_fifo)->i_pts;
+            DECODER_FIFO_START(*p_lpcmdec->p_fifo)->i_pts = 0;
         }
         else
         {
-               p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame] = LAST_MDATE;
+            p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame] = LAST_MDATE;
         }
 
-       p_lpcmdec->p_aout_fifo->l_rate = sync_info.sample_rate;
+        p_lpcmdec->p_aout_fifo->l_rate = sync_info.sample_rate;
 
-           buffer = ((s16 *)p_lpcmdec->p_aout_fifo->buffer) + (p_lpcmdec->p_aout_fifo->l_end_frame * LPCMDEC_FRAME_SIZE);
+        buffer = ((s16 *)p_lpcmdec->p_aout_fifo->buffer) + (p_lpcmdec->p_aout_fifo->l_end_frame * LPCMDEC_FRAME_SIZE);
 
-           if (lpcm_decode_frame (&p_lpcmdec->lpcm_decoder, buffer))
+        if (lpcm_decode_frame (&p_lpcmdec->lpcm_decoder, buffer))
         {
-               sync = 0;
-               goto bad_frame;
-           }
+            sync = 0;
+            goto bad_frame;
+        }
 
-           vlc_mutex_lock (&p_lpcmdec->p_aout_fifo->data_lock);
-           p_lpcmdec->p_aout_fifo->l_end_frame = (p_lpcmdec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
-           vlc_cond_signal (&p_lpcmdec->p_aout_fifo->data_wait);
-           vlc_mutex_unlock (&p_lpcmdec->p_aout_fifo->data_lock);
+        vlc_mutex_lock (&p_lpcmdec->p_aout_fifo->data_lock);
+        p_lpcmdec->p_aout_fifo->l_end_frame = (p_lpcmdec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+        vlc_cond_signal (&p_lpcmdec->p_aout_fifo->data_wait);
+        vlc_mutex_unlock (&p_lpcmdec->p_aout_fifo->data_lock);
 
         intf_DbgMsg( "LPCM Debug: %x", *buffer );
-        bad_frame:
+
+    bad_frame:
+        continue;
     }
 
     /* If b_error is set, the lpcm decoder thread enters the error loop */