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>
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.
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.
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 * Unless otherwise indicated, Source Code is licensed under MIT license.
22 * See further explanation attached in License Statement (distributed in the file
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:
32 * The above copyright notice and this permission notice shall be included in all
33 * copies or substantial portions of the Software.
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
44 #include "gstqtmuxmap.h"
47 /* static info related to various format */
49 #define COMMON_VIDEO_CAPS \
50 "width = (int) [ 16, MAX ], " \
51 "height = (int) [ 16, MAX ]"
53 #define COMMON_VIDEO_CAPS_NO_FRAMERATE \
54 "width = (int) [ 16, MAX ], " \
55 "height = (int) [ 16, MAX ] "
63 "stream-format = (string) avc, " \
64 "alignment = (string) au, " \
69 "mpegversion = (int) 4, "\
70 "systemstream = (boolean) false, " \
71 COMMON_VIDEO_CAPS "; " \
73 "divxversion = (int) 5, "\
77 "video/x-prores, variant = (string) {standard, lt, hq, proxy}, " \
82 "svqversion = (int) 3, " \
85 #define COMMON_AUDIO_CAPS(c, r) \
86 "channels = (int) [ 1, " G_STRINGIFY (c) " ], " \
87 "rate = (int) [ 1, " G_STRINGIFY (r) " ]"
91 "format = (string) { S16LE, S16BE, S8, U8 }, " \
92 "layout = (string) interleaved, " \
93 COMMON_AUDIO_CAPS (2, MAX)
95 #define PCM_CAPS_FULL \
97 "format = (string) { S32LE, S32BE, S24LE, S24BE, S16LE, S16BE, S8, U8 }, " \
98 "layout = (string) interleaved, " \
99 COMMON_AUDIO_CAPS (2, MAX)
103 "mpegversion = (int) 1, " \
104 "layer = (int) 3, " \
105 COMMON_AUDIO_CAPS (2, MAX)
109 "mpegversion = (int) 4, " \
110 "stream-format = (string) raw, " \
111 COMMON_AUDIO_CAPS (8, MAX)
115 COMMON_AUDIO_CAPS (6, MAX)
119 "rate = (int) 8000, " \
120 "channels = [ 1, 2 ]; " \
122 "rate = (int) 16000, " \
123 "channels = [ 1, 2 ] "
127 "layout = (string)dvi, " \
128 "block_align = (int)[64, 8096], " \
129 COMMON_AUDIO_CAPS(2, MAX)
133 COMMON_AUDIO_CAPS(2, MAX)
137 "channel-mapping-family = (int) [0, 255], " \
138 COMMON_AUDIO_CAPS(8, MAX)
143 "format=(string)utf8"
145 /* FIXME 0.11 - take a look at bugs #580005 and #340375 */
146 GstQTMuxFormatProp gst_qt_mux_format_list[] = {
147 /* original QuickTime format; see Apple site (e.g. qtff.pdf) */
149 GST_QT_MUX_FORMAT_QT,
154 GST_STATIC_CAPS ("video/quicktime, variant = (string) apple; "
156 GST_STATIC_CAPS ("video/x-raw, "
157 "format = (string) { RGB, UYVY, v210 }, "
158 COMMON_VIDEO_CAPS "; "
165 "systemstream = (boolean) false, "
166 COMMON_VIDEO_CAPS "; "
168 COMMON_VIDEO_CAPS_NO_FRAMERATE "; "
170 COMMON_VIDEO_CAPS "; "
172 COMMON_VIDEO_CAPS "; " "video/x-qt-part, " COMMON_VIDEO_CAPS),
173 GST_STATIC_CAPS (PCM_CAPS_FULL "; "
177 "audio/x-alaw, " COMMON_AUDIO_CAPS (2, MAX) "; "
178 "audio/x-mulaw, " COMMON_AUDIO_CAPS (2, MAX) "; "
179 AMR_CAPS " ; " ALAC_CAPS),
180 GST_STATIC_CAPS (TEXT_UTF8)}
182 /* ISO 14496-14: mp42 as ISO base media extension
183 * (supersedes original ISO 144996-1 mp41) */
185 GST_QT_MUX_FORMAT_MP4,
190 GST_STATIC_CAPS ("video/quicktime, variant = (string) iso"),
191 GST_STATIC_CAPS (MPEG4V_CAPS "; " H264_CAPS ";"
192 "video/x-mp4-part," COMMON_VIDEO_CAPS),
193 GST_STATIC_CAPS (MP3_CAPS "; "
194 AAC_CAPS " ; " AC3_CAPS " ; " ALAC_CAPS " ; " OPUS_CAPS),
195 GST_STATIC_CAPS (TEXT_UTF8)}
197 /* Microsoft Smooth Streaming fmp4/isml */
198 /* TODO add WMV/WMA support */
200 GST_QT_MUX_FORMAT_ISML,
205 GST_STATIC_CAPS ("video/quicktime, variant = (string) iso-fragmented"),
206 GST_STATIC_CAPS (MPEG4V_CAPS "; " H264_CAPS),
207 GST_STATIC_CAPS (MP3_CAPS "; " AAC_CAPS),
208 GST_STATIC_CAPS_NONE}
210 /* 3GPP Technical Specification 26.244 V7.3.0
211 * (extended in 3GPP2 File Formats for Multimedia Services) */
213 GST_QT_MUX_FORMAT_3GP,
218 GST_STATIC_CAPS ("video/quicktime, variant = (string) 3gpp"),
219 GST_STATIC_CAPS (H263_CAPS "; " MPEG4V_CAPS "; " H264_CAPS),
220 GST_STATIC_CAPS (AMR_CAPS "; " MP3_CAPS "; " AAC_CAPS "; " AC3_CAPS),
221 GST_STATIC_CAPS (TEXT_UTF8)}
223 /* ISO 15444-3: Motion-JPEG-2000 (also ISO base media extension) */
225 GST_QT_MUX_FORMAT_MJ2,
230 GST_STATIC_CAPS ("video/mj2"),
231 GST_STATIC_CAPS ("image/x-j2c, " COMMON_VIDEO_CAPS "; "
232 "image/x-jpc, " COMMON_VIDEO_CAPS),
233 GST_STATIC_CAPS (PCM_CAPS),
234 GST_STATIC_CAPS_NONE}
237 GST_QT_MUX_FORMAT_NONE,
241 /* pretty static, but may turn out needed a few times */
243 gst_qt_mux_map_format_to_flavor (GstQTMuxFormat format)
245 if (format == GST_QT_MUX_FORMAT_QT)
246 return ATOMS_TREE_FLAVOR_MOV;
247 else if (format == GST_QT_MUX_FORMAT_3GP)
248 return ATOMS_TREE_FLAVOR_3GP;
249 else if (format == GST_QT_MUX_FORMAT_ISML)
250 return ATOMS_TREE_FLAVOR_ISML;
252 return ATOMS_TREE_FLAVOR_ISOM;
256 gst_qt_mux_map_check_tracks (AtomMOOV * moov, gint * _video, gint * _audio,
257 gboolean * _has_h264)
260 gint video = 0, audio = 0;
261 gboolean has_h264 = FALSE;
263 for (it = moov->traks; it != NULL; it = g_list_next (it)) {
264 AtomTRAK *track = it->data;
266 if (track->is_video) {
279 *_has_h264 = has_h264;
282 /* pretty static, but possibly dynamic format info */
285 * - avc1 brand is not used, since the specific extensions indicated by it
286 * are not used (e.g. sample groupings, etc)
287 * - TODO: maybe even more 3GPP brand fine-tuning ??
288 * (but that might need ftyp rewriting at the end) */
290 gst_qt_mux_map_format_to_header (GstQTMuxFormat format, GstBuffer ** _prefix,
291 guint32 * _major, guint32 * _version, GList ** _compatible, AtomMOOV * moov,
292 GstClockTime longest_chunk, gboolean faststart)
294 static const guint32 qt_brands[] = { 0 };
295 static const guint32 mp4_brands[] =
296 { FOURCC_mp41, FOURCC_isom, FOURCC_iso2, 0 };
297 static const guint32 isml_brands[] = { FOURCC_iso2, 0 };
298 static const guint32 gpp_brands[] = { FOURCC_isom, FOURCC_iso2, 0 };
299 static const guint32 mjp2_brands[] = { FOURCC_isom, FOURCC_iso2, 0 };
300 static const guint8 mjp2_prefix[] =
301 { 0, 0, 0, 12, 'j', 'P', ' ', ' ', 0x0D, 0x0A, 0x87, 0x0A };
302 const guint32 *comp = NULL;
303 guint32 major = 0, version = 0;
304 GstBuffer *prefix = NULL;
305 GList *result = NULL;
307 g_return_if_fail (_prefix != NULL);
308 g_return_if_fail (_major != NULL);
309 g_return_if_fail (_version != NULL);
310 g_return_if_fail (_compatible != NULL);
313 case GST_QT_MUX_FORMAT_QT:
316 version = 0x20050300;
318 case GST_QT_MUX_FORMAT_MP4:
322 case GST_QT_MUX_FORMAT_ISML:
326 case GST_QT_MUX_FORMAT_3GP:
331 gst_qt_mux_map_check_tracks (moov, &video, &audio, &has_h264);
332 /* only track restriction really matters for Basic Profile */
333 if (video <= 1 && audio <= 1) {
334 /* it seems only newer spec knows about H264 */
335 major = has_h264 ? FOURCC_3gp6 : FOURCC_3gp4;
336 version = has_h264 ? 0x100 : 0x200;
344 * We assume that we have chunks in dts order
346 if (faststart && longest_chunk <= GST_SECOND) {
347 /* add progressive download profile */
348 result = g_list_append (result, GUINT_TO_POINTER (FOURCC_3gr6));
352 case GST_QT_MUX_FORMAT_MJ2:
357 prefix = gst_buffer_new_and_alloc (sizeof (mjp2_prefix));
358 gst_buffer_fill (prefix, 0, mjp2_prefix, sizeof (mjp2_prefix));
362 g_assert_not_reached ();
366 /* convert list to list, hm */
367 while (comp && *comp != 0) {
368 /* order matters over efficiency */
369 result = g_list_append (result, GUINT_TO_POINTER (*comp));
376 *_compatible = result;
378 /* TODO 3GPP may include mp42 as compatible if applicable */
379 /* TODO 3GPP major brand 3gp7 if at most 1 video and audio track */