[gegl/video-rejuvenation: 21/60] ff-load: add support for more audio formats



commit 2716c55242ee18124bff5e3d1352616d57a7a08e
Author: Øyvind Kolås <pippin gimp org>
Date:   Sat Oct 17 01:34:34 2015 +0200

    ff-load: add support for more audio formats

 bin/mrg-ui.c                  |   51 +++++++++++++++++++++++-----------------
 operations/external/ff-load.c |   45 +++++++++++++++++-------------------
 2 files changed, 50 insertions(+), 46 deletions(-)
---
diff --git a/bin/mrg-ui.c b/bin/mrg-ui.c
index f6b2e45..37b756c 100644
--- a/bin/mrg-ui.c
+++ b/bin/mrg-ui.c
@@ -55,7 +55,7 @@
 static int audio_len   = 0;
 static int audio_pos   = 0;
 static int audio_post   = 0;
-static int audio_start = 0; /* which sample no is at the start of our circular buffer */
+//static int audio_start = 0; /* which sample no is at the start of our circular buffer */
 
 #define AUDIO_BUF_LEN 819200000
 
@@ -264,6 +264,11 @@ static int str_has_video_suffix (char *path)
   return g_str_has_suffix (path, ".avi") ||
          g_str_has_suffix (path, ".AVI") ||
          g_str_has_suffix (path, ".mp4") ||
+         g_str_has_suffix (path, ".mp3") ||
+         g_str_has_suffix (path, ".mpg") ||
+         g_str_has_suffix (path, ".ogv") ||
+         g_str_has_suffix (path, ".MPG") ||
+         g_str_has_suffix (path, ".webm") ||
          g_str_has_suffix (path, ".MP4") ||
          g_str_has_suffix (path, ".mkv") ||
          g_str_has_suffix (path, ".MKV") ||
@@ -336,25 +341,24 @@ static State *hack_state = NULL;  // XXX: this shoudl be factored away
 char **ops = NULL;
 
 
-static void init_audio (void)
+static void open_audio (int frequency)
 {
-  SDL_AudioSpec AudioSettings = {0};
-
+  SDL_AudioSpec spec = {0};
   SDL_Init(SDL_INIT_AUDIO);
-  AudioSettings.freq = 48000;
-  AudioSettings.format = AUDIO_S16SYS;
-  AudioSettings.channels = 2;
-  AudioSettings.samples = 1024;
-  AudioSettings.callback = sdl_audio_cb;
-  SDL_OpenAudio(&AudioSettings, 0);
-
-  if (AudioSettings.format != AUDIO_S16SYS)
+  spec.freq = frequency;
+  spec.format = AUDIO_S16SYS;
+  spec.channels = 2;
+  spec.samples = 1024;
+  spec.callback = sdl_audio_cb;
+  SDL_OpenAudio(&spec, 0);
+
+  if (spec.format != AUDIO_S16SYS)
    {
       fprintf (stderr, "not getting format we wanted\n");
    }
-  if (AudioSettings.freq != 48000)
+  if (spec.freq != frequency)
    {
-      fprintf (stderr, "not getting rate we wanted\n");
+      fprintf (stderr, "not getting desires samplerate(%i) we wanted got %i instead\n", frequency, 
spec.freq);
    }
 }
 
@@ -368,7 +372,6 @@ int mrg_ui_main (int argc, char **argv, char **ops)
   Mrg *mrg = mrg_new (1024, 768, NULL);
   State o = {NULL,};
 
-  init_audio ();
 #ifdef USE_MIPMAPS
   /* to use this UI comfortably, mipmap rendering needs to be enabled, there are
    * still a few glitches, but for basic full frame un-panned, un-cropped use it
@@ -1018,12 +1021,15 @@ static void gegl_ui (Mrg *mrg, void *data)
   {
     GeglAudio *audio = NULL;
     gdouble fps;
-    gegl_node_get (o->load, "audio", &audio, "frame-rate", &fps, NULL);
-    if (audio->samples > 0)
+    if (o->is_video)
+    {
+      gegl_node_get (o->load, "audio", &audio, "frame-rate", &fps, NULL);
+    if (audio && audio->samples > 0)
     {
        int i;
        if (!audio_started)
         {
+         open_audio (audio->samplerate);
           SDL_PauseAudio(0);
           audio_started = 1;
         }
@@ -1031,14 +1037,15 @@ static void gegl_ui (Mrg *mrg, void *data)
        {
          sdl_add_audio_sample (0, audio->left[i], audio->right[i]);
        }
-    }
 
-    while ( (audio_post / 4.0) / audio->samplerate < (o->frame_no / fps) - 0.05 )
-    {
-      g_usleep (500); /* sync audio */
-    }
+       while ( (audio_post / 4.0) / audio->samplerate < (o->frame_no / fps) - 0.05 )
+       {
+         g_usleep (100); /* sync audio */
+       }
 
     g_object_unref (audio);
+    }
+    }
   }
   
   if (o->show_controls)
diff --git a/operations/external/ff-load.c b/operations/external/ff-load.c
index 30e4700..adec1f4 100644
--- a/operations/external/ff-load.c
+++ b/operations/external/ff-load.c
@@ -283,43 +283,40 @@ decode_frame (GeglOperation *operation,
                            frame.nb_samples,
                            p->audio_context->sample_fmt,
                            1);
-                       g_assert (data_size < 16000);
+                       g_assert (frame.nb_samples < MAX_AUDIO_SAMPLES);
 
                        /* XXX: it might not be stereoo.. */
+                       af->channels = p->audio_context->channels;
+
                        switch (p->audio_context->sample_fmt)
                        {
+                         case AV_SAMPLE_FMT_FLT:
+                           if (af->channels != 1)
+                             g_warning ("receiving chunky float data!\n");
                          case AV_SAMPLE_FMT_FLTP:
                           for (gint i = 0; i < frame.nb_samples; i++)
-                          {
-                            af->data[0][i] = ((float *)frame.data[0])[i];
-                            af->data[1][i] = ((float *)frame.data[1])[i];
-                          }
+                            for (gint c = 0; c < af->channels; c++)
+                              af->data[c][i] = ((float *)frame.data[c])[i];
                            break;
+                         case AV_SAMPLE_FMT_S16:
+                           if (af->channels != 1)
+                             g_warning ("receiving chunky 16bit data!\n");
                          case AV_SAMPLE_FMT_S16P:
                           for (gint i = 0; i < frame.nb_samples; i++)
-                          {
-                            af->data[0][i] = ((int16_t *)frame.data[0])[i] / 32768.0;
-                            af->data[1][i] = ((int16_t *)frame.data[1])[i] / 32768.0;
-                          }
+                            for (gint c = 0; c < af->channels; c++)
+                              af->data[c][i] = ((int16_t *)frame.data[c])[i] / 32768.0;
+                           break;
+                         case AV_SAMPLE_FMT_S32:
+                           if (af->channels != 1)
+                             g_warning ("receiving chunky 32bit data!\n");
+                         case AV_SAMPLE_FMT_S32P:
+                          for (gint i = 0; i < frame.nb_samples; i++)
+                            for (gint c = 0; c < af->channels; c++)
+                              af->data[c][i] = ((int16_t *)frame.data[c])[i] / 2147483648.0;
                            break;
                          default:
                            fprintf (stderr, "undealt with sample format\n");
                        }
-#if 0
-                       if (p->audio_context->sample_fmt == AV_SAMPLE_FMT_FLT)
-                       {
-                       }
-                       else
-                       {
-                         /* XXX: do not hardcode this planar to chunky conversion */
-                         int i;
-                         for (i = 0; i < frame.nb_samples; i++)
-                         {
-                           ((int16_t *)af->buf)[i*2] =  ((int16_t *)frame.data[0])[i];
-                           ((int16_t *)af->buf)[i*2+1] =  ((int16_t *)frame.data[1])[i];
-                         }
-                       }
-#endif
                        af->len = frame.nb_samples;
                        af->pos = p->audio_pos;
                        p->audio_pos += af->len;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]