[gegl/video-rejuvenation] GeglAudioFragment: add defaults to construction



commit 8d083c469e35c375865bd3a04edaee5dd5ec79d7
Author: Øyvind Kolås <pippin gimp org>
Date:   Fri Nov 20 13:24:24 2015 +0100

    GeglAudioFragment: add defaults to construction

 bin/mrg-ui.c                              |    4 +-
 examples/gegl-video.c                     |   12 +++---
 gegl/gegl-op.h                            |    2 +-
 gegl/property-types/gegl-audio-fragment.c |   40 ++++++++++++-----------
 gegl/property-types/gegl-audio-fragment.h |   17 +++++----
 operations/external/ff-load.c             |   51 ++++++++++++++++-------------
 operations/external/ff-save.c             |   16 ++++-----
 7 files changed, 74 insertions(+), 68 deletions(-)
---
diff --git a/bin/mrg-ui.c b/bin/mrg-ui.c
index f1b14f4..1009dcc 100644
--- a/bin/mrg-ui.c
+++ b/bin/mrg-ui.c
@@ -1032,7 +1032,7 @@ static void gegl_ui (Mrg *mrg, void *data)
     gegl_node_get (o->load, "audio", &audio, "frame-rate", &fps, NULL);
     if (audio)
     {
-       if (audio->samples > 0)
+       if (audio->xsample_count > 0)
        {
          int i;
          if (!audio_started)
@@ -1041,7 +1041,7 @@ static void gegl_ui (Mrg *mrg, void *data)
            SDL_PauseAudio(0);
            audio_started = 1;
          }
-         for (i = 0; i < audio->samples; i++)
+         for (i = 0; i < audio->xsample_count; i++)
          {
            sdl_add_audio_sample (0, audio->data[0][i], audio->data[1][i]);
          }
diff --git a/examples/gegl-video.c b/examples/gegl-video.c
index bf86d29..86398f6 100644
--- a/examples/gegl-video.c
+++ b/examples/gegl-video.c
@@ -280,7 +280,7 @@ main (gint    argc,
         gegl_node_get (load, "audio", &audio,
                              "frame-rate", &fps, NULL);
 
-        if (audio->samples > 0)
+        if (audio->xsample_count > 0)
         {
           int i;
           if (!audio_started)
@@ -288,7 +288,7 @@ main (gint    argc,
              SDL_PauseAudio(0);
              audio_started = 1;
            }
-          for (i = 0; i < audio->samples; i++)
+          for (i = 0; i < audio->xsample_count; i++)
           {
             audio_data[audio_len/2 + 0] = audio->data[0][i] * 32767.0;
             audio_data[audio_len/2 + 1] = audio->data[1][i] * 32767.0;
@@ -362,11 +362,11 @@ gegl_meta_set_audio (const char        *path,
     if (gexiv2_metadata_has_tag (e2m, "Xmp.xmp.GEGL"))
       gexiv2_metadata_clear_tag (e2m, "Xmp.xmp.GEGL");
 
-    g_string_append_printf (str, "%i %i %i %i", audio->sample_rate, audio->channels,
-                            audio->channel_layout, audio->samples);
+    g_string_append_printf (str, "%i %i %i %i", audio->sample_rate, audio->xchannels,
+                            audio->xchannel_layout, audio->xsample_count);
 
-    for (i = 0; i < audio->samples; i++)
-      for (c = 0; c < audio->channels; c++)
+    for (i = 0; i < audio->xsample_count; i++)
+      for (c = 0; c < audio->xchannels; c++)
         g_string_append_printf (str, " %0.5f", audio->data[c][i]);
 
     gexiv2_metadata_set_tag_string (e2m, "Xmp.xmp.GeglAudio", str->str);
diff --git a/gegl/gegl-op.h b/gegl/gegl-op.h
index 09f9df0..8d9db3a 100644
--- a/gegl/gegl-op.h
+++ b/gegl/gegl-op.h
@@ -695,7 +695,7 @@ gegl_op_constructor (GType                  type,
 #define property_curve(name, label, def_val)
 #define property_audio_fragment(name, label, def_val)\
     if (properties->name == NULL)                   \
-    {properties->name = gegl_audio_fragment_new();}
+    {properties->name = gegl_audio_fragment_new(48000, 2, 0, 8192);}
 #define property_color(name, label, def_val)\
     if (properties->name == NULL)                   \
     {properties->name = gegl_color_new(def_val?def_val:"black");}
diff --git a/gegl/property-types/gegl-audio-fragment.c b/gegl/property-types/gegl-audio-fragment.c
index 9e58120..16cc47e 100644
--- a/gegl/property-types/gegl-audio-fragment.c
+++ b/gegl/property-types/gegl-audio-fragment.c
@@ -48,6 +48,7 @@ static void
 gegl_audio_fragment_init (GeglAudioFragment *self)
 {
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), GEGL_TYPE_AUDIO_FRAGMENT, GeglAudioFragmentPrivate);
+  self->max_samples = GEGL_MAX_AUDIO_SAMPLES;
 }
 
 static void
@@ -101,20 +102,21 @@ get_property (GObject    *gobject,
 }
 
 GeglAudioFragment *
-gegl_audio_fragment_new (void)
+gegl_audio_fragment_new (int sample_rate, int channels, int channel_layout, int max_samples)
 {
-  void *string = NULL;
-  if (string)
-    return g_object_new (GEGL_TYPE_AUDIO_FRAGMENT, "string", string, NULL);
-
-  return g_object_new (GEGL_TYPE_AUDIO_FRAGMENT, NULL);
+  GeglAudioFragment *ret = g_object_new (GEGL_TYPE_AUDIO_FRAGMENT, NULL);
+  gegl_audio_fragment_set_max_samples (ret, max_samples);
+  gegl_audio_fragment_set_sample_rate (ret, sample_rate);
+  gegl_audio_fragment_set_channels (ret, channels);
+  gegl_audio_fragment_set_channel_layout (ret, channel_layout);
+  return ret;
 }
 
 void
 gegl_audio_fragment_set_max_samples (GeglAudioFragment *audio,
                                      int                max_samples)
 {
-  // still a define
+  audio->max_samples = max_samples;
 }
 
 void
@@ -128,21 +130,21 @@ void
 gegl_audio_fragment_set_channels (GeglAudioFragment *audio,
                                   int                channels)
 {
-  audio->channels = channels;
+  audio->xchannels = channels;
 }
 
 void
-gegl_audio_fragment_set_channel_layput (GeglAudioFragment *audio,
+gegl_audio_fragment_set_channel_layout (GeglAudioFragment *audio,
                                         int                channel_layout)
 {
-  audio->channel_layout = channel_layout;
+  audio->xchannel_layout = channel_layout;
 }
 
 void
-gegl_audio_fragment_set_samples (GeglAudioFragment *audio,
-                                 int                samples)
+gegl_audio_fragment_set_sample_count (GeglAudioFragment *audio,
+                                      int                samples)
 {
-  audio->samples = samples;
+  audio->xsample_count = samples;
 }
 
 void
@@ -155,7 +157,7 @@ gegl_audio_fragment_set_pos (GeglAudioFragment *audio,
 int
 gegl_audio_fragment_get_max_samples (GeglAudioFragment *audio)
 {
-  return GEGL_MAX_AUDIO_SAMPLES;
+  return audio->max_samples;
 }
 
 
@@ -168,13 +170,13 @@ gegl_audio_fragment_get_sample_rate (GeglAudioFragment *audio)
 int
 gegl_audio_fragment_get_channels (GeglAudioFragment *audio)
 {
-  return audio->channels;
+  return audio->xchannels;
 }
 
 int
-gegl_audio_fragment_get_samples (GeglAudioFragment *audio)
+gegl_audio_fragment_get_sample_count (GeglAudioFragment *audio)
 {
-  return audio->samples;
+  return audio->xsample_count;
 }
 
 int
@@ -184,9 +186,9 @@ gegl_audio_fragment_get_pos     (GeglAudioFragment *audio)
 }
 
 int
-gegl_audio_fragment_get_channel_layput (GeglAudioFragment *audio)
+gegl_audio_fragment_get_channel_layout (GeglAudioFragment *audio)
 {
-  return audio->channel_layout;
+  return audio->xchannel_layout;
 }
 
 /* --------------------------------------------------------------------------
diff --git a/gegl/property-types/gegl-audio-fragment.h b/gegl/property-types/gegl-audio-fragment.h
index abbebc9..9ffc394 100644
--- a/gegl/property-types/gegl-audio-fragment.h
+++ b/gegl/property-types/gegl-audio-fragment.h
@@ -40,11 +40,12 @@ typedef struct _GeglAudioFragmentPrivate GeglAudioFragmentPrivate;
 struct _GeglAudioFragment
 {
   GObject parent_instance;
+  int   max_samples;
+  int   xsample_count;
+  int   xchannels;
+  int   xchannel_layout;/* unused - assumed channels = 1 is mono 2 stereo */
   int   sample_rate;
-  int   samples;
   int   pos;
-  int   channels;
-  int   channel_layout;/* unused - assumed channels = 1 is mono 2 stereo */
   float data[GEGL_MAX_AUDIO_CHANNELS][GEGL_MAX_AUDIO_SAMPLES]; 
   GeglAudioFragmentPrivate *priv;
 };
@@ -56,21 +57,21 @@ struct _GeglAudioFragmentClass
 
 GType gegl_audio_fragment_get_type (void) G_GNUC_CONST;
 
-GeglAudioFragment *  gegl_audio_fragment_new                    (void);
+GeglAudioFragment *  gegl_audio_fragment_new                    (int sample_rate, int channels, int 
channel_layout, int max_samples);
 
 void gegl_audio_fragment_set_max_samples (GeglAudioFragment *audio, int max_samples);
 void gegl_audio_fragment_set_sample_rate (GeglAudioFragment *audio, int sample_rate);
 void gegl_audio_fragment_set_channels (GeglAudioFragment *audio,    int channels);
-void gegl_audio_fragment_set_channel_layput (GeglAudioFragment *audio, int channel_layout);
-void gegl_audio_fragment_set_samples (GeglAudioFragment *audio,     int samples);
+void gegl_audio_fragment_set_channel_layout (GeglAudioFragment *audio, int channel_layout);
+void gegl_audio_fragment_set_sample_count (GeglAudioFragment *audio,     int sample_count);
 void gegl_audio_fragment_set_pos     (GeglAudioFragment *audio,     int pos);
 
 int gegl_audio_fragment_get_max_samples (GeglAudioFragment *audio);
 int gegl_audio_fragment_get_sample_rate (GeglAudioFragment *audio);
 int gegl_audio_fragment_get_channels (GeglAudioFragment *audio);
-int gegl_audio_fragment_get_samples (GeglAudioFragment *audio);
+int gegl_audio_fragment_get_sample_count (GeglAudioFragment *audio);
 int gegl_audio_fragment_get_pos     (GeglAudioFragment *audio);
-int gegl_audio_fragment_get_channel_layput (GeglAudioFragment *audio);
+int gegl_audio_fragment_get_channel_layout (GeglAudioFragment *audio);
 
 
 
diff --git a/operations/external/ff-load.c b/operations/external/ff-load.c
index 03530f5..f5c3f39 100644
--- a/operations/external/ff-load.c
+++ b/operations/external/ff-load.c
@@ -228,51 +228,52 @@ decode_audio (GeglOperation *operation,
             while (samples_left)
             {
                int sample_count = MIN (samples_left, GEGL_MAX_AUDIO_SAMPLES);
-
-               GeglAudioFragment *af = gegl_audio_fragment_new ();
-          
-               af->channels = MIN(p->audio_stream->codec->channels, GEGL_MAX_AUDIO_CHANNELS);
+               int channels = MIN(p->audio_stream->codec->channels, GEGL_MAX_AUDIO_CHANNELS);
+               GeglAudioFragment *af = gegl_audio_fragment_new (o->audio_sample_rate, channels,
+                          AV_CH_LAYOUT_STEREO, GEGL_MAX_AUDIO_SAMPLES); // XXX : use samples_left directly?
+//);
+               //af->channels = MIN(p->audio_stream->codec->channels, GEGL_MAX_AUDIO_CHANNELS);
 
                switch (p->audio_stream->codec->sample_fmt)
                {
                  case AV_SAMPLE_FMT_FLT:
                    for (gint i = 0; i < sample_count; i++)
-                     for (gint c = 0; c < af->channels; c++)
-                       af->data[c][i] = ((int16_t *)frame.data[0])[(i + si) * af->channels + c];
+                     for (gint c = 0; c < channels; c++)
+                       af->data[c][i] = ((int16_t *)frame.data[0])[(i + si) * channels + c];
                    break;
                  case AV_SAMPLE_FMT_FLTP:
                    for (gint i = 0; i < sample_count; i++)
-                     for (gint c = 0; c < af->channels; c++)
+                     for (gint c = 0; c < channels; c++)
                        {
                          af->data[c][i] = ((float *)frame.data[c])[i + si];
                        }
                    break;
                  case AV_SAMPLE_FMT_S16:
                    for (gint i = 0; i < sample_count; i++)
-                     for (gint c = 0; c < af->channels; c++)
-                       af->data[c][i] = ((int16_t *)frame.data[0])[(i + si) * af->channels + c] / 32768.0;
+                     for (gint c = 0; c < channels; c++)
+                       af->data[c][i] = ((int16_t *)frame.data[0])[(i + si) * channels + c] / 32768.0;
                    break;
                  case AV_SAMPLE_FMT_S16P:
                    for (gint i = 0; i < sample_count; i++)
-                     for (gint c = 0; c < af->channels; c++)
+                     for (gint c = 0; c < channels; c++)
                        af->data[c][i] = ((int16_t *)frame.data[c])[i + si] / 32768.0;
                    break;
                  case AV_SAMPLE_FMT_S32:
                    for (gint i = 0; i < sample_count; i++)
-                     for (gint c = 0; c < af->channels; c++)
-                       af->data[c][i] = ((int32_t *)frame.data[0])[(i + si) * af->channels + c] / 
2147483648.0;
+                     for (gint c = 0; c < channels; c++)
+                       af->data[c][i] = ((int32_t *)frame.data[0])[(i + si) * channels + c] / 2147483648.0;
                   break;
                 case AV_SAMPLE_FMT_S32P:
                    for (gint i = 0; i < sample_count; i++)
-                    for (gint c = 0; c < af->channels; c++)
+                    for (gint c = 0; c < channels; c++)
                       af->data[c][i] = ((int32_t *)frame.data[c])[i + si] / 2147483648.0;
                   break;
                 default:
                   g_warning ("undealt with sample format\n");
                 }
-                af->samples = sample_count;
+                af->xsample_count = sample_count;
                 af->pos = p->audio_pos;
-                p->audio_pos += af->samples;
+                p->audio_pos += af->xsample_count;
                 p->audio_track = g_list_append (p->audio_track, af);
 
                 samples_left -= sample_count;
@@ -568,17 +569,17 @@ static void get_sample_data (Priv *p, long sample_no, float *left, float *right)
   for (; l; l = l->next)
   {
     GeglAudioFragment *af = l->data;
-    if (sample_no > af->pos + af->samples)
+    if (sample_no > af->pos + af->xsample_count)
     {
       to_remove ++;
     }
 
     if (af->pos <= sample_no &&
-        sample_no < af->pos + af->samples)
+        sample_no < af->pos + af->xsample_count)
       {
         int i = sample_no - af->pos;
         *left  = af->data[0][i];
-        if (af->channels == 1)
+        if (af->xchannels == 1)
           *right = af->data[0][i];
         else
           *right = af->data[1][i];
@@ -589,7 +590,7 @@ static void get_sample_data (Priv *p, long sample_no, float *left, float *right)
           for (l = p->audio_track; l; l = l->next)
           {
             GeglAudioFragment *af = l->data;
-            if (sample_no > af->pos + af->samples)
+            if (sample_no > af->pos + af->xsample_count)
             {
               p->audio_track = g_list_remove (p->audio_track, af);
               g_object_unref (af);
@@ -626,15 +627,19 @@ process (GeglOperation       *operation,
        if (p->audio_stream && p->audio_stream->codec) // XXX: remove second clause
         {
           o->audio->sample_rate = p->audio_stream->codec->sample_rate;
-          o->audio->channels = 2;
-          o->audio->channel_layout = AV_CH_LAYOUT_STEREO;
-          o->audio->samples = samples_per_frame (o->frame,
+          o->audio->xchannels = 2;
+          o->audio->xchannel_layout = AV_CH_LAYOUT_STEREO;
+
+          /* XXX: should compare against max and fix if going over */
+          o->audio->xsample_count = samples_per_frame (o->frame,
                o->frame_rate, o->audio->sample_rate,
                &sample_start);
+
+
          decode_audio (operation, p->prevpts, p->prevpts + 5.0);
           {
             int i;
-            for (i = 0; i < o->audio->samples; i++)
+            for (i = 0; i < o->audio->xsample_count; i++)
             {
               get_sample_data (p, sample_start + i, &o->audio->data[0][i],
                                   &o->audio->data[1][i]);
diff --git a/operations/external/ff-save.c b/operations/external/ff-save.c
index f8db74f..c7c7b14 100644
--- a/operations/external/ff-save.c
+++ b/operations/external/ff-save.c
@@ -125,17 +125,17 @@ static void get_sample_data (Priv *p, long sample_no, float *left, float *right)
   for (; l; l = l->next)
   {
     GeglAudioFragment *af = l->data;
-    if (sample_no > af->pos + af->samples)
+    if (sample_no > af->pos + af->xsample_count)
     {
       to_remove ++;
     }
 
     if (af->pos <= sample_no &&
-        sample_no < af->pos + af->samples)
+        sample_no < af->pos + af->xsample_count)
       {
         int i = sample_no - af->pos;
         *left  = af->data[0][i];
-        if (af->channels == 1)
+        if (af->xchannels == 1)
           *right = af->data[0][i];
         else
           *right = af->data[1][i];
@@ -146,7 +146,7 @@ static void get_sample_data (Priv *p, long sample_no, float *left, float *right)
           for (l = p->audio_track; l; l = l->next)
           {
             GeglAudioFragment *af = l->data;
-            if (sample_no > af->pos + af->samples)
+            if (sample_no > af->pos + af->xsample_count)
             {
               p->audio_track = g_list_remove (p->audio_track, af);
               g_object_unref (af);
@@ -326,16 +326,14 @@ write_audio_frame (GeglProperties *o, AVFormatContext * oc, AVStream * st)
   /* first we add incoming frames audio samples */
   {
     int i;
-    GeglAudioFragment *af = gegl_audio_fragment_new ();
-    af->channels = 2; //o->audio->channels;
-    af->samples = o->audio->samples;
-    for (i = 0; i < af->samples; i++)
+    GeglAudioFragment *af = gegl_audio_fragment_new (o->audio->sample_rate, o->audio->xchannels, 
o->audio->xchannel_layout, o->audio->xsample_count);
+    for (i = 0; i < af->xsample_count; i++)
       {
         af->data[0][i] = o->audio->data[0][i];
         af->data[1][i] = o->audio->data[1][i];
       }
     af->pos = p->audio_pos;
-    p->audio_pos += af->samples;
+    p->audio_pos += af->xsample_count;
     p->audio_track = g_list_append (p->audio_track, af);
   }
 


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