Branch data Line data Source code
1 : : /* Quicktime muxer plugin for GStreamer
2 : : * Copyright (C) 2008 Thiago Sousa Santos <thiagoss@embedded.ufcg.edu.br>
3 : : * Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.net>
4 : : *
5 : : * This library is free software; you can redistribute it and/or
6 : : * modify it under the terms of the GNU Library General Public
7 : : * License as published by the Free Software Foundation; either
8 : : * version 2 of the License, or (at your option) any later version.
9 : : *
10 : : * This library is distributed in the hope that it will be useful,
11 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : : * Library General Public License for more details.
14 : : *
15 : : * You should have received a copy of the GNU Library General Public
16 : : * License along with this library; if not, write to the
17 : : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 : : * Boston, MA 02111-1307, USA.
19 : : */
20 : : /*
21 : : * Unless otherwise indicated, Source Code is licensed under MIT license.
22 : : * See further explanation attached in License Statement (distributed in the file
23 : : * LICENSE).
24 : : *
25 : : * Permission is hereby granted, free of charge, to any person obtaining a copy of
26 : : * this software and associated documentation files (the "Software"), to deal in
27 : : * the Software without restriction, including without limitation the rights to
28 : : * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
29 : : * of the Software, and to permit persons to whom the Software is furnished to do
30 : : * so, subject to the following conditions:
31 : : *
32 : : * The above copyright notice and this permission notice shall be included in all
33 : : * copies or substantial portions of the Software.
34 : : *
35 : : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 : : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 : : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 : : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 : : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 : : * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41 : : * SOFTWARE.
42 : : */
43 : :
44 : : #include "gstqtmuxmap.h"
45 : : #include "fourcc.h"
46 : : #include "ftypcc.h"
47 : :
48 : : /* static info related to various format */
49 : :
50 : : #define COMMON_VIDEO_CAPS \
51 : : "width = (int) [ 16, 4096 ], " \
52 : : "height = (int) [ 16, 4096 ], " \
53 : : "framerate = (fraction) [ 0, MAX ]"
54 : :
55 : : #define COMMON_VIDEO_CAPS_NO_FRAMERATE \
56 : : "width = (int) [ 16, 4096 ], " \
57 : : "height = (int) [ 16, 4096 ] "
58 : :
59 : : #define H263_CAPS \
60 : : "video/x-h263, " \
61 : : COMMON_VIDEO_CAPS
62 : :
63 : : #define H264_CAPS \
64 : : "video/x-h264, " \
65 : : "stream-format = (string) avc, " \
66 : : COMMON_VIDEO_CAPS
67 : :
68 : : #define MPEG4V_CAPS \
69 : : "video/mpeg, " \
70 : : "mpegversion = (int) 4, "\
71 : : "systemstream = (boolean) false, " \
72 : : COMMON_VIDEO_CAPS "; " \
73 : : "video/x-divx, " \
74 : : "divxversion = (int) 5, "\
75 : : COMMON_VIDEO_CAPS
76 : :
77 : : #define SVQ_CAPS \
78 : : "video/x-svq, " \
79 : : "svqversion = (int) 3, " \
80 : : COMMON_VIDEO_CAPS
81 : :
82 : : #define COMMON_AUDIO_CAPS(c, r) \
83 : : "channels = (int) [ 1, " G_STRINGIFY (c) " ], " \
84 : : "rate = (int) [ 1, " G_STRINGIFY (r) " ]"
85 : :
86 : : #define PCM_CAPS \
87 : : "audio/x-raw-int, " \
88 : : "width = (int) 8, " \
89 : : "depth = (int) 8, " \
90 : : COMMON_AUDIO_CAPS (2, MAX) ", " \
91 : : "signed = (boolean) { true, false }; " \
92 : : "audio/x-raw-int, " \
93 : : "width = (int) 16, " \
94 : : "depth = (int) 16, " \
95 : : "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }, " \
96 : : COMMON_AUDIO_CAPS (2, MAX) ", " \
97 : : "signed = (boolean) true " \
98 : :
99 : : #define PCM_CAPS_FULL \
100 : : PCM_CAPS "; " \
101 : : "audio/x-raw-int, " \
102 : : "width = (int) 24, " \
103 : : "depth = (int) 24, " \
104 : : "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }, " \
105 : : COMMON_AUDIO_CAPS (2, MAX) ", " \
106 : : "signed = (boolean) true; " \
107 : : "audio/x-raw-int, " \
108 : : "width = (int) 32, " \
109 : : "depth = (int) 32, " \
110 : : "endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN }, " \
111 : : COMMON_AUDIO_CAPS (2, MAX) ", " \
112 : : "signed = (boolean) true "
113 : :
114 : : #define MP3_CAPS \
115 : : "audio/mpeg, " \
116 : : "mpegversion = (int) 1, " \
117 : : "layer = (int) 3, " \
118 : : COMMON_AUDIO_CAPS (2, MAX)
119 : :
120 : : #define AAC_CAPS \
121 : : "audio/mpeg, " \
122 : : "mpegversion = (int) 4, " \
123 : : "stream-format = (string) raw, " \
124 : : COMMON_AUDIO_CAPS (8, MAX)
125 : :
126 : : #define AMR_CAPS \
127 : : "audio/AMR, " \
128 : : "rate = (int) 8000, " \
129 : : "channels = [ 1, 2 ]; " \
130 : : "audio/AMR-WB, " \
131 : : "rate = (int) 16000, " \
132 : : "channels = [ 1, 2 ] "
133 : :
134 : : #define ADPCM_CAPS \
135 : : "audio/x-adpcm, " \
136 : : "layout = (string)dvi, " \
137 : : "block_align = (int)[64, 8096], " \
138 : : COMMON_AUDIO_CAPS(2, MAX)
139 : :
140 : : #define ALAC_CAPS \
141 : : "audio/x-alac, " \
142 : : COMMON_AUDIO_CAPS(2, MAX)
143 : :
144 : : /* FIXME 0.11 - take a look at bugs #580005 and #340375 */
145 : : GstQTMuxFormatProp gst_qt_mux_format_list[] = {
146 : : /* original QuickTime format; see Apple site (e.g. qtff.pdf) */
147 : : {
148 : : GST_QT_MUX_FORMAT_QT,
149 : : "qtmux",
150 : : "QuickTime",
151 : : "GstQTMux",
152 : : GST_STATIC_CAPS ("video/quicktime, variant = (string) apple"),
153 : : GST_STATIC_CAPS ("video/x-raw-rgb, "
154 : : COMMON_VIDEO_CAPS "; "
155 : : "video/x-raw-yuv, "
156 : : "format = (fourcc) UYVY, "
157 : : COMMON_VIDEO_CAPS "; "
158 : : MPEG4V_CAPS "; "
159 : : H263_CAPS "; "
160 : : H264_CAPS "; "
161 : : SVQ_CAPS "; "
162 : : "video/x-dv, "
163 : : "systemstream = (boolean) false, "
164 : : COMMON_VIDEO_CAPS "; "
165 : : "image/jpeg, "
166 : : COMMON_VIDEO_CAPS_NO_FRAMERATE "; "
167 : : "video/x-vp8, "
168 : : COMMON_VIDEO_CAPS "; " "video/x-qt-part, " COMMON_VIDEO_CAPS),
169 : : GST_STATIC_CAPS (PCM_CAPS_FULL "; "
170 : : MP3_CAPS " ; "
171 : : AAC_CAPS " ; "
172 : : ADPCM_CAPS " ; "
173 : : "audio/x-alaw, " COMMON_AUDIO_CAPS (2, MAX) "; "
174 : : AMR_CAPS " ; " ALAC_CAPS)
175 : : }
176 : : ,
177 : : /* ISO 14496-14: mp42 as ISO base media extension
178 : : * (supersedes original ISO 144996-1 mp41) */
179 : : {
180 : : GST_QT_MUX_FORMAT_MP4,
181 : : "mp4mux",
182 : : "MP4",
183 : : "GstMP4Mux",
184 : : GST_STATIC_CAPS ("video/quicktime, variant = (string) iso"),
185 : : GST_STATIC_CAPS (MPEG4V_CAPS "; " H264_CAPS ";"
186 : : "video/x-mp4-part," COMMON_VIDEO_CAPS),
187 : : GST_STATIC_CAPS (MP3_CAPS "; " AAC_CAPS " ; " ALAC_CAPS)
188 : : }
189 : : ,
190 : : /* Microsoft Smooth Streaming fmp4/isml */
191 : : /* TODO add WMV/WMA support */
192 : : {
193 : : GST_QT_MUX_FORMAT_ISML,
194 : : "ismlmux",
195 : : "ISML",
196 : : "GstISMLMux",
197 : : GST_STATIC_CAPS ("video/quicktime, variant = (string) iso"),
198 : : GST_STATIC_CAPS (MPEG4V_CAPS "; " H264_CAPS),
199 : : GST_STATIC_CAPS (MP3_CAPS "; " AAC_CAPS)
200 : : }
201 : : ,
202 : : /* 3GPP Technical Specification 26.244 V7.3.0
203 : : * (extended in 3GPP2 File Formats for Multimedia Services) */
204 : : {
205 : : GST_QT_MUX_FORMAT_3GP,
206 : : "gppmux",
207 : : "3GPP",
208 : : "GstGPPMux",
209 : : GST_STATIC_CAPS ("video/quicktime, variant = (string) 3gpp"),
210 : : GST_STATIC_CAPS (H263_CAPS "; " MPEG4V_CAPS "; " H264_CAPS),
211 : : GST_STATIC_CAPS (AMR_CAPS "; " MP3_CAPS "; " AAC_CAPS)
212 : : }
213 : : ,
214 : : /* ISO 15444-3: Motion-JPEG-2000 (also ISO base media extension) */
215 : : {
216 : : GST_QT_MUX_FORMAT_MJ2,
217 : : "mj2mux",
218 : : "MJ2",
219 : : "GstMJ2Mux",
220 : : GST_STATIC_CAPS ("video/mj2"),
221 : : GST_STATIC_CAPS ("image/x-j2c, " COMMON_VIDEO_CAPS "; "
222 : : "image/x-jpc, " COMMON_VIDEO_CAPS),
223 : : GST_STATIC_CAPS (PCM_CAPS)
224 : : }
225 : : ,
226 : : {
227 : : GST_QT_MUX_FORMAT_NONE,
228 : : }
229 : : ,
230 : : };
231 : :
232 : : /* pretty static, but may turn out needed a few times */
233 : : AtomsTreeFlavor
234 : 36 : gst_qt_mux_map_format_to_flavor (GstQTMuxFormat format)
235 : : {
236 [ + + ]: 36 : if (format == GST_QT_MUX_FORMAT_QT)
237 : 14 : return ATOMS_TREE_FLAVOR_MOV;
238 [ + + ]: 22 : else if (format == GST_QT_MUX_FORMAT_3GP)
239 : 7 : return ATOMS_TREE_FLAVOR_3GP;
240 [ + + ]: 15 : else if (format == GST_QT_MUX_FORMAT_ISML)
241 : 4 : return ATOMS_TREE_FLAVOR_ISML;
242 : : else
243 : 36 : return ATOMS_TREE_FLAVOR_ISOM;
244 : : }
245 : :
246 : : static void
247 : 3 : gst_qt_mux_map_check_tracks (AtomMOOV * moov, gint * _video, gint * _audio,
248 : : gboolean * _has_h264)
249 : : {
250 : : GList *it;
251 : 3 : gint video = 0, audio = 0;
252 : 3 : gboolean has_h264 = FALSE;
253 : :
254 [ + - ][ + + ]: 6 : for (it = moov->traks; it != NULL; it = g_list_next (it)) {
255 : 3 : AtomTRAK *track = it->data;
256 : :
257 [ + - ]: 3 : if (track->is_video) {
258 : 3 : video++;
259 [ + - ]: 3 : if (track->is_h264)
260 : 3 : has_h264 = TRUE;
261 : : } else
262 : 0 : audio++;
263 : : }
264 : :
265 [ + - ]: 3 : if (_video)
266 : 3 : *_video = video;
267 [ + - ]: 3 : if (_audio)
268 : 3 : *_audio = audio;
269 [ + - ]: 3 : if (_has_h264)
270 : 3 : *_has_h264 = has_h264;
271 : 3 : }
272 : :
273 : : /* pretty static, but possibly dynamic format info */
274 : :
275 : : /* notes:
276 : : * - avc1 brand is not used, since the specific extensions indicated by it
277 : : * are not used (e.g. sample groupings, etc)
278 : : * - TODO: maybe even more 3GPP brand fine-tuning ??
279 : : * (but that might need ftyp rewriting at the end) */
280 : : void
281 : 16 : gst_qt_mux_map_format_to_header (GstQTMuxFormat format, GstBuffer ** _prefix,
282 : : guint32 * _major, guint32 * _version, GList ** _compatible, AtomMOOV * moov,
283 : : GstClockTime longest_chunk, gboolean faststart)
284 : : {
285 : : static guint32 qt_brands[] = { 0 };
286 : : static guint32 mp4_brands[] = { FOURCC_mp41, FOURCC_isom, FOURCC_iso2, 0 };
287 : : static guint32 isml_brands[] = { FOURCC_iso2, 0 };
288 : : static guint32 gpp_brands[] = { FOURCC_isom, FOURCC_iso2, 0 };
289 : : static guint32 mjp2_brands[] = { FOURCC_isom, FOURCC_iso2, 0 };
290 : : static guint8 mjp2_prefix[] =
291 : : { 0, 0, 0, 12, 'j', 'P', ' ', ' ', 0x0D, 0x0A, 0x87, 0x0A };
292 : 16 : guint32 *comp = NULL;
293 : 16 : guint32 major = 0, version = 0;
294 : 16 : GstBuffer *prefix = NULL;
295 : 16 : GList *result = NULL;
296 : :
297 [ - + ]: 16 : g_return_if_fail (_prefix != NULL);
298 [ - + ]: 16 : g_return_if_fail (_major != NULL);
299 [ - + ]: 16 : g_return_if_fail (_version != NULL);
300 [ - + ]: 16 : g_return_if_fail (_compatible != NULL);
301 : :
302 [ + + - + : 16 : switch (format) {
- - ]
303 : : case GST_QT_MUX_FORMAT_QT:
304 : 10 : major = FOURCC_qt__;
305 : 10 : comp = qt_brands;
306 : 10 : version = 0x20050300;
307 : 10 : break;
308 : : case GST_QT_MUX_FORMAT_MP4:
309 : 3 : major = FOURCC_mp42;
310 : 3 : comp = mp4_brands;
311 : 3 : break;
312 : : case GST_QT_MUX_FORMAT_ISML:
313 : 0 : major = FOURCC_isml;
314 : 0 : comp = isml_brands;
315 : 0 : break;
316 : : case GST_QT_MUX_FORMAT_3GP:
317 : : {
318 : : gint video, audio;
319 : : gboolean has_h264;
320 : :
321 : 3 : gst_qt_mux_map_check_tracks (moov, &video, &audio, &has_h264);
322 : : /* only track restriction really matters for Basic Profile */
323 [ + - ][ + - ]: 3 : if (video <= 1 && audio <= 1) {
324 : : /* it seems only newer spec knows about H264 */
325 [ + - ]: 3 : major = has_h264 ? FOURCC_3gp6 : FOURCC_3gp4;
326 [ + - ]: 3 : version = has_h264 ? 0x100 : 0x200;
327 : : } else {
328 : 0 : major = FOURCC_3gg6;
329 : 0 : version = 0x100;
330 : : }
331 : 3 : comp = gpp_brands;
332 : :
333 : : /*
334 : : * We assume that we have chunks in dts order
335 : : */
336 [ - + ][ # # ]: 3 : if (faststart && longest_chunk <= GST_SECOND) {
337 : : /* add progressive download profile */
338 : 0 : result = g_list_append (result, GUINT_TO_POINTER (FOURCC_3gr6));
339 : : }
340 : 3 : break;
341 : : }
342 : : case GST_QT_MUX_FORMAT_MJ2:
343 : 0 : major = FOURCC_mjp2;
344 : 0 : comp = mjp2_brands;
345 : 0 : version = 0;
346 : 0 : prefix = gst_buffer_new_and_alloc (sizeof (mjp2_prefix));
347 : 0 : memcpy (GST_BUFFER_DATA (prefix), mjp2_prefix, GST_BUFFER_SIZE (prefix));
348 : 0 : break;
349 : : default:
350 : 0 : g_assert_not_reached ();
351 : : break;
352 : : }
353 : :
354 : : /* convert list to list, hm */
355 [ + - ][ + + ]: 31 : while (comp && *comp != 0) {
356 : : /* order matters over efficiency */
357 : 15 : result = g_list_append (result, GUINT_TO_POINTER (*comp));
358 : 15 : comp++;
359 : : }
360 : :
361 : 16 : *_major = major;
362 : 16 : *_version = version;
363 : 16 : *_prefix = prefix;
364 : 16 : *_compatible = result;
365 : :
366 : : /* TODO 3GPP may include mp42 as compatible if applicable */
367 : : /* TODO 3GPP major brand 3gp7 if at most 1 video and audio track */
368 : : }
|