1 /*
2 * Copyright (C) 2010 Ole André Vadla Ravnås <oleavr@soundrop.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "vtutil.h"
21
22 gchar *
gst_vtutil_object_to_string(CFTypeRef obj)23 gst_vtutil_object_to_string (CFTypeRef obj)
24 {
25 gchar *result;
26 CFStringRef s;
27
28 if (obj == NULL)
29 return g_strdup ("(null)");
30
31 s = CFCopyDescription (obj);
32 result = gst_vtutil_string_to_utf8 (s);
33 CFRelease (s);
34
35 return result;
36 }
37
38 gchar *
gst_vtutil_string_to_utf8(CFStringRef s)39 gst_vtutil_string_to_utf8 (CFStringRef s)
40 {
41 gchar *result;
42 CFIndex size;
43
44 size = CFStringGetMaximumSizeForEncoding (CFStringGetLength (s),
45 kCFStringEncodingUTF8);
46 result = g_malloc (size + 1);
47 CFStringGetCString (s, result, size + 1, kCFStringEncodingUTF8);
48
49 return result;
50 }
51
52 void
gst_vtutil_dict_set_i32(CFMutableDictionaryRef dict,CFStringRef key,gint32 value)53 gst_vtutil_dict_set_i32 (CFMutableDictionaryRef dict, CFStringRef key,
54 gint32 value)
55 {
56 CFNumberRef number;
57
58 number = CFNumberCreate (NULL, kCFNumberSInt32Type, &value);
59 CFDictionarySetValue (dict, key, number);
60 CFRelease (number);
61 }
62
63 void
gst_vtutil_dict_set_string(CFMutableDictionaryRef dict,CFStringRef key,const gchar * value)64 gst_vtutil_dict_set_string (CFMutableDictionaryRef dict, CFStringRef key,
65 const gchar * value)
66 {
67 CFStringRef string;
68
69 string = CFStringCreateWithCString (NULL, value, kCFStringEncodingASCII);
70 CFDictionarySetValue (dict, key, string);
71 CFRelease (string);
72 }
73
74 void
gst_vtutil_dict_set_boolean(CFMutableDictionaryRef dict,CFStringRef key,gboolean value)75 gst_vtutil_dict_set_boolean (CFMutableDictionaryRef dict, CFStringRef key,
76 gboolean value)
77 {
78 CFDictionarySetValue (dict, key, value ? kCFBooleanTrue : kCFBooleanFalse);
79 }
80
81 void
gst_vtutil_dict_set_data(CFMutableDictionaryRef dict,CFStringRef key,guint8 * value,guint64 length)82 gst_vtutil_dict_set_data (CFMutableDictionaryRef dict, CFStringRef key,
83 guint8 * value, guint64 length)
84 {
85 CFDataRef data;
86
87 data = CFDataCreate (NULL, value, length);
88 CFDictionarySetValue (dict, key, data);
89 CFRelease (data);
90 }
91
92 void
gst_vtutil_dict_set_object(CFMutableDictionaryRef dict,CFStringRef key,CFTypeRef * value)93 gst_vtutil_dict_set_object (CFMutableDictionaryRef dict, CFStringRef key,
94 CFTypeRef * value)
95 {
96 CFDictionarySetValue (dict, key, value);
97 CFRelease (value);
98 }
99
100 CMVideoCodecType
gst_vtutil_codec_type_from_prores_variant(const char * variant)101 gst_vtutil_codec_type_from_prores_variant (const char *variant)
102 {
103 if (g_strcmp0 (variant, "standard") == 0)
104 return kCMVideoCodecType_AppleProRes422;
105 else if (g_strcmp0 (variant, "4444xq") == 0)
106 return kCMVideoCodecType_AppleProRes4444XQ;
107 else if (g_strcmp0 (variant, "4444") == 0)
108 return kCMVideoCodecType_AppleProRes4444;
109 else if (g_strcmp0 (variant, "hq") == 0)
110 return kCMVideoCodecType_AppleProRes422HQ;
111 else if (g_strcmp0 (variant, "lt") == 0)
112 return kCMVideoCodecType_AppleProRes422LT;
113 else if (g_strcmp0 (variant, "proxy") == 0)
114 return kCMVideoCodecType_AppleProRes422Proxy;
115 return GST_kCMVideoCodecType_Some_AppleProRes;
116 }
117
118 const char *
gst_vtutil_codec_type_to_prores_variant(CMVideoCodecType codec_type)119 gst_vtutil_codec_type_to_prores_variant (CMVideoCodecType codec_type)
120 {
121 switch (codec_type) {
122 case kCMVideoCodecType_AppleProRes422:
123 return "standard";
124 case kCMVideoCodecType_AppleProRes4444XQ:
125 return "4444xq";
126 case kCMVideoCodecType_AppleProRes4444:
127 return "4444";
128 case kCMVideoCodecType_AppleProRes422HQ:
129 return "hq";
130 case kCMVideoCodecType_AppleProRes422LT:
131 return "lt";
132 case kCMVideoCodecType_AppleProRes422Proxy:
133 return "proxy";
134 default:
135 g_assert_not_reached ();
136 }
137 }
138
139 GstCaps *
gst_vtutil_caps_append_video_format(GstCaps * caps,const char * vfmt)140 gst_vtutil_caps_append_video_format (GstCaps * caps, const char *vfmt)
141 {
142 GstStructure *s;
143 GValueArray *arr;
144 GValue val = G_VALUE_INIT;
145
146 caps = gst_caps_make_writable (caps);
147 s = gst_caps_get_structure (caps, 0);
148 gst_structure_get_list (s, "format", &arr);
149
150 g_value_init (&val, G_TYPE_STRING);
151
152 g_value_set_string (&val, vfmt);
153 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
154 arr = g_value_array_append (arr, &val);
155 G_GNUC_END_IGNORE_DEPRECATIONS;
156
157 g_value_unset (&val);
158
159 gst_structure_set_list (s, "format", arr);
160 return caps;
161 }
162