Advertisement
Forage

Untitled

Aug 20th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.81 KB | None | 0 0
  1. typedef enum _ItdbVideoFormat ItdbVideoFormat;
  2. enum _ItdbVideoFormat {
  3.     VIDEO_FORMAT_MPEG4,
  4.     VIDEO_FORMAT_H263,
  5.     VIDEO_FORMAT_H264
  6. };
  7.  
  8. typedef struct _Itdb_VideoFormat Itdb_VideoFormat;
  9. struct _Itdb_VideoFormat {
  10.         ItdbVideoFormat format;
  11.        
  12.         gchar *profile;
  13.         gint level;        
  14.         gboolean supports_b_frames;
  15. };
  16.  
  17. static Itdb_VideoFormat *g_value_to_video_format (GHashTable *dict)
  18. {
  19.     Itdb_VideoFormat *video_spec;
  20.  
  21.     g_return_val_if_fail (dict != NULL, NULL);
  22.  
  23.     video_spec = g_new0 (Itdb_VideoFormat, 1);
  24.  
  25.     if (video_spec == NULL) {
  26.         return NULL;
  27.     }
  28.    
  29.     dict_to_struct (dict, sysinfo_video_format_fields_mapping, video_spec);
  30.  
  31.     return video_spec;
  32. }
  33.  
  34. static GList *parse_video_format_list (GHashTable *sysinfo_dict,
  35.                                       const char *key)
  36. {
  37.     GValue *to_parse;
  38.     GList *formats = NULL;
  39.    
  40.     GHashTableIter codec_iter;
  41.     gpointer codec_key, codec_value;
  42.  
  43.     to_parse = g_hash_table_lookup (sysinfo_dict, key);
  44.     if (to_parse == NULL) {
  45.         return NULL;
  46.     }
  47.     if (!G_VALUE_HOLDS (to_parse, G_TYPE_HASH_TABLE)) {
  48.         return NULL;
  49.     }
  50.  
  51.     g_hash_table_iter_init (&codec_iter, g_value_get_boxed (to_parse));
  52.     while (g_hash_table_iter_next (&codec_iter, &codec_key, &codec_value)) {
  53.         GHashTable *codec_dict;
  54.         GValue *mul_profiles;
  55.         Itdb_VideoFormat *format;
  56.        
  57.         g_return_val_if_fail (G_VALUE_HOLDS (codec_value, G_TYPE_HASH_TABLE), NULL);
  58.         codec_dict = g_value_get_boxed (codec_value);
  59.         g_return_val_if_fail (codec_dict != NULL, NULL);
  60.  
  61.         format = g_value_to_video_format (codec_dict);
  62.     if (format != NULL) {
  63.             mul_profiles = g_hash_table_lookup (codec_dict, "Profiles");
  64.            
  65.             if (mul_profiles != NULL
  66.                     && G_VALUE_HOLDS (mul_profiles, G_TYPE_HASH_TABLE)) {
  67.  
  68.                     GHashTable *profile_dict;
  69.                     Itdb_VideoFormat *new_format;
  70.                     GHashTableIter profile_iter;
  71.                     gpointer profile_key, profile_value;
  72.                    
  73.                     g_hash_table_iter_init (&profile_iter, g_value_get_boxed (mul_profiles));
  74.                     while (g_hash_table_iter_next (&profile_iter, &profile_key, &profile_value)) {
  75.                         new_format = format;
  76.                         new_format->profile = malloc(sizeof(format->profile));
  77.                         new_format->profile = g_strdup (format->profile);
  78.                        
  79.                         formats = g_list_prepend (formats, new_format);
  80.                     }
  81.             } else {
  82.                 formats = g_list_prepend (formats, format);
  83.             }
  84.     }
  85.     }
  86.  
  87.     g_hash_table_remove (sysinfo_dict, key);
  88.     return formats;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement