]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/file.c
Reset input titles before adding new ones.
[vlc] / modules / audio_output / file.c
index fcdbf791362975bc8612aa9a51d1e07eb06966b4..f34c4c7262f04b16fa9ed4e8c5f56d2281f039ed 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * file.c : audio output which writes the samples to a file
  *****************************************************************************
- * Copyright (C) 2002 the VideoLAN team
+ * Copyright (C) 2002 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@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
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -30,6 +30,9 @@
 # include "config.h"
 #endif
 
+#include <stdio.h>
+#include <errno.h>
+
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_aout.h>
@@ -71,7 +74,8 @@ static const int pi_channels_maps[CHANNELS_MAX+1] =
  * Local prototypes.
  *****************************************************************************/
 static int     Open        ( vlc_object_t * );
-static void    Play        ( audio_output_t *, block_t *, mtime_t * );
+static void    Play        ( audio_output_t *, block_t * );
+static void    Flush       ( audio_output_t *, bool );
 
 /*****************************************************************************
  * Module descriptor
@@ -86,18 +90,20 @@ static void    Play        ( audio_output_t *, block_t *, mtime_t * );
 #define WAV_LONGTEXT N_("Instead of writing a raw file, you can add a WAV " \
                         "header to the file.")
 
-static const char *const format_list[] = { "u8", "s8", "u16", "s16", "u16_le",
-                                     "s16_le", "u16_be", "s16_be",
-                                     "float32", "spdif" };
-static const int format_int[] = { VLC_CODEC_U8,
-                                  VLC_CODEC_S8,
-                                  VLC_CODEC_U16N, VLC_CODEC_S16N,
-                                  VLC_CODEC_U16L,
-                                  VLC_CODEC_S16L,
-                                  VLC_CODEC_U16B,
-                                  VLC_CODEC_S16B,
-                                  VLC_CODEC_F32L,
-                                  VLC_CODEC_SPDIFL };
+static const char *const format_list[] = {
+    "u8", "s16",
+#ifndef WORDS_BIGENDIAN
+    "float32",
+#endif
+    "spdif",
+};
+static const int format_int[] = {
+    VLC_CODEC_U8, VLC_CODEC_S16N,
+#ifndef WORDS_BIGENDIAN
+    VLC_CODEC_FL32,
+#endif
+    VLC_CODEC_SPDIFL,
+};
 
 #define FILE_TEXT N_("Output file")
 #define FILE_LONGTEXT N_("File to which the audio samples will be written to. (\"-\" for stdout")
@@ -154,9 +160,10 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
         return VLC_EGENERIC;
     }
 
+    p_aout->time_get = NULL;
     p_aout->play = Play;
     p_aout->pause = NULL;
-    p_aout->flush = NULL;
+    p_aout->flush = Flush;
 
     /* Audio format */
     psz_format = var_InheritString( p_aout, "audiofile-format" );
@@ -208,15 +215,16 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
 
         switch( fmt->i_format )
         {
-        case VLC_CODEC_F32L:
+#ifndef WORDS_BIGENDIAN
+        case VLC_CODEC_FL32:
             wh->Format     = WAVE_FORMAT_IEEE_FLOAT;
             wh->BitsPerSample = sizeof(float) * 8;
             break;
+#endif
         case VLC_CODEC_U8:
             wh->Format     = WAVE_FORMAT_PCM;
             wh->BitsPerSample = 8;
             break;
-        case VLC_CODEC_S16L:
         default:
             wh->Format     = WAVE_FORMAT_PCM;
             wh->BitsPerSample = 16;
@@ -249,7 +257,7 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
         if( fwrite( wh, sizeof(WAVEHEADER), 1,
                     p_aout->sys->p_file ) != 1 )
         {
-            msg_Err( p_aout, "write error (%m)" );
+            msg_Err( p_aout, "write error: %s", vlc_strerror_c(errno) );
         }
     }
 
@@ -272,7 +280,7 @@ static void Stop( audio_output_t *p_aout )
         /* Write Wave Header */
         if( fseek( p_aout->sys->p_file, 0, SEEK_SET ) )
         {
-            msg_Err( p_aout, "seek error (%m)" );
+            msg_Err( p_aout, "seek error: %s", vlc_strerror_c(errno) );
         }
 
         /* Header -> little endian format */
@@ -284,7 +292,7 @@ static void Stop( audio_output_t *p_aout )
         if( fwrite( &p_aout->sys->waveh, sizeof(WAVEHEADER), 1,
                     p_aout->sys->p_file ) != 1 )
         {
-            msg_Err( p_aout, "write error (%m)" );
+            msg_Err( p_aout, "write error: %s", vlc_strerror_c(errno) );
         }
     }
 
@@ -296,13 +304,12 @@ static void Stop( audio_output_t *p_aout )
 /*****************************************************************************
  * Play: pretend to play a sound
  *****************************************************************************/
-static void Play( audio_output_t * p_aout, block_t *p_buffer,
-                  mtime_t *restrict drift )
+static void Play( audio_output_t * p_aout, block_t *p_buffer )
 {
     if( fwrite( p_buffer->p_buffer, p_buffer->i_buffer, 1,
                 p_aout->sys->p_file ) != 1 )
     {
-        msg_Err( p_aout, "write error (%m)" );
+        msg_Err( p_aout, "write error: %s", vlc_strerror_c(errno) );
     }
 
     if( p_aout->sys->b_add_wav_header )
@@ -312,7 +319,13 @@ static void Play( audio_output_t * p_aout, block_t *p_buffer,
     }
 
     block_Release( p_buffer );
-    (void) drift;
+}
+
+static void Flush( audio_output_t *aout, bool wait )
+{
+    if( fflush( aout->sys->p_file ) )
+        msg_Err( aout, "flush error: %s", vlc_strerror_c(errno) );
+    (void) wait;
 }
 
 static int Open(vlc_object_t *obj)