[gegl/video-rejuvenation] GeglAudioFragment: add channel layout defines from ffmpeg



commit d539b53a256d817a9a5261f9a7b4a36802885e87
Author: Øyvind Kolås <pippin gimp org>
Date:   Fri Nov 20 23:55:54 2015 +0100

    GeglAudioFragment: add channel layout defines from ffmpeg

 gegl/property-types/gegl-audio-fragment.c |   43 ++++++++++++++++-
 gegl/property-types/gegl-audio-fragment.h |   74 ++++++++++++++++++++++++++---
 2 files changed, 108 insertions(+), 9 deletions(-)
---
diff --git a/gegl/property-types/gegl-audio-fragment.c b/gegl/property-types/gegl-audio-fragment.c
index 16cc47e..146f179 100644
--- a/gegl/property-types/gegl-audio-fragment.c
+++ b/gegl/property-types/gegl-audio-fragment.c
@@ -44,11 +44,46 @@ static void      get_property (GObject    *gobject,
 
 G_DEFINE_TYPE (GeglAudioFragment, gegl_audio_fragment, G_TYPE_OBJECT)
 
+
+static void deallocate_data (GeglAudioFragment *audio)
+{
+  int i;
+  for (i = 0; i < GEGL_MAX_AUDIO_CHANNELS; i++)
+  {
+    if (audio->data[i])
+    {
+      g_free (audio->data[i]);
+      audio->data[i] = NULL;
+    }
+  }
+}
+
+static void allocate_data (GeglAudioFragment *audio)
+{
+  int i;
+  deallocate_data (audio);
+  if (audio->xchannels * audio->max_samples == 0)
+    return;
+  for (i = 0; i < audio->xchannels; i++)
+  {
+    audio->data[i] = g_malloc (sizeof (float) * audio->max_samples);
+  }
+}
+
+
 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;
+  allocate_data (self);
+}
+
+static void
+gegl_audio_fragment_finalize (GObject *self)
+{
+  GeglAudioFragment *audio = (void*)self;
+  deallocate_data (audio);
 }
 
 static void
@@ -58,6 +93,7 @@ gegl_audio_fragment_class_init (GeglAudioFragmentClass *klass)
 
   gobject_class->set_property = set_property;
   gobject_class->get_property = get_property;
+  gobject_class->finalize = gegl_audio_fragment_finalize;
 
   g_object_class_install_property (gobject_class, PROP_STRING,
                                    g_param_spec_string ("string",
@@ -101,14 +137,15 @@ get_property (GObject    *gobject,
     }
 }
 
+
 GeglAudioFragment *
 gegl_audio_fragment_new (int sample_rate, int channels, int channel_layout, int max_samples)
 {
   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);
+  gegl_audio_fragment_set_max_samples (ret, max_samples);
+  gegl_audio_fragment_set_channels (ret, channels);
   return ret;
 }
 
@@ -117,6 +154,7 @@ gegl_audio_fragment_set_max_samples (GeglAudioFragment *audio,
                                      int                max_samples)
 {
   audio->max_samples = max_samples;
+  allocate_data (audio);
 }
 
 void
@@ -131,6 +169,7 @@ gegl_audio_fragment_set_channels (GeglAudioFragment *audio,
                                   int                channels)
 {
   audio->xchannels = channels;
+  allocate_data (audio);
 }
 
 void
diff --git a/gegl/property-types/gegl-audio-fragment.h b/gegl/property-types/gegl-audio-fragment.h
index 9ffc394..3d56c81 100644
--- a/gegl/property-types/gegl-audio-fragment.h
+++ b/gegl/property-types/gegl-audio-fragment.h
@@ -37,16 +37,76 @@ typedef struct _GeglAudioFragmentPrivate GeglAudioFragmentPrivate;
 #define GEGL_MAX_AUDIO_CHANNELS 6
 #define GEGL_MAX_AUDIO_SAMPLES  2400   // this limits us to 20fps and higher for regular sample rates
 
+
+/* the values for channel_layout are designed to match and be compatible with
+ * the ones in ffmpegs libavutil
+ */
+#define GEGL_CH_FRONT_LEFT             0x00000001
+#define GEGL_CH_FRONT_RIGHT            0x00000002
+#define GEGL_CH_FRONT_CENTER           0x00000004
+#define GEGL_CH_LOW_FREQUENCY          0x00000008
+#define GEGL_CH_BACK_LEFT              0x00000010
+#define GEGL_CH_BACK_RIGHT             0x00000020
+#define GEGL_CH_FRONT_LEFT_OF_CENTER   0x00000040
+#define GEGL_CH_FRONT_RIGHT_OF_CENTER  0x00000080
+#define GEGL_CH_BACK_CENTER            0x00000100
+#define GEGL_CH_SIDE_LEFT              0x00000200
+#define GEGL_CH_SIDE_RIGHT             0x00000400
+#define GEGL_CH_TOP_CENTER             0x00000800
+#define GEGL_CH_TOP_FRONT_LEFT         0x00001000
+#define GEGL_CH_TOP_FRONT_CENTER       0x00002000
+#define GEGL_CH_TOP_FRONT_RIGHT        0x00004000
+#define GEGL_CH_TOP_BACK_LEFT          0x00008000
+#define GEGL_CH_TOP_BACK_CENTER        0x00010000
+#define GEGL_CH_TOP_BACK_RIGHT         0x00020000
+#define GEGL_CH_STEREO_LEFT            0x20000000  ///< Stereo downmix.
+#define GEGL_CH_STEREO_RIGHT           0x40000000  ///< See GEGL_CH_STEREO_LEFT.
+#define GEGL_CH_WIDE_LEFT              0x0000000080000000ULL
+#define GEGL_CH_WIDE_RIGHT             0x0000000100000000ULL
+#define GEGL_CH_SURROUND_DIRECT_LEFT   0x0000000200000000ULL
+#define GEGL_CH_SURROUND_DIRECT_RIGHT  0x0000000400000000ULL
+#define GEGL_CH_LOW_FREQUENCY_2        0x0000000800000000ULL
+
+#define GEGL_CH_LAYOUT_NATIVE          0x8000000000000000ULL
+#define GEGL_CH_LAYOUT_MONO              (GEGL_CH_FRONT_CENTER)
+#define GEGL_CH_LAYOUT_STEREO            (GEGL_CH_FRONT_LEFT|GEGL_CH_FRONT_RIGHT)
+#define GEGL_CH_LAYOUT_2POINT1           (GEGL_CH_LAYOUT_STEREO|GEGL_CH_LOW_FREQUENCY)
+#define GEGL_CH_LAYOUT_2_1               (GEGL_CH_LAYOUT_STEREO|GEGL_CH_BACK_CENTER)
+#define GEGL_CH_LAYOUT_SURROUND          (GEGL_CH_LAYOUT_STEREO|GEGL_CH_FRONT_CENTER)
+#define GEGL_CH_LAYOUT_3POINT1           (GEGL_CH_LAYOUT_SURROUND|GEGL_CH_LOW_FREQUENCY)
+#define GEGL_CH_LAYOUT_4POINT0           (GEGL_CH_LAYOUT_SURROUND|GEGL_CH_BACK_CENTER)
+#define GEGL_CH_LAYOUT_4POINT1           (GEGL_CH_LAYOUT_4POINT0|GEGL_CH_LOW_FREQUENCY)
+#define GEGL_CH_LAYOUT_2_2               (GEGL_CH_LAYOUT_STEREO|GEGL_CH_SIDE_LEFT|GEGL_CH_SIDE_RIGHT)
+#define GEGL_CH_LAYOUT_QUAD              (GEGL_CH_LAYOUT_STEREO|GEGL_CH_BACK_LEFT|GEGL_CH_BACK_RIGHT)
+#define GEGL_CH_LAYOUT_5POINT0           (GEGL_CH_LAYOUT_SURROUND|GEGL_CH_SIDE_LEFT|GEGL_CH_SIDE_RIGHT)
+#define GEGL_CH_LAYOUT_5POINT1           (GEGL_CH_LAYOUT_5POINT0|GEGL_CH_LOW_FREQUENCY)
+#define GEGL_CH_LAYOUT_5POINT0_BACK      (GEGL_CH_LAYOUT_SURROUND|GEGL_CH_BACK_LEFT|GEGL_CH_BACK_RIGHT)
+#define GEGL_CH_LAYOUT_5POINT1_BACK      (GEGL_CH_LAYOUT_5POINT0_BACK|GEGL_CH_LOW_FREQUENCY)
+#define GEGL_CH_LAYOUT_6POINT0           (GEGL_CH_LAYOUT_5POINT0|GEGL_CH_BACK_CENTER)
+#define GEGL_CH_LAYOUT_6POINT0_FRONT     
(GEGL_CH_LAYOUT_2_2|GEGL_CH_FRONT_LEFT_OF_CENTER|GEGL_CH_FRONT_RIGHT_OF_CENTER)
+#define GEGL_CH_LAYOUT_HEXAGONAL         (GEGL_CH_LAYOUT_5POINT0_BACK|GEGL_CH_BACK_CENTER)
+#define GEGL_CH_LAYOUT_6POINT1           (GEGL_CH_LAYOUT_5POINT1|GEGL_CH_BACK_CENTER)
+#define GEGL_CH_LAYOUT_6POINT1_BACK      (GEGL_CH_LAYOUT_5POINT1_BACK|GEGL_CH_BACK_CENTER)
+#define GEGL_CH_LAYOUT_6POINT1_FRONT     (GEGL_CH_LAYOUT_6POINT0_FRONT|GEGL_CH_LOW_FREQUENCY)
+#define GEGL_CH_LAYOUT_7POINT0           (GEGL_CH_LAYOUT_5POINT0|GEGL_CH_BACK_LEFT|GEGL_CH_BACK_RIGHT)
+#define GEGL_CH_LAYOUT_7POINT0_FRONT     
(GEGL_CH_LAYOUT_5POINT0|GEGL_CH_FRONT_LEFT_OF_CENTER|GEGL_CH_FRONT_RIGHT_OF_CENTER)
+#define GEGL_CH_LAYOUT_7POINT1           (GEGL_CH_LAYOUT_5POINT1|GEGL_CH_BACK_LEFT|GEGL_CH_BACK_RIGHT)
+#define GEGL_CH_LAYOUT_7POINT1_WIDE      
(GEGL_CH_LAYOUT_5POINT1|GEGL_CH_FRONT_LEFT_OF_CENTER|GEGL_CH_FRONT_RIGHT_OF_CENTER)
+#define GEGL_CH_LAYOUT_7POINT1_WIDE_BACK 
(GEGL_CH_LAYOUT_5POINT1_BACK|GEGL_CH_FRONT_LEFT_OF_CENTER|GEGL_CH_FRONT_RIGHT_OF_CENTER)
+#define GEGL_CH_LAYOUT_OCTAGONAL         
(GEGL_CH_LAYOUT_5POINT0|GEGL_CH_BACK_LEFT|GEGL_CH_BACK_CENTER|GEGL_CH_BACK_RIGHT)
+#define GEGL_CH_LAYOUT_HEXADECAGONAL     
(GEGL_CH_LAYOUT_OCTAGONAL|GEGL_CH_WIDE_LEFT|GEGL_CH_WIDE_RIGHT|GEGL_CH_TOP_BACK_LEFT|GEGL_CH_TOP_BACK_RIGHT|GEGL_CH_TOP_BACK_CENTER|GEGL_CH_TOP_FRONT_CENTER|GEGL_CH_TOP_FRONT_LEFT|GEGL_CH_TOP_FRONT_RIGHT)
+#define GEGL_CH_LAYOUT_STEREO_DOWNMIX    (GEGL_CH_STEREO_LEFT|GEGL_CH_STEREO_RIGHT)
+
 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   pos;
-  float data[GEGL_MAX_AUDIO_CHANNELS][GEGL_MAX_AUDIO_SAMPLES]; 
+  int     max_samples;
+  int     xsample_count;
+  int     xchannels;
+  int     xchannel_layout;
+  int     sample_rate;
+  int     pos;
+  float  *data[GEGL_MAX_AUDIO_CHANNELS];
   GeglAudioFragmentPrivate *priv;
 };
 


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