[sound-juicer/wip/encoding-presets: 4/7] Add function to a get list of encoder presets



commit 69d78143ba6c4eb4a5a9fcdeb1379b5571fd455d
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Mon Feb 9 15:38:35 2015 +0000

    Add function to a get list of encoder presets
    
    This is based on a similar function from rhythmbox.

 libjuicer/rb-gst-media-types.c |   76 ++++++++++++++++++++++++++++++++++++++++
 libjuicer/rb-gst-media-types.h |    9 +++++
 2 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/libjuicer/rb-gst-media-types.c b/libjuicer/rb-gst-media-types.c
index 11fbc55..9c8ca89 100644
--- a/libjuicer/rb-gst-media-types.c
+++ b/libjuicer/rb-gst-media-types.c
@@ -295,6 +295,44 @@ rb_gst_get_audio_encoding_profile (GstEncodingProfile *profile)
        return NULL;
 }
 
+static GstElementFactory *
+get_audio_encoder_factory (GstEncodingProfile *profile)
+{
+       GstEncodingProfile *p = rb_gst_get_audio_encoding_profile (profile);
+       GstElementFactory *f;
+       GList *l;
+       GList *fl;
+
+       if (p == NULL)
+               return NULL;
+
+       l = gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_ENCODER, GST_RANK_MARGINAL);
+       fl = gst_element_factory_list_filter (l, gst_encoding_profile_get_format (p), GST_PAD_SRC, FALSE);
+
+       if (fl != NULL) {
+               f = gst_object_ref (fl->data);
+       } else {
+               g_warning ("no encoder factory for profile %s", gst_encoding_profile_get_name (profile));
+               f = NULL;
+       }
+       gst_plugin_feature_list_free (l);
+       gst_plugin_feature_list_free (fl);
+       return f;
+}
+
+GstElement *
+rb_gst_encoding_profile_get_encoder (GstEncodingProfile *profile)
+{
+       GstElementFactory *factory;
+
+       factory = get_audio_encoder_factory (profile);
+       if (factory == NULL) {
+               return NULL;
+       }
+
+       return gst_element_factory_create (factory, NULL);
+}
+
 void
 rb_gst_encoding_profile_set_preset (GstEncodingProfile *profile, const char *preset)
 {
@@ -321,6 +359,44 @@ rb_gst_encoding_profile_get_preset (GstEncodingProfile *profile)
        return (preset == NULL) ? "" : preset;
 }
 
+static void
+clear_preset_info (gpointer data)
+{
+       SjPresetInfo *info = data;
+
+       g_free (info->name);
+       g_free (info->description);
+}
+
+GArray *
+rb_gst_encoding_profile_get_presets (GstEncodingProfile *profile)
+{
+       GArray *array;
+       GstElement *encoder;
+
+       array = g_array_new (FALSE, FALSE, sizeof(SjPresetInfo));
+       g_array_set_clear_func (array, clear_preset_info);
+       encoder = rb_gst_encoding_profile_get_encoder (profile);
+       if (encoder != NULL && GST_IS_PRESET (encoder)) {
+               gchar **presets;
+               int i;
+
+               presets = gst_preset_get_preset_names (GST_PRESET (encoder));
+               for (i = 0; presets != NULL && presets[i] != NULL; i++) {
+                       SjPresetInfo info;
+
+                       info.description = NULL;
+                       info.name = g_strdup (presets[i]);
+                       gst_preset_get_meta (GST_PRESET (encoder), presets[i], "comment", &info.description);
+                       g_array_append_val (array, info);
+               }
+               g_strfreev (presets);
+       }
+       if (encoder != NULL)
+               g_object_unref (encoder);
+       return array;
+}
+
 gboolean
 rb_gst_check_missing_plugins (GstEncodingProfile *profile,
                              char ***details,
diff --git a/libjuicer/rb-gst-media-types.h b/libjuicer/rb-gst-media-types.h
index 65f97b4..25258d2 100644
--- a/libjuicer/rb-gst-media-types.h
+++ b/libjuicer/rb-gst-media-types.h
@@ -40,6 +40,11 @@ G_BEGIN_DECLS
 #define RB_GST_MEDIA_TYPE_FLAC                 "audio/x-flac"
 #define RB_GST_MEDIA_TYPE_AAC          "audio/x-aac"
 
+typedef struct {
+  gchar *name;
+  gchar *description;
+} SjPresetInfo;
+
 /* media type categories */
 typedef enum {
        MEDIA_TYPE_NONE = 0,
@@ -68,10 +73,14 @@ char *              rb_gst_encoding_profile_get_media_type (GstEncodingProfile *profile);
 
 GstEncodingProfile *rb_gst_get_audio_encoding_profile (GstEncodingProfile *profile);
 
+GArray *       rb_gst_encoding_profile_get_presets (GstEncodingProfile *profile);
+
 void           rb_gst_encoding_profile_set_preset (GstEncodingProfile *profile, const char *preset);
 
 const char *   rb_gst_encoding_profile_get_preset (GstEncodingProfile *profile);
 
+GstElement *   rb_gst_encoding_profile_get_encoder (GstEncodingProfile *profile);
+
 gboolean       rb_gst_media_type_is_lossless (const char *media_type);
 gboolean       rb_gst_check_missing_plugins (GstEncodingProfile *profile,
                                              char ***details,


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