Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst-libs / gst / pbutils / encoding-target.c
index 0a42ff3..bb8223d 100644 (file)
@@ -31,7 +31,7 @@
  *
  * GKeyFile style.
  *
- * [_gstencodingtarget_]
+ * [GStreamer Encoding Target]
  * name : <name>
  * category : <category>
  * description : <description> #translatable
  */
 
 
-#define GST_ENCODING_TARGET_HEADER "_gstencodingtarget_"
+#define GST_ENCODING_TARGET_HEADER "GStreamer Encoding Target"
 #define GST_ENCODING_TARGET_DIRECTORY "encoding-profiles"
 #define GST_ENCODING_TARGET_SUFFIX ".gep"
 
 struct _GstEncodingTarget
 {
-  GstMiniObject parent;
+  GObject parent;
 
   gchar *name;
   gchar *category;
@@ -85,7 +85,7 @@ struct _GstEncodingTarget
   gchar *keyfile;
 };
 
-G_DEFINE_TYPE (GstEncodingTarget, gst_encoding_target, GST_TYPE_MINI_OBJECT);
+G_DEFINE_TYPE (GstEncodingTarget, gst_encoding_target, G_TYPE_OBJECT);
 
 static void
 gst_encoding_target_init (GstEncodingTarget * target)
@@ -94,8 +94,10 @@ gst_encoding_target_init (GstEncodingTarget * target)
 }
 
 static void
-gst_encoding_target_finalize (GstEncodingTarget * target)
+gst_encoding_target_finalize (GObject * object)
 {
+  GstEncodingTarget *target = (GstEncodingTarget *) object;
+
   GST_DEBUG ("Finalizing");
 
   if (target->name)
@@ -105,15 +107,14 @@ gst_encoding_target_finalize (GstEncodingTarget * target)
   if (target->description)
     g_free (target->description);
 
-  g_list_foreach (target->profiles, (GFunc) gst_mini_object_unref, NULL);
+  g_list_foreach (target->profiles, (GFunc) g_object_unref, NULL);
   g_list_free (target->profiles);
 }
 
 static void
-gst_encoding_target_class_init (GstMiniObjectClass * klass)
+gst_encoding_target_class_init (GObjectClass * klass)
 {
-  klass->finalize =
-      (GstMiniObjectFinalizeFunction) gst_encoding_target_finalize;
+  klass->finalize = gst_encoding_target_finalize;
 }
 
 /**
@@ -281,7 +282,7 @@ gst_encoding_target_new (const gchar * name, const gchar * category,
   if (!validate_name (category))
     goto invalid_category;
 
-  res = (GstEncodingTarget *) gst_mini_object_new (GST_TYPE_ENCODING_TARGET);
+  res = (GstEncodingTarget *) g_object_new (GST_TYPE_ENCODING_TARGET, NULL);
   res->name = g_strdup (name);
   res->category = g_strdup (category);
   res->description = g_strdup (description);
@@ -409,6 +410,36 @@ serialize_stream_profiles (GKeyFile * out, GstEncodingProfile * sprof,
   return TRUE;
 }
 
+static gchar *
+get_locale (void)
+{
+  const char *loc = NULL;
+  gchar *ret;
+
+#ifdef ENABLE_NLS
+#if defined(LC_MESSAGES)
+  loc = setlocale (LC_MESSAGES, NULL);
+  GST_LOG ("LC_MESSAGES: %s", GST_STR_NULL (loc));
+#elif defined(LC_ALL)
+  loc = setlocale (LC_ALL, NULL);
+  GST_LOG ("LC_ALL: %s", GST_STR_NULL (loc));
+#else
+  GST_LOG ("Neither LC_ALL nor LC_MESSAGES defined");
+#endif
+#else /* !ENABLE_NLS */
+  GST_LOG ("i18n disabled");
+#endif
+
+  if (loc == NULL || g_ascii_strncasecmp (loc, "en", 2) == 0)
+    return NULL;
+
+  /* en_GB.UTF-8 => en */
+  ret = g_ascii_strdown (loc, -1);
+  ret = g_strcanon (ret, "abcdefghijklmnopqrstuvwxyz", '\0');
+  GST_LOG ("using locale: %s", ret);
+  return ret;
+}
+
 /* Serialize the top-level profiles
  * Note: They don't have to be containerprofiles */
 static gboolean
@@ -418,25 +449,32 @@ serialize_encoding_profile (GKeyFile * out, GstEncodingProfile * prof)
   const GList *tmp;
   guint i;
   const gchar *profname, *profdesc, *profpreset, *proftype;
-  const GstCaps *profformat, *profrestriction;
+  const GstCaps *profformat;
 
   profname = gst_encoding_profile_get_name (prof);
   profdesc = gst_encoding_profile_get_description (prof);
   profformat = gst_encoding_profile_get_format (prof);
   profpreset = gst_encoding_profile_get_preset (prof);
   proftype = gst_encoding_profile_get_type_nick (prof);
-  profrestriction = gst_encoding_profile_get_restriction (prof);
 
   profgroupname = g_strdup_printf ("profile-%s", profname);
 
   g_key_file_set_string (out, profgroupname, "name", profname);
 
-  g_key_file_set_value (out, profgroupname, "type",
-      gst_encoding_profile_get_type_nick (prof));
+  g_key_file_set_value (out, profgroupname, "type", proftype);
 
-  if (profdesc)
-    g_key_file_set_locale_string (out, profgroupname, "description",
-        setlocale (LC_ALL, NULL), profdesc);
+  if (profdesc) {
+    gchar *locale;
+
+    locale = get_locale ();
+    if (locale != NULL) {
+      g_key_file_set_locale_string (out, profgroupname, "description",
+          locale, profdesc);
+      g_free (locale);
+    } else {
+      g_key_file_set_string (out, profgroupname, "description", profdesc);
+    }
+  }
   if (profformat) {
     gchar *tmpc = gst_caps_to_string (profformat);
     g_key_file_set_string (out, profgroupname, "format", tmpc);
@@ -534,11 +572,25 @@ parse_encoding_profile (GKeyFile * in, gchar * parentprofilename,
   pname = g_key_file_get_value (in, profilename, "name", NULL);
 
   /* First try to get localized description */
-  description =
-      g_key_file_get_locale_string (in, profilename, "description",
-      setlocale (LC_ALL, NULL), NULL);
-  if (description == NULL)
-    description = g_key_file_get_value (in, profilename, "description", NULL);
+  {
+    gchar *locale;
+
+    locale = get_locale ();
+    if (locale != NULL) {
+      /* will try to fall back to untranslated string if no translation found */
+      description = g_key_file_get_locale_string (in, profilename,
+          "description", locale, NULL);
+      g_free (locale);
+    } else {
+      description =
+          g_key_file_get_string (in, profilename, "description", NULL);
+    }
+  }
+
+  /* Note: a missing description is normal for non-container profiles */
+  if (description == NULL) {
+    GST_LOG ("Missing 'description' field for streamprofile %s", profilename);
+  }
 
   /* Parse the remaining fields */
   proftype = g_key_file_get_value (in, profilename, "type", NULL);
@@ -654,6 +706,9 @@ load_file_and_read_header (const gchar * path, gchar ** targetname,
 {
   GKeyFile *in;
   gboolean res;
+  GError *key_error = NULL;
+
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   in = g_key_file_new ();
 
@@ -661,12 +716,13 @@ load_file_and_read_header (const gchar * path, gchar ** targetname,
 
   res =
       g_key_file_load_from_file (in, path,
-      G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, error);
-  if (!res || error != NULL)
+      G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &key_error);
+  if (!res || key_error != NULL)
     goto load_error;
 
+  key_error = NULL;
   *targetname =
-      g_key_file_get_value (in, GST_ENCODING_TARGET_HEADER, "name", error);
+      g_key_file_get_value (in, GST_ENCODING_TARGET_HEADER, "name", &key_error);
   if (!*targetname)
     goto empty_name;
 
@@ -681,14 +737,16 @@ load_file_and_read_header (const gchar * path, gchar ** targetname,
 load_error:
   {
     GST_WARNING ("Unable to read GstEncodingTarget file %s: %s",
-        path, (*error)->message);
+        path, key_error->message);
+    g_propagate_error (error, key_error);
     g_key_file_free (in);
     return NULL;
   }
 
 empty_name:
   {
-    GST_WARNING ("Wrong header in file %s: %s", path, (*error)->message);
+    GST_WARNING ("Wrong header in file %s: %s", path, key_error->message);
+    g_propagate_error (error, key_error);
     g_key_file_free (in);
     return NULL;
   }
@@ -942,7 +1000,6 @@ gst_encoding_target_save (GstEncodingTarget * target, GError ** error)
 {
   gchar *filename;
   gchar *lfilename;
-  gboolean res;
 
   g_return_val_if_fail (GST_IS_ENCODING_TARGET (target), FALSE);
   g_return_val_if_fail (target->category != NULL, FALSE);
@@ -953,7 +1010,7 @@ gst_encoding_target_save (GstEncodingTarget * target, GError ** error)
       GST_ENCODING_TARGET_DIRECTORY, target->category, lfilename, NULL);
   g_free (lfilename);
 
-  res = gst_encoding_target_save_to_file (target, filename, error);
+  gst_encoding_target_save_to_file (target, filename, error);
   g_free (filename);
 
   return TRUE;
@@ -991,7 +1048,9 @@ get_categories (gchar * path)
  *
  * Returns: (transfer full) (element-type gchar*): A list
  * of #GstEncodingTarget categories.
-*/
+ *
+ * Since: 0.10.32
+ */
 GList *
 gst_encoding_list_available_categories (void)
 {
@@ -1105,6 +1164,8 @@ compare_targets (const GstEncodingTarget * ta, const GstEncodingTarget * tb)
  * if @categoryname is %NULL.
  *
  * Returns: (transfer full) (element-type GstEncodingTarget): The list of #GstEncodingTarget
+ *
+ * Since: 0.10.32
  */
 GList *
 gst_encoding_list_all_targets (const gchar * categoryname)