Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1 | /* Quicktime muxer plugin for GStreamer |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 2 | * Copyright (C) 2008-2010 Thiago Santos <thiagoss@embedded.ufcg.edu.br> |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.net> |
Mark Nauwelaerts | b852dde | 2011-01-03 10:43:15 +0100 | [diff] [blame] | 4 | * Copyright (C) 2010 Nokia Corporation. All rights reserved. |
| 5 | * Contact: Stefan Kost <stefan.kost@nokia.com> |
| 6 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public |
| 18 | * License along with this library; if not, write to the |
Tim-Philipp Müller | 230cf41 | 2012-11-04 00:07:18 +0000 | [diff] [blame] | 19 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 21 | */ |
Mark Nauwelaerts | 9b0cbfe | 2008-12-19 18:33:47 +0000 | [diff] [blame] | 22 | /* |
| 23 | * Unless otherwise indicated, Source Code is licensed under MIT license. |
| 24 | * See further explanation attached in License Statement (distributed in the file |
| 25 | * LICENSE). |
| 26 | * |
| 27 | * Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 28 | * this software and associated documentation files (the "Software"), to deal in |
| 29 | * the Software without restriction, including without limitation the rights to |
| 30 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 31 | * of the Software, and to permit persons to whom the Software is furnished to do |
| 32 | * so, subject to the following conditions: |
| 33 | * |
| 34 | * The above copyright notice and this permission notice shall be included in all |
| 35 | * copies or substantial portions of the Software. |
| 36 | * |
| 37 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 38 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 39 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 40 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 41 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 42 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 43 | * SOFTWARE. |
| 44 | */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | /** |
Mark Nauwelaerts | 07be810 | 2010-12-03 18:09:41 +0100 | [diff] [blame] | 48 | * SECTION:element-qtmux |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 49 | * @short_description: Muxer for quicktime(.mov) files |
| 50 | * |
Mark Nauwelaerts | 07be810 | 2010-12-03 18:09:41 +0100 | [diff] [blame] | 51 | * This element merges streams (audio and video) into QuickTime(.mov) files. |
| 52 | * |
| 53 | * The following background intends to explain why various similar muxers |
| 54 | * are present in this plugin. |
| 55 | * |
| 56 | * The <ulink url="http://www.apple.com/quicktime/resources/qtfileformat.pdf"> |
| 57 | * QuickTime file format specification</ulink> served as basis for the MP4 file |
| 58 | * format specification (mp4mux), and as such the QuickTime file structure is |
| 59 | * nearly identical to the so-called ISO Base Media file format defined in |
| 60 | * ISO 14496-12 (except for some media specific parts). |
| 61 | * In turn, the latter ISO Base Media format was further specialized as a |
| 62 | * Motion JPEG-2000 file format in ISO 15444-3 (mj2mux) |
| 63 | * and in various 3GPP(2) specs (gppmux). |
| 64 | * The fragmented file features defined (only) in ISO Base Media are used by |
| 65 | * ISMV files making up (a.o.) Smooth Streaming (ismlmux). |
| 66 | * |
Stefan Sauer | 35da463 | 2014-02-18 21:44:24 +0100 | [diff] [blame] | 67 | * A few properties (#GstQTMux:movie-timescale, #GstQTMux:trak-timescale) allow |
| 68 | * adjusting some technical parameters, which might be useful in (rare) cases to |
| 69 | * resolve compatibility issues in some situations. |
Mark Nauwelaerts | b852dde | 2011-01-03 10:43:15 +0100 | [diff] [blame] | 70 | * |
| 71 | * Some other properties influence the result more fundamentally. |
Stefan Sauer | 35da463 | 2014-02-18 21:44:24 +0100 | [diff] [blame] | 72 | * A typical mov/mp4 file's metadata (aka moov) is located at the end of the |
| 73 | * file, somewhat contrary to this usually being called "the header". |
| 74 | * However, a #GstQTMux:faststart file will (with some effort) arrange this to |
| 75 | * be located near start of the file, which then allows it e.g. to be played |
| 76 | * while downloading. Alternatively, rather than having one chunk of metadata at |
| 77 | * start (or end), there can be some metadata at start and most of the other |
| 78 | * data can be spread out into fragments of #GstQTMux:fragment-duration. |
Mark Nauwelaerts | b852dde | 2011-01-03 10:43:15 +0100 | [diff] [blame] | 79 | * If such fragmented layout is intended for streaming purposes, then |
Stefan Sauer | 35da463 | 2014-02-18 21:44:24 +0100 | [diff] [blame] | 80 | * #GstQTMux:streamable allows foregoing to add index metadata (at the end of |
| 81 | * file). |
Mark Nauwelaerts | b852dde | 2011-01-03 10:43:15 +0100 | [diff] [blame] | 82 | * |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 83 | * <refsect2> |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 84 | * <title>Example pipelines</title> |
Mark Nauwelaerts | 07be810 | 2010-12-03 18:09:41 +0100 | [diff] [blame] | 85 | * |[ |
Tim-Philipp Müller | 4bb52bb | 2012-08-26 22:39:55 +0100 | [diff] [blame] | 86 | * gst-launch-1.0 v4l2src num-buffers=500 ! video/x-raw,width=320,height=240 ! videoconvert ! qtmux ! filesink location=video.mov |
Mark Nauwelaerts | 07be810 | 2010-12-03 18:09:41 +0100 | [diff] [blame] | 87 | * ]| |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 88 | * Records a video stream captured from a v4l2 device and muxes it into a qt file. |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 89 | * </refsect2> |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 90 | */ |
| 91 | |
| 92 | /* |
| 93 | * Based on avimux |
| 94 | */ |
| 95 | |
| 96 | #ifdef HAVE_CONFIG_H |
| 97 | #include "config.h" |
| 98 | #endif |
| 99 | |
| 100 | #include <glib/gstdio.h> |
| 101 | |
| 102 | #include <gst/gst.h> |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 103 | #include <gst/base/gstcollectpads.h> |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 104 | #include <gst/audio/audio.h> |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 105 | #include <gst/video/video.h> |
Matej Knopp | d8ac666 | 2013-03-22 02:24:01 +0100 | [diff] [blame] | 106 | #include <gst/tag/tag.h> |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 107 | |
Wim Taymans | 1fbca3b | 2009-03-23 11:17:39 +0100 | [diff] [blame] | 108 | #include <sys/types.h> |
LRN | 61d88bd | 2009-03-20 14:20:16 +0100 | [diff] [blame] | 109 | #ifdef G_OS_WIN32 |
| 110 | #include <io.h> /* lseek, open, close, read */ |
| 111 | #undef lseek |
| 112 | #define lseek _lseeki64 |
| 113 | #undef off_t |
| 114 | #define off_t guint64 |
| 115 | #endif |
| 116 | |
David Hoyt | 62484ac | 2010-12-01 10:45:49 +0100 | [diff] [blame] | 117 | #ifdef _MSC_VER |
| 118 | #define ftruncate g_win32_ftruncate |
| 119 | #endif |
| 120 | |
Wim Taymans | 1fbca3b | 2009-03-23 11:17:39 +0100 | [diff] [blame] | 121 | #ifdef HAVE_UNISTD_H |
| 122 | # include <unistd.h> |
| 123 | #endif |
| 124 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 125 | #include "gstqtmux.h" |
| 126 | |
| 127 | GST_DEBUG_CATEGORY_STATIC (gst_qt_mux_debug); |
| 128 | #define GST_CAT_DEFAULT gst_qt_mux_debug |
| 129 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 130 | /* Hacker notes. |
| 131 | * |
| 132 | * The basic building blocks of MP4 files are: |
| 133 | * - an 'ftyp' box at the very start |
| 134 | * - an 'mdat' box which contains the raw audio/video/subtitle data; |
| 135 | * this is just a bunch of bytes, completely unframed and possibly |
| 136 | * unordered with no additional meta-information |
| 137 | * - a 'moov' box that contains information about the different streams |
| 138 | * and what they contain, as well as sample tables for each stream |
| 139 | * that tell the demuxer where in the mdat box each buffer/sample is |
| 140 | * and what its duration/timestamp etc. is, and whether it's a |
| 141 | * keyframe etc. |
| 142 | * Additionally, fragmented MP4 works by writing chunks of data in |
| 143 | * pairs of 'moof' and 'mdat' boxes: |
| 144 | * - 'moof' boxes, header preceding each mdat fragment describing the |
| 145 | * contents, like a moov but only for that fragment. |
| 146 | * - a 'mfra' box for Fragmented MP4, which is written at the end and |
| 147 | * contains a summary of all fragments and seek tables. |
| 148 | * |
| 149 | * Currently mp4mux can work in 3 different modes / generate 3 types |
| 150 | * of output files/streams: |
| 151 | * |
| 152 | * - Normal mp4: mp4mux will write a little ftyp identifier at the |
| 153 | * beginning, then start an mdat box into which it will write all the |
| 154 | * sample data. At EOS it will then write the moov header with track |
| 155 | * headers and sample tables at the end of the file, and rewrite the |
| 156 | * start of the file to fix up the mdat box size at the beginning. |
| 157 | * It has to wait for EOS to write the moov (which includes the |
| 158 | * sample tables) because it doesn't know how much space those |
| 159 | * tables will be. The output downstream must be seekable to rewrite |
| 160 | * the mdat box at EOS. |
| 161 | * |
| 162 | * - Fragmented mp4: moov header with track headers at start |
Jan Schmidt | 0c1bcc6 | 2015-04-08 01:41:18 +1000 | [diff] [blame] | 163 | * but no sample table, followed by N fragments, each containing |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 164 | * track headers with sample tables followed by some data. Downstream |
| 165 | * does not need to be seekable if the 'streamable' flag is TRUE, |
| 166 | * as the final mfra and total duration will be omitted. |
| 167 | * |
| 168 | * - Fast-start mp4: the goal here is to create a file where the moov |
| 169 | * headers are at the beginning; what mp4mux will do is write all |
| 170 | * sample data into a temp file and build moov header plus sample |
| 171 | * tables in memory and then when EOS comes, it will push out the |
| 172 | * moov header plus sample tables at the beginning, followed by the |
| 173 | * mdat sample data at the end which is read in from the temp file |
| 174 | * Files created in this mode are better for streaming over the |
| 175 | * network, since the client doesn't have to seek to the end of the |
| 176 | * file to get the headers, but it requires copying all sample data |
| 177 | * out of the temp file at EOS, which can be expensive. Downstream does |
| 178 | * not need to be seekable, because of the use of the temp file. |
| 179 | * |
| 180 | */ |
| 181 | |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 182 | #ifndef GST_REMOVE_DEPRECATED |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 183 | enum |
| 184 | { |
| 185 | DTS_METHOD_DD, |
| 186 | DTS_METHOD_REORDER, |
| 187 | DTS_METHOD_ASC |
| 188 | }; |
| 189 | |
| 190 | static GType |
| 191 | gst_qt_mux_dts_method_get_type (void) |
| 192 | { |
| 193 | static GType gst_qt_mux_dts_method = 0; |
| 194 | |
| 195 | if (!gst_qt_mux_dts_method) { |
| 196 | static const GEnumValue dts_methods[] = { |
| 197 | {DTS_METHOD_DD, "delta/duration", "dd"}, |
| 198 | {DTS_METHOD_REORDER, "reorder", "reorder"}, |
| 199 | {DTS_METHOD_ASC, "ascending", "asc"}, |
| 200 | {0, NULL, NULL}, |
| 201 | }; |
| 202 | |
| 203 | gst_qt_mux_dts_method = |
| 204 | g_enum_register_static ("GstQTMuxDtsMethods", dts_methods); |
| 205 | } |
| 206 | |
| 207 | return gst_qt_mux_dts_method; |
| 208 | } |
| 209 | |
| 210 | #define GST_TYPE_QT_MUX_DTS_METHOD \ |
| 211 | (gst_qt_mux_dts_method_get_type ()) |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 212 | #endif |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 213 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 214 | /* QTMux signals and args */ |
| 215 | enum |
| 216 | { |
| 217 | /* FILL ME */ |
| 218 | LAST_SIGNAL |
| 219 | }; |
| 220 | |
| 221 | enum |
| 222 | { |
| 223 | PROP_0, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 224 | PROP_MOVIE_TIMESCALE, |
Marc-André Lureau | bee00aa | 2010-07-30 12:48:29 +0200 | [diff] [blame] | 225 | PROP_TRAK_TIMESCALE, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 226 | PROP_FAST_START, |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 227 | PROP_FAST_START_TEMP_FILE, |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 228 | PROP_MOOV_RECOV_FILE, |
Marc-André Lureau | 61964eb | 2010-08-06 13:26:27 +0200 | [diff] [blame] | 229 | PROP_FRAGMENT_DURATION, |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 230 | PROP_STREAMABLE, |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 231 | #ifndef GST_REMOVE_DEPRECATED |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 232 | PROP_DTS_METHOD, |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 233 | #endif |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 234 | PROP_DO_CTTS, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 237 | /* some spare for header size as well */ |
| 238 | #define MDAT_LARGE_FILE_LIMIT ((guint64) 1024 * 1024 * 1024 * 2) |
| 239 | |
Jan Schmidt | 6e7930a | 2014-08-15 10:09:56 +1000 | [diff] [blame] | 240 | #define DEFAULT_MOVIE_TIMESCALE 1800 |
Marc-André Lureau | bee00aa | 2010-07-30 12:48:29 +0200 | [diff] [blame] | 241 | #define DEFAULT_TRAK_TIMESCALE 0 |
Tim-Philipp Müller | c8b5014 | 2011-04-13 12:37:09 +0100 | [diff] [blame] | 242 | #define DEFAULT_DO_CTTS TRUE |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 243 | #define DEFAULT_FAST_START FALSE |
| 244 | #define DEFAULT_FAST_START_TEMP_FILE NULL |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 245 | #define DEFAULT_MOOV_RECOV_FILE NULL |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 246 | #define DEFAULT_FRAGMENT_DURATION 0 |
Andoni Morales Alastruey | 9ae5082 | 2013-09-17 12:06:06 +0200 | [diff] [blame] | 247 | #define DEFAULT_STREAMABLE TRUE |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 248 | #ifndef GST_REMOVE_DEPRECATED |
Tim-Philipp Müller | c8b5014 | 2011-04-13 12:37:09 +0100 | [diff] [blame] | 249 | #define DEFAULT_DTS_METHOD DTS_METHOD_REORDER |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 250 | #endif |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 251 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 252 | static void gst_qt_mux_finalize (GObject * object); |
| 253 | |
| 254 | static GstStateChangeReturn gst_qt_mux_change_state (GstElement * element, |
| 255 | GstStateChange transition); |
| 256 | |
| 257 | /* property functions */ |
| 258 | static void gst_qt_mux_set_property (GObject * object, |
| 259 | guint prop_id, const GValue * value, GParamSpec * pspec); |
| 260 | static void gst_qt_mux_get_property (GObject * object, |
| 261 | guint prop_id, GValue * value, GParamSpec * pspec); |
| 262 | |
| 263 | /* pad functions */ |
| 264 | static GstPad *gst_qt_mux_request_new_pad (GstElement * element, |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 265 | GstPadTemplate * templ, const gchar * name, const GstCaps * caps); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 266 | static void gst_qt_mux_release_pad (GstElement * element, GstPad * pad); |
| 267 | |
| 268 | /* event */ |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 269 | static gboolean gst_qt_mux_sink_event (GstCollectPads * pads, |
| 270 | GstCollectData * data, GstEvent * event, gpointer user_data); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 271 | |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 272 | static GstFlowReturn gst_qt_mux_handle_buffer (GstCollectPads * pads, |
| 273 | GstCollectData * cdata, GstBuffer * buf, gpointer user_data); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 274 | static GstFlowReturn gst_qt_mux_add_buffer (GstQTMux * qtmux, GstQTPad * pad, |
| 275 | GstBuffer * buf); |
| 276 | |
| 277 | static GstElementClass *parent_class = NULL; |
| 278 | |
| 279 | static void |
| 280 | gst_qt_mux_base_init (gpointer g_class) |
| 281 | { |
| 282 | GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); |
| 283 | GstQTMuxClass *klass = (GstQTMuxClass *) g_class; |
| 284 | GstQTMuxClassParams *params; |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 285 | GstPadTemplate *videosinktempl, *audiosinktempl, *subtitlesinktempl; |
| 286 | GstPadTemplate *srctempl; |
Benjamin Otte | af347a9 | 2010-03-18 17:30:26 +0100 | [diff] [blame] | 287 | gchar *longname, *description; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 288 | |
| 289 | params = |
| 290 | (GstQTMuxClassParams *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class), |
| 291 | GST_QT_MUX_PARAMS_QDATA); |
| 292 | g_assert (params != NULL); |
| 293 | |
| 294 | /* construct the element details struct */ |
Benjamin Otte | af347a9 | 2010-03-18 17:30:26 +0100 | [diff] [blame] | 295 | longname = g_strdup_printf ("%s Muxer", params->prop->long_name); |
Tim-Philipp Müller | cf9b214 | 2012-07-06 12:54:02 +0100 | [diff] [blame] | 296 | description = g_strdup_printf ("Multiplex audio and video into a %s file", |
| 297 | params->prop->long_name); |
Tim-Philipp Müller | e09ae57 | 2012-04-10 00:51:41 +0100 | [diff] [blame] | 298 | gst_element_class_set_static_metadata (element_class, longname, |
Benjamin Otte | af347a9 | 2010-03-18 17:30:26 +0100 | [diff] [blame] | 299 | "Codec/Muxer", description, |
| 300 | "Thiago Sousa Santos <thiagoss@embedded.ufcg.edu.br>"); |
| 301 | g_free (longname); |
| 302 | g_free (description); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 303 | |
| 304 | /* pad templates */ |
| 305 | srctempl = gst_pad_template_new ("src", GST_PAD_SRC, |
| 306 | GST_PAD_ALWAYS, params->src_caps); |
| 307 | gst_element_class_add_pad_template (element_class, srctempl); |
| 308 | |
| 309 | if (params->audio_sink_caps) { |
Wim Taymans | a95acb7 | 2011-11-04 11:58:22 +0100 | [diff] [blame] | 310 | audiosinktempl = gst_pad_template_new ("audio_%u", |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 311 | GST_PAD_SINK, GST_PAD_REQUEST, params->audio_sink_caps); |
| 312 | gst_element_class_add_pad_template (element_class, audiosinktempl); |
| 313 | } |
| 314 | |
| 315 | if (params->video_sink_caps) { |
Wim Taymans | a95acb7 | 2011-11-04 11:58:22 +0100 | [diff] [blame] | 316 | videosinktempl = gst_pad_template_new ("video_%u", |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 317 | GST_PAD_SINK, GST_PAD_REQUEST, params->video_sink_caps); |
| 318 | gst_element_class_add_pad_template (element_class, videosinktempl); |
| 319 | } |
| 320 | |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 321 | if (params->subtitle_sink_caps) { |
| 322 | subtitlesinktempl = gst_pad_template_new ("subtitle_%u", |
| 323 | GST_PAD_SINK, GST_PAD_REQUEST, params->subtitle_sink_caps); |
| 324 | gst_element_class_add_pad_template (element_class, subtitlesinktempl); |
| 325 | } |
| 326 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 327 | klass->format = params->prop->format; |
| 328 | } |
| 329 | |
| 330 | static void |
| 331 | gst_qt_mux_class_init (GstQTMuxClass * klass) |
| 332 | { |
| 333 | GObjectClass *gobject_class; |
| 334 | GstElementClass *gstelement_class; |
Tim-Philipp Müller | 3956f5a | 2014-11-02 16:51:23 +0000 | [diff] [blame] | 335 | GParamFlags streamable_flags; |
Andoni Morales Alastruey | 5732684 | 2013-09-17 12:01:30 +0200 | [diff] [blame] | 336 | const gchar *streamable_desc; |
Andoni Morales Alastruey | 9ae5082 | 2013-09-17 12:06:06 +0200 | [diff] [blame] | 337 | gboolean streamable; |
Andoni Morales Alastruey | 5732684 | 2013-09-17 12:01:30 +0200 | [diff] [blame] | 338 | #define STREAMABLE_DESC "If set to true, the output should be as if it is to "\ |
| 339 | "be streamed and hence no indexes written or duration written." |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 340 | |
| 341 | gobject_class = (GObjectClass *) klass; |
| 342 | gstelement_class = (GstElementClass *) klass; |
| 343 | |
| 344 | parent_class = g_type_class_peek_parent (klass); |
| 345 | |
| 346 | gobject_class->finalize = gst_qt_mux_finalize; |
| 347 | gobject_class->get_property = gst_qt_mux_get_property; |
| 348 | gobject_class->set_property = gst_qt_mux_set_property; |
| 349 | |
Tim-Philipp Müller | 3956f5a | 2014-11-02 16:51:23 +0000 | [diff] [blame] | 350 | streamable_flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; |
Andoni Morales Alastruey | 5732684 | 2013-09-17 12:01:30 +0200 | [diff] [blame] | 351 | if (klass->format == GST_QT_MUX_FORMAT_ISML) { |
| 352 | streamable_desc = STREAMABLE_DESC; |
Andoni Morales Alastruey | 9ae5082 | 2013-09-17 12:06:06 +0200 | [diff] [blame] | 353 | streamable = DEFAULT_STREAMABLE; |
Andoni Morales Alastruey | 5732684 | 2013-09-17 12:01:30 +0200 | [diff] [blame] | 354 | } else { |
| 355 | streamable_desc = |
| 356 | STREAMABLE_DESC " (DEPRECATED, only valid for fragmented MP4)"; |
Tim-Philipp Müller | 3956f5a | 2014-11-02 16:51:23 +0000 | [diff] [blame] | 357 | streamable_flags |= G_PARAM_DEPRECATED; |
Andoni Morales Alastruey | 9ae5082 | 2013-09-17 12:06:06 +0200 | [diff] [blame] | 358 | streamable = FALSE; |
Andoni Morales Alastruey | 5732684 | 2013-09-17 12:01:30 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 361 | g_object_class_install_property (gobject_class, PROP_MOVIE_TIMESCALE, |
| 362 | g_param_spec_uint ("movie-timescale", "Movie timescale", |
| 363 | "Timescale to use in the movie (units per second)", |
| 364 | 1, G_MAXUINT32, DEFAULT_MOVIE_TIMESCALE, |
Thiago Santos | 5ccc066 | 2010-10-03 23:45:46 -0300 | [diff] [blame] | 365 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); |
Marc-André Lureau | bee00aa | 2010-07-30 12:48:29 +0200 | [diff] [blame] | 366 | g_object_class_install_property (gobject_class, PROP_TRAK_TIMESCALE, |
| 367 | g_param_spec_uint ("trak-timescale", "Track timescale", |
| 368 | "Timescale to use for the tracks (units per second, 0 is automatic)", |
| 369 | 0, G_MAXUINT32, DEFAULT_TRAK_TIMESCALE, |
| 370 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 371 | g_object_class_install_property (gobject_class, PROP_DO_CTTS, |
| 372 | g_param_spec_boolean ("presentation-time", |
| 373 | "Include presentation-time info", |
Thiago Sousa Santos | d24d1e4 | 2009-11-17 09:26:05 -0300 | [diff] [blame] | 374 | "Calculate and include presentation/composition time " |
Tim-Philipp Müller | c8b5014 | 2011-04-13 12:37:09 +0100 | [diff] [blame] | 375 | "(in addition to decoding time)", DEFAULT_DO_CTTS, |
Thiago Santos | 5ccc066 | 2010-10-03 23:45:46 -0300 | [diff] [blame] | 376 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 377 | #ifndef GST_REMOVE_DEPRECATED |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 378 | g_object_class_install_property (gobject_class, PROP_DTS_METHOD, |
| 379 | g_param_spec_enum ("dts-method", "dts-method", |
Tim-Philipp Müller | 3956f5a | 2014-11-02 16:51:23 +0000 | [diff] [blame] | 380 | "Method to determine DTS time (DEPRECATED)", |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 381 | GST_TYPE_QT_MUX_DTS_METHOD, DEFAULT_DTS_METHOD, |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 382 | G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | |
| 383 | G_PARAM_STATIC_STRINGS)); |
| 384 | #endif |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 385 | g_object_class_install_property (gobject_class, PROP_FAST_START, |
| 386 | g_param_spec_boolean ("faststart", "Format file to faststart", |
Tim-Philipp Müller | c8b5014 | 2011-04-13 12:37:09 +0100 | [diff] [blame] | 387 | "If the file should be formatted for faststart (headers first)", |
Thiago Santos | 5ccc066 | 2010-10-03 23:45:46 -0300 | [diff] [blame] | 388 | DEFAULT_FAST_START, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 389 | g_object_class_install_property (gobject_class, PROP_FAST_START_TEMP_FILE, |
| 390 | g_param_spec_string ("faststart-file", "File to use for storing buffers", |
Thiago Sousa Santos | d24d1e4 | 2009-11-17 09:26:05 -0300 | [diff] [blame] | 391 | "File that will be used temporarily to store data from the stream " |
| 392 | "when creating a faststart file. If null a filepath will be " |
| 393 | "created automatically", DEFAULT_FAST_START_TEMP_FILE, |
Thiago Santos | 5ccc066 | 2010-10-03 23:45:46 -0300 | [diff] [blame] | 394 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 395 | g_object_class_install_property (gobject_class, PROP_MOOV_RECOV_FILE, |
Thiago Santos | 5ccc066 | 2010-10-03 23:45:46 -0300 | [diff] [blame] | 396 | g_param_spec_string ("moov-recovery-file", |
| 397 | "File to store data for posterior moov atom recovery", |
| 398 | "File to be used to store " |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 399 | "data for moov atom making movie file recovery possible in case " |
| 400 | "of a crash during muxing. Null for disabled. (Experimental)", |
Thiago Santos | 5ccc066 | 2010-10-03 23:45:46 -0300 | [diff] [blame] | 401 | DEFAULT_MOOV_RECOV_FILE, |
| 402 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 403 | g_object_class_install_property (gobject_class, PROP_FRAGMENT_DURATION, |
| 404 | g_param_spec_uint ("fragment-duration", "Fragment duration", |
| 405 | "Fragment durations in ms (produce a fragmented file if > 0)", |
Mark Nauwelaerts | f490e3a | 2010-11-19 19:17:45 +0100 | [diff] [blame] | 406 | 0, G_MAXUINT32, klass->format == GST_QT_MUX_FORMAT_ISML ? |
| 407 | 2000 : DEFAULT_FRAGMENT_DURATION, |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 408 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); |
Marc-André Lureau | 61964eb | 2010-08-06 13:26:27 +0200 | [diff] [blame] | 409 | g_object_class_install_property (gobject_class, PROP_STREAMABLE, |
Andoni Morales Alastruey | 5732684 | 2013-09-17 12:01:30 +0200 | [diff] [blame] | 410 | g_param_spec_boolean ("streamable", "Streamable", streamable_desc, |
Tim-Philipp Müller | 3956f5a | 2014-11-02 16:51:23 +0000 | [diff] [blame] | 411 | streamable, streamable_flags | G_PARAM_STATIC_STRINGS)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 412 | |
| 413 | gstelement_class->request_new_pad = |
| 414 | GST_DEBUG_FUNCPTR (gst_qt_mux_request_new_pad); |
| 415 | gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_qt_mux_change_state); |
| 416 | gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_qt_mux_release_pad); |
| 417 | } |
| 418 | |
| 419 | static void |
| 420 | gst_qt_mux_pad_reset (GstQTPad * qtpad) |
| 421 | { |
| 422 | qtpad->fourcc = 0; |
| 423 | qtpad->is_out_of_order = FALSE; |
| 424 | qtpad->sample_size = 0; |
| 425 | qtpad->sync = FALSE; |
| 426 | qtpad->last_dts = 0; |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 427 | qtpad->first_ts = GST_CLOCK_TIME_NONE; |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 428 | qtpad->prepare_buf_func = NULL; |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 429 | qtpad->create_empty_buffer = NULL; |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 430 | qtpad->avg_bitrate = 0; |
| 431 | qtpad->max_bitrate = 0; |
Thiago Santos | 7a143ea | 2011-09-28 11:41:49 -0300 | [diff] [blame] | 432 | qtpad->total_duration = 0; |
| 433 | qtpad->total_bytes = 0; |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 434 | qtpad->sparse = FALSE; |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 435 | |
| 436 | qtpad->buf_head = 0; |
| 437 | qtpad->buf_tail = 0; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 438 | |
Thiago Santos | 84b7cf6 | 2015-02-18 10:10:53 -0300 | [diff] [blame] | 439 | gst_buffer_replace (&qtpad->last_buf, NULL); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 440 | |
Thiago Santos | e52b2cb | 2015-01-31 14:32:34 -0300 | [diff] [blame] | 441 | if (qtpad->tags) { |
| 442 | gst_tag_list_unref (qtpad->tags); |
| 443 | qtpad->tags = NULL; |
| 444 | } |
| 445 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 446 | /* reference owned elsewhere */ |
| 447 | qtpad->trak = NULL; |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 448 | |
| 449 | if (qtpad->traf) { |
| 450 | atom_traf_free (qtpad->traf); |
| 451 | qtpad->traf = NULL; |
| 452 | } |
| 453 | atom_array_clear (&qtpad->fragment_buffers); |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 454 | |
| 455 | /* reference owned elsewhere */ |
| 456 | qtpad->tfra = NULL; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /* |
| 460 | * Takes GstQTMux back to its initial state |
| 461 | */ |
| 462 | static void |
| 463 | gst_qt_mux_reset (GstQTMux * qtmux, gboolean alloc) |
| 464 | { |
| 465 | GSList *walk; |
| 466 | |
| 467 | qtmux->state = GST_QT_MUX_STATE_NONE; |
| 468 | qtmux->header_size = 0; |
| 469 | qtmux->mdat_size = 0; |
| 470 | qtmux->mdat_pos = 0; |
Thiago Santos | 4ff2fad | 2009-10-16 10:47:32 -0300 | [diff] [blame] | 471 | qtmux->longest_chunk = GST_CLOCK_TIME_NONE; |
Stefan Kost | 05257fe | 2009-12-27 23:51:50 +0200 | [diff] [blame] | 472 | qtmux->video_pads = 0; |
| 473 | qtmux->audio_pads = 0; |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 474 | qtmux->fragment_sequence = 0; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 475 | |
| 476 | if (qtmux->ftyp) { |
| 477 | atom_ftyp_free (qtmux->ftyp); |
| 478 | qtmux->ftyp = NULL; |
| 479 | } |
| 480 | if (qtmux->moov) { |
| 481 | atom_moov_free (qtmux->moov); |
| 482 | qtmux->moov = NULL; |
| 483 | } |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 484 | if (qtmux->mfra) { |
| 485 | atom_mfra_free (qtmux->mfra); |
| 486 | qtmux->mfra = NULL; |
| 487 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 488 | if (qtmux->fast_start_file) { |
| 489 | fclose (qtmux->fast_start_file); |
Marc-André Lureau | 3e6a415 | 2009-09-28 16:53:51 +0200 | [diff] [blame] | 490 | g_remove (qtmux->fast_start_file_path); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 491 | qtmux->fast_start_file = NULL; |
| 492 | } |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 493 | if (qtmux->moov_recov_file) { |
| 494 | fclose (qtmux->moov_recov_file); |
| 495 | qtmux->moov_recov_file = NULL; |
| 496 | } |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 497 | for (walk = qtmux->extra_atoms; walk; walk = g_slist_next (walk)) { |
| 498 | AtomInfo *ainfo = (AtomInfo *) walk->data; |
| 499 | ainfo->free_func (ainfo->atom); |
Sebastian Dröge | d8a690e | 2010-12-19 12:53:34 +0100 | [diff] [blame] | 500 | g_free (ainfo); |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 501 | } |
| 502 | g_slist_free (qtmux->extra_atoms); |
| 503 | qtmux->extra_atoms = NULL; |
Michael Smith | 8b3aca9 | 2010-02-26 11:50:25 -0800 | [diff] [blame] | 504 | |
| 505 | GST_OBJECT_LOCK (qtmux); |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 506 | gst_tag_setter_reset_tags (GST_TAG_SETTER (qtmux)); |
Michael Smith | 8b3aca9 | 2010-02-26 11:50:25 -0800 | [diff] [blame] | 507 | GST_OBJECT_UNLOCK (qtmux); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 508 | |
| 509 | /* reset pad data */ |
Thiago Santos | c92785e | 2010-02-22 10:48:11 -0300 | [diff] [blame] | 510 | for (walk = qtmux->sinkpads; walk; walk = g_slist_next (walk)) { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 511 | GstQTPad *qtpad = (GstQTPad *) walk->data; |
| 512 | gst_qt_mux_pad_reset (qtpad); |
| 513 | |
| 514 | /* hm, moov_free above yanked the traks away from us, |
| 515 | * so do not free, but do clear */ |
| 516 | qtpad->trak = NULL; |
| 517 | } |
| 518 | |
| 519 | if (alloc) { |
| 520 | qtmux->moov = atom_moov_new (qtmux->context); |
Mark Nauwelaerts | 4da6cd7 | 2009-03-25 21:24:44 +0100 | [diff] [blame] | 521 | /* ensure all is as nice and fresh as request_new_pad would provide it */ |
Thiago Santos | c92785e | 2010-02-22 10:48:11 -0300 | [diff] [blame] | 522 | for (walk = qtmux->sinkpads; walk; walk = g_slist_next (walk)) { |
Mark Nauwelaerts | 4da6cd7 | 2009-03-25 21:24:44 +0100 | [diff] [blame] | 523 | GstQTPad *qtpad = (GstQTPad *) walk->data; |
| 524 | |
Mark Nauwelaerts | ce865cc | 2010-11-05 12:08:15 +0100 | [diff] [blame] | 525 | qtpad->trak = atom_trak_new (qtmux->context); |
| 526 | atom_moov_add_trak (qtmux->moov, qtpad->trak); |
Mark Nauwelaerts | 4da6cd7 | 2009-03-25 21:24:44 +0100 | [diff] [blame] | 527 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | gst_qt_mux_init (GstQTMux * qtmux, GstQTMuxClass * qtmux_klass) |
| 533 | { |
| 534 | GstElementClass *klass = GST_ELEMENT_CLASS (qtmux_klass); |
| 535 | GstPadTemplate *templ; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 536 | |
| 537 | templ = gst_element_class_get_pad_template (klass, "src"); |
| 538 | qtmux->srcpad = gst_pad_new_from_template (templ, "src"); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 539 | gst_pad_use_fixed_caps (qtmux->srcpad); |
| 540 | gst_element_add_pad (GST_ELEMENT (qtmux), qtmux->srcpad); |
| 541 | |
Thiago Santos | c92785e | 2010-02-22 10:48:11 -0300 | [diff] [blame] | 542 | qtmux->sinkpads = NULL; |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 543 | qtmux->collect = gst_collect_pads_new (); |
| 544 | gst_collect_pads_set_buffer_function (qtmux->collect, |
Mark Nauwelaerts | 0c7a491 | 2011-12-16 18:03:01 +0100 | [diff] [blame] | 545 | GST_DEBUG_FUNCPTR (gst_qt_mux_handle_buffer), qtmux); |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 546 | gst_collect_pads_set_event_function (qtmux->collect, |
Mark Nauwelaerts | 0c7a491 | 2011-12-16 18:03:01 +0100 | [diff] [blame] | 547 | GST_DEBUG_FUNCPTR (gst_qt_mux_sink_event), qtmux); |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 548 | gst_collect_pads_set_clip_function (qtmux->collect, |
| 549 | GST_DEBUG_FUNCPTR (gst_collect_pads_clip_running_time), qtmux); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 550 | |
| 551 | /* properties set to default upon construction */ |
| 552 | |
| 553 | /* always need this */ |
| 554 | qtmux->context = |
| 555 | atoms_context_new (gst_qt_mux_map_format_to_flavor (qtmux_klass->format)); |
| 556 | |
| 557 | /* internals to initial state */ |
| 558 | gst_qt_mux_reset (qtmux, TRUE); |
| 559 | } |
| 560 | |
| 561 | |
| 562 | static void |
| 563 | gst_qt_mux_finalize (GObject * object) |
| 564 | { |
| 565 | GstQTMux *qtmux = GST_QT_MUX_CAST (object); |
| 566 | |
| 567 | gst_qt_mux_reset (qtmux, FALSE); |
| 568 | |
Thiago Santos | 6dc515b | 2010-01-26 13:44:04 -0300 | [diff] [blame] | 569 | g_free (qtmux->fast_start_file_path); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 570 | g_free (qtmux->moov_recov_file_path); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 571 | |
| 572 | atoms_context_free (qtmux->context); |
| 573 | gst_object_unref (qtmux->collect); |
| 574 | |
Mark Nauwelaerts | 50464d5 | 2010-11-19 14:44:45 +0100 | [diff] [blame] | 575 | g_slist_free (qtmux->sinkpads); |
| 576 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 577 | G_OBJECT_CLASS (parent_class)->finalize (object); |
| 578 | } |
| 579 | |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 580 | static GstBuffer * |
| 581 | gst_qt_mux_prepare_jpc_buffer (GstQTPad * qtpad, GstBuffer * buf, |
| 582 | GstQTMux * qtmux) |
| 583 | { |
| 584 | GstBuffer *newbuf; |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 585 | GstMapInfo map; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 586 | gsize size; |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 587 | |
| 588 | GST_LOG_OBJECT (qtmux, "Preparing jpc buffer"); |
| 589 | |
| 590 | if (buf == NULL) |
| 591 | return NULL; |
| 592 | |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 593 | size = gst_buffer_get_size (buf); |
| 594 | newbuf = gst_buffer_new_and_alloc (size + 8); |
| 595 | gst_buffer_copy_into (newbuf, buf, GST_BUFFER_COPY_ALL, 8, size); |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 596 | |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 597 | gst_buffer_map (newbuf, &map, GST_MAP_WRITE); |
| 598 | GST_WRITE_UINT32_BE (map.data, map.size); |
| 599 | GST_WRITE_UINT32_LE (map.data + 4, FOURCC_jp2c); |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 600 | |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 601 | gst_buffer_unmap (buf, &map); |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 602 | gst_buffer_unref (buf); |
| 603 | |
| 604 | return newbuf; |
| 605 | } |
| 606 | |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 607 | static GstBuffer * |
| 608 | gst_qt_mux_prepare_tx3g_buffer (GstQTPad * qtpad, GstBuffer * buf, |
| 609 | GstQTMux * qtmux) |
| 610 | { |
| 611 | GstBuffer *newbuf; |
| 612 | GstMapInfo frommap; |
| 613 | GstMapInfo tomap; |
| 614 | gsize size; |
| 615 | |
| 616 | GST_LOG_OBJECT (qtmux, "Preparing tx3g buffer %" GST_PTR_FORMAT, buf); |
| 617 | |
| 618 | if (buf == NULL) |
| 619 | return NULL; |
| 620 | |
Matej Knopp | 6695341 | 2014-09-23 19:07:25 +0200 | [diff] [blame] | 621 | gst_buffer_map (buf, &frommap, GST_MAP_READ); |
| 622 | |
| 623 | size = (gint16) strnlen ((const char *) frommap.data, frommap.size); |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 624 | newbuf = gst_buffer_new_and_alloc (size + 2); |
| 625 | |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 626 | gst_buffer_map (newbuf, &tomap, GST_MAP_WRITE); |
| 627 | |
| 628 | GST_WRITE_UINT16_BE (tomap.data, size); |
| 629 | memcpy (tomap.data + 2, frommap.data, size); |
| 630 | |
| 631 | gst_buffer_unmap (newbuf, &tomap); |
| 632 | gst_buffer_unmap (buf, &frommap); |
| 633 | |
| 634 | gst_buffer_copy_into (newbuf, buf, GST_BUFFER_COPY_METADATA, 0, size); |
| 635 | |
Matej Knopp | 6695341 | 2014-09-23 19:07:25 +0200 | [diff] [blame] | 636 | /* gst_buffer_copy_into is trying to be too clever and |
| 637 | * won't copy duration when size is different */ |
| 638 | GST_BUFFER_DURATION (newbuf) = GST_BUFFER_DURATION (buf); |
| 639 | |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 640 | gst_buffer_unref (buf); |
| 641 | |
| 642 | return newbuf; |
| 643 | } |
| 644 | |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 645 | static GstBuffer * |
| 646 | gst_qt_mux_create_empty_tx3g_buffer (GstQTPad * qtpad, gint64 duration) |
| 647 | { |
| 648 | guint8 *data; |
| 649 | |
| 650 | data = g_malloc (2); |
| 651 | GST_WRITE_UINT16_BE (data, 0); |
| 652 | |
Matej Knopp | 6695341 | 2014-09-23 19:07:25 +0200 | [diff] [blame] | 653 | return gst_buffer_new_wrapped (data, 2); |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 654 | } |
| 655 | |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 656 | static void |
| 657 | gst_qt_mux_add_mp4_tag (GstQTMux * qtmux, const GstTagList * list, |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 658 | AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc) |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 659 | { |
| 660 | switch (gst_tag_get_type (tag)) { |
| 661 | /* strings */ |
| 662 | case G_TYPE_STRING: |
| 663 | { |
| 664 | gchar *str = NULL; |
| 665 | |
| 666 | if (!gst_tag_list_get_string (list, tag, &str) || !str) |
| 667 | break; |
| 668 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s", |
| 669 | GST_FOURCC_ARGS (fourcc), str); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 670 | atom_udta_add_str_tag (udta, fourcc, str); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 671 | g_free (str); |
| 672 | break; |
| 673 | } |
| 674 | /* double */ |
| 675 | case G_TYPE_DOUBLE: |
| 676 | { |
| 677 | gdouble value; |
| 678 | |
| 679 | if (!gst_tag_list_get_double (list, tag, &value)) |
| 680 | break; |
| 681 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %u", |
| 682 | GST_FOURCC_ARGS (fourcc), (gint) value); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 683 | atom_udta_add_uint_tag (udta, fourcc, 21, (gint) value); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 684 | break; |
| 685 | } |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 686 | case G_TYPE_UINT: |
| 687 | { |
Thiago Santos | ac7f4cb | 2010-06-25 20:19:20 -0300 | [diff] [blame] | 688 | guint value = 0; |
Thiago Santos | 592171b | 2009-12-21 13:58:30 -0300 | [diff] [blame] | 689 | if (tag2) { |
| 690 | /* paired unsigned integers */ |
Thiago Santos | ac7f4cb | 2010-06-25 20:19:20 -0300 | [diff] [blame] | 691 | guint count = 0; |
Mark Nauwelaerts | 57684fe | 2011-10-31 16:18:32 +0100 | [diff] [blame] | 692 | gboolean got_tag; |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 693 | |
Mark Nauwelaerts | 57684fe | 2011-10-31 16:18:32 +0100 | [diff] [blame] | 694 | got_tag = gst_tag_list_get_uint (list, tag, &value); |
| 695 | got_tag = gst_tag_list_get_uint (list, tag2, &count) || got_tag; |
| 696 | if (!got_tag) |
Thiago Santos | 592171b | 2009-12-21 13:58:30 -0300 | [diff] [blame] | 697 | break; |
| 698 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %u/%u", |
| 699 | GST_FOURCC_ARGS (fourcc), value, count); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 700 | atom_udta_add_uint_tag (udta, fourcc, 0, |
Thiago Santos | 592171b | 2009-12-21 13:58:30 -0300 | [diff] [blame] | 701 | value << 16 | (count & 0xFFFF)); |
| 702 | } else { |
| 703 | /* unpaired unsigned integers */ |
| 704 | if (!gst_tag_list_get_uint (list, tag, &value)) |
| 705 | break; |
| 706 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %u", |
| 707 | GST_FOURCC_ARGS (fourcc), value); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 708 | atom_udta_add_uint_tag (udta, fourcc, 1, value); |
Thiago Santos | 592171b | 2009-12-21 13:58:30 -0300 | [diff] [blame] | 709 | } |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 710 | break; |
| 711 | } |
| 712 | default: |
| 713 | g_assert_not_reached (); |
| 714 | break; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | static void |
| 719 | gst_qt_mux_add_mp4_date (GstQTMux * qtmux, const GstTagList * list, |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 720 | AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc) |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 721 | { |
| 722 | GDate *date = NULL; |
| 723 | GDateYear year; |
| 724 | GDateMonth month; |
| 725 | GDateDay day; |
| 726 | gchar *str; |
| 727 | |
Tim-Philipp Müller | d681af8 | 2012-01-12 23:55:31 +0000 | [diff] [blame] | 728 | g_return_if_fail (gst_tag_get_type (tag) == G_TYPE_DATE); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 729 | |
| 730 | if (!gst_tag_list_get_date (list, tag, &date) || !date) |
| 731 | return; |
| 732 | |
| 733 | year = g_date_get_year (date); |
| 734 | month = g_date_get_month (date); |
| 735 | day = g_date_get_day (date); |
| 736 | |
Mark Nauwelaerts | cc526d2 | 2011-06-29 12:05:04 +0200 | [diff] [blame] | 737 | g_date_free (date); |
| 738 | |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 739 | if (year == G_DATE_BAD_YEAR && month == G_DATE_BAD_MONTH && |
| 740 | day == G_DATE_BAD_DAY) { |
| 741 | GST_WARNING_OBJECT (qtmux, "invalid date in tag"); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | str = g_strdup_printf ("%u-%u-%u", year, month, day); |
| 746 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s", |
| 747 | GST_FOURCC_ARGS (fourcc), str); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 748 | atom_udta_add_str_tag (udta, fourcc, str); |
Thiago Sousa Santos | d24d1e4 | 2009-11-17 09:26:05 -0300 | [diff] [blame] | 749 | g_free (str); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | static void |
| 753 | gst_qt_mux_add_mp4_cover (GstQTMux * qtmux, const GstTagList * list, |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 754 | AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc) |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 755 | { |
| 756 | GValue value = { 0, }; |
| 757 | GstBuffer *buf; |
Matej Knopp | 688e820 | 2012-03-07 04:20:00 -0500 | [diff] [blame] | 758 | GstSample *sample; |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 759 | GstCaps *caps; |
| 760 | GstStructure *structure; |
| 761 | gint flags = 0; |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 762 | GstMapInfo map; |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 763 | |
Matej Knopp | 688e820 | 2012-03-07 04:20:00 -0500 | [diff] [blame] | 764 | g_return_if_fail (gst_tag_get_type (tag) == GST_TYPE_SAMPLE); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 765 | |
| 766 | if (!gst_tag_list_copy_value (&value, list, tag)) |
| 767 | return; |
| 768 | |
Matej Knopp | 688e820 | 2012-03-07 04:20:00 -0500 | [diff] [blame] | 769 | sample = gst_value_get_sample (&value); |
| 770 | |
| 771 | if (!sample) |
| 772 | goto done; |
| 773 | |
| 774 | buf = gst_sample_get_buffer (sample); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 775 | if (!buf) |
| 776 | goto done; |
| 777 | |
Matej Knopp | 688e820 | 2012-03-07 04:20:00 -0500 | [diff] [blame] | 778 | caps = gst_sample_get_caps (sample); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 779 | if (!caps) { |
| 780 | GST_WARNING_OBJECT (qtmux, "preview image without caps"); |
| 781 | goto done; |
| 782 | } |
| 783 | |
| 784 | GST_DEBUG_OBJECT (qtmux, "preview image caps %" GST_PTR_FORMAT, caps); |
| 785 | |
| 786 | structure = gst_caps_get_structure (caps, 0); |
| 787 | if (gst_structure_has_name (structure, "image/jpeg")) |
| 788 | flags = 13; |
| 789 | else if (gst_structure_has_name (structure, "image/png")) |
| 790 | flags = 14; |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 791 | |
| 792 | if (!flags) { |
| 793 | GST_WARNING_OBJECT (qtmux, "preview image format not supported"); |
| 794 | goto done; |
| 795 | } |
| 796 | |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 797 | gst_buffer_map (buf, &map, GST_MAP_READ); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 798 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 799 | " -> image size %" G_GSIZE_FORMAT "", GST_FOURCC_ARGS (fourcc), map.size); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 800 | atom_udta_add_tag (udta, fourcc, flags, map.data, map.size); |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 801 | gst_buffer_unmap (buf, &map); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 802 | done: |
| 803 | g_value_unset (&value); |
| 804 | } |
| 805 | |
| 806 | static void |
| 807 | gst_qt_mux_add_3gp_str (GstQTMux * qtmux, const GstTagList * list, |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 808 | AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc) |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 809 | { |
| 810 | gchar *str = NULL; |
| 811 | guint number; |
| 812 | |
| 813 | g_return_if_fail (gst_tag_get_type (tag) == G_TYPE_STRING); |
| 814 | g_return_if_fail (!tag2 || gst_tag_get_type (tag2) == G_TYPE_UINT); |
| 815 | |
| 816 | if (!gst_tag_list_get_string (list, tag, &str) || !str) |
| 817 | return; |
| 818 | |
| 819 | if (tag2) |
| 820 | if (!gst_tag_list_get_uint (list, tag2, &number)) |
| 821 | tag2 = NULL; |
| 822 | |
| 823 | if (!tag2) { |
| 824 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s", |
| 825 | GST_FOURCC_ARGS (fourcc), str); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 826 | atom_udta_add_3gp_str_tag (udta, fourcc, str); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 827 | } else { |
| 828 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s/%d", |
| 829 | GST_FOURCC_ARGS (fourcc), str, number); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 830 | atom_udta_add_3gp_str_int_tag (udta, fourcc, str, number); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | g_free (str); |
| 834 | } |
| 835 | |
| 836 | static void |
| 837 | gst_qt_mux_add_3gp_date (GstQTMux * qtmux, const GstTagList * list, |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 838 | AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc) |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 839 | { |
| 840 | GDate *date = NULL; |
| 841 | GDateYear year; |
| 842 | |
Tim-Philipp Müller | d681af8 | 2012-01-12 23:55:31 +0000 | [diff] [blame] | 843 | g_return_if_fail (gst_tag_get_type (tag) == G_TYPE_DATE); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 844 | |
| 845 | if (!gst_tag_list_get_date (list, tag, &date) || !date) |
| 846 | return; |
| 847 | |
| 848 | year = g_date_get_year (date); |
| 849 | |
| 850 | if (year == G_DATE_BAD_YEAR) { |
| 851 | GST_WARNING_OBJECT (qtmux, "invalid date in tag"); |
| 852 | return; |
| 853 | } |
| 854 | |
Edward Hervey | 430953e | 2009-06-25 08:38:10 +0200 | [diff] [blame] | 855 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %d", |
| 856 | GST_FOURCC_ARGS (fourcc), year); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 857 | atom_udta_add_3gp_uint_tag (udta, fourcc, year); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static void |
| 861 | gst_qt_mux_add_3gp_location (GstQTMux * qtmux, const GstTagList * list, |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 862 | AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc) |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 863 | { |
| 864 | gdouble latitude = -360, longitude = -360, altitude = 0; |
| 865 | gchar *location = NULL; |
| 866 | guint8 *data, *ddata; |
| 867 | gint size = 0, len = 0; |
| 868 | gboolean ret = FALSE; |
| 869 | |
| 870 | g_return_if_fail (strcmp (tag, GST_TAG_GEO_LOCATION_NAME) == 0); |
| 871 | |
| 872 | ret = gst_tag_list_get_string (list, tag, &location); |
| 873 | ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_LONGITUDE, |
| 874 | &longitude); |
| 875 | ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_LATITUDE, |
| 876 | &latitude); |
| 877 | ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_ELEVATION, |
| 878 | &altitude); |
| 879 | |
| 880 | if (!ret) |
| 881 | return; |
| 882 | |
| 883 | if (location) |
| 884 | len = strlen (location); |
| 885 | size += len + 1 + 2; |
| 886 | |
| 887 | /* role + (long, lat, alt) + body + notes */ |
| 888 | size += 1 + 3 * 4 + 1 + 1; |
| 889 | |
| 890 | data = ddata = g_malloc (size); |
| 891 | |
| 892 | /* language tag */ |
| 893 | GST_WRITE_UINT16_BE (data, language_code (GST_QT_MUX_DEFAULT_TAG_LANGUAGE)); |
| 894 | /* location */ |
| 895 | if (location) |
| 896 | memcpy (data + 2, location, len); |
| 897 | GST_WRITE_UINT8 (data + 2 + len, 0); |
| 898 | data += len + 1 + 2; |
| 899 | /* role */ |
| 900 | GST_WRITE_UINT8 (data, 0); |
| 901 | /* long, lat, alt */ |
Edward Hervey | cca48a4 | 2011-05-05 13:24:23 +0200 | [diff] [blame] | 902 | #define QT_WRITE_SFP32(data, fp) GST_WRITE_UINT32_BE(data, (guint32) ((gint) (fp * 65536.0))) |
| 903 | QT_WRITE_SFP32 (data + 1, longitude); |
| 904 | QT_WRITE_SFP32 (data + 5, latitude); |
| 905 | QT_WRITE_SFP32 (data + 9, altitude); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 906 | /* neither astronomical body nor notes */ |
| 907 | GST_WRITE_UINT16_BE (data + 13, 0); |
| 908 | |
| 909 | GST_DEBUG_OBJECT (qtmux, "Adding tag 'loci'"); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 910 | atom_udta_add_3gp_tag (udta, fourcc, ddata, size); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 911 | g_free (ddata); |
| 912 | } |
| 913 | |
| 914 | static void |
| 915 | gst_qt_mux_add_3gp_keywords (GstQTMux * qtmux, const GstTagList * list, |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 916 | AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc) |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 917 | { |
| 918 | gchar *keywords = NULL; |
| 919 | guint8 *data, *ddata; |
| 920 | gint size = 0, i; |
| 921 | gchar **kwds; |
| 922 | |
| 923 | g_return_if_fail (strcmp (tag, GST_TAG_KEYWORDS) == 0); |
| 924 | |
| 925 | if (!gst_tag_list_get_string (list, tag, &keywords) || !keywords) |
| 926 | return; |
| 927 | |
| 928 | kwds = g_strsplit (keywords, ",", 0); |
Sebastian Dröge | 6e350ec | 2010-12-19 12:50:30 +0100 | [diff] [blame] | 929 | g_free (keywords); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 930 | |
| 931 | size = 0; |
| 932 | for (i = 0; kwds[i]; i++) { |
| 933 | /* size byte + null-terminator */ |
| 934 | size += strlen (kwds[i]) + 1 + 1; |
| 935 | } |
| 936 | |
| 937 | /* language tag + count + keywords */ |
| 938 | size += 2 + 1; |
| 939 | |
| 940 | data = ddata = g_malloc (size); |
| 941 | |
| 942 | /* language tag */ |
| 943 | GST_WRITE_UINT16_BE (data, language_code (GST_QT_MUX_DEFAULT_TAG_LANGUAGE)); |
| 944 | /* count */ |
| 945 | GST_WRITE_UINT8 (data + 2, i); |
| 946 | data += 3; |
| 947 | /* keywords */ |
| 948 | for (i = 0; kwds[i]; ++i) { |
| 949 | gint len = strlen (kwds[i]); |
| 950 | |
| 951 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s", |
| 952 | GST_FOURCC_ARGS (fourcc), kwds[i]); |
| 953 | /* size */ |
| 954 | GST_WRITE_UINT8 (data, len + 1); |
| 955 | memcpy (data + 1, kwds[i], len + 1); |
| 956 | data += len + 2; |
| 957 | } |
| 958 | |
| 959 | g_strfreev (kwds); |
| 960 | |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 961 | atom_udta_add_3gp_tag (udta, fourcc, ddata, size); |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 962 | g_free (ddata); |
| 963 | } |
| 964 | |
Thiago Santos | 083f825 | 2009-12-10 16:53:19 -0300 | [diff] [blame] | 965 | static gboolean |
| 966 | gst_qt_mux_parse_classification_string (GstQTMux * qtmux, const gchar * input, |
| 967 | guint32 * p_fourcc, guint16 * p_table, gchar ** p_content) |
| 968 | { |
| 969 | guint32 fourcc; |
| 970 | gint table; |
| 971 | gint size; |
| 972 | const gchar *data; |
| 973 | |
| 974 | data = input; |
| 975 | size = strlen (input); |
| 976 | |
| 977 | if (size < 4 + 3 + 1 + 1 + 1) { |
| 978 | /* at least the minimum xxxx://y/z */ |
| 979 | GST_WARNING_OBJECT (qtmux, "Classification tag input (%s) too short, " |
| 980 | "ignoring", input); |
| 981 | return FALSE; |
| 982 | } |
| 983 | |
| 984 | /* read the fourcc */ |
| 985 | memcpy (&fourcc, data, 4); |
| 986 | size -= 4; |
| 987 | data += 4; |
| 988 | |
| 989 | if (strncmp (data, "://", 3) != 0) { |
| 990 | goto mismatch; |
| 991 | } |
| 992 | data += 3; |
| 993 | size -= 3; |
| 994 | |
| 995 | /* read the table number */ |
| 996 | if (sscanf (data, "%d", &table) != 1) { |
| 997 | goto mismatch; |
| 998 | } |
| 999 | if (table < 0) { |
| 1000 | GST_WARNING_OBJECT (qtmux, "Invalid table number in classification tag (%d)" |
| 1001 | ", table numbers should be positive, ignoring tag", table); |
| 1002 | return FALSE; |
| 1003 | } |
| 1004 | |
| 1005 | /* find the next / */ |
| 1006 | while (size > 0 && data[0] != '/') { |
| 1007 | data += 1; |
| 1008 | size -= 1; |
| 1009 | } |
| 1010 | if (size == 0) { |
| 1011 | goto mismatch; |
| 1012 | } |
| 1013 | g_assert (data[0] == '/'); |
| 1014 | |
| 1015 | /* skip the '/' */ |
| 1016 | data += 1; |
| 1017 | size -= 1; |
| 1018 | if (size == 0) { |
| 1019 | goto mismatch; |
| 1020 | } |
| 1021 | |
| 1022 | /* read up the rest of the string */ |
| 1023 | *p_content = g_strdup (data); |
| 1024 | *p_table = (guint16) table; |
| 1025 | *p_fourcc = fourcc; |
| 1026 | return TRUE; |
| 1027 | |
| 1028 | mismatch: |
| 1029 | { |
| 1030 | GST_WARNING_OBJECT (qtmux, "Ignoring classification tag as " |
| 1031 | "input (%s) didn't match the expected entitycode://table/content", |
| 1032 | input); |
| 1033 | return FALSE; |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | static void |
| 1038 | gst_qt_mux_add_3gp_classification (GstQTMux * qtmux, const GstTagList * list, |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1039 | AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc) |
Thiago Santos | 083f825 | 2009-12-10 16:53:19 -0300 | [diff] [blame] | 1040 | { |
| 1041 | gchar *clsf_data = NULL; |
| 1042 | gint size = 0; |
| 1043 | guint32 entity = 0; |
| 1044 | guint16 table = 0; |
| 1045 | gchar *content = NULL; |
| 1046 | guint8 *data; |
| 1047 | |
| 1048 | g_return_if_fail (strcmp (tag, GST_TAG_3GP_CLASSIFICATION) == 0); |
| 1049 | |
| 1050 | if (!gst_tag_list_get_string (list, tag, &clsf_data) || !clsf_data) |
| 1051 | return; |
| 1052 | |
| 1053 | GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s", |
| 1054 | GST_FOURCC_ARGS (fourcc), clsf_data); |
| 1055 | |
| 1056 | /* parse the string, format is: |
| 1057 | * entityfourcc://table/content |
| 1058 | */ |
| 1059 | gst_qt_mux_parse_classification_string (qtmux, clsf_data, &entity, &table, |
| 1060 | &content); |
| 1061 | g_free (clsf_data); |
| 1062 | /* +1 for the \0 */ |
| 1063 | size = strlen (content) + 1; |
| 1064 | |
| 1065 | /* now we have everything, build the atom |
| 1066 | * atom description is at 3GPP TS 26.244 V8.2.0 (2009-09) */ |
| 1067 | data = g_malloc (4 + 2 + 2 + size); |
| 1068 | GST_WRITE_UINT32_LE (data, entity); |
| 1069 | GST_WRITE_UINT16_BE (data + 4, (guint16) table); |
| 1070 | GST_WRITE_UINT16_BE (data + 6, 0); |
| 1071 | memcpy (data + 8, content, size); |
| 1072 | g_free (content); |
| 1073 | |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1074 | atom_udta_add_3gp_tag (udta, fourcc, data, 4 + 2 + 2 + size); |
Thiago Santos | 083f825 | 2009-12-10 16:53:19 -0300 | [diff] [blame] | 1075 | g_free (data); |
| 1076 | } |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1077 | |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1078 | typedef void (*GstQTMuxAddUdtaTagFunc) (GstQTMux * mux, |
| 1079 | const GstTagList * list, AtomUDTA * udta, const char *tag, |
| 1080 | const char *tag2, guint32 fourcc); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1081 | |
| 1082 | /* |
| 1083 | * Struct to record mappings from gstreamer tags to fourcc codes |
| 1084 | */ |
| 1085 | typedef struct _GstTagToFourcc |
| 1086 | { |
| 1087 | guint32 fourcc; |
| 1088 | const gchar *gsttag; |
| 1089 | const gchar *gsttag2; |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1090 | const GstQTMuxAddUdtaTagFunc func; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1091 | } GstTagToFourcc; |
| 1092 | |
| 1093 | /* tag list tags to fourcc matching */ |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1094 | static const GstTagToFourcc tag_matches_mp4[] = { |
| 1095 | {FOURCC__alb, GST_TAG_ALBUM, NULL, gst_qt_mux_add_mp4_tag}, |
Thiago Santos | 9a6514e | 2009-12-21 12:05:37 -0300 | [diff] [blame] | 1096 | {FOURCC_soal, GST_TAG_ALBUM_SORTNAME, NULL, gst_qt_mux_add_mp4_tag}, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1097 | {FOURCC__ART, GST_TAG_ARTIST, NULL, gst_qt_mux_add_mp4_tag}, |
Thiago Santos | 9a6514e | 2009-12-21 12:05:37 -0300 | [diff] [blame] | 1098 | {FOURCC_soar, GST_TAG_ARTIST_SORTNAME, NULL, gst_qt_mux_add_mp4_tag}, |
| 1099 | {FOURCC_aART, GST_TAG_ALBUM_ARTIST, NULL, gst_qt_mux_add_mp4_tag}, |
| 1100 | {FOURCC_soaa, GST_TAG_ALBUM_ARTIST_SORTNAME, NULL, gst_qt_mux_add_mp4_tag}, |
Thiago Santos | f0fde8b | 2015-01-31 10:47:40 -0300 | [diff] [blame] | 1101 | {FOURCC__swr, GST_TAG_APPLICATION_NAME, NULL, gst_qt_mux_add_mp4_tag}, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1102 | {FOURCC__cmt, GST_TAG_COMMENT, NULL, gst_qt_mux_add_mp4_tag}, |
| 1103 | {FOURCC__wrt, GST_TAG_COMPOSER, NULL, gst_qt_mux_add_mp4_tag}, |
Thiago Santos | 9a6514e | 2009-12-21 12:05:37 -0300 | [diff] [blame] | 1104 | {FOURCC_soco, GST_TAG_COMPOSER_SORTNAME, NULL, gst_qt_mux_add_mp4_tag}, |
| 1105 | {FOURCC_tvsh, GST_TAG_SHOW_NAME, NULL, gst_qt_mux_add_mp4_tag}, |
| 1106 | {FOURCC_sosn, GST_TAG_SHOW_SORTNAME, NULL, gst_qt_mux_add_mp4_tag}, |
| 1107 | {FOURCC_tvsn, GST_TAG_SHOW_SEASON_NUMBER, NULL, gst_qt_mux_add_mp4_tag}, |
| 1108 | {FOURCC_tves, GST_TAG_SHOW_EPISODE_NUMBER, NULL, gst_qt_mux_add_mp4_tag}, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1109 | {FOURCC__gen, GST_TAG_GENRE, NULL, gst_qt_mux_add_mp4_tag}, |
| 1110 | {FOURCC__nam, GST_TAG_TITLE, NULL, gst_qt_mux_add_mp4_tag}, |
Thiago Santos | 9a6514e | 2009-12-21 12:05:37 -0300 | [diff] [blame] | 1111 | {FOURCC_sonm, GST_TAG_TITLE_SORTNAME, NULL, gst_qt_mux_add_mp4_tag}, |
| 1112 | {FOURCC_perf, GST_TAG_PERFORMER, NULL, gst_qt_mux_add_mp4_tag}, |
| 1113 | {FOURCC__grp, GST_TAG_GROUPING, NULL, gst_qt_mux_add_mp4_tag}, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1114 | {FOURCC__des, GST_TAG_DESCRIPTION, NULL, gst_qt_mux_add_mp4_tag}, |
Thiago Santos | 9a6514e | 2009-12-21 12:05:37 -0300 | [diff] [blame] | 1115 | {FOURCC__lyr, GST_TAG_LYRICS, NULL, gst_qt_mux_add_mp4_tag}, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1116 | {FOURCC__too, GST_TAG_ENCODER, NULL, gst_qt_mux_add_mp4_tag}, |
| 1117 | {FOURCC_cprt, GST_TAG_COPYRIGHT, NULL, gst_qt_mux_add_mp4_tag}, |
| 1118 | {FOURCC_keyw, GST_TAG_KEYWORDS, NULL, gst_qt_mux_add_mp4_tag}, |
| 1119 | {FOURCC__day, GST_TAG_DATE, NULL, gst_qt_mux_add_mp4_date}, |
| 1120 | {FOURCC_tmpo, GST_TAG_BEATS_PER_MINUTE, NULL, gst_qt_mux_add_mp4_tag}, |
| 1121 | {FOURCC_trkn, GST_TAG_TRACK_NUMBER, GST_TAG_TRACK_COUNT, |
| 1122 | gst_qt_mux_add_mp4_tag}, |
| 1123 | {FOURCC_disk, GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_ALBUM_VOLUME_COUNT, |
| 1124 | gst_qt_mux_add_mp4_tag}, |
| 1125 | {FOURCC_covr, GST_TAG_PREVIEW_IMAGE, NULL, gst_qt_mux_add_mp4_cover}, |
Antonio Frediani | 63d350c | 2011-05-30 12:09:31 +0200 | [diff] [blame] | 1126 | {FOURCC_covr, GST_TAG_IMAGE, NULL, gst_qt_mux_add_mp4_cover}, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1127 | {0, NULL,} |
| 1128 | }; |
| 1129 | |
| 1130 | static const GstTagToFourcc tag_matches_3gp[] = { |
| 1131 | {FOURCC_titl, GST_TAG_TITLE, NULL, gst_qt_mux_add_3gp_str}, |
| 1132 | {FOURCC_dscp, GST_TAG_DESCRIPTION, NULL, gst_qt_mux_add_3gp_str}, |
| 1133 | {FOURCC_cprt, GST_TAG_COPYRIGHT, NULL, gst_qt_mux_add_3gp_str}, |
| 1134 | {FOURCC_perf, GST_TAG_ARTIST, NULL, gst_qt_mux_add_3gp_str}, |
| 1135 | {FOURCC_auth, GST_TAG_COMPOSER, NULL, gst_qt_mux_add_3gp_str}, |
| 1136 | {FOURCC_gnre, GST_TAG_GENRE, NULL, gst_qt_mux_add_3gp_str}, |
| 1137 | {FOURCC_kywd, GST_TAG_KEYWORDS, NULL, gst_qt_mux_add_3gp_keywords}, |
| 1138 | {FOURCC_yrrc, GST_TAG_DATE, NULL, gst_qt_mux_add_3gp_date}, |
| 1139 | {FOURCC_albm, GST_TAG_ALBUM, GST_TAG_TRACK_NUMBER, gst_qt_mux_add_3gp_str}, |
| 1140 | {FOURCC_loci, GST_TAG_GEO_LOCATION_NAME, NULL, gst_qt_mux_add_3gp_location}, |
Thiago Santos | 083f825 | 2009-12-10 16:53:19 -0300 | [diff] [blame] | 1141 | {FOURCC_clsf, GST_TAG_3GP_CLASSIFICATION, NULL, |
| 1142 | gst_qt_mux_add_3gp_classification}, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1143 | {0, NULL,} |
| 1144 | }; |
| 1145 | |
| 1146 | /* qtdemux produces these for atoms it cannot parse */ |
| 1147 | #define GST_QT_DEMUX_PRIVATE_TAG "private-qt-tag" |
| 1148 | |
| 1149 | static void |
Thiago Santos | a740adc | 2010-02-22 16:45:34 -0300 | [diff] [blame] | 1150 | gst_qt_mux_add_xmp_tags (GstQTMux * qtmux, const GstTagList * list) |
| 1151 | { |
| 1152 | GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux)); |
Thiago Santos | aba8000 | 2011-03-21 10:56:51 -0300 | [diff] [blame] | 1153 | GstBuffer *xmp = NULL; |
Thiago Santos | a740adc | 2010-02-22 16:45:34 -0300 | [diff] [blame] | 1154 | |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 1155 | /* adobe specs only have 'quicktime' and 'mp4', |
| 1156 | * but I guess we can extrapolate to gpp. |
| 1157 | * Keep mj2 out for now as we don't add any tags for it yet. |
Thiago Santos | 281ef57 | 2010-03-12 10:53:36 -0300 | [diff] [blame] | 1158 | * If you have further info about xmp on these formats, please share */ |
| 1159 | if (qtmux_klass->format == GST_QT_MUX_FORMAT_MJ2) |
| 1160 | return; |
Thiago Santos | a740adc | 2010-02-22 16:45:34 -0300 | [diff] [blame] | 1161 | |
| 1162 | GST_DEBUG_OBJECT (qtmux, "Adding xmp tags"); |
| 1163 | |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 1164 | if (qtmux_klass->format == GST_QT_MUX_FORMAT_QT) { |
Thiago Santos | aba8000 | 2011-03-21 10:56:51 -0300 | [diff] [blame] | 1165 | xmp = gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER (qtmux), |
| 1166 | list, TRUE); |
| 1167 | if (xmp) |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1168 | atom_udta_add_xmp_tags (&qtmux->moov->udta, xmp); |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 1169 | } else { |
Thiago Santos | aba8000 | 2011-03-21 10:56:51 -0300 | [diff] [blame] | 1170 | AtomInfo *ainfo; |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 1171 | /* for isom/mp4, it is a top level uuid atom */ |
Thiago Santos | aba8000 | 2011-03-21 10:56:51 -0300 | [diff] [blame] | 1172 | xmp = gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER (qtmux), |
| 1173 | list, TRUE); |
| 1174 | if (xmp) { |
| 1175 | ainfo = build_uuid_xmp_atom (xmp); |
| 1176 | if (ainfo) { |
| 1177 | qtmux->extra_atoms = g_slist_prepend (qtmux->extra_atoms, ainfo); |
| 1178 | } |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 1179 | } |
| 1180 | } |
Thiago Santos | aba8000 | 2011-03-21 10:56:51 -0300 | [diff] [blame] | 1181 | if (xmp) |
| 1182 | gst_buffer_unref (xmp); |
Thiago Santos | a740adc | 2010-02-22 16:45:34 -0300 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | static void |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1186 | gst_qt_mux_add_metadata_tags (GstQTMux * qtmux, const GstTagList * list, |
| 1187 | AtomUDTA * udta) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1188 | { |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1189 | GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1190 | guint32 fourcc; |
| 1191 | gint i; |
| 1192 | const gchar *tag, *tag2; |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1193 | const GstTagToFourcc *tag_matches; |
| 1194 | |
| 1195 | switch (qtmux_klass->format) { |
| 1196 | case GST_QT_MUX_FORMAT_3GP: |
| 1197 | tag_matches = tag_matches_3gp; |
| 1198 | break; |
| 1199 | case GST_QT_MUX_FORMAT_MJ2: |
| 1200 | tag_matches = NULL; |
| 1201 | break; |
| 1202 | default: |
| 1203 | /* sort of iTunes style for mp4 and QT (?) */ |
| 1204 | tag_matches = tag_matches_mp4; |
| 1205 | break; |
| 1206 | } |
| 1207 | |
| 1208 | if (!tag_matches) |
| 1209 | return; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1210 | |
| 1211 | for (i = 0; tag_matches[i].fourcc; i++) { |
| 1212 | fourcc = tag_matches[i].fourcc; |
| 1213 | tag = tag_matches[i].gsttag; |
| 1214 | tag2 = tag_matches[i].gsttag2; |
| 1215 | |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1216 | g_assert (tag_matches[i].func); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1217 | tag_matches[i].func (qtmux, list, udta, tag, tag2, fourcc); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | /* add unparsed blobs if present */ |
| 1221 | if (gst_tag_exists (GST_QT_DEMUX_PRIVATE_TAG)) { |
| 1222 | guint num_tags; |
| 1223 | |
| 1224 | num_tags = gst_tag_list_get_tag_size (list, GST_QT_DEMUX_PRIVATE_TAG); |
| 1225 | for (i = 0; i < num_tags; ++i) { |
Mark Nauwelaerts | dd25411 | 2012-07-27 12:05:44 +0200 | [diff] [blame] | 1226 | GstSample *sample = NULL; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1227 | GstBuffer *buf; |
Mark Nauwelaerts | dd25411 | 2012-07-27 12:05:44 +0200 | [diff] [blame] | 1228 | const GstStructure *s; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1229 | |
Mark Nauwelaerts | dd25411 | 2012-07-27 12:05:44 +0200 | [diff] [blame] | 1230 | if (!gst_tag_list_get_sample_index (list, GST_QT_DEMUX_PRIVATE_TAG, i, |
| 1231 | &sample)) |
| 1232 | continue; |
| 1233 | buf = gst_sample_get_buffer (sample); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1234 | |
Mark Nauwelaerts | dd25411 | 2012-07-27 12:05:44 +0200 | [diff] [blame] | 1235 | if (buf && (s = gst_sample_get_info (sample))) { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1236 | const gchar *style = NULL; |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1237 | GstMapInfo map; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1238 | |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1239 | gst_buffer_map (buf, &map, GST_MAP_READ); |
Matej Knopp | 1e5dd9e | 2011-11-21 20:31:31 +0100 | [diff] [blame] | 1240 | GST_DEBUG_OBJECT (qtmux, |
Mark Nauwelaerts | dd25411 | 2012-07-27 12:05:44 +0200 | [diff] [blame] | 1241 | "Found private tag %d/%d; size %" G_GSIZE_FORMAT ", info %" |
| 1242 | GST_PTR_FORMAT, i, num_tags, map.size, s); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1243 | if (s && (style = gst_structure_get_string (s, "style"))) { |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1244 | /* try to prevent some style tag ending up into another variant |
| 1245 | * (todo: make into a list if more cases) */ |
| 1246 | if ((strcmp (style, "itunes") == 0 && |
| 1247 | qtmux_klass->format == GST_QT_MUX_FORMAT_MP4) || |
| 1248 | (strcmp (style, "iso") == 0 && |
| 1249 | qtmux_klass->format == GST_QT_MUX_FORMAT_3GP)) { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1250 | GST_DEBUG_OBJECT (qtmux, "Adding private tag"); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1251 | atom_udta_add_blob_tag (udta, map.data, map.size); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1252 | } |
| 1253 | } |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1254 | gst_buffer_unmap (buf, &map); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | /* |
| 1263 | * Gets the tagsetter iface taglist and puts the known tags |
| 1264 | * into the output stream |
| 1265 | */ |
| 1266 | static void |
| 1267 | gst_qt_mux_setup_metadata (GstQTMux * qtmux) |
| 1268 | { |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 1269 | const GstTagList *tags; |
Thiago Santos | e52b2cb | 2015-01-31 14:32:34 -0300 | [diff] [blame] | 1270 | GSList *walk; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1271 | |
Michael Smith | 8b3aca9 | 2010-02-26 11:50:25 -0800 | [diff] [blame] | 1272 | GST_OBJECT_LOCK (qtmux); |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 1273 | tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (qtmux)); |
Michael Smith | 8b3aca9 | 2010-02-26 11:50:25 -0800 | [diff] [blame] | 1274 | GST_OBJECT_UNLOCK (qtmux); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1275 | |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 1276 | GST_LOG_OBJECT (qtmux, "tags: %" GST_PTR_FORMAT, tags); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1277 | |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 1278 | if (tags && !gst_tag_list_is_empty (tags)) { |
Edward Hervey | 099ad63 | 2010-07-02 12:45:20 +0200 | [diff] [blame] | 1279 | GstTagList *copy = gst_tag_list_copy (tags); |
| 1280 | |
| 1281 | GST_DEBUG_OBJECT (qtmux, "Removing bogus tags"); |
| 1282 | gst_tag_list_remove_tag (copy, GST_TAG_VIDEO_CODEC); |
| 1283 | gst_tag_list_remove_tag (copy, GST_TAG_AUDIO_CODEC); |
| 1284 | gst_tag_list_remove_tag (copy, GST_TAG_CONTAINER_FORMAT); |
| 1285 | |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 1286 | GST_DEBUG_OBJECT (qtmux, "Formatting tags"); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1287 | gst_qt_mux_add_metadata_tags (qtmux, copy, &qtmux->moov->udta); |
Edward Hervey | 099ad63 | 2010-07-02 12:45:20 +0200 | [diff] [blame] | 1288 | gst_qt_mux_add_xmp_tags (qtmux, copy); |
Tim-Philipp Müller | c074bfd | 2012-08-04 16:10:16 +0100 | [diff] [blame] | 1289 | gst_tag_list_unref (copy); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1290 | } else { |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 1291 | GST_DEBUG_OBJECT (qtmux, "No tags received"); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1292 | } |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1293 | |
Thiago Santos | e52b2cb | 2015-01-31 14:32:34 -0300 | [diff] [blame] | 1294 | for (walk = qtmux->sinkpads; walk; walk = g_slist_next (walk)) { |
| 1295 | GstCollectData *cdata = (GstCollectData *) walk->data; |
| 1296 | GstQTPad *qpad = (GstQTPad *) cdata; |
| 1297 | GstPad *pad = qpad->collect.pad; |
| 1298 | |
| 1299 | if (qpad->tags) { |
| 1300 | GST_DEBUG_OBJECT (pad, "Adding tags"); |
| 1301 | gst_tag_list_remove_tag (qpad->tags, GST_TAG_CONTAINER_FORMAT); |
| 1302 | gst_qt_mux_add_metadata_tags (qtmux, qpad->tags, &qpad->trak->udta); |
| 1303 | GST_DEBUG_OBJECT (pad, "Tags added"); |
| 1304 | } else { |
| 1305 | GST_DEBUG_OBJECT (pad, "No tags received"); |
| 1306 | } |
| 1307 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
Mark Nauwelaerts | 79f565f | 2010-11-09 15:01:15 +0100 | [diff] [blame] | 1310 | static inline GstBuffer * |
| 1311 | _gst_buffer_new_take_data (guint8 * data, guint size) |
| 1312 | { |
| 1313 | GstBuffer *buf; |
| 1314 | |
| 1315 | buf = gst_buffer_new (); |
Wim Taymans | 3d61d12 | 2012-03-30 18:13:08 +0200 | [diff] [blame] | 1316 | gst_buffer_append_memory (buf, |
Wim Taymans | ca9532c | 2012-02-22 02:06:17 +0100 | [diff] [blame] | 1317 | gst_memory_new_wrapped (0, data, size, 0, size, data, g_free)); |
Mark Nauwelaerts | 79f565f | 2010-11-09 15:01:15 +0100 | [diff] [blame] | 1318 | |
| 1319 | return buf; |
| 1320 | } |
| 1321 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1322 | static GstFlowReturn |
| 1323 | gst_qt_mux_send_buffer (GstQTMux * qtmux, GstBuffer * buf, guint64 * offset, |
| 1324 | gboolean mind_fast) |
| 1325 | { |
| 1326 | GstFlowReturn res; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1327 | gsize size; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1328 | |
| 1329 | g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR); |
| 1330 | |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1331 | size = gst_buffer_get_size (buf); |
Matej Knopp | 1e5dd9e | 2011-11-21 20:31:31 +0100 | [diff] [blame] | 1332 | GST_LOG_OBJECT (qtmux, "sending buffer size %" G_GSIZE_FORMAT, size); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1333 | |
| 1334 | if (mind_fast && qtmux->fast_start_file) { |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1335 | GstMapInfo map; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1336 | gint ret; |
| 1337 | |
| 1338 | GST_LOG_OBJECT (qtmux, "to temporary file"); |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1339 | gst_buffer_map (buf, &map, GST_MAP_READ); |
| 1340 | ret = fwrite (map.data, sizeof (guint8), map.size, qtmux->fast_start_file); |
| 1341 | gst_buffer_unmap (buf, &map); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1342 | gst_buffer_unref (buf); |
| 1343 | if (ret != size) |
| 1344 | goto write_error; |
| 1345 | else |
| 1346 | res = GST_FLOW_OK; |
| 1347 | } else { |
| 1348 | GST_LOG_OBJECT (qtmux, "downstream"); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1349 | res = gst_pad_push (qtmux->srcpad, buf); |
| 1350 | } |
| 1351 | |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1352 | if (G_LIKELY (offset)) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1353 | *offset += size; |
| 1354 | |
| 1355 | return res; |
| 1356 | |
| 1357 | /* ERRORS */ |
| 1358 | write_error: |
| 1359 | { |
| 1360 | GST_ELEMENT_ERROR (qtmux, RESOURCE, WRITE, |
| 1361 | ("Failed to write to temporary file"), GST_ERROR_SYSTEM); |
| 1362 | return GST_FLOW_ERROR; |
| 1363 | } |
| 1364 | } |
| 1365 | |
Marc-André Lureau | c2718fd | 2009-09-30 17:16:30 +0200 | [diff] [blame] | 1366 | static gboolean |
| 1367 | gst_qt_mux_seek_to_beginning (FILE * f) |
| 1368 | { |
| 1369 | #ifdef HAVE_FSEEKO |
| 1370 | if (fseeko (f, (off_t) 0, SEEK_SET) != 0) |
| 1371 | return FALSE; |
| 1372 | #elif defined (G_OS_UNIX) || defined (G_OS_WIN32) |
| 1373 | if (lseek (fileno (f), (off_t) 0, SEEK_SET) == (off_t) - 1) |
| 1374 | return FALSE; |
| 1375 | #else |
| 1376 | if (fseek (f, (long) 0, SEEK_SET) != 0) |
| 1377 | return FALSE; |
| 1378 | #endif |
| 1379 | return TRUE; |
| 1380 | } |
| 1381 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1382 | static GstFlowReturn |
| 1383 | gst_qt_mux_send_buffered_data (GstQTMux * qtmux, guint64 * offset) |
| 1384 | { |
| 1385 | GstFlowReturn ret = GST_FLOW_OK; |
| 1386 | GstBuffer *buf = NULL; |
| 1387 | |
| 1388 | if (fflush (qtmux->fast_start_file)) |
| 1389 | goto flush_failed; |
| 1390 | |
Marc-André Lureau | c2718fd | 2009-09-30 17:16:30 +0200 | [diff] [blame] | 1391 | if (!gst_qt_mux_seek_to_beginning (qtmux->fast_start_file)) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1392 | goto seek_failed; |
| 1393 | |
| 1394 | /* hm, this could all take a really really long time, |
| 1395 | * but there may not be another way to get moov atom first |
| 1396 | * (somehow optimize copy?) */ |
| 1397 | GST_DEBUG_OBJECT (qtmux, "Sending buffered data"); |
| 1398 | while (ret == GST_FLOW_OK) { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1399 | const int bufsize = 4096; |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1400 | GstMapInfo map; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1401 | gsize size; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1402 | |
| 1403 | buf = gst_buffer_new_and_alloc (bufsize); |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1404 | gst_buffer_map (buf, &map, GST_MAP_WRITE); |
| 1405 | size = fread (map.data, sizeof (guint8), bufsize, qtmux->fast_start_file); |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1406 | if (size == 0) { |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1407 | gst_buffer_unmap (buf, &map); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1408 | break; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1409 | } |
Michael Smith | b85c5f2 | 2013-03-19 18:09:31 -0700 | [diff] [blame] | 1410 | GST_LOG_OBJECT (qtmux, "Pushing buffered buffer of size %d", (gint) size); |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1411 | gst_buffer_unmap (buf, &map); |
Michael Smith | b85c5f2 | 2013-03-19 18:09:31 -0700 | [diff] [blame] | 1412 | if (size != bufsize) |
| 1413 | gst_buffer_set_size (buf, size); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1414 | ret = gst_qt_mux_send_buffer (qtmux, buf, offset, FALSE); |
| 1415 | buf = NULL; |
| 1416 | } |
| 1417 | if (buf) |
| 1418 | gst_buffer_unref (buf); |
| 1419 | |
Marc-André Lureau | c2718fd | 2009-09-30 17:16:30 +0200 | [diff] [blame] | 1420 | if (ftruncate (fileno (qtmux->fast_start_file), 0)) |
| 1421 | goto seek_failed; |
| 1422 | if (!gst_qt_mux_seek_to_beginning (qtmux->fast_start_file)) |
| 1423 | goto seek_failed; |
| 1424 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1425 | return ret; |
| 1426 | |
| 1427 | /* ERRORS */ |
| 1428 | flush_failed: |
| 1429 | { |
| 1430 | GST_ELEMENT_ERROR (qtmux, RESOURCE, WRITE, |
| 1431 | ("Failed to flush temporary file"), GST_ERROR_SYSTEM); |
| 1432 | ret = GST_FLOW_ERROR; |
Mark Nauwelaerts | c350744 | 2010-11-05 11:08:01 +0100 | [diff] [blame] | 1433 | goto fail; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1434 | } |
| 1435 | seek_failed: |
| 1436 | { |
| 1437 | GST_ELEMENT_ERROR (qtmux, RESOURCE, SEEK, |
| 1438 | ("Failed to seek temporary file"), GST_ERROR_SYSTEM); |
| 1439 | ret = GST_FLOW_ERROR; |
Mark Nauwelaerts | c350744 | 2010-11-05 11:08:01 +0100 | [diff] [blame] | 1440 | goto fail; |
| 1441 | } |
| 1442 | fail: |
| 1443 | { |
| 1444 | /* clear descriptor so we don't remove temp file later on, |
| 1445 | * might be possible to recover */ |
| 1446 | fclose (qtmux->fast_start_file); |
| 1447 | qtmux->fast_start_file = NULL; |
Marc-André Lureau | 3e6a415 | 2009-09-28 16:53:51 +0200 | [diff] [blame] | 1448 | return ret; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | /* |
| 1453 | * Sends the initial mdat atom fields (size fields and fourcc type), |
| 1454 | * the subsequent buffers are considered part of it's data. |
| 1455 | * As we can't predict the amount of data that we are going to place in mdat |
| 1456 | * we need to record the position of the size field in the stream so we can |
| 1457 | * seek back to it later and update when the streams have finished. |
| 1458 | */ |
| 1459 | static GstFlowReturn |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1460 | gst_qt_mux_send_mdat_header (GstQTMux * qtmux, guint64 * off, guint64 size, |
| 1461 | gboolean extended) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1462 | { |
| 1463 | Atom *node_header; |
| 1464 | GstBuffer *buf; |
| 1465 | guint8 *data = NULL; |
| 1466 | guint64 offset = 0; |
| 1467 | |
| 1468 | GST_DEBUG_OBJECT (qtmux, "Sending mdat's atom header, " |
| 1469 | "size %" G_GUINT64_FORMAT, size); |
| 1470 | |
| 1471 | node_header = g_malloc0 (sizeof (Atom)); |
| 1472 | node_header->type = FOURCC_mdat; |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1473 | if (extended) { |
| 1474 | /* use extended size */ |
| 1475 | node_header->size = 1; |
| 1476 | node_header->extended_size = 0; |
| 1477 | if (size) |
| 1478 | node_header->extended_size = size + 16; |
| 1479 | } else { |
| 1480 | node_header->size = size + 8; |
| 1481 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1482 | |
| 1483 | size = offset = 0; |
| 1484 | if (atom_copy_data (node_header, &data, &size, &offset) == 0) |
| 1485 | goto serialize_error; |
| 1486 | |
Mark Nauwelaerts | 79f565f | 2010-11-09 15:01:15 +0100 | [diff] [blame] | 1487 | buf = _gst_buffer_new_take_data (data, offset); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1488 | g_free (node_header); |
| 1489 | |
| 1490 | GST_LOG_OBJECT (qtmux, "Pushing mdat start"); |
| 1491 | return gst_qt_mux_send_buffer (qtmux, buf, off, FALSE); |
| 1492 | |
| 1493 | /* ERRORS */ |
| 1494 | serialize_error: |
| 1495 | { |
| 1496 | GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 1497 | ("Failed to serialize mdat")); |
Edward Hervey | 112d948 | 2014-05-12 16:53:32 +0200 | [diff] [blame] | 1498 | g_free (node_header); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1499 | return GST_FLOW_ERROR; |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | /* |
| 1504 | * We get the position of the mdat size field, seek back to it |
| 1505 | * and overwrite with the real value |
| 1506 | */ |
| 1507 | static GstFlowReturn |
| 1508 | gst_qt_mux_update_mdat_size (GstQTMux * qtmux, guint64 mdat_pos, |
| 1509 | guint64 mdat_size, guint64 * offset) |
| 1510 | { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1511 | GstBuffer *buf; |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1512 | gboolean large_file; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1513 | GstSegment segment; |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1514 | GstMapInfo map; |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1515 | |
| 1516 | large_file = (mdat_size > MDAT_LARGE_FILE_LIMIT); |
| 1517 | |
| 1518 | if (large_file) |
| 1519 | mdat_pos += 8; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1520 | |
| 1521 | /* seek and rewrite the header */ |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1522 | gst_segment_init (&segment, GST_FORMAT_BYTES); |
| 1523 | segment.start = mdat_pos; |
| 1524 | gst_pad_push_event (qtmux->srcpad, gst_event_new_segment (&segment)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1525 | |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1526 | if (large_file) { |
| 1527 | buf = gst_buffer_new_and_alloc (sizeof (guint64)); |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1528 | gst_buffer_map (buf, &map, GST_MAP_WRITE); |
| 1529 | GST_WRITE_UINT64_BE (map.data, mdat_size + 16); |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1530 | } else { |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1531 | buf = gst_buffer_new_and_alloc (16); |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1532 | gst_buffer_map (buf, &map, GST_MAP_WRITE); |
| 1533 | GST_WRITE_UINT32_BE (map.data, 8); |
| 1534 | GST_WRITE_UINT32_LE (map.data + 4, FOURCC_free); |
| 1535 | GST_WRITE_UINT32_BE (map.data + 8, mdat_size + 8); |
| 1536 | GST_WRITE_UINT32_LE (map.data + 12, FOURCC_mdat); |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 1537 | } |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 1538 | gst_buffer_unmap (buf, &map); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1539 | |
| 1540 | return gst_qt_mux_send_buffer (qtmux, buf, offset, FALSE); |
| 1541 | } |
| 1542 | |
| 1543 | static GstFlowReturn |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1544 | gst_qt_mux_send_ftyp (GstQTMux * qtmux, guint64 * off) |
| 1545 | { |
| 1546 | GstBuffer *buf; |
| 1547 | guint64 size = 0, offset = 0; |
| 1548 | guint8 *data = NULL; |
| 1549 | |
| 1550 | GST_DEBUG_OBJECT (qtmux, "Sending ftyp atom"); |
| 1551 | |
| 1552 | if (!atom_ftyp_copy_data (qtmux->ftyp, &data, &size, &offset)) |
| 1553 | goto serialize_error; |
| 1554 | |
Mark Nauwelaerts | 79f565f | 2010-11-09 15:01:15 +0100 | [diff] [blame] | 1555 | buf = _gst_buffer_new_take_data (data, offset); |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1556 | |
| 1557 | GST_LOG_OBJECT (qtmux, "Pushing ftyp"); |
| 1558 | return gst_qt_mux_send_buffer (qtmux, buf, off, FALSE); |
| 1559 | |
| 1560 | /* ERRORS */ |
| 1561 | serialize_error: |
| 1562 | { |
| 1563 | GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), |
| 1564 | ("Failed to serialize ftyp")); |
| 1565 | return GST_FLOW_ERROR; |
| 1566 | } |
| 1567 | } |
| 1568 | |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 1569 | static void |
| 1570 | gst_qt_mux_prepare_ftyp (GstQTMux * qtmux, AtomFTYP ** p_ftyp, |
| 1571 | GstBuffer ** p_prefix) |
| 1572 | { |
| 1573 | GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux)); |
| 1574 | guint32 major, version; |
| 1575 | GList *comp; |
| 1576 | GstBuffer *prefix = NULL; |
| 1577 | AtomFTYP *ftyp = NULL; |
| 1578 | |
| 1579 | GST_DEBUG_OBJECT (qtmux, "Preparing ftyp and possible prefix atom"); |
| 1580 | |
| 1581 | /* init and send context and ftyp based on current property state */ |
| 1582 | gst_qt_mux_map_format_to_header (qtmux_klass->format, &prefix, &major, |
| 1583 | &version, &comp, qtmux->moov, qtmux->longest_chunk, |
| 1584 | qtmux->fast_start_file != NULL); |
| 1585 | ftyp = atom_ftyp_new (qtmux->context, major, version, comp); |
| 1586 | if (comp) |
| 1587 | g_list_free (comp); |
| 1588 | if (prefix) { |
| 1589 | if (p_prefix) |
| 1590 | *p_prefix = prefix; |
| 1591 | else |
| 1592 | gst_buffer_unref (prefix); |
| 1593 | } |
| 1594 | *p_ftyp = ftyp; |
| 1595 | } |
| 1596 | |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1597 | static GstFlowReturn |
| 1598 | gst_qt_mux_prepare_and_send_ftyp (GstQTMux * qtmux) |
| 1599 | { |
| 1600 | GstFlowReturn ret = GST_FLOW_OK; |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 1601 | GstBuffer *prefix = NULL; |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1602 | |
| 1603 | GST_DEBUG_OBJECT (qtmux, "Preparing to send ftyp atom"); |
| 1604 | |
| 1605 | /* init and send context and ftyp based on current property state */ |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 1606 | if (qtmux->ftyp) { |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1607 | atom_ftyp_free (qtmux->ftyp); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 1608 | qtmux->ftyp = NULL; |
| 1609 | } |
| 1610 | gst_qt_mux_prepare_ftyp (qtmux, &qtmux->ftyp, &prefix); |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1611 | if (prefix) { |
| 1612 | ret = gst_qt_mux_send_buffer (qtmux, prefix, &qtmux->header_size, FALSE); |
| 1613 | if (ret != GST_FLOW_OK) |
| 1614 | return ret; |
| 1615 | } |
| 1616 | return gst_qt_mux_send_ftyp (qtmux, &qtmux->header_size); |
| 1617 | } |
| 1618 | |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1619 | static void |
Marc-André Lureau | bd0d320 | 2010-07-22 19:40:07 +0200 | [diff] [blame] | 1620 | gst_qt_mux_set_header_on_caps (GstQTMux * mux, GstBuffer * buf) |
| 1621 | { |
| 1622 | GstStructure *structure; |
| 1623 | GValue array = { 0 }; |
| 1624 | GValue value = { 0 }; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1625 | GstCaps *caps, *tcaps; |
Marc-André Lureau | bd0d320 | 2010-07-22 19:40:07 +0200 | [diff] [blame] | 1626 | |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1627 | tcaps = gst_pad_get_current_caps (mux->srcpad); |
| 1628 | caps = gst_caps_copy (tcaps); |
| 1629 | gst_caps_unref (tcaps); |
| 1630 | |
Marc-André Lureau | bd0d320 | 2010-07-22 19:40:07 +0200 | [diff] [blame] | 1631 | structure = gst_caps_get_structure (caps, 0); |
| 1632 | |
| 1633 | g_value_init (&array, GST_TYPE_ARRAY); |
| 1634 | |
Wim Taymans | bb2bd60 | 2012-01-30 17:16:51 +0100 | [diff] [blame] | 1635 | GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER); |
Marc-André Lureau | bd0d320 | 2010-07-22 19:40:07 +0200 | [diff] [blame] | 1636 | g_value_init (&value, GST_TYPE_BUFFER); |
| 1637 | gst_value_take_buffer (&value, gst_buffer_ref (buf)); |
| 1638 | gst_value_array_append_value (&array, &value); |
| 1639 | g_value_unset (&value); |
| 1640 | |
| 1641 | gst_structure_set_value (structure, "streamheader", &array); |
| 1642 | g_value_unset (&array); |
| 1643 | gst_pad_set_caps (mux->srcpad, caps); |
| 1644 | gst_caps_unref (caps); |
| 1645 | } |
| 1646 | |
| 1647 | static void |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1648 | gst_qt_mux_configure_moov (GstQTMux * qtmux, guint32 * _timescale) |
| 1649 | { |
Mark Nauwelaerts | 60c8ed2 | 2010-12-03 15:23:00 +0100 | [diff] [blame] | 1650 | gboolean fragmented; |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1651 | guint32 timescale; |
| 1652 | |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1653 | GST_OBJECT_LOCK (qtmux); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 1654 | timescale = qtmux->timescale; |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 1655 | fragmented = qtmux->fragment_sequence > 0; |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1656 | GST_OBJECT_UNLOCK (qtmux); |
| 1657 | |
| 1658 | /* inform lower layers of our property wishes, and determine duration. |
| 1659 | * Let moov take care of this using its list of traks; |
| 1660 | * so that released pads are also included */ |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1661 | GST_DEBUG_OBJECT (qtmux, "Updating timescale to %" G_GUINT32_FORMAT, |
| 1662 | timescale); |
| 1663 | atom_moov_update_timescale (qtmux->moov, timescale); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 1664 | atom_moov_set_fragmented (qtmux->moov, fragmented); |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1665 | |
| 1666 | atom_moov_update_duration (qtmux->moov); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 1667 | |
| 1668 | if (_timescale) |
| 1669 | *_timescale = timescale; |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | static GstFlowReturn |
| 1673 | gst_qt_mux_send_moov (GstQTMux * qtmux, guint64 * _offset, gboolean mind_fast) |
| 1674 | { |
| 1675 | guint64 offset = 0, size = 0; |
| 1676 | guint8 *data; |
| 1677 | GstBuffer *buf; |
| 1678 | GstFlowReturn ret = GST_FLOW_OK; |
| 1679 | |
| 1680 | /* serialize moov */ |
| 1681 | offset = size = 0; |
| 1682 | data = NULL; |
| 1683 | GST_LOG_OBJECT (qtmux, "Copying movie header into buffer"); |
| 1684 | if (!atom_moov_copy_data (qtmux->moov, &data, &size, &offset)) |
| 1685 | goto serialize_error; |
| 1686 | |
| 1687 | buf = _gst_buffer_new_take_data (data, offset); |
| 1688 | GST_DEBUG_OBJECT (qtmux, "Pushing moov atoms"); |
Marc-André Lureau | bd0d320 | 2010-07-22 19:40:07 +0200 | [diff] [blame] | 1689 | gst_qt_mux_set_header_on_caps (qtmux, buf); |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1690 | ret = gst_qt_mux_send_buffer (qtmux, buf, _offset, mind_fast); |
| 1691 | |
| 1692 | return ret; |
| 1693 | |
| 1694 | serialize_error: |
| 1695 | { |
| 1696 | g_free (data); |
| 1697 | return GST_FLOW_ERROR; |
| 1698 | } |
| 1699 | } |
| 1700 | |
Mark Nauwelaerts | 35e028f | 2010-11-09 15:54:44 +0100 | [diff] [blame] | 1701 | /* either calculates size of extra atoms or pushes them */ |
| 1702 | static GstFlowReturn |
| 1703 | gst_qt_mux_send_extra_atoms (GstQTMux * qtmux, gboolean send, guint64 * offset, |
| 1704 | gboolean mind_fast) |
| 1705 | { |
| 1706 | GSList *walk; |
| 1707 | guint64 loffset = 0, size = 0; |
| 1708 | guint8 *data; |
| 1709 | GstFlowReturn ret = GST_FLOW_OK; |
| 1710 | |
| 1711 | for (walk = qtmux->extra_atoms; walk; walk = g_slist_next (walk)) { |
| 1712 | AtomInfo *ainfo = (AtomInfo *) walk->data; |
| 1713 | |
| 1714 | loffset = size = 0; |
| 1715 | data = NULL; |
| 1716 | if (!ainfo->copy_data_func (ainfo->atom, |
| 1717 | send ? &data : NULL, &size, &loffset)) |
| 1718 | goto serialize_error; |
| 1719 | |
| 1720 | if (send) { |
| 1721 | GstBuffer *buf; |
| 1722 | |
| 1723 | GST_DEBUG_OBJECT (qtmux, |
| 1724 | "Pushing extra top-level atom %" GST_FOURCC_FORMAT, |
| 1725 | GST_FOURCC_ARGS (ainfo->atom->type)); |
| 1726 | buf = _gst_buffer_new_take_data (data, loffset); |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 1727 | ret = gst_qt_mux_send_buffer (qtmux, buf, offset, FALSE); |
Mark Nauwelaerts | 35e028f | 2010-11-09 15:54:44 +0100 | [diff] [blame] | 1728 | if (ret != GST_FLOW_OK) |
| 1729 | break; |
| 1730 | } else { |
| 1731 | if (offset) |
| 1732 | *offset += loffset; |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | return ret; |
| 1737 | |
| 1738 | serialize_error: |
| 1739 | { |
| 1740 | g_free (data); |
| 1741 | return GST_FLOW_ERROR; |
| 1742 | } |
| 1743 | } |
| 1744 | |
Jan Schmidt | 3d59b5f | 2015-04-01 23:46:13 +1100 | [diff] [blame] | 1745 | static gboolean |
| 1746 | gst_qt_mux_downstream_is_seekable (GstQTMux * qtmux) |
| 1747 | { |
| 1748 | gboolean seekable = FALSE; |
| 1749 | GstQuery *query = gst_query_new_seeking (GST_FORMAT_BYTES); |
| 1750 | |
| 1751 | if (gst_pad_peer_query (qtmux->srcpad, query)) { |
| 1752 | gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL); |
| 1753 | GST_INFO_OBJECT (qtmux, "downstream is %sseekable", seekable ? "" : "not "); |
| 1754 | } else { |
| 1755 | /* have to assume seeking is not supported if query not handled downstream */ |
| 1756 | GST_WARNING_OBJECT (qtmux, "downstream did not handle seeking query"); |
| 1757 | seekable = FALSE; |
| 1758 | } |
| 1759 | gst_query_unref (query); |
| 1760 | |
| 1761 | return seekable; |
| 1762 | } |
| 1763 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1764 | static void |
| 1765 | gst_qt_mux_prepare_moov_recovery (GstQTMux * qtmux) |
| 1766 | { |
| 1767 | GSList *walk; |
| 1768 | gboolean fail = FALSE; |
| 1769 | AtomFTYP *ftyp = NULL; |
| 1770 | GstBuffer *prefix = NULL; |
| 1771 | |
| 1772 | GST_DEBUG_OBJECT (qtmux, "Openning moov recovery file: %s", |
| 1773 | qtmux->moov_recov_file_path); |
| 1774 | |
| 1775 | qtmux->moov_recov_file = g_fopen (qtmux->moov_recov_file_path, "wb+"); |
| 1776 | if (qtmux->moov_recov_file == NULL) { |
| 1777 | GST_WARNING_OBJECT (qtmux, "Failed to open moov recovery file in %s", |
| 1778 | qtmux->moov_recov_file_path); |
| 1779 | return; |
| 1780 | } |
| 1781 | |
| 1782 | gst_qt_mux_prepare_ftyp (qtmux, &ftyp, &prefix); |
| 1783 | |
| 1784 | if (!atoms_recov_write_headers (qtmux->moov_recov_file, ftyp, prefix, |
| 1785 | qtmux->moov, qtmux->timescale, g_slist_length (qtmux->sinkpads))) { |
| 1786 | GST_WARNING_OBJECT (qtmux, "Failed to write moov recovery file " "headers"); |
| 1787 | goto fail; |
| 1788 | } |
| 1789 | |
| 1790 | atom_ftyp_free (ftyp); |
| 1791 | if (prefix) |
| 1792 | gst_buffer_unref (prefix); |
| 1793 | |
| 1794 | for (walk = qtmux->sinkpads; walk && !fail; walk = g_slist_next (walk)) { |
| 1795 | GstCollectData *cdata = (GstCollectData *) walk->data; |
| 1796 | GstQTPad *qpad = (GstQTPad *) cdata; |
| 1797 | /* write info for each stream */ |
| 1798 | fail = atoms_recov_write_trak_info (qtmux->moov_recov_file, qpad->trak); |
| 1799 | if (fail) { |
| 1800 | GST_WARNING_OBJECT (qtmux, "Failed to write trak info to recovery " |
| 1801 | "file"); |
| 1802 | break; |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | fail: |
| 1807 | /* cleanup */ |
| 1808 | fclose (qtmux->moov_recov_file); |
| 1809 | qtmux->moov_recov_file = NULL; |
| 1810 | GST_WARNING_OBJECT (qtmux, "An error was detected while writing to " |
| 1811 | "recover file, moov recovery won't work"); |
| 1812 | } |
Jan Schmidt | 3d59b5f | 2015-04-01 23:46:13 +1100 | [diff] [blame] | 1813 | |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1814 | static GstFlowReturn |
| 1815 | gst_qt_mux_start_file (GstQTMux * qtmux) |
| 1816 | { |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1817 | GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux)); |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1818 | GstFlowReturn ret = GST_FLOW_OK; |
Mark Nauwelaerts | 20e4bde | 2011-01-13 15:27:36 +0100 | [diff] [blame] | 1819 | GstCaps *caps; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1820 | GstSegment segment; |
Tim-Philipp Müller | bc37b9f | 2012-09-23 15:57:35 +0100 | [diff] [blame] | 1821 | gchar s_id[32]; |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1822 | |
| 1823 | GST_DEBUG_OBJECT (qtmux, "starting file"); |
| 1824 | |
Tim-Philipp Müller | bc37b9f | 2012-09-23 15:57:35 +0100 | [diff] [blame] | 1825 | /* stream-start (FIXME: create id based on input ids) */ |
| 1826 | g_snprintf (s_id, sizeof (s_id), "qtmux-%08x", g_random_int ()); |
| 1827 | gst_pad_push_event (qtmux->srcpad, gst_event_new_stream_start (s_id)); |
| 1828 | |
Mark Nauwelaerts | 20e4bde | 2011-01-13 15:27:36 +0100 | [diff] [blame] | 1829 | caps = gst_caps_copy (gst_pad_get_pad_template_caps (qtmux->srcpad)); |
Tim-Philipp Müller | 025417f | 2011-04-13 15:18:11 +0100 | [diff] [blame] | 1830 | /* qtmux has structure with and without variant, remove all but the first */ |
| 1831 | while (gst_caps_get_size (caps) > 1) |
| 1832 | gst_caps_remove_structure (caps, 1); |
Mark Nauwelaerts | 20e4bde | 2011-01-13 15:27:36 +0100 | [diff] [blame] | 1833 | gst_pad_set_caps (qtmux->srcpad, caps); |
| 1834 | gst_caps_unref (caps); |
| 1835 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1836 | /* Default is 'normal' mode */ |
| 1837 | qtmux->mux_mode = GST_QT_MUX_MODE_MOOV_AT_END; |
| 1838 | |
| 1839 | /* Require a sensible fragment duration when muxing |
| 1840 | * using the ISML muxer */ |
| 1841 | if (qtmux_klass->format == GST_QT_MUX_FORMAT_ISML && |
| 1842 | qtmux->fragment_duration == 0) |
| 1843 | goto invalid_isml; |
| 1844 | |
| 1845 | if (qtmux->fragment_duration > 0) { |
| 1846 | if (qtmux->streamable) |
| 1847 | qtmux->mux_mode = GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE; |
| 1848 | else |
| 1849 | qtmux->mux_mode = GST_QT_MUX_MODE_FRAGMENTED; |
| 1850 | } else if (qtmux->fast_start) { |
| 1851 | qtmux->mux_mode = GST_QT_MUX_MODE_FAST_START; |
| 1852 | } |
| 1853 | |
| 1854 | switch (qtmux->mux_mode) { |
| 1855 | case GST_QT_MUX_MODE_MOOV_AT_END: |
| 1856 | /* We have to be able to seek to rewrite the mdat header, or any |
| 1857 | * moov atom we write will not be visible in the file, because an |
| 1858 | * MDAT with 0 as the size covers the rest of the file. A file |
| 1859 | * with no moov is not playable, so error out now. */ |
| 1860 | if (!gst_qt_mux_downstream_is_seekable (qtmux)) { |
| 1861 | GST_ELEMENT_ERROR (qtmux, STREAM, MUX, |
| 1862 | ("Downstream is not seekable - will not be able to create a playable file"), |
| 1863 | (NULL)); |
| 1864 | return GST_FLOW_ERROR; |
| 1865 | } |
| 1866 | break; |
| 1867 | case GST_QT_MUX_MODE_FAST_START: |
| 1868 | case GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE: |
| 1869 | break; /* Don't need seekability, ignore */ |
| 1870 | case GST_QT_MUX_MODE_FRAGMENTED: |
| 1871 | if (!gst_qt_mux_downstream_is_seekable (qtmux)) { |
Andoni Morales Alastruey | cfefdae | 2013-09-17 12:17:54 +0200 | [diff] [blame] | 1872 | GST_WARNING_OBJECT (qtmux, "downstream is not seekable, but " |
| 1873 | "streamable=false. Will ignore that and create streamable output " |
| 1874 | "instead"); |
| 1875 | qtmux->streamable = TRUE; |
| 1876 | g_object_notify (G_OBJECT (qtmux), "streamable"); |
| 1877 | } |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1878 | break; |
Tim-Philipp Müller | 676b371 | 2012-02-25 15:55:15 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1881 | /* let downstream know we think in BYTES and expect to do seeking later on */ |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 1882 | gst_segment_init (&segment, GST_FORMAT_BYTES); |
| 1883 | gst_pad_push_event (qtmux->srcpad, gst_event_new_segment (&segment)); |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1884 | |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 1885 | /* initialize our moov recovery file */ |
| 1886 | GST_OBJECT_LOCK (qtmux); |
| 1887 | if (qtmux->moov_recov_file_path) { |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1888 | gst_qt_mux_prepare_moov_recovery (qtmux); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 1889 | } |
| 1890 | GST_OBJECT_UNLOCK (qtmux); |
| 1891 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1892 | /* |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1893 | * send mdat header if already needed, and mark position for later update. |
| 1894 | * We don't send ftyp now if we are on fast start mode, because we can |
| 1895 | * better fine tune using the information we gather to create the whole moov |
| 1896 | * atom. |
| 1897 | */ |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1898 | switch (qtmux->mux_mode) { |
| 1899 | case GST_QT_MUX_MODE_MOOV_AT_END: |
| 1900 | ret = gst_qt_mux_prepare_and_send_ftyp (qtmux); |
| 1901 | if (ret != GST_FLOW_OK) |
| 1902 | break; |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1903 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1904 | /* store the mdat position for rewriting later ... */ |
| 1905 | qtmux->mdat_pos = qtmux->header_size; |
| 1906 | /* extended atom in case we go over 4GB while writing and need |
| 1907 | * the full 64-bit atom */ |
| 1908 | ret = gst_qt_mux_send_mdat_header (qtmux, &qtmux->header_size, 0, TRUE); |
| 1909 | break; |
| 1910 | case GST_QT_MUX_MODE_FAST_START: |
| 1911 | GST_OBJECT_LOCK (qtmux); |
| 1912 | qtmux->fast_start_file = g_fopen (qtmux->fast_start_file_path, "wb+"); |
| 1913 | if (!qtmux->fast_start_file) |
| 1914 | goto open_failed; |
| 1915 | GST_OBJECT_UNLOCK (qtmux); |
| 1916 | /* send a dummy buffer for preroll */ |
| 1917 | ret = gst_qt_mux_send_buffer (qtmux, gst_buffer_new (), NULL, FALSE); |
| 1918 | break; |
| 1919 | case GST_QT_MUX_MODE_FRAGMENTED: |
| 1920 | case GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE: |
| 1921 | ret = gst_qt_mux_prepare_and_send_ftyp (qtmux); |
| 1922 | if (ret != GST_FLOW_OK) |
| 1923 | break; |
| 1924 | /* well, it's moov pos if fragmented ... */ |
| 1925 | qtmux->mdat_pos = qtmux->header_size; |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 1926 | GST_DEBUG_OBJECT (qtmux, "fragment duration %d ms, writing headers", |
| 1927 | qtmux->fragment_duration); |
| 1928 | /* also used as snapshot marker to indicate fragmented file */ |
| 1929 | qtmux->fragment_sequence = 1; |
| 1930 | /* prepare moov and/or tags */ |
| 1931 | gst_qt_mux_configure_moov (qtmux, NULL); |
| 1932 | gst_qt_mux_setup_metadata (qtmux); |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 1933 | ret = gst_qt_mux_send_moov (qtmux, &qtmux->header_size, FALSE); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 1934 | if (ret != GST_FLOW_OK) |
| 1935 | return ret; |
| 1936 | /* extra atoms */ |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 1937 | ret = |
| 1938 | gst_qt_mux_send_extra_atoms (qtmux, TRUE, &qtmux->header_size, FALSE); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 1939 | if (ret != GST_FLOW_OK) |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1940 | break; |
| 1941 | /* prepare index if not streamable */ |
| 1942 | if (qtmux->mux_mode == GST_QT_MUX_MODE_FRAGMENTED) |
Marc-André Lureau | 61964eb | 2010-08-06 13:26:27 +0200 | [diff] [blame] | 1943 | qtmux->mfra = atom_mfra_new (qtmux->context); |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1944 | break; |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1945 | } |
| 1946 | |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1947 | return ret; |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1948 | /* ERRORS */ |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1949 | invalid_isml: |
| 1950 | { |
| 1951 | GST_ELEMENT_ERROR (qtmux, STREAM, MUX, |
| 1952 | ("Cannot create an ISML file with 0 fragment duration"), (NULL)); |
| 1953 | return GST_FLOW_ERROR; |
| 1954 | } |
| 1955 | |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1956 | open_failed: |
| 1957 | { |
| 1958 | GST_ELEMENT_ERROR (qtmux, RESOURCE, OPEN_READ_WRITE, |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1959 | (("Could not open temporary file \"%s\""), |
| 1960 | qtmux->fast_start_file_path), GST_ERROR_SYSTEM); |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 1961 | GST_OBJECT_UNLOCK (qtmux); |
| 1962 | return GST_FLOW_ERROR; |
| 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | static GstFlowReturn |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1967 | gst_qt_mux_stop_file (GstQTMux * qtmux) |
| 1968 | { |
| 1969 | gboolean ret = GST_FLOW_OK; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1970 | guint64 offset = 0, size = 0; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1971 | GSList *walk; |
| 1972 | gboolean large_file; |
| 1973 | guint32 timescale; |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 1974 | GstClockTime first_ts = GST_CLOCK_TIME_NONE; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1975 | |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 1976 | /* for setting some subtitles fields */ |
| 1977 | guint max_width = 0; |
| 1978 | guint max_height = 0; |
| 1979 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1980 | GST_DEBUG_OBJECT (qtmux, "Updating remaining values and sending last data"); |
| 1981 | |
| 1982 | /* pushing last buffers for each pad */ |
| 1983 | for (walk = qtmux->collect->data; walk; walk = g_slist_next (walk)) { |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 1984 | GstCollectData *cdata = (GstCollectData *) walk->data; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1985 | GstQTPad *qtpad = (GstQTPad *) cdata; |
| 1986 | |
Lasse Laukkanen | 056e918 | 2011-09-16 16:53:22 +0300 | [diff] [blame] | 1987 | /* avoid add_buffer complaining if not negotiated |
| 1988 | * in which case no buffers either, so skipping */ |
| 1989 | if (!qtpad->fourcc) { |
| 1990 | GST_DEBUG_OBJECT (qtmux, "Pad %s has never had buffers", |
| 1991 | GST_PAD_NAME (qtpad->collect.pad)); |
| 1992 | continue; |
| 1993 | } |
| 1994 | |
| 1995 | /* send last buffer; also flushes possibly queued buffers/ts */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1996 | GST_DEBUG_OBJECT (qtmux, "Sending the last buffer for pad %s", |
| 1997 | GST_PAD_NAME (qtpad->collect.pad)); |
| 1998 | ret = gst_qt_mux_add_buffer (qtmux, qtpad, NULL); |
Lasse Laukkanen | 056e918 | 2011-09-16 16:53:22 +0300 | [diff] [blame] | 1999 | if (ret != GST_FLOW_OK) { |
Thiago Santos | 009d104 | 2009-11-06 00:46:12 -0300 | [diff] [blame] | 2000 | GST_WARNING_OBJECT (qtmux, "Failed to send last buffer for %s, " |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2001 | "flow return: %s", GST_PAD_NAME (qtpad->collect.pad), |
| 2002 | gst_flow_get_name (ret)); |
Lasse Laukkanen | 056e918 | 2011-09-16 16:53:22 +0300 | [diff] [blame] | 2003 | } |
Mark Nauwelaerts | 4df05e7 | 2011-04-15 12:34:05 +0200 | [diff] [blame] | 2004 | |
Lasse Laukkanen | 056e918 | 2011-09-16 16:53:22 +0300 | [diff] [blame] | 2005 | /* having flushed above, can check for buffers now */ |
Mark Nauwelaerts | 4df05e7 | 2011-04-15 12:34:05 +0200 | [diff] [blame] | 2006 | if (!GST_CLOCK_TIME_IS_VALID (qtpad->first_ts)) { |
| 2007 | GST_DEBUG_OBJECT (qtmux, "Pad %s has no buffers", |
| 2008 | GST_PAD_NAME (qtpad->collect.pad)); |
| 2009 | continue; |
| 2010 | } |
| 2011 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2012 | /* determine max stream duration */ |
| 2013 | if (!GST_CLOCK_TIME_IS_VALID (first_ts) || |
| 2014 | (GST_CLOCK_TIME_IS_VALID (qtpad->first_ts) && |
| 2015 | qtpad->last_dts > first_ts)) { |
| 2016 | first_ts = qtpad->last_dts; |
| 2017 | } |
Thiago Santos | 7a143ea | 2011-09-28 11:41:49 -0300 | [diff] [blame] | 2018 | |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 2019 | /* subtitles need to know the video width/height, |
| 2020 | * it is stored shifted 16 bits to the left according to the |
| 2021 | * spec */ |
| 2022 | max_width = MAX (max_width, (qtpad->trak->tkhd.width >> 16)); |
| 2023 | max_height = MAX (max_height, (qtpad->trak->tkhd.height >> 16)); |
| 2024 | |
Thiago Santos | 7a143ea | 2011-09-28 11:41:49 -0300 | [diff] [blame] | 2025 | /* update average bitrate of streams if needed */ |
| 2026 | { |
| 2027 | guint32 avgbitrate = 0; |
| 2028 | guint32 maxbitrate = qtpad->max_bitrate; |
| 2029 | |
| 2030 | if (qtpad->avg_bitrate) |
| 2031 | avgbitrate = qtpad->avg_bitrate; |
| 2032 | else if (qtpad->total_duration > 0) |
| 2033 | avgbitrate = (guint32) gst_util_uint64_scale_round (qtpad->total_bytes, |
| 2034 | 8 * GST_SECOND, qtpad->total_duration); |
| 2035 | |
| 2036 | atom_trak_update_bitrates (qtpad->trak, avgbitrate, maxbitrate); |
| 2037 | } |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2038 | } |
| 2039 | |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 2040 | /* need to update values on subtitle traks now that we know the |
| 2041 | * max width and height */ |
| 2042 | for (walk = qtmux->collect->data; walk; walk = g_slist_next (walk)) { |
| 2043 | GstCollectData *cdata = (GstCollectData *) walk->data; |
| 2044 | GstQTPad *qtpad = (GstQTPad *) cdata; |
| 2045 | |
| 2046 | if (!qtpad->fourcc) { |
| 2047 | GST_DEBUG_OBJECT (qtmux, "Pad %s has never had buffers", |
| 2048 | GST_PAD_NAME (qtpad->collect.pad)); |
| 2049 | continue; |
| 2050 | } |
| 2051 | |
| 2052 | if (qtpad->fourcc == FOURCC_tx3g) { |
| 2053 | atom_trak_tx3g_update_dimension (qtpad->trak, max_width, max_height); |
| 2054 | } |
| 2055 | } |
| 2056 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2057 | switch (qtmux->mux_mode) { |
| 2058 | case GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE: |
| 2059 | { |
| 2060 | /* Streamable mode; no need to write duration or MFRA */ |
| 2061 | GST_DEBUG_OBJECT (qtmux, "streamable file; nothing to stop"); |
| 2062 | return GST_FLOW_OK; |
| 2063 | } |
| 2064 | case GST_QT_MUX_MODE_FRAGMENTED: |
| 2065 | { |
| 2066 | GstSegment segment; |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2067 | guint8 *data = NULL; |
| 2068 | GstBuffer *buf; |
| 2069 | |
| 2070 | size = offset = 0; |
| 2071 | GST_DEBUG_OBJECT (qtmux, "adding mfra"); |
| 2072 | if (!atom_mfra_copy_data (qtmux->mfra, &data, &size, &offset)) |
| 2073 | goto serialize_error; |
| 2074 | buf = _gst_buffer_new_take_data (data, offset); |
| 2075 | ret = gst_qt_mux_send_buffer (qtmux, buf, NULL, FALSE); |
| 2076 | if (ret != GST_FLOW_OK) |
| 2077 | return ret; |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2078 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2079 | timescale = qtmux->timescale; |
| 2080 | /* only mvex duration is updated, |
| 2081 | * mvhd should be consistent with empty moov |
| 2082 | * (but TODO maybe some clients do not handle that well ?) */ |
| 2083 | qtmux->moov->mvex.mehd.fragment_duration = |
| 2084 | gst_util_uint64_scale (first_ts, timescale, GST_SECOND); |
| 2085 | GST_DEBUG_OBJECT (qtmux, "rewriting moov with mvex duration %" |
| 2086 | GST_TIME_FORMAT, GST_TIME_ARGS (first_ts)); |
| 2087 | /* seek and rewrite the header */ |
| 2088 | gst_segment_init (&segment, GST_FORMAT_BYTES); |
| 2089 | segment.start = qtmux->mdat_pos; |
| 2090 | gst_pad_push_event (qtmux->srcpad, gst_event_new_segment (&segment)); |
| 2091 | /* no need to seek back */ |
| 2092 | return gst_qt_mux_send_moov (qtmux, NULL, FALSE); |
| 2093 | } |
| 2094 | default: |
| 2095 | break; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2096 | } |
| 2097 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2098 | /* Moov-at-end or fast-start mode from here down */ |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 2099 | gst_qt_mux_configure_moov (qtmux, ×cale); |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2100 | /* check for late streams. First, find the earliest start time */ |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2101 | first_ts = GST_CLOCK_TIME_NONE; |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2102 | for (walk = qtmux->collect->data; walk; walk = g_slist_next (walk)) { |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 2103 | GstCollectData *cdata = (GstCollectData *) walk->data; |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2104 | GstQTPad *qtpad = (GstQTPad *) cdata; |
| 2105 | |
| 2106 | if (!GST_CLOCK_TIME_IS_VALID (first_ts) || |
| 2107 | (GST_CLOCK_TIME_IS_VALID (qtpad->first_ts) && |
| 2108 | qtpad->first_ts < first_ts)) { |
| 2109 | first_ts = qtpad->first_ts; |
| 2110 | } |
| 2111 | } |
Jan Schmidt | 3d7b343 | 2015-04-01 00:58:52 +1100 | [diff] [blame^] | 2112 | |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2113 | GST_DEBUG_OBJECT (qtmux, "Media first ts selected: %" GST_TIME_FORMAT, |
| 2114 | GST_TIME_ARGS (first_ts)); |
Jan Schmidt | 3d7b343 | 2015-04-01 00:58:52 +1100 | [diff] [blame^] | 2115 | /* add/update EDTSs for late streams. configure_moov will have |
| 2116 | * set the trak durations above by summing the sample tables */ |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2117 | for (walk = qtmux->collect->data; walk; walk = g_slist_next (walk)) { |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 2118 | GstCollectData *cdata = (GstCollectData *) walk->data; |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2119 | GstQTPad *qtpad = (GstQTPad *) cdata; |
| 2120 | guint32 lateness; |
| 2121 | guint32 duration; |
| 2122 | |
Jan Schmidt | 3d7b343 | 2015-04-01 00:58:52 +1100 | [diff] [blame^] | 2123 | if (GST_CLOCK_TIME_IS_VALID (qtpad->first_ts) |
| 2124 | && qtpad->first_ts > first_ts) { |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2125 | GST_DEBUG_OBJECT (qtmux, "Pad %s is a late stream by %" GST_TIME_FORMAT, |
| 2126 | GST_PAD_NAME (qtpad->collect.pad), |
| 2127 | GST_TIME_ARGS (qtpad->first_ts - first_ts)); |
Jan Schmidt | 3d7b343 | 2015-04-01 00:58:52 +1100 | [diff] [blame^] | 2128 | lateness = |
| 2129 | gst_util_uint64_scale_round (qtpad->first_ts - first_ts, timescale, |
| 2130 | GST_SECOND); |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2131 | duration = qtpad->trak->tkhd.duration; |
Jan Schmidt | 3d7b343 | 2015-04-01 00:58:52 +1100 | [diff] [blame^] | 2132 | atom_trak_set_elst_entry (qtpad->trak, 0, lateness, (guint32) - 1, |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2133 | (guint32) (1 * 65536.0)); |
Jan Schmidt | 3d7b343 | 2015-04-01 00:58:52 +1100 | [diff] [blame^] | 2134 | atom_trak_set_elst_entry (qtpad->trak, 1, duration, 0, |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2135 | (guint32) (1 * 65536.0)); |
| 2136 | |
| 2137 | /* need to add the empty time to the trak duration */ |
Jan Schmidt | d9e1aa4 | 2014-08-08 03:58:14 +1000 | [diff] [blame] | 2138 | duration += lateness; |
| 2139 | |
| 2140 | qtpad->trak->tkhd.duration = duration; |
| 2141 | |
| 2142 | /* And possibly grow the moov duration */ |
| 2143 | if (duration > qtmux->moov->mvhd.time_info.duration) { |
| 2144 | qtmux->moov->mvhd.time_info.duration = duration; |
| 2145 | qtmux->moov->mvex.mehd.fragment_duration = duration; |
| 2146 | } |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 2147 | } |
| 2148 | } |
| 2149 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2150 | /* tags into file metadata */ |
| 2151 | gst_qt_mux_setup_metadata (qtmux); |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 2152 | large_file = (qtmux->mdat_size > MDAT_LARGE_FILE_LIMIT); |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2153 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2154 | /* if faststart, update the offset of the atoms in the movie with the offset |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 2155 | * that the movie headers before mdat will cause. |
| 2156 | * Also, send the ftyp */ |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2157 | if (qtmux->mux_mode == GST_QT_MUX_MODE_FAST_START) { |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 2158 | GstFlowReturn flow_ret; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2159 | offset = size = 0; |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 2160 | |
| 2161 | flow_ret = gst_qt_mux_prepare_and_send_ftyp (qtmux); |
| 2162 | if (flow_ret != GST_FLOW_OK) { |
| 2163 | goto ftyp_error; |
| 2164 | } |
| 2165 | /* copy into NULL to obtain size */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2166 | if (!atom_moov_copy_data (qtmux->moov, NULL, &size, &offset)) |
| 2167 | goto serialize_error; |
| 2168 | GST_DEBUG_OBJECT (qtmux, "calculated moov atom size %" G_GUINT64_FORMAT, |
Mark Nauwelaerts | 7bf67a6 | 2009-11-19 11:36:14 +0100 | [diff] [blame] | 2169 | offset); |
Mark Nauwelaerts | c3f462d | 2009-06-11 15:54:42 +0200 | [diff] [blame] | 2170 | offset += qtmux->header_size + (large_file ? 16 : 8); |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 2171 | |
| 2172 | /* sum up with the extra atoms size */ |
Mark Nauwelaerts | 35e028f | 2010-11-09 15:54:44 +0100 | [diff] [blame] | 2173 | ret = gst_qt_mux_send_extra_atoms (qtmux, FALSE, &offset, FALSE); |
| 2174 | if (ret != GST_FLOW_OK) |
| 2175 | return ret; |
| 2176 | } else { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2177 | offset = qtmux->header_size; |
Mark Nauwelaerts | 35e028f | 2010-11-09 15:54:44 +0100 | [diff] [blame] | 2178 | } |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2179 | |
| 2180 | /* Now that we know the size of moov + extra atoms, we can adjust |
| 2181 | * the chunk offsets stored into the moov */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2182 | atom_moov_chunks_add_offset (qtmux->moov, offset); |
| 2183 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2184 | /* write out moov and extra atoms */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2185 | /* note: as of this point, we no longer care about tracking written data size, |
| 2186 | * since there is no more use for it anyway */ |
Mark Nauwelaerts | 69d0746 | 2010-11-09 16:49:07 +0100 | [diff] [blame] | 2187 | ret = gst_qt_mux_send_moov (qtmux, NULL, FALSE); |
Mark Nauwelaerts | 35e028f | 2010-11-09 15:54:44 +0100 | [diff] [blame] | 2188 | if (ret != GST_FLOW_OK) |
| 2189 | return ret; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2190 | |
Mark Nauwelaerts | 35e028f | 2010-11-09 15:54:44 +0100 | [diff] [blame] | 2191 | /* extra atoms */ |
| 2192 | ret = gst_qt_mux_send_extra_atoms (qtmux, TRUE, NULL, FALSE); |
| 2193 | if (ret != GST_FLOW_OK) |
| 2194 | return ret; |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 2195 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2196 | switch (qtmux->mux_mode) { |
| 2197 | case GST_QT_MUX_MODE_MOOV_AT_END: |
| 2198 | { |
| 2199 | /* mdat needs update iff not using faststart */ |
| 2200 | GST_DEBUG_OBJECT (qtmux, "updating mdat size"); |
| 2201 | ret = gst_qt_mux_update_mdat_size (qtmux, qtmux->mdat_pos, |
| 2202 | qtmux->mdat_size, NULL); |
| 2203 | /* note; no seeking back to the end of file is done, |
| 2204 | * since we no longer write anything anyway */ |
| 2205 | break; |
| 2206 | } |
| 2207 | case GST_QT_MUX_MODE_FAST_START: |
| 2208 | { |
| 2209 | /* send mdat atom and move buffered data into it */ |
| 2210 | /* mdat_size = accumulated (buffered data) */ |
| 2211 | ret = gst_qt_mux_send_mdat_header (qtmux, NULL, qtmux->mdat_size, |
| 2212 | large_file); |
| 2213 | if (ret != GST_FLOW_OK) |
| 2214 | return ret; |
| 2215 | ret = gst_qt_mux_send_buffered_data (qtmux, NULL); |
| 2216 | if (ret != GST_FLOW_OK) |
| 2217 | return ret; |
| 2218 | break; |
| 2219 | } |
| 2220 | default: |
| 2221 | g_assert_not_reached (); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | return ret; |
| 2225 | |
| 2226 | /* ERRORS */ |
| 2227 | serialize_error: |
| 2228 | { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2229 | GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), |
| 2230 | ("Failed to serialize moov")); |
| 2231 | return GST_FLOW_ERROR; |
| 2232 | } |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 2233 | ftyp_error: |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2234 | { |
Thiago Santos | e8c21f1 | 2009-10-15 21:11:16 -0300 | [diff] [blame] | 2235 | GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), ("Failed to send ftyp")); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2236 | return GST_FLOW_ERROR; |
| 2237 | } |
| 2238 | } |
| 2239 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2240 | static GstFlowReturn |
| 2241 | gst_qt_mux_pad_fragment_add_buffer (GstQTMux * qtmux, GstQTPad * pad, |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2242 | GstBuffer * buf, gboolean force, guint32 nsamples, gint64 dts, |
Mark Nauwelaerts | b6945d4 | 2011-01-03 16:56:57 +0100 | [diff] [blame] | 2243 | guint32 delta, guint32 size, gboolean sync, gint64 pts_offset) |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2244 | { |
| 2245 | GstFlowReturn ret = GST_FLOW_OK; |
| 2246 | |
| 2247 | /* setup if needed */ |
| 2248 | if (G_UNLIKELY (!pad->traf || force)) |
| 2249 | goto init; |
| 2250 | |
| 2251 | flush: |
| 2252 | /* flush pad fragment if threshold reached, |
| 2253 | * or at new keyframe if we should be minding those in the first place */ |
| 2254 | if (G_UNLIKELY (force || (sync && pad->sync) || |
| 2255 | pad->fragment_duration < (gint64) delta)) { |
| 2256 | AtomMOOF *moof; |
| 2257 | guint64 size = 0, offset = 0; |
| 2258 | guint8 *data = NULL; |
| 2259 | GstBuffer *buffer; |
| 2260 | guint i, total_size; |
| 2261 | |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2262 | /* now we know where moof ends up, update offset in tfra */ |
| 2263 | if (pad->tfra) |
| 2264 | atom_tfra_update_offset (pad->tfra, qtmux->header_size); |
| 2265 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2266 | moof = atom_moof_new (qtmux->context, qtmux->fragment_sequence); |
| 2267 | /* takes ownership */ |
| 2268 | atom_moof_add_traf (moof, pad->traf); |
| 2269 | pad->traf = NULL; |
| 2270 | atom_moof_copy_data (moof, &data, &size, &offset); |
| 2271 | buffer = _gst_buffer_new_take_data (data, offset); |
Matej Knopp | 1e5dd9e | 2011-11-21 20:31:31 +0100 | [diff] [blame] | 2272 | GST_LOG_OBJECT (qtmux, "writing moof size %" G_GSIZE_FORMAT, |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2273 | gst_buffer_get_size (buffer)); |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2274 | ret = gst_qt_mux_send_buffer (qtmux, buffer, &qtmux->header_size, FALSE); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2275 | |
| 2276 | /* and actual data */ |
| 2277 | total_size = 0; |
| 2278 | for (i = 0; i < atom_array_get_len (&pad->fragment_buffers); i++) { |
| 2279 | total_size += |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2280 | gst_buffer_get_size (atom_array_index (&pad->fragment_buffers, i)); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | GST_LOG_OBJECT (qtmux, "writing %d buffers, total_size %d", |
| 2284 | atom_array_get_len (&pad->fragment_buffers), total_size); |
| 2285 | if (ret == GST_FLOW_OK) |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2286 | ret = gst_qt_mux_send_mdat_header (qtmux, &qtmux->header_size, total_size, |
| 2287 | FALSE); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2288 | for (i = 0; i < atom_array_get_len (&pad->fragment_buffers); i++) { |
| 2289 | if (G_LIKELY (ret == GST_FLOW_OK)) |
| 2290 | ret = gst_qt_mux_send_buffer (qtmux, |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2291 | atom_array_index (&pad->fragment_buffers, i), &qtmux->header_size, |
| 2292 | FALSE); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2293 | else |
| 2294 | gst_buffer_unref (atom_array_index (&pad->fragment_buffers, i)); |
| 2295 | } |
| 2296 | |
| 2297 | atom_array_clear (&pad->fragment_buffers); |
| 2298 | atom_moof_free (moof); |
| 2299 | qtmux->fragment_sequence++; |
| 2300 | force = FALSE; |
| 2301 | } |
| 2302 | |
| 2303 | init: |
| 2304 | if (G_UNLIKELY (!pad->traf)) { |
| 2305 | GST_LOG_OBJECT (qtmux, "setting up new fragment"); |
| 2306 | pad->traf = atom_traf_new (qtmux->context, atom_trak_get_id (pad->trak)); |
| 2307 | atom_array_init (&pad->fragment_buffers, 512); |
| 2308 | pad->fragment_duration = gst_util_uint64_scale (qtmux->fragment_duration, |
| 2309 | atom_trak_get_timescale (pad->trak), 1000); |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2310 | |
| 2311 | if (G_UNLIKELY (qtmux->mfra && !pad->tfra)) { |
| 2312 | pad->tfra = atom_tfra_new (qtmux->context, atom_trak_get_id (pad->trak)); |
| 2313 | atom_mfra_add_tfra (qtmux->mfra, pad->tfra); |
| 2314 | } |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | /* add buffer and metadata */ |
Mark Nauwelaerts | b6945d4 | 2011-01-03 16:56:57 +0100 | [diff] [blame] | 2318 | atom_traf_add_samples (pad->traf, delta, size, sync, pts_offset, |
Mark Nauwelaerts | 92b8a00 | 2010-11-19 17:41:41 +0100 | [diff] [blame] | 2319 | pad->sync && sync); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2320 | atom_array_append (&pad->fragment_buffers, buf, 256); |
| 2321 | pad->fragment_duration -= delta; |
| 2322 | |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 2323 | if (pad->tfra) { |
| 2324 | guint32 sn = atom_traf_get_sample_num (pad->traf); |
| 2325 | |
| 2326 | if ((sync && pad->sync) || (sn == 1 && !pad->sync)) |
| 2327 | atom_tfra_add_entry (pad->tfra, dts, sn); |
| 2328 | } |
| 2329 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2330 | if (G_UNLIKELY (force)) |
| 2331 | goto flush; |
| 2332 | |
| 2333 | return ret; |
| 2334 | } |
| 2335 | |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 2336 | static GstFlowReturn |
| 2337 | gst_qt_mux_register_and_push_sample (GstQTMux * qtmux, GstQTPad * pad, |
| 2338 | GstBuffer * buffer, gboolean is_last_buffer, guint nsamples, |
| 2339 | gint64 last_dts, gint64 scaled_duration, guint sample_size, |
Matej Knopp | 2505e34 | 2014-12-09 02:43:00 +0100 | [diff] [blame] | 2340 | guint64 chunk_offset, gboolean sync, gboolean do_pts, gint64 pts_offset) |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 2341 | { |
| 2342 | GstFlowReturn ret = GST_FLOW_OK; |
| 2343 | |
| 2344 | /* note that a new chunk is started each time (not fancy but works) */ |
| 2345 | if (qtmux->moov_recov_file) { |
| 2346 | if (!atoms_recov_write_trak_samples (qtmux->moov_recov_file, pad->trak, |
| 2347 | nsamples, (gint32) scaled_duration, sample_size, chunk_offset, sync, |
| 2348 | do_pts, pts_offset)) { |
| 2349 | GST_WARNING_OBJECT (qtmux, "Failed to write sample information to " |
| 2350 | "recovery file, disabling recovery"); |
| 2351 | fclose (qtmux->moov_recov_file); |
| 2352 | qtmux->moov_recov_file = NULL; |
| 2353 | } |
| 2354 | } |
| 2355 | |
Jan Schmidt | fe739b7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 2356 | switch (qtmux->mux_mode) { |
| 2357 | case GST_QT_MUX_MODE_MOOV_AT_END: |
| 2358 | case GST_QT_MUX_MODE_FAST_START: |
| 2359 | |
| 2360 | atom_trak_add_samples (pad->trak, nsamples, (gint32) scaled_duration, |
| 2361 | sample_size, chunk_offset, sync, pts_offset); |
| 2362 | ret = gst_qt_mux_send_buffer (qtmux, buffer, &qtmux->mdat_size, TRUE); |
| 2363 | break; |
| 2364 | case GST_QT_MUX_MODE_FRAGMENTED: |
| 2365 | case GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE: |
| 2366 | /* ensure that always sync samples are marked as such */ |
| 2367 | ret = gst_qt_mux_pad_fragment_add_buffer (qtmux, pad, buffer, |
| 2368 | is_last_buffer, nsamples, last_dts, (gint32) scaled_duration, |
| 2369 | sample_size, !pad->sync || sync, pts_offset); |
| 2370 | break; |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | return ret; |
| 2374 | } |
| 2375 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2376 | /* |
| 2377 | * Here we push the buffer and update the tables in the track atoms |
| 2378 | */ |
| 2379 | static GstFlowReturn |
| 2380 | gst_qt_mux_add_buffer (GstQTMux * qtmux, GstQTPad * pad, GstBuffer * buf) |
| 2381 | { |
| 2382 | GstBuffer *last_buf = NULL; |
| 2383 | GstClockTime duration; |
| 2384 | guint nsamples, sample_size; |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 2385 | guint64 chunk_offset; |
| 2386 | gint64 last_dts, scaled_duration; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2387 | gint64 pts_offset = 0; |
Thiago Santos | 39c0928 | 2015-04-07 16:12:40 -0300 | [diff] [blame] | 2388 | gboolean sync = FALSE; |
Mark Nauwelaerts | 4df05e7 | 2011-04-15 12:34:05 +0200 | [diff] [blame] | 2389 | GstFlowReturn ret = GST_FLOW_OK; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2390 | |
| 2391 | if (!pad->fourcc) |
| 2392 | goto not_negotiated; |
| 2393 | |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 2394 | /* if this pad has a prepare function, call it */ |
| 2395 | if (pad->prepare_buf_func != NULL) { |
| 2396 | buf = pad->prepare_buf_func (pad, buf, qtmux); |
| 2397 | } |
| 2398 | |
Mark Nauwelaerts | 4df05e7 | 2011-04-15 12:34:05 +0200 | [diff] [blame] | 2399 | last_buf = pad->last_buf; |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 2400 | |
Matej Knopp | 9f85dfd | 2014-09-23 23:33:37 +0200 | [diff] [blame] | 2401 | /* DTS delta is used to calculate sample duration. |
| 2402 | * If buffer has missing DTS, we take either segment start or |
| 2403 | * previous buffer end time, whichever is later. |
| 2404 | * This must only be done for non sparse streams, sparse streams |
| 2405 | * can have gaps between buffers (which is handled later by adding |
| 2406 | * extra empty buffer with duration that fills the gap). */ |
| 2407 | if (!pad->sparse && buf && !GST_BUFFER_DTS_IS_VALID (buf)) { |
Matej Knopp | 4e3c13c | 2013-09-14 15:54:29 +0200 | [diff] [blame] | 2408 | GstClockTime last_buf_duration = last_buf |
| 2409 | && GST_BUFFER_DURATION_IS_VALID (last_buf) ? |
| 2410 | GST_BUFFER_DURATION (last_buf) : 0; |
| 2411 | |
| 2412 | buf = gst_buffer_make_writable (buf); |
Thiago Santos | 5780afe | 2015-04-07 00:53:35 -0300 | [diff] [blame] | 2413 | GST_BUFFER_DTS (buf) = 0; /* running-time 0 */ |
Matej Knopp | 4e3c13c | 2013-09-14 15:54:29 +0200 | [diff] [blame] | 2414 | |
| 2415 | if (last_buf |
| 2416 | && (GST_BUFFER_DTS (last_buf) + last_buf_duration) > |
| 2417 | GST_BUFFER_DTS (buf)) { |
| 2418 | GST_BUFFER_DTS (buf) = GST_BUFFER_DTS (last_buf) + last_buf_duration; |
| 2419 | } |
Thiago Santos | f5f27f7 | 2014-02-07 10:07:41 -0300 | [diff] [blame] | 2420 | |
| 2421 | if (GST_BUFFER_PTS_IS_VALID (buf)) |
| 2422 | GST_BUFFER_DTS (buf) = MIN (GST_BUFFER_DTS (buf), GST_BUFFER_PTS (buf)); |
Matej Knopp | 4e3c13c | 2013-09-14 15:54:29 +0200 | [diff] [blame] | 2423 | } |
| 2424 | |
Matej Knopp | 39f7e52 | 2013-09-14 15:55:22 +0200 | [diff] [blame] | 2425 | if (last_buf && !buf && !GST_BUFFER_DURATION_IS_VALID (last_buf)) { |
| 2426 | /* this is last buffer; there is no next buffer so we need valid number as duration */ |
| 2427 | last_buf = gst_buffer_make_writable (last_buf); |
| 2428 | GST_BUFFER_DURATION (last_buf) = 0; |
| 2429 | } |
| 2430 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2431 | if (last_buf == NULL) { |
| 2432 | #ifndef GST_DISABLE_GST_DEBUG |
| 2433 | if (buf == NULL) { |
| 2434 | GST_DEBUG_OBJECT (qtmux, "Pad %s has no previous buffer stored and " |
| 2435 | "received NULL buffer, doing nothing", |
| 2436 | GST_PAD_NAME (pad->collect.pad)); |
| 2437 | } else { |
| 2438 | GST_LOG_OBJECT (qtmux, |
| 2439 | "Pad %s has no previous buffer stored, storing now", |
| 2440 | GST_PAD_NAME (pad->collect.pad)); |
| 2441 | } |
| 2442 | #endif |
| 2443 | pad->last_buf = buf; |
Mark Nauwelaerts | 4df05e7 | 2011-04-15 12:34:05 +0200 | [diff] [blame] | 2444 | goto exit; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2445 | } else |
| 2446 | gst_buffer_ref (last_buf); |
| 2447 | |
Thiago Santos | 261d11a | 2011-09-09 09:12:56 -0300 | [diff] [blame] | 2448 | /* if this is the first buffer, store the timestamp */ |
| 2449 | if (G_UNLIKELY (pad->first_ts == GST_CLOCK_TIME_NONE) && last_buf) { |
Thiago Santos | f5f27f7 | 2014-02-07 10:07:41 -0300 | [diff] [blame] | 2450 | if (GST_BUFFER_DTS_IS_VALID (last_buf)) { |
Matej Knopp | b363832 | 2013-09-14 15:56:04 +0200 | [diff] [blame] | 2451 | pad->first_ts = GST_BUFFER_DTS (last_buf); |
| 2452 | } else if (GST_BUFFER_PTS_IS_VALID (last_buf)) { |
David Schleef | 258c40c | 2013-02-14 16:34:34 -0800 | [diff] [blame] | 2453 | pad->first_ts = GST_BUFFER_PTS (last_buf); |
Matej Knopp | b363832 | 2013-09-14 15:56:04 +0200 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | if (GST_CLOCK_TIME_IS_VALID (pad->first_ts)) { |
David Schleef | ee56a7c | 2013-03-13 17:08:03 -0700 | [diff] [blame] | 2457 | GST_DEBUG ("setting first_ts to %" G_GUINT64_FORMAT, pad->first_ts); |
Thiago Santos | 261d11a | 2011-09-09 09:12:56 -0300 | [diff] [blame] | 2458 | } else { |
Thiago Santos | 5780afe | 2015-04-07 00:53:35 -0300 | [diff] [blame] | 2459 | GST_WARNING_OBJECT (qtmux, "First buffer for pad %s has no timestamp, " |
Thiago Santos | 261d11a | 2011-09-09 09:12:56 -0300 | [diff] [blame] | 2460 | "using 0 as first timestamp", GST_PAD_NAME (pad->collect.pad)); |
| 2461 | pad->first_ts = 0; |
| 2462 | } |
| 2463 | GST_DEBUG_OBJECT (qtmux, "Stored first timestamp for pad %s %" |
| 2464 | GST_TIME_FORMAT, GST_PAD_NAME (pad->collect.pad), |
| 2465 | GST_TIME_ARGS (pad->first_ts)); |
Thiago Santos | 261d11a | 2011-09-09 09:12:56 -0300 | [diff] [blame] | 2466 | } |
| 2467 | |
David Schleef | ee56a7c | 2013-03-13 17:08:03 -0700 | [diff] [blame] | 2468 | if (last_buf && buf && GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (buf)) && |
| 2469 | GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (last_buf)) && |
| 2470 | GST_BUFFER_DTS (buf) < GST_BUFFER_DTS (last_buf)) { |
| 2471 | GST_ERROR ("decreasing DTS value %" GST_TIME_FORMAT " < %" GST_TIME_FORMAT, |
| 2472 | GST_TIME_ARGS (GST_BUFFER_DTS (buf)), |
| 2473 | GST_TIME_ARGS (GST_BUFFER_DTS (last_buf))); |
| 2474 | GST_BUFFER_DTS (buf) = GST_BUFFER_DTS (last_buf); |
| 2475 | } |
| 2476 | |
Matej Knopp | 5686512 | 2013-03-23 05:22:23 +0100 | [diff] [blame] | 2477 | /* duration actually means time delta between samples, so we calculate |
| 2478 | * the duration based on the difference in DTS or PTS, falling back |
| 2479 | * to DURATION if the other two don't exist, such as with the last |
| 2480 | * sample before EOS. */ |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 2481 | duration = GST_BUFFER_DURATION (last_buf); |
| 2482 | if (!pad->sparse) { |
| 2483 | if (last_buf && buf && GST_BUFFER_DTS_IS_VALID (buf) |
| 2484 | && GST_BUFFER_DTS_IS_VALID (last_buf)) |
| 2485 | duration = GST_BUFFER_DTS (buf) - GST_BUFFER_DTS (last_buf); |
| 2486 | else if (last_buf && buf && GST_BUFFER_PTS_IS_VALID (buf) |
| 2487 | && GST_BUFFER_PTS_IS_VALID (last_buf)) |
| 2488 | duration = GST_BUFFER_PTS (buf) - GST_BUFFER_PTS (last_buf); |
| 2489 | } |
| 2490 | |
| 2491 | gst_buffer_replace (&pad->last_buf, buf); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2492 | |
Thiago Santos | 7a143ea | 2011-09-28 11:41:49 -0300 | [diff] [blame] | 2493 | /* for computing the avg bitrate */ |
| 2494 | if (G_LIKELY (last_buf)) { |
Wim Taymans | 9402122 | 2011-10-06 12:26:33 +0200 | [diff] [blame] | 2495 | pad->total_bytes += gst_buffer_get_size (last_buf); |
Thiago Santos | 7a143ea | 2011-09-28 11:41:49 -0300 | [diff] [blame] | 2496 | pad->total_duration += duration; |
| 2497 | } |
| 2498 | |
Thiago Santos | 79a9031 | 2009-11-25 21:41:27 -0300 | [diff] [blame] | 2499 | last_dts = gst_util_uint64_scale_round (pad->last_dts, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2500 | atom_trak_get_timescale (pad->trak), GST_SECOND); |
| 2501 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 2502 | /* fragments only deal with 1 buffer == 1 chunk (== 1 sample) */ |
| 2503 | if (pad->sample_size && !qtmux->fragment_sequence) { |
Michael Smith | d784a8d | 2010-01-27 15:37:37 -0800 | [diff] [blame] | 2504 | /* Constant size packets: usually raw audio (with many samples per |
| 2505 | buffer (= chunk)), but can also be fixed-packet-size codecs like ADPCM |
| 2506 | */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2507 | sample_size = pad->sample_size; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2508 | if (gst_buffer_get_size (last_buf) % sample_size != 0) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2509 | goto fragmented_sample; |
| 2510 | /* note: qt raw audio storage warps it implicitly into a timewise |
| 2511 | * perfect stream, discarding buffer times */ |
Michael Smith | d784a8d | 2010-01-27 15:37:37 -0800 | [diff] [blame] | 2512 | if (GST_BUFFER_DURATION (last_buf) != GST_CLOCK_TIME_NONE) { |
| 2513 | nsamples = gst_util_uint64_scale_round (GST_BUFFER_DURATION (last_buf), |
| 2514 | atom_trak_get_timescale (pad->trak), GST_SECOND); |
| 2515 | } else { |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2516 | nsamples = gst_buffer_get_size (last_buf) / sample_size; |
Michael Smith | d784a8d | 2010-01-27 15:37:37 -0800 | [diff] [blame] | 2517 | } |
Vincent Penquerc'h | 1be86eb | 2014-05-02 10:21:09 +0100 | [diff] [blame] | 2518 | if (nsamples > 0) |
| 2519 | duration = GST_BUFFER_DURATION (last_buf) / nsamples; |
| 2520 | else |
| 2521 | duration = 0; |
Michael Smith | d784a8d | 2010-01-27 15:37:37 -0800 | [diff] [blame] | 2522 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2523 | /* timescale = samplerate */ |
| 2524 | scaled_duration = 1; |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 2525 | pad->last_dts += duration * nsamples; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2526 | } else { |
| 2527 | nsamples = 1; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2528 | sample_size = gst_buffer_get_size (last_buf); |
Thiago Santos | f5f27f7 | 2014-02-07 10:07:41 -0300 | [diff] [blame] | 2529 | if ((pad->last_buf && GST_BUFFER_DTS_IS_VALID (pad->last_buf)) |
| 2530 | || GST_BUFFER_DTS_IS_VALID (last_buf)) { |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 2531 | gint64 scaled_dts; |
Thiago Santos | f5f27f7 | 2014-02-07 10:07:41 -0300 | [diff] [blame] | 2532 | if (pad->last_buf && GST_BUFFER_DTS_IS_VALID (pad->last_buf)) { |
Matej Knopp | 85728c0 | 2013-09-03 18:14:04 +0200 | [diff] [blame] | 2533 | pad->last_dts = GST_BUFFER_DTS (pad->last_buf); |
David Schleef | ee56a7c | 2013-03-13 17:08:03 -0700 | [diff] [blame] | 2534 | } else { |
| 2535 | pad->last_dts = GST_BUFFER_DTS (last_buf) + |
| 2536 | GST_BUFFER_DURATION (last_buf); |
| 2537 | } |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 2538 | if ((gint64) (pad->last_dts) < 0) { |
Thiago Santos | 79a9031 | 2009-11-25 21:41:27 -0300 | [diff] [blame] | 2539 | scaled_dts = -gst_util_uint64_scale_round (-pad->last_dts, |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 2540 | atom_trak_get_timescale (pad->trak), GST_SECOND); |
| 2541 | } else { |
Thiago Santos | 79a9031 | 2009-11-25 21:41:27 -0300 | [diff] [blame] | 2542 | scaled_dts = gst_util_uint64_scale_round (pad->last_dts, |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 2543 | atom_trak_get_timescale (pad->trak), GST_SECOND); |
| 2544 | } |
| 2545 | scaled_duration = scaled_dts - last_dts; |
| 2546 | last_dts = scaled_dts; |
| 2547 | } else { |
| 2548 | /* first convert intended timestamp (in GstClockTime resolution) to |
| 2549 | * trak timescale, then derive delta; |
| 2550 | * this ensures sums of (scale)delta add up to converted timestamp, |
| 2551 | * which only deviates at most 1/scale from timestamp itself */ |
Thiago Santos | 79a9031 | 2009-11-25 21:41:27 -0300 | [diff] [blame] | 2552 | scaled_duration = gst_util_uint64_scale_round (pad->last_dts + duration, |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 2553 | atom_trak_get_timescale (pad->trak), GST_SECOND) - last_dts; |
| 2554 | pad->last_dts += duration; |
| 2555 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2556 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2557 | chunk_offset = qtmux->mdat_size; |
| 2558 | |
| 2559 | GST_LOG_OBJECT (qtmux, |
| 2560 | "Pad (%s) dts updated to %" GST_TIME_FORMAT, |
| 2561 | GST_PAD_NAME (pad->collect.pad), GST_TIME_ARGS (pad->last_dts)); |
| 2562 | GST_LOG_OBJECT (qtmux, |
| 2563 | "Adding %d samples to track, duration: %" G_GUINT64_FORMAT |
| 2564 | " size: %" G_GUINT32_FORMAT " chunk offset: %" G_GUINT64_FORMAT, |
| 2565 | nsamples, scaled_duration, sample_size, chunk_offset); |
| 2566 | |
| 2567 | /* might be a sync sample */ |
| 2568 | if (pad->sync && |
| 2569 | !GST_BUFFER_FLAG_IS_SET (last_buf, GST_BUFFER_FLAG_DELTA_UNIT)) { |
| 2570 | GST_LOG_OBJECT (qtmux, "Adding new sync sample entry for track of pad %s", |
| 2571 | GST_PAD_NAME (pad->collect.pad)); |
| 2572 | sync = TRUE; |
| 2573 | } |
| 2574 | |
David Schleef | 258c40c | 2013-02-14 16:34:34 -0800 | [diff] [blame] | 2575 | if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (last_buf))) { |
David Schleef | 258c40c | 2013-02-14 16:34:34 -0800 | [diff] [blame] | 2576 | last_dts = gst_util_uint64_scale_round (GST_BUFFER_DTS (last_buf), |
| 2577 | atom_trak_get_timescale (pad->trak), GST_SECOND); |
| 2578 | pts_offset = |
| 2579 | (gint64) (gst_util_uint64_scale_round (GST_BUFFER_PTS (last_buf), |
| 2580 | atom_trak_get_timescale (pad->trak), GST_SECOND) - last_dts); |
| 2581 | |
| 2582 | } else { |
| 2583 | pts_offset = 0; |
David Schleef | 258c40c | 2013-02-14 16:34:34 -0800 | [diff] [blame] | 2584 | last_dts = gst_util_uint64_scale_round (GST_BUFFER_PTS (last_buf), |
| 2585 | atom_trak_get_timescale (pad->trak), GST_SECOND); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2586 | } |
David Schleef | 258c40c | 2013-02-14 16:34:34 -0800 | [diff] [blame] | 2587 | GST_DEBUG ("dts: %" GST_TIME_FORMAT " pts: %" GST_TIME_FORMAT |
| 2588 | " timebase_dts: %d pts_offset: %d", |
| 2589 | GST_TIME_ARGS (GST_BUFFER_DTS (last_buf)), |
| 2590 | GST_TIME_ARGS (GST_BUFFER_PTS (last_buf)), |
| 2591 | (int) (last_dts), (int) (pts_offset)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2592 | |
Thiago Santos | 4ff2fad | 2009-10-16 10:47:32 -0300 | [diff] [blame] | 2593 | /* |
| 2594 | * Each buffer starts a new chunk, so we can assume the buffer |
| 2595 | * duration is the chunk duration |
| 2596 | */ |
| 2597 | if (GST_CLOCK_TIME_IS_VALID (duration) && (duration > qtmux->longest_chunk || |
| 2598 | !GST_CLOCK_TIME_IS_VALID (qtmux->longest_chunk))) { |
| 2599 | GST_DEBUG_OBJECT (qtmux, "New longest chunk found: %" GST_TIME_FORMAT |
| 2600 | ", pad %s", GST_TIME_ARGS (duration), GST_PAD_NAME (pad->collect.pad)); |
| 2601 | qtmux->longest_chunk = duration; |
| 2602 | } |
| 2603 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2604 | /* now we go and register this buffer/sample all over */ |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 2605 | ret = gst_qt_mux_register_and_push_sample (qtmux, pad, last_buf, |
| 2606 | buf == NULL, nsamples, last_dts, scaled_duration, sample_size, |
Thiago Santos | 39c0928 | 2015-04-07 16:12:40 -0300 | [diff] [blame] | 2607 | chunk_offset, sync, TRUE, pts_offset); |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 2608 | |
| 2609 | /* if this is sparse and we have a next buffer, check if there is any gap |
| 2610 | * between them to insert an empty sample */ |
| 2611 | if (pad->sparse && buf) { |
| 2612 | if (pad->create_empty_buffer) { |
| 2613 | GstBuffer *empty_buf; |
| 2614 | gint64 empty_duration = |
| 2615 | GST_BUFFER_TIMESTAMP (buf) - (GST_BUFFER_TIMESTAMP (last_buf) + |
| 2616 | duration); |
| 2617 | gint64 empty_duration_scaled; |
| 2618 | |
| 2619 | empty_buf = pad->create_empty_buffer (pad, empty_duration); |
| 2620 | |
| 2621 | empty_duration_scaled = gst_util_uint64_scale_round (empty_duration, |
| 2622 | atom_trak_get_timescale (pad->trak), GST_SECOND); |
| 2623 | |
| 2624 | pad->total_bytes += gst_buffer_get_size (empty_buf); |
| 2625 | pad->total_duration += duration; |
| 2626 | |
| 2627 | ret = |
| 2628 | gst_qt_mux_register_and_push_sample (qtmux, pad, empty_buf, FALSE, 1, |
| 2629 | last_dts + scaled_duration, empty_duration_scaled, |
Thiago Santos | 39c0928 | 2015-04-07 16:12:40 -0300 | [diff] [blame] | 2630 | gst_buffer_get_size (empty_buf), qtmux->mdat_size, sync, TRUE, 0); |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 2631 | } else { |
| 2632 | /* our only case currently is tx3g subtitles, so there is no reason to fill this yet */ |
| 2633 | g_assert_not_reached (); |
| 2634 | GST_WARNING_OBJECT (qtmux, |
| 2635 | "no empty buffer creation function found for pad %s", |
| 2636 | GST_PAD_NAME (pad->collect.pad)); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 2637 | } |
| 2638 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2639 | |
| 2640 | if (buf) |
| 2641 | gst_buffer_unref (buf); |
| 2642 | |
Mark Nauwelaerts | 4df05e7 | 2011-04-15 12:34:05 +0200 | [diff] [blame] | 2643 | exit: |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 2644 | |
| 2645 | return ret; |
| 2646 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2647 | /* ERRORS */ |
| 2648 | bail: |
| 2649 | { |
| 2650 | if (buf) |
| 2651 | gst_buffer_unref (buf); |
| 2652 | gst_buffer_unref (last_buf); |
| 2653 | return GST_FLOW_ERROR; |
| 2654 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2655 | fragmented_sample: |
| 2656 | { |
| 2657 | GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), |
| 2658 | ("Audio buffer contains fragmented sample.")); |
| 2659 | goto bail; |
| 2660 | } |
| 2661 | not_negotiated: |
| 2662 | { |
| 2663 | GST_ELEMENT_ERROR (qtmux, CORE, NEGOTIATION, (NULL), |
| 2664 | ("format wasn't negotiated before buffer flow on pad %s", |
| 2665 | GST_PAD_NAME (pad->collect.pad))); |
Thiago Santos | 009d104 | 2009-11-06 00:46:12 -0300 | [diff] [blame] | 2666 | if (buf) |
| 2667 | gst_buffer_unref (buf); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2668 | return GST_FLOW_NOT_NEGOTIATED; |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | static GstFlowReturn |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 2673 | gst_qt_mux_handle_buffer (GstCollectPads * pads, GstCollectData * cdata, |
Mark Nauwelaerts | 0c7a491 | 2011-12-16 18:03:01 +0100 | [diff] [blame] | 2674 | GstBuffer * buf, gpointer user_data) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2675 | { |
| 2676 | GstFlowReturn ret = GST_FLOW_OK; |
| 2677 | GstQTMux *qtmux = GST_QT_MUX_CAST (user_data); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2678 | GstQTPad *best_pad = NULL; |
Mark Nauwelaerts | 0c7a491 | 2011-12-16 18:03:01 +0100 | [diff] [blame] | 2679 | GstClockTime best_time = GST_CLOCK_TIME_NONE; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2680 | |
| 2681 | if (G_UNLIKELY (qtmux->state == GST_QT_MUX_STATE_STARTED)) { |
| 2682 | if ((ret = gst_qt_mux_start_file (qtmux)) != GST_FLOW_OK) |
| 2683 | return ret; |
| 2684 | else |
| 2685 | qtmux->state = GST_QT_MUX_STATE_DATA; |
| 2686 | } |
| 2687 | |
| 2688 | if (G_UNLIKELY (qtmux->state == GST_QT_MUX_STATE_EOS)) |
Wim Taymans | 5fd2b7a | 2012-01-03 15:26:21 +0100 | [diff] [blame] | 2689 | return GST_FLOW_EOS; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2690 | |
Mark Nauwelaerts | 0c7a491 | 2011-12-16 18:03:01 +0100 | [diff] [blame] | 2691 | best_pad = (GstQTPad *) cdata; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2692 | |
Mark Nauwelaerts | 0c7a491 | 2011-12-16 18:03:01 +0100 | [diff] [blame] | 2693 | /* clipping already converted to running time */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2694 | if (best_pad != NULL) { |
Mark Nauwelaerts | 0c7a491 | 2011-12-16 18:03:01 +0100 | [diff] [blame] | 2695 | g_assert (buf); |
David Schleef | 258c40c | 2013-02-14 16:34:34 -0800 | [diff] [blame] | 2696 | best_time = GST_BUFFER_PTS (buf); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2697 | GST_LOG_OBJECT (qtmux, "selected pad %s with time %" GST_TIME_FORMAT, |
| 2698 | GST_PAD_NAME (best_pad->collect.pad), GST_TIME_ARGS (best_time)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2699 | ret = gst_qt_mux_add_buffer (qtmux, best_pad, buf); |
| 2700 | } else { |
| 2701 | ret = gst_qt_mux_stop_file (qtmux); |
| 2702 | if (ret == GST_FLOW_OK) { |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 2703 | GST_DEBUG_OBJECT (qtmux, "Pushing eos"); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2704 | gst_pad_push_event (qtmux->srcpad, gst_event_new_eos ()); |
Wim Taymans | 5fd2b7a | 2012-01-03 15:26:21 +0100 | [diff] [blame] | 2705 | ret = GST_FLOW_EOS; |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 2706 | } else { |
| 2707 | GST_WARNING_OBJECT (qtmux, "Failed to stop file: %s", |
| 2708 | gst_flow_get_name (ret)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2709 | } |
| 2710 | qtmux->state = GST_QT_MUX_STATE_EOS; |
| 2711 | } |
| 2712 | |
| 2713 | return ret; |
| 2714 | } |
| 2715 | |
| 2716 | static gboolean |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 2717 | check_field (GQuark field_id, const GValue * value, gpointer user_data) |
| 2718 | { |
| 2719 | GstStructure *structure = (GstStructure *) user_data; |
| 2720 | const GValue *other = gst_structure_id_get_value (structure, field_id); |
| 2721 | if (other == NULL) |
| 2722 | return FALSE; |
| 2723 | return gst_value_compare (value, other) == GST_VALUE_EQUAL; |
| 2724 | } |
| 2725 | |
| 2726 | static gboolean |
| 2727 | gst_qtmux_caps_is_subset_full (GstQTMux * qtmux, GstCaps * subset, |
| 2728 | GstCaps * superset) |
| 2729 | { |
| 2730 | GstStructure *sub_s = gst_caps_get_structure (subset, 0); |
| 2731 | GstStructure *sup_s = gst_caps_get_structure (superset, 0); |
| 2732 | |
| 2733 | return gst_structure_foreach (sub_s, check_field, sup_s); |
| 2734 | } |
| 2735 | |
| 2736 | static gboolean |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 2737 | gst_qt_mux_audio_sink_set_caps (GstQTPad * qtpad, GstCaps * caps) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2738 | { |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 2739 | GstPad *pad = qtpad->collect.pad; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2740 | GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad)); |
| 2741 | GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2742 | GstStructure *structure; |
| 2743 | const gchar *mimetype; |
| 2744 | gint rate, channels; |
| 2745 | const GValue *value = NULL; |
| 2746 | const GstBuffer *codec_data = NULL; |
| 2747 | GstQTMuxFormat format; |
| 2748 | AudioSampleEntry entry = { 0, }; |
| 2749 | AtomInfo *ext_atom = NULL; |
| 2750 | gint constant_size = 0; |
Thiago Santos | cbc0b05 | 2010-01-11 10:34:32 -0300 | [diff] [blame] | 2751 | const gchar *stream_format; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2752 | |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 2753 | qtpad->prepare_buf_func = NULL; |
| 2754 | |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 2755 | /* does not go well to renegotiate stream mid-way, unless |
| 2756 | * the old caps are a subset of the new one (this means upstream |
| 2757 | * added more info to the caps, as both should be 'fixed' caps) */ |
| 2758 | if (qtpad->fourcc) { |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2759 | GstCaps *current_caps; |
| 2760 | |
| 2761 | current_caps = gst_pad_get_current_caps (pad); |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 2762 | g_assert (caps != NULL); |
| 2763 | |
| 2764 | if (!gst_qtmux_caps_is_subset_full (qtmux, current_caps, caps)) { |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2765 | gst_caps_unref (current_caps); |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 2766 | goto refuse_renegotiation; |
| 2767 | } |
| 2768 | GST_DEBUG_OBJECT (qtmux, |
| 2769 | "pad %s accepted renegotiation to %" GST_PTR_FORMAT " from %" |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2770 | GST_PTR_FORMAT, GST_PAD_NAME (pad), caps, current_caps); |
| 2771 | gst_caps_unref (current_caps); |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 2772 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2773 | |
| 2774 | GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT, |
| 2775 | GST_DEBUG_PAD_NAME (pad), caps); |
| 2776 | |
| 2777 | format = qtmux_klass->format; |
| 2778 | structure = gst_caps_get_structure (caps, 0); |
| 2779 | mimetype = gst_structure_get_name (structure); |
| 2780 | |
| 2781 | /* common info */ |
| 2782 | if (!gst_structure_get_int (structure, "channels", &channels) || |
| 2783 | !gst_structure_get_int (structure, "rate", &rate)) { |
| 2784 | goto refuse_caps; |
| 2785 | } |
| 2786 | |
| 2787 | /* optional */ |
| 2788 | value = gst_structure_get_value (structure, "codec_data"); |
| 2789 | if (value != NULL) |
| 2790 | codec_data = gst_value_get_buffer (value); |
| 2791 | |
| 2792 | qtpad->is_out_of_order = FALSE; |
| 2793 | |
| 2794 | /* set common properties */ |
| 2795 | entry.sample_rate = rate; |
| 2796 | entry.channels = channels; |
| 2797 | /* default */ |
| 2798 | entry.sample_size = 16; |
| 2799 | /* this is the typical compressed case */ |
| 2800 | if (format == GST_QT_MUX_FORMAT_QT) { |
| 2801 | entry.version = 1; |
| 2802 | entry.compression_id = -2; |
| 2803 | } |
| 2804 | |
| 2805 | /* now map onto a fourcc, and some extra properties */ |
| 2806 | if (strcmp (mimetype, "audio/mpeg") == 0) { |
| 2807 | gint mpegversion = 0; |
| 2808 | gint layer = -1; |
| 2809 | |
| 2810 | gst_structure_get_int (structure, "mpegversion", &mpegversion); |
| 2811 | switch (mpegversion) { |
| 2812 | case 1: |
| 2813 | gst_structure_get_int (structure, "layer", &layer); |
| 2814 | switch (layer) { |
| 2815 | case 3: |
| 2816 | /* mp3 */ |
| 2817 | /* note: QuickTime player does not like mp3 either way in iso/mp4 */ |
| 2818 | if (format == GST_QT_MUX_FORMAT_QT) |
| 2819 | entry.fourcc = FOURCC__mp3; |
| 2820 | else { |
| 2821 | entry.fourcc = FOURCC_mp4a; |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 2822 | ext_atom = |
| 2823 | build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG1_P3, |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 2824 | ESDS_STREAM_TYPE_AUDIO, codec_data, qtpad->avg_bitrate, |
| 2825 | qtpad->max_bitrate); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2826 | } |
| 2827 | entry.samples_per_packet = 1152; |
| 2828 | entry.bytes_per_sample = 2; |
| 2829 | break; |
| 2830 | } |
| 2831 | break; |
| 2832 | case 4: |
Thiago Santos | cbc0b05 | 2010-01-11 10:34:32 -0300 | [diff] [blame] | 2833 | |
| 2834 | /* check stream-format */ |
| 2835 | stream_format = gst_structure_get_string (structure, "stream-format"); |
| 2836 | if (stream_format) { |
Thiago Santos | 87450c1 | 2010-01-11 13:13:41 -0300 | [diff] [blame] | 2837 | if (strcmp (stream_format, "raw") != 0) { |
Thiago Santos | cbc0b05 | 2010-01-11 10:34:32 -0300 | [diff] [blame] | 2838 | GST_WARNING_OBJECT (qtmux, "Unsupported AAC stream-format %s, " |
Thiago Santos | 87450c1 | 2010-01-11 13:13:41 -0300 | [diff] [blame] | 2839 | "please use 'raw'", stream_format); |
Thiago Santos | cbc0b05 | 2010-01-11 10:34:32 -0300 | [diff] [blame] | 2840 | goto refuse_caps; |
| 2841 | } |
| 2842 | } else { |
| 2843 | GST_WARNING_OBJECT (qtmux, "No stream-format present in caps, " |
Thiago Santos | 87450c1 | 2010-01-11 13:13:41 -0300 | [diff] [blame] | 2844 | "assuming 'raw'"); |
Thiago Santos | cbc0b05 | 2010-01-11 10:34:32 -0300 | [diff] [blame] | 2845 | } |
| 2846 | |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2847 | if (!codec_data || gst_buffer_get_size ((GstBuffer *) codec_data) < 2) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2848 | GST_WARNING_OBJECT (qtmux, "no (valid) codec_data for AAC audio"); |
| 2849 | else { |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2850 | guint8 profile; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2851 | |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2852 | gst_buffer_extract ((GstBuffer *) codec_data, 0, &profile, 1); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2853 | /* warn if not Low Complexity profile */ |
| 2854 | profile >>= 3; |
| 2855 | if (profile != 2) |
| 2856 | GST_WARNING_OBJECT (qtmux, |
| 2857 | "non-LC AAC may not run well on (Apple) QuickTime/iTunes"); |
| 2858 | } |
Thiago Santos | cbc0b05 | 2010-01-11 10:34:32 -0300 | [diff] [blame] | 2859 | |
| 2860 | /* AAC */ |
| 2861 | entry.fourcc = FOURCC_mp4a; |
| 2862 | |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 2863 | if (format == GST_QT_MUX_FORMAT_QT) |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 2864 | ext_atom = build_mov_aac_extension (qtpad->trak, codec_data, |
| 2865 | qtpad->avg_bitrate, qtpad->max_bitrate); |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 2866 | else |
| 2867 | ext_atom = |
| 2868 | build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG4_P3, |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 2869 | ESDS_STREAM_TYPE_AUDIO, codec_data, qtpad->avg_bitrate, |
| 2870 | qtpad->max_bitrate); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | default: |
| 2873 | break; |
| 2874 | } |
| 2875 | } else if (strcmp (mimetype, "audio/AMR") == 0) { |
| 2876 | entry.fourcc = FOURCC_samr; |
| 2877 | entry.sample_size = 16; |
| 2878 | entry.samples_per_packet = 160; |
| 2879 | entry.bytes_per_sample = 2; |
Mark Nauwelaerts | ffd2ff3 | 2009-01-28 13:25:14 +0100 | [diff] [blame] | 2880 | ext_atom = build_amr_extension (); |
| 2881 | } else if (strcmp (mimetype, "audio/AMR-WB") == 0) { |
| 2882 | entry.fourcc = FOURCC_sawb; |
| 2883 | entry.sample_size = 16; |
| 2884 | entry.samples_per_packet = 320; |
| 2885 | entry.bytes_per_sample = 2; |
| 2886 | ext_atom = build_amr_extension (); |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2887 | } else if (strcmp (mimetype, "audio/x-raw") == 0) { |
| 2888 | GstAudioInfo info; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2889 | |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2890 | gst_audio_info_init (&info); |
| 2891 | if (!gst_audio_info_from_caps (&info, caps)) |
Jan Urbanski | d43db1b | 2009-08-04 12:58:35 +0200 | [diff] [blame] | 2892 | goto refuse_caps; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2893 | |
| 2894 | /* spec has no place for a distinction in these */ |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2895 | if (info.finfo->width != info.finfo->depth) { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2896 | GST_DEBUG_OBJECT (qtmux, "width must be same as depth!"); |
| 2897 | goto refuse_caps; |
| 2898 | } |
| 2899 | |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2900 | if ((info.finfo->flags & GST_AUDIO_FORMAT_FLAG_SIGNED)) { |
| 2901 | if (info.finfo->endianness == G_LITTLE_ENDIAN) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2902 | entry.fourcc = FOURCC_sowt; |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2903 | else if (info.finfo->endianness == G_BIG_ENDIAN) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2904 | entry.fourcc = FOURCC_twos; |
| 2905 | /* maximum backward compatibility; only new version for > 16 bit */ |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2906 | if (info.finfo->depth <= 16) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2907 | entry.version = 0; |
| 2908 | /* not compressed in any case */ |
| 2909 | entry.compression_id = 0; |
| 2910 | /* QT spec says: max at 16 bit even if sample size were actually larger, |
| 2911 | * however, most players (e.g. QuickTime!) seem to disagree, so ... */ |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2912 | entry.sample_size = info.finfo->depth; |
| 2913 | entry.bytes_per_sample = info.finfo->depth / 8; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2914 | entry.samples_per_packet = 1; |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2915 | entry.bytes_per_packet = info.finfo->depth / 8; |
| 2916 | entry.bytes_per_frame = entry.bytes_per_packet * info.channels; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2917 | } else { |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2918 | if (info.finfo->width == 8 && info.finfo->depth == 8) { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2919 | /* fall back to old 8-bit version */ |
| 2920 | entry.fourcc = FOURCC_raw_; |
| 2921 | entry.version = 0; |
| 2922 | entry.compression_id = 0; |
| 2923 | entry.sample_size = 8; |
| 2924 | } else { |
| 2925 | GST_DEBUG_OBJECT (qtmux, "non 8-bit PCM must be signed"); |
| 2926 | goto refuse_caps; |
| 2927 | } |
| 2928 | } |
Sebastian Dröge | 940807b | 2012-01-04 11:29:26 +0100 | [diff] [blame] | 2929 | constant_size = (info.finfo->depth / 8) * info.channels; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2930 | } else if (strcmp (mimetype, "audio/x-alaw") == 0) { |
| 2931 | entry.fourcc = FOURCC_alaw; |
| 2932 | entry.samples_per_packet = 1023; |
| 2933 | entry.bytes_per_sample = 2; |
| 2934 | } else if (strcmp (mimetype, "audio/x-mulaw") == 0) { |
| 2935 | entry.fourcc = FOURCC_ulaw; |
| 2936 | entry.samples_per_packet = 1023; |
| 2937 | entry.bytes_per_sample = 2; |
Michael Smith | d74567c | 2009-12-08 17:55:56 -0800 | [diff] [blame] | 2938 | } else if (strcmp (mimetype, "audio/x-adpcm") == 0) { |
| 2939 | gint blocksize; |
| 2940 | if (!gst_structure_get_int (structure, "block_align", &blocksize)) { |
| 2941 | GST_DEBUG_OBJECT (qtmux, "broken caps, block_align missing"); |
| 2942 | goto refuse_caps; |
| 2943 | } |
Michael Smith | a597bd7 | 2009-12-08 17:59:04 -0800 | [diff] [blame] | 2944 | /* Currently only supports WAV-style IMA ADPCM, for which the codec id is |
| 2945 | 0x11 */ |
Michael Smith | d74567c | 2009-12-08 17:55:56 -0800 | [diff] [blame] | 2946 | entry.fourcc = MS_WAVE_FOURCC (0x11); |
Michael Smith | a597bd7 | 2009-12-08 17:59:04 -0800 | [diff] [blame] | 2947 | /* 4 byte header per channel (including one sample). 2 samples per byte |
| 2948 | remaining. Simplifying gives the following (samples per block per |
| 2949 | channel) */ |
Michael Smith | d74567c | 2009-12-08 17:55:56 -0800 | [diff] [blame] | 2950 | entry.samples_per_packet = 2 * blocksize / channels - 7; |
| 2951 | entry.bytes_per_sample = 2; |
| 2952 | |
Michael Smith | d784a8d | 2010-01-27 15:37:37 -0800 | [diff] [blame] | 2953 | entry.bytes_per_frame = blocksize; |
| 2954 | entry.bytes_per_packet = blocksize / channels; |
| 2955 | /* ADPCM has constant size packets */ |
| 2956 | constant_size = 1; |
| 2957 | /* TODO: I don't really understand why this helps, but it does! Constant |
| 2958 | * size and compression_id of -2 seem to be incompatible, and other files |
| 2959 | * in the wild use this too. */ |
| 2960 | entry.compression_id = -1; |
| 2961 | |
Michael Smith | d74567c | 2009-12-08 17:55:56 -0800 | [diff] [blame] | 2962 | ext_atom = build_ima_adpcm_extension (channels, rate, blocksize); |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2963 | } else if (strcmp (mimetype, "audio/x-alac") == 0) { |
| 2964 | GstBuffer *codec_config; |
| 2965 | gint len; |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 2966 | GstMapInfo map; |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2967 | |
| 2968 | entry.fourcc = FOURCC_alac; |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 2969 | gst_buffer_map ((GstBuffer *) codec_data, &map, GST_MAP_READ); |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2970 | /* let's check if codec data already comes with 'alac' atom prefix */ |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 2971 | if (!codec_data || (len = map.size) < 28) { |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2972 | GST_DEBUG_OBJECT (qtmux, "broken caps, codec data missing"); |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 2973 | gst_buffer_unmap ((GstBuffer *) codec_data, &map); |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2974 | goto refuse_caps; |
| 2975 | } |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 2976 | if (GST_READ_UINT32_LE (map.data + 4) == FOURCC_alac) { |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2977 | len -= 8; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 2978 | codec_config = |
Tim-Philipp Müller | aa94fc6 | 2014-12-25 21:32:40 +0000 | [diff] [blame] | 2979 | gst_buffer_copy_region ((GstBuffer *) codec_data, |
| 2980 | GST_BUFFER_COPY_MEMORY, 8, len); |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2981 | } else { |
| 2982 | codec_config = gst_buffer_ref ((GstBuffer *) codec_data); |
| 2983 | } |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 2984 | gst_buffer_unmap ((GstBuffer *) codec_data, &map); |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2985 | if (len != 28) { |
| 2986 | /* does not look good, but perhaps some trailing unneeded stuff */ |
| 2987 | GST_WARNING_OBJECT (qtmux, "unexpected codec-data size, possibly broken"); |
| 2988 | } |
| 2989 | if (format == GST_QT_MUX_FORMAT_QT) |
| 2990 | ext_atom = build_mov_alac_extension (qtpad->trak, codec_config); |
| 2991 | else |
| 2992 | ext_atom = build_codec_data_extension (FOURCC_alac, codec_config); |
| 2993 | /* set some more info */ |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 2994 | gst_buffer_map (codec_config, &map, GST_MAP_READ); |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2995 | entry.bytes_per_sample = 2; |
Wim Taymans | 583d39d | 2012-01-23 17:25:37 +0100 | [diff] [blame] | 2996 | entry.samples_per_packet = GST_READ_UINT32_BE (map.data + 4); |
| 2997 | gst_buffer_unmap (codec_config, &map); |
Mark Nauwelaerts | bcc9fe0 | 2010-02-16 16:24:12 +0100 | [diff] [blame] | 2998 | gst_buffer_unref (codec_config); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | if (!entry.fourcc) |
| 3002 | goto refuse_caps; |
| 3003 | |
| 3004 | /* ok, set the pad info accordingly */ |
| 3005 | qtpad->fourcc = entry.fourcc; |
| 3006 | qtpad->sample_size = constant_size; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3007 | atom_trak_set_audio_type (qtpad->trak, qtmux->context, &entry, |
Marc-André Lureau | bee00aa | 2010-07-30 12:48:29 +0200 | [diff] [blame] | 3008 | qtmux->trak_timescale ? qtmux->trak_timescale : entry.sample_rate, |
| 3009 | ext_atom, constant_size); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3010 | |
| 3011 | gst_object_unref (qtmux); |
| 3012 | return TRUE; |
| 3013 | |
| 3014 | /* ERRORS */ |
| 3015 | refuse_caps: |
| 3016 | { |
| 3017 | GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT, |
| 3018 | GST_PAD_NAME (pad), caps); |
| 3019 | gst_object_unref (qtmux); |
| 3020 | return FALSE; |
| 3021 | } |
| 3022 | refuse_renegotiation: |
| 3023 | { |
| 3024 | GST_WARNING_OBJECT (qtmux, |
| 3025 | "pad %s refused renegotiation to %" GST_PTR_FORMAT, |
| 3026 | GST_PAD_NAME (pad), caps); |
| 3027 | gst_object_unref (qtmux); |
| 3028 | return FALSE; |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | /* scale rate up or down by factor of 10 to fit into [1000,10000] interval */ |
| 3033 | static guint32 |
| 3034 | adjust_rate (guint64 rate) |
| 3035 | { |
Mark Nauwelaerts | a5edbe3 | 2010-10-13 17:47:29 +0200 | [diff] [blame] | 3036 | if (rate == 0) |
| 3037 | return 10000; |
| 3038 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3039 | while (rate >= 10000) |
| 3040 | rate /= 10; |
| 3041 | |
| 3042 | while (rate < 1000) |
| 3043 | rate *= 10; |
| 3044 | |
| 3045 | return (guint32) rate; |
| 3046 | } |
| 3047 | |
| 3048 | static gboolean |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3049 | gst_qt_mux_video_sink_set_caps (GstQTPad * qtpad, GstCaps * caps) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3050 | { |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3051 | GstPad *pad = qtpad->collect.pad; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3052 | GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad)); |
| 3053 | GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux)); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3054 | GstStructure *structure; |
| 3055 | const gchar *mimetype; |
| 3056 | gint width, height, depth = -1; |
| 3057 | gint framerate_num, framerate_den; |
| 3058 | guint32 rate; |
| 3059 | const GValue *value = NULL; |
| 3060 | const GstBuffer *codec_data = NULL; |
| 3061 | VisualSampleEntry entry = { 0, }; |
| 3062 | GstQTMuxFormat format; |
| 3063 | AtomInfo *ext_atom = NULL; |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 3064 | GList *ext_atom_list = NULL; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3065 | gboolean sync = FALSE; |
David Schleef | 71eacf8 | 2008-11-18 01:09:09 +0000 | [diff] [blame] | 3066 | int par_num, par_den; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3067 | |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 3068 | qtpad->prepare_buf_func = NULL; |
| 3069 | |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 3070 | /* does not go well to renegotiate stream mid-way, unless |
| 3071 | * the old caps are a subset of the new one (this means upstream |
| 3072 | * added more info to the caps, as both should be 'fixed' caps) */ |
| 3073 | if (qtpad->fourcc) { |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3074 | GstCaps *current_caps; |
| 3075 | |
| 3076 | current_caps = gst_pad_get_current_caps (pad); |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 3077 | g_assert (caps != NULL); |
| 3078 | |
| 3079 | if (!gst_qtmux_caps_is_subset_full (qtmux, current_caps, caps)) { |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3080 | gst_caps_unref (current_caps); |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 3081 | goto refuse_renegotiation; |
| 3082 | } |
| 3083 | GST_DEBUG_OBJECT (qtmux, |
| 3084 | "pad %s accepted renegotiation to %" GST_PTR_FORMAT " from %" |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3085 | GST_PTR_FORMAT, GST_PAD_NAME (pad), caps, current_caps); |
| 3086 | gst_caps_unref (current_caps); |
Thiago Santos | a5f22f0 | 2010-01-13 23:33:51 -0300 | [diff] [blame] | 3087 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3088 | |
| 3089 | GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT, |
| 3090 | GST_DEBUG_PAD_NAME (pad), caps); |
| 3091 | |
| 3092 | format = qtmux_klass->format; |
| 3093 | structure = gst_caps_get_structure (caps, 0); |
| 3094 | mimetype = gst_structure_get_name (structure); |
| 3095 | |
| 3096 | /* required parts */ |
| 3097 | if (!gst_structure_get_int (structure, "width", &width) || |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 3098 | !gst_structure_get_int (structure, "height", &height)) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3099 | goto refuse_caps; |
| 3100 | |
| 3101 | /* optional */ |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 3102 | depth = -1; |
| 3103 | /* works as a default timebase */ |
| 3104 | framerate_num = 10000; |
| 3105 | framerate_den = 1; |
| 3106 | gst_structure_get_fraction (structure, "framerate", &framerate_num, |
| 3107 | &framerate_den); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3108 | gst_structure_get_int (structure, "depth", &depth); |
| 3109 | value = gst_structure_get_value (structure, "codec_data"); |
| 3110 | if (value != NULL) |
| 3111 | codec_data = gst_value_get_buffer (value); |
| 3112 | |
David Schleef | 71eacf8 | 2008-11-18 01:09:09 +0000 | [diff] [blame] | 3113 | par_num = 1; |
| 3114 | par_den = 1; |
| 3115 | gst_structure_get_fraction (structure, "pixel-aspect-ratio", &par_num, |
| 3116 | &par_den); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3117 | |
| 3118 | qtpad->is_out_of_order = FALSE; |
| 3119 | |
| 3120 | /* bring frame numerator into a range that ensures both reasonable resolution |
| 3121 | * as well as a fair duration */ |
Marc-André Lureau | bee00aa | 2010-07-30 12:48:29 +0200 | [diff] [blame] | 3122 | rate = qtmux->trak_timescale ? |
| 3123 | qtmux->trak_timescale : adjust_rate (framerate_num); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3124 | GST_DEBUG_OBJECT (qtmux, "Rate of video track selected: %" G_GUINT32_FORMAT, |
| 3125 | rate); |
| 3126 | |
| 3127 | /* set common properties */ |
| 3128 | entry.width = width; |
| 3129 | entry.height = height; |
Mark Nauwelaerts | 65b69dd | 2009-06-01 23:00:44 +0200 | [diff] [blame] | 3130 | entry.par_n = par_num; |
| 3131 | entry.par_d = par_den; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3132 | /* should be OK according to qt and iso spec, override if really needed */ |
| 3133 | entry.color_table_id = -1; |
| 3134 | entry.frame_count = 1; |
| 3135 | entry.depth = 24; |
| 3136 | |
| 3137 | /* sync entries by default */ |
| 3138 | sync = TRUE; |
| 3139 | |
| 3140 | /* now map onto a fourcc, and some extra properties */ |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3141 | if (strcmp (mimetype, "video/x-raw") == 0) { |
| 3142 | const gchar *format; |
| 3143 | GstVideoFormat fmt; |
Wim Taymans | 5fa0c28 | 2011-08-05 08:59:59 +0200 | [diff] [blame] | 3144 | const GstVideoFormatInfo *vinfo; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3145 | |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3146 | format = gst_structure_get_string (structure, "format"); |
| 3147 | fmt = gst_video_format_from_string (format); |
Wim Taymans | 5fa0c28 | 2011-08-05 08:59:59 +0200 | [diff] [blame] | 3148 | vinfo = gst_video_format_get_info (fmt); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3149 | |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3150 | switch (fmt) { |
| 3151 | case GST_VIDEO_FORMAT_UYVY: |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3152 | if (depth == -1) |
| 3153 | depth = 24; |
| 3154 | entry.fourcc = FOURCC_2vuy; |
| 3155 | entry.depth = depth; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3156 | sync = FALSE; |
| 3157 | break; |
Sebastian Dröge | dc2251a | 2015-01-13 19:05:20 +0100 | [diff] [blame] | 3158 | case GST_VIDEO_FORMAT_v210: |
| 3159 | if (depth == -1) |
| 3160 | depth = 24; |
| 3161 | entry.fourcc = FOURCC_v210; |
| 3162 | entry.depth = depth; |
| 3163 | sync = FALSE; |
| 3164 | break; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3165 | default: |
Wim Taymans | 5fa0c28 | 2011-08-05 08:59:59 +0200 | [diff] [blame] | 3166 | if (GST_VIDEO_FORMAT_INFO_FLAGS (vinfo) & GST_VIDEO_FORMAT_FLAG_RGB) { |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3167 | entry.fourcc = FOURCC_raw_; |
Wim Taymans | 5fa0c28 | 2011-08-05 08:59:59 +0200 | [diff] [blame] | 3168 | entry.depth = GST_VIDEO_FORMAT_INFO_PSTRIDE (vinfo, 0) * 8; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3169 | sync = FALSE; |
| 3170 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3171 | break; |
| 3172 | } |
| 3173 | } else if (strcmp (mimetype, "video/x-h263") == 0) { |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 3174 | ext_atom = NULL; |
Mark Nauwelaerts | 4dbeaee | 2009-05-28 13:56:10 +0200 | [diff] [blame] | 3175 | if (format == GST_QT_MUX_FORMAT_QT) |
| 3176 | entry.fourcc = FOURCC_h263; |
| 3177 | else |
| 3178 | entry.fourcc = FOURCC_s263; |
Mark Nauwelaerts | ffd2ff3 | 2009-01-28 13:25:14 +0100 | [diff] [blame] | 3179 | ext_atom = build_h263_extension (); |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 3180 | if (ext_atom != NULL) |
| 3181 | ext_atom_list = g_list_prepend (ext_atom_list, ext_atom); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3182 | } else if (strcmp (mimetype, "video/x-divx") == 0 || |
| 3183 | strcmp (mimetype, "video/mpeg") == 0) { |
| 3184 | gint version = 0; |
| 3185 | |
| 3186 | if (strcmp (mimetype, "video/x-divx") == 0) { |
| 3187 | gst_structure_get_int (structure, "divxversion", &version); |
| 3188 | version = version == 5 ? 1 : 0; |
| 3189 | } else { |
| 3190 | gst_structure_get_int (structure, "mpegversion", &version); |
| 3191 | version = version == 4 ? 1 : 0; |
| 3192 | } |
| 3193 | if (version) { |
| 3194 | entry.fourcc = FOURCC_mp4v; |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 3195 | ext_atom = |
| 3196 | build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG4_P2, |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 3197 | ESDS_STREAM_TYPE_VISUAL, codec_data, qtpad->avg_bitrate, |
| 3198 | qtpad->max_bitrate); |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 3199 | if (ext_atom != NULL) |
| 3200 | ext_atom_list = g_list_prepend (ext_atom_list, ext_atom); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3201 | if (!codec_data) |
| 3202 | GST_WARNING_OBJECT (qtmux, "no codec_data for MPEG4 video; " |
| 3203 | "output might not play in Apple QuickTime (try global-headers?)"); |
| 3204 | } |
| 3205 | } else if (strcmp (mimetype, "video/x-h264") == 0) { |
Thiago Santos | c385a46 | 2011-04-13 16:37:07 +0100 | [diff] [blame] | 3206 | /* check if we accept these caps */ |
| 3207 | if (gst_structure_has_field (structure, "stream-format")) { |
| 3208 | const gchar *format; |
| 3209 | const gchar *alignment; |
| 3210 | |
| 3211 | format = gst_structure_get_string (structure, "stream-format"); |
| 3212 | alignment = gst_structure_get_string (structure, "alignment"); |
| 3213 | |
| 3214 | if (strcmp (format, "avc") != 0 || alignment == NULL || |
| 3215 | strcmp (alignment, "au") != 0) { |
| 3216 | GST_WARNING_OBJECT (qtmux, "Rejecting h264 caps, qtmux only accepts " |
| 3217 | "avc format with AU aligned samples"); |
| 3218 | goto refuse_caps; |
| 3219 | } |
| 3220 | } else { |
| 3221 | GST_WARNING_OBJECT (qtmux, "no stream-format field in h264 caps"); |
Tim-Philipp Müller | cf953fe | 2011-04-16 18:17:01 +0100 | [diff] [blame] | 3222 | goto refuse_caps; |
Thiago Santos | c385a46 | 2011-04-13 16:37:07 +0100 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | if (!codec_data) { |
| 3226 | GST_WARNING_OBJECT (qtmux, "no codec_data in h264 caps"); |
Tim-Philipp Müller | cf953fe | 2011-04-16 18:17:01 +0100 | [diff] [blame] | 3227 | goto refuse_caps; |
Thiago Santos | c385a46 | 2011-04-13 16:37:07 +0100 | [diff] [blame] | 3228 | } |
| 3229 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3230 | entry.fourcc = FOURCC_avc1; |
Marc-André Lureau | 9e79307 | 2010-07-28 16:15:53 +0200 | [diff] [blame] | 3231 | if (qtpad->avg_bitrate == 0) { |
| 3232 | gint avg_bitrate = 0; |
| 3233 | gst_structure_get_int (structure, "bitrate", &avg_bitrate); |
| 3234 | qtpad->avg_bitrate = avg_bitrate; |
| 3235 | } |
Arun Raghavan | 9e5c575 | 2010-07-06 14:48:08 +0530 | [diff] [blame] | 3236 | ext_atom = build_btrt_extension (0, qtpad->avg_bitrate, qtpad->max_bitrate); |
| 3237 | if (ext_atom != NULL) |
| 3238 | ext_atom_list = g_list_prepend (ext_atom_list, ext_atom); |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 3239 | ext_atom = build_codec_data_extension (FOURCC_avcC, codec_data); |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 3240 | if (ext_atom != NULL) |
| 3241 | ext_atom_list = g_list_prepend (ext_atom_list, ext_atom); |
| 3242 | } else if (strcmp (mimetype, "video/x-svq") == 0) { |
| 3243 | gint version = 0; |
| 3244 | const GstBuffer *seqh = NULL; |
| 3245 | const GValue *seqh_value; |
| 3246 | gdouble gamma = 0; |
| 3247 | |
| 3248 | gst_structure_get_int (structure, "svqversion", &version); |
| 3249 | if (version == 3) { |
| 3250 | entry.fourcc = FOURCC_SVQ3; |
| 3251 | entry.version = 3; |
| 3252 | entry.depth = 32; |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 3253 | |
| 3254 | seqh_value = gst_structure_get_value (structure, "seqh"); |
| 3255 | if (seqh_value) { |
| 3256 | seqh = gst_value_get_buffer (seqh_value); |
| 3257 | ext_atom = build_SMI_atom (seqh); |
| 3258 | if (ext_atom) |
| 3259 | ext_atom_list = g_list_prepend (ext_atom_list, ext_atom); |
| 3260 | } |
| 3261 | |
| 3262 | /* we need to add the gamma anyway because quicktime might crash |
| 3263 | * when it doesn't find it */ |
| 3264 | if (!gst_structure_get_double (structure, "applied-gamma", &gamma)) { |
| 3265 | /* it seems that using 0 here makes it ignored */ |
| 3266 | gamma = 0.0; |
| 3267 | } |
| 3268 | ext_atom = build_gama_atom (gamma); |
| 3269 | if (ext_atom) |
| 3270 | ext_atom_list = g_list_prepend (ext_atom_list, ext_atom); |
| 3271 | } else { |
| 3272 | GST_WARNING_OBJECT (qtmux, "SVQ version %d not supported. Please file " |
| 3273 | "a bug at http://bugzilla.gnome.org", version); |
| 3274 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3275 | } else if (strcmp (mimetype, "video/x-dv") == 0) { |
| 3276 | gint version = 0; |
| 3277 | gboolean pal = TRUE; |
| 3278 | |
| 3279 | sync = FALSE; |
| 3280 | if (framerate_num != 25 || framerate_den != 1) |
| 3281 | pal = FALSE; |
| 3282 | gst_structure_get_int (structure, "dvversion", &version); |
| 3283 | /* fall back to typical one */ |
| 3284 | if (!version) |
| 3285 | version = 25; |
| 3286 | switch (version) { |
| 3287 | case 25: |
| 3288 | if (pal) |
| 3289 | entry.fourcc = GST_MAKE_FOURCC ('d', 'v', 'c', 'p'); |
| 3290 | else |
| 3291 | entry.fourcc = GST_MAKE_FOURCC ('d', 'v', 'c', ' '); |
| 3292 | break; |
| 3293 | case 50: |
| 3294 | if (pal) |
| 3295 | entry.fourcc = GST_MAKE_FOURCC ('d', 'v', '5', 'p'); |
| 3296 | else |
| 3297 | entry.fourcc = GST_MAKE_FOURCC ('d', 'v', '5', 'n'); |
| 3298 | break; |
| 3299 | default: |
| 3300 | GST_WARNING_OBJECT (qtmux, "unrecognized dv version"); |
| 3301 | break; |
| 3302 | } |
| 3303 | } else if (strcmp (mimetype, "image/jpeg") == 0) { |
| 3304 | entry.fourcc = FOURCC_jpeg; |
| 3305 | sync = FALSE; |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 3306 | } else if (strcmp (mimetype, "image/x-j2c") == 0 || |
| 3307 | strcmp (mimetype, "image/x-jpc") == 0) { |
Wim Taymans | 9d63714 | 2011-08-22 12:24:15 +0200 | [diff] [blame] | 3308 | const gchar *colorspace; |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 3309 | const GValue *cmap_array; |
| 3310 | const GValue *cdef_array; |
| 3311 | gint ncomp = 0; |
| 3312 | gint fields = 1; |
| 3313 | |
| 3314 | if (strcmp (mimetype, "image/x-jpc") == 0) { |
| 3315 | qtpad->prepare_buf_func = gst_qt_mux_prepare_jpc_buffer; |
| 3316 | } |
| 3317 | |
| 3318 | gst_structure_get_int (structure, "num-components", &ncomp); |
| 3319 | gst_structure_get_int (structure, "fields", &fields); |
| 3320 | cmap_array = gst_structure_get_value (structure, "component-map"); |
| 3321 | cdef_array = gst_structure_get_value (structure, "channel-definitions"); |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 3322 | |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 3323 | ext_atom = NULL; |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 3324 | entry.fourcc = FOURCC_mjp2; |
| 3325 | sync = FALSE; |
Wim Taymans | 9d63714 | 2011-08-22 12:24:15 +0200 | [diff] [blame] | 3326 | |
| 3327 | colorspace = gst_structure_get_string (structure, "colorspace"); |
| 3328 | if (colorspace && |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 3329 | (ext_atom = |
Wim Taymans | 9d63714 | 2011-08-22 12:24:15 +0200 | [diff] [blame] | 3330 | build_jp2h_extension (qtpad->trak, width, height, colorspace, ncomp, |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 3331 | cmap_array, cdef_array)) != NULL) { |
| 3332 | ext_atom_list = g_list_append (ext_atom_list, ext_atom); |
| 3333 | |
| 3334 | ext_atom = build_fiel_extension (fields); |
| 3335 | if (ext_atom) |
| 3336 | ext_atom_list = g_list_append (ext_atom_list, ext_atom); |
| 3337 | |
| 3338 | ext_atom = build_jp2x_extension (codec_data); |
| 3339 | if (ext_atom) |
| 3340 | ext_atom_list = g_list_append (ext_atom_list, ext_atom); |
| 3341 | } else { |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 3342 | GST_DEBUG_OBJECT (qtmux, "missing or invalid fourcc in jp2 caps"); |
| 3343 | goto refuse_caps; |
| 3344 | } |
David Schleef | 4bb9ffa | 2010-05-12 18:50:34 -0700 | [diff] [blame] | 3345 | } else if (strcmp (mimetype, "video/x-vp8") == 0) { |
| 3346 | entry.fourcc = FOURCC_VP80; |
| 3347 | sync = FALSE; |
David Schleef | 4dcc9ee | 2011-07-06 17:18:05 -0700 | [diff] [blame] | 3348 | } else if (strcmp (mimetype, "video/x-dirac") == 0) { |
| 3349 | entry.fourcc = FOURCC_drac; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3350 | } else if (strcmp (mimetype, "video/x-qt-part") == 0) { |
| 3351 | guint32 fourcc; |
| 3352 | |
Wim Taymans | 9d63714 | 2011-08-22 12:24:15 +0200 | [diff] [blame] | 3353 | gst_structure_get_uint (structure, "format", &fourcc); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3354 | entry.fourcc = fourcc; |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 3355 | } else if (strcmp (mimetype, "video/x-mp4-part") == 0) { |
| 3356 | guint32 fourcc; |
| 3357 | |
Wim Taymans | 9d63714 | 2011-08-22 12:24:15 +0200 | [diff] [blame] | 3358 | gst_structure_get_uint (structure, "format", &fourcc); |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 3359 | entry.fourcc = fourcc; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | if (!entry.fourcc) |
| 3363 | goto refuse_caps; |
| 3364 | |
| 3365 | /* ok, set the pad info accordingly */ |
| 3366 | qtpad->fourcc = entry.fourcc; |
| 3367 | qtpad->sync = sync; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3368 | atom_trak_set_video_type (qtpad->trak, qtmux->context, &entry, rate, |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 3369 | ext_atom_list); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3370 | |
| 3371 | gst_object_unref (qtmux); |
| 3372 | return TRUE; |
| 3373 | |
| 3374 | /* ERRORS */ |
| 3375 | refuse_caps: |
| 3376 | { |
| 3377 | GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT, |
| 3378 | GST_PAD_NAME (pad), caps); |
| 3379 | gst_object_unref (qtmux); |
| 3380 | return FALSE; |
| 3381 | } |
| 3382 | refuse_renegotiation: |
| 3383 | { |
| 3384 | GST_WARNING_OBJECT (qtmux, |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3385 | "pad %s refused renegotiation to %" GST_PTR_FORMAT, GST_PAD_NAME (pad), |
| 3386 | caps); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3387 | gst_object_unref (qtmux); |
| 3388 | return FALSE; |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | static gboolean |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3393 | gst_qt_mux_subtitle_sink_set_caps (GstQTPad * qtpad, GstCaps * caps) |
| 3394 | { |
| 3395 | GstPad *pad = qtpad->collect.pad; |
| 3396 | GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad)); |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 3397 | GstStructure *structure; |
| 3398 | SubtitleSampleEntry entry = { 0, }; |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3399 | |
| 3400 | qtpad->prepare_buf_func = NULL; |
| 3401 | |
| 3402 | /* does not go well to renegotiate stream mid-way, unless |
| 3403 | * the old caps are a subset of the new one (this means upstream |
| 3404 | * added more info to the caps, as both should be 'fixed' caps) */ |
| 3405 | if (qtpad->fourcc) { |
| 3406 | GstCaps *current_caps; |
| 3407 | |
| 3408 | current_caps = gst_pad_get_current_caps (pad); |
| 3409 | g_assert (caps != NULL); |
| 3410 | |
| 3411 | if (!gst_qtmux_caps_is_subset_full (qtmux, current_caps, caps)) { |
| 3412 | gst_caps_unref (current_caps); |
| 3413 | goto refuse_renegotiation; |
| 3414 | } |
| 3415 | GST_DEBUG_OBJECT (qtmux, |
| 3416 | "pad %s accepted renegotiation to %" GST_PTR_FORMAT " from %" |
| 3417 | GST_PTR_FORMAT, GST_PAD_NAME (pad), caps, current_caps); |
| 3418 | gst_caps_unref (current_caps); |
| 3419 | } |
| 3420 | |
| 3421 | GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT, |
| 3422 | GST_DEBUG_PAD_NAME (pad), caps); |
| 3423 | |
| 3424 | /* subtitles default */ |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 3425 | subtitle_sample_entry_init (&entry); |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3426 | qtpad->is_out_of_order = FALSE; |
| 3427 | qtpad->sync = FALSE; |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 3428 | qtpad->sparse = TRUE; |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 3429 | qtpad->prepare_buf_func = NULL; |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3430 | |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 3431 | structure = gst_caps_get_structure (caps, 0); |
| 3432 | |
| 3433 | if (gst_structure_has_name (structure, "text/x-raw")) { |
| 3434 | const gchar *format = gst_structure_get_string (structure, "format"); |
| 3435 | if (format && strcmp (format, "utf8") == 0) { |
| 3436 | entry.fourcc = FOURCC_tx3g; |
| 3437 | qtpad->prepare_buf_func = gst_qt_mux_prepare_tx3g_buffer; |
Thiago Santos | f89ba82 | 2014-02-07 01:49:26 -0300 | [diff] [blame] | 3438 | qtpad->create_empty_buffer = gst_qt_mux_create_empty_tx3g_buffer; |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | if (!entry.fourcc) |
| 3443 | goto refuse_caps; |
| 3444 | |
| 3445 | qtpad->fourcc = entry.fourcc; |
| 3446 | atom_trak_set_subtitle_type (qtpad->trak, qtmux->context, &entry); |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3447 | |
| 3448 | gst_object_unref (qtmux); |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 3449 | return TRUE; |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3450 | |
| 3451 | /* ERRORS */ |
Thiago Santos | 99e966e | 2014-02-06 12:15:22 -0300 | [diff] [blame] | 3452 | refuse_caps: |
| 3453 | { |
| 3454 | GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT, |
| 3455 | GST_PAD_NAME (pad), caps); |
| 3456 | gst_object_unref (qtmux); |
| 3457 | return FALSE; |
| 3458 | } |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3459 | refuse_renegotiation: |
| 3460 | { |
| 3461 | GST_WARNING_OBJECT (qtmux, |
| 3462 | "pad %s refused renegotiation to %" GST_PTR_FORMAT, GST_PAD_NAME (pad), |
| 3463 | caps); |
| 3464 | gst_object_unref (qtmux); |
| 3465 | return FALSE; |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | static gboolean |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 3470 | gst_qt_mux_sink_event (GstCollectPads * pads, GstCollectData * data, |
Mark Nauwelaerts | 7480b44 | 2011-12-15 16:15:22 +0100 | [diff] [blame] | 3471 | GstEvent * event, gpointer user_data) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3472 | { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3473 | GstQTMux *qtmux; |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 3474 | guint32 avg_bitrate = 0, max_bitrate = 0; |
Mark Nauwelaerts | 7480b44 | 2011-12-15 16:15:22 +0100 | [diff] [blame] | 3475 | GstPad *pad = data->pad; |
Mark Nauwelaerts | 04b4d30 | 2012-04-16 16:37:49 +0200 | [diff] [blame] | 3476 | gboolean ret = TRUE; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3477 | |
Mark Nauwelaerts | 7480b44 | 2011-12-15 16:15:22 +0100 | [diff] [blame] | 3478 | qtmux = GST_QT_MUX_CAST (user_data); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3479 | switch (GST_EVENT_TYPE (event)) { |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3480 | case GST_EVENT_CAPS: |
| 3481 | { |
| 3482 | GstCaps *caps; |
| 3483 | GstQTPad *collect_pad; |
| 3484 | |
| 3485 | gst_event_parse_caps (event, &caps); |
| 3486 | |
| 3487 | /* find stream data */ |
| 3488 | collect_pad = (GstQTPad *) gst_pad_get_element_private (pad); |
| 3489 | g_assert (collect_pad); |
| 3490 | g_assert (collect_pad->set_caps); |
| 3491 | |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3492 | ret = collect_pad->set_caps (collect_pad, caps); |
Sebastian Dröge | 30689a8 | 2012-01-26 10:40:06 +0100 | [diff] [blame] | 3493 | gst_event_unref (event); |
Mark Nauwelaerts | 04b4d30 | 2012-04-16 16:37:49 +0200 | [diff] [blame] | 3494 | event = NULL; |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3495 | break; |
| 3496 | } |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 3497 | case GST_EVENT_TAG:{ |
| 3498 | GstTagList *list; |
| 3499 | GstTagSetter *setter = GST_TAG_SETTER (qtmux); |
Michael Smith | 8b3aca9 | 2010-02-26 11:50:25 -0800 | [diff] [blame] | 3500 | GstTagMergeMode mode; |
Matej Knopp | d8ac666 | 2013-03-22 02:24:01 +0100 | [diff] [blame] | 3501 | gchar *code; |
Thiago Santos | e52b2cb | 2015-01-31 14:32:34 -0300 | [diff] [blame] | 3502 | GstQTPad *collect_pad; |
Michael Smith | 8b3aca9 | 2010-02-26 11:50:25 -0800 | [diff] [blame] | 3503 | |
| 3504 | GST_OBJECT_LOCK (qtmux); |
| 3505 | mode = gst_tag_setter_get_tag_merge_mode (setter); |
Thiago Santos | e52b2cb | 2015-01-31 14:32:34 -0300 | [diff] [blame] | 3506 | collect_pad = (GstQTPad *) gst_pad_get_element_private (pad); |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 3507 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3508 | gst_event_parse_tag (event, &list); |
Thiago Santos | 4a5364d | 2011-12-12 11:51:06 -0300 | [diff] [blame] | 3509 | GST_DEBUG_OBJECT (qtmux, "received tag event on pad %s:%s : %" |
| 3510 | GST_PTR_FORMAT, GST_DEBUG_PAD_NAME (pad), list); |
Michael Smith | 8b3aca9 | 2010-02-26 11:50:25 -0800 | [diff] [blame] | 3511 | |
Thiago Santos | e52b2cb | 2015-01-31 14:32:34 -0300 | [diff] [blame] | 3512 | if (gst_tag_list_get_scope (list) == GST_TAG_SCOPE_GLOBAL) { |
| 3513 | gst_tag_setter_merge_tags (setter, list, mode); |
| 3514 | } else { |
| 3515 | if (!collect_pad->tags) |
| 3516 | collect_pad->tags = gst_tag_list_new_empty (); |
| 3517 | gst_tag_list_insert (collect_pad->tags, list, mode); |
| 3518 | } |
Michael Smith | 8b3aca9 | 2010-02-26 11:50:25 -0800 | [diff] [blame] | 3519 | GST_OBJECT_UNLOCK (qtmux); |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 3520 | |
| 3521 | if (gst_tag_list_get_uint (list, GST_TAG_BITRATE, &avg_bitrate) | |
| 3522 | gst_tag_list_get_uint (list, GST_TAG_MAXIMUM_BITRATE, &max_bitrate)) { |
| 3523 | GstQTPad *qtpad = gst_pad_get_element_private (pad); |
| 3524 | g_assert (qtpad); |
| 3525 | |
| 3526 | if (avg_bitrate > 0 && avg_bitrate < G_MAXUINT32) |
| 3527 | qtpad->avg_bitrate = avg_bitrate; |
| 3528 | if (max_bitrate > 0 && max_bitrate < G_MAXUINT32) |
| 3529 | qtpad->max_bitrate = max_bitrate; |
| 3530 | } |
| 3531 | |
Matej Knopp | d8ac666 | 2013-03-22 02:24:01 +0100 | [diff] [blame] | 3532 | if (gst_tag_list_get_string (list, GST_TAG_LANGUAGE_CODE, &code)) { |
| 3533 | const char *iso_code = gst_tag_get_language_code_iso_639_2T (code); |
| 3534 | if (iso_code) { |
| 3535 | GstQTPad *qtpad = gst_pad_get_element_private (pad); |
| 3536 | g_assert (qtpad); |
| 3537 | if (qtpad->trak) { |
| 3538 | /* https://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html */ |
| 3539 | qtpad->trak->mdia.mdhd.language_code = |
| 3540 | (iso_code[0] - 0x60) * 0x400 + (iso_code[1] - 0x60) * 0x20 + |
| 3541 | (iso_code[2] - 0x60); |
| 3542 | } |
| 3543 | } |
| 3544 | g_free (code); |
| 3545 | } |
| 3546 | |
Sebastian Dröge | 30689a8 | 2012-01-26 10:40:06 +0100 | [diff] [blame] | 3547 | gst_event_unref (event); |
Mark Nauwelaerts | 04b4d30 | 2012-04-16 16:37:49 +0200 | [diff] [blame] | 3548 | event = NULL; |
Sebastian Dröge | 30689a8 | 2012-01-26 10:40:06 +0100 | [diff] [blame] | 3549 | ret = TRUE; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3550 | break; |
Stefan Kost | 6a47f1f | 2008-12-16 16:26:52 +0000 | [diff] [blame] | 3551 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3552 | default: |
| 3553 | break; |
| 3554 | } |
| 3555 | |
Mark Nauwelaerts | 04b4d30 | 2012-04-16 16:37:49 +0200 | [diff] [blame] | 3556 | if (event != NULL) |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 3557 | return gst_collect_pads_event_default (pads, data, event, FALSE); |
Mark Nauwelaerts | 04b4d30 | 2012-04-16 16:37:49 +0200 | [diff] [blame] | 3558 | |
Sebastian Dröge | 30689a8 | 2012-01-26 10:40:06 +0100 | [diff] [blame] | 3559 | return ret; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | static void |
| 3563 | gst_qt_mux_release_pad (GstElement * element, GstPad * pad) |
| 3564 | { |
| 3565 | GstQTMux *mux = GST_QT_MUX_CAST (element); |
Thiago Santos | c92785e | 2010-02-22 10:48:11 -0300 | [diff] [blame] | 3566 | GSList *walk; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3567 | |
Edward Hervey | 0fa380b | 2010-06-21 19:39:54 +0200 | [diff] [blame] | 3568 | GST_DEBUG_OBJECT (element, "Releasing %s:%s", GST_DEBUG_PAD_NAME (pad)); |
| 3569 | |
| 3570 | for (walk = mux->sinkpads; walk; walk = g_slist_next (walk)) { |
| 3571 | GstQTPad *qtpad = (GstQTPad *) walk->data; |
| 3572 | GST_DEBUG ("Checking %s:%s", GST_DEBUG_PAD_NAME (qtpad->collect.pad)); |
| 3573 | if (qtpad->collect.pad == pad) { |
| 3574 | /* this is it, remove */ |
| 3575 | mux->sinkpads = g_slist_delete_link (mux->sinkpads, walk); |
| 3576 | gst_element_remove_pad (element, pad); |
| 3577 | break; |
Thiago Santos | c92785e | 2010-02-22 10:48:11 -0300 | [diff] [blame] | 3578 | } |
Thiago Santos | c92785e | 2010-02-22 10:48:11 -0300 | [diff] [blame] | 3579 | } |
Edward Hervey | 0fa380b | 2010-06-21 19:39:54 +0200 | [diff] [blame] | 3580 | |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 3581 | gst_collect_pads_remove_pad (mux->collect, pad); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | static GstPad * |
| 3585 | gst_qt_mux_request_new_pad (GstElement * element, |
Mark Nauwelaerts | f886681 | 2011-06-29 12:46:20 +0200 | [diff] [blame] | 3586 | GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3587 | { |
| 3588 | GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); |
| 3589 | GstQTMux *qtmux = GST_QT_MUX_CAST (element); |
| 3590 | GstQTPad *collect_pad; |
| 3591 | GstPad *newpad; |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3592 | GstQTPadSetCapsFunc setcaps_func; |
Stefan Kost | 05257fe | 2009-12-27 23:51:50 +0200 | [diff] [blame] | 3593 | gchar *name; |
Mark Nauwelaerts | 611c950 | 2011-07-04 11:07:13 +0200 | [diff] [blame] | 3594 | gint pad_id; |
Matej Knopp | fd3e8c5 | 2014-09-23 19:08:48 +0200 | [diff] [blame] | 3595 | gboolean lock = TRUE; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3596 | |
Stefan Kost | 7d9ed16 | 2009-12-27 23:32:58 +0200 | [diff] [blame] | 3597 | if (templ->direction != GST_PAD_SINK) |
| 3598 | goto wrong_direction; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3599 | |
Mark Nauwelaerts | 6beda8a | 2010-01-13 19:30:45 +0100 | [diff] [blame] | 3600 | if (qtmux->state > GST_QT_MUX_STATE_STARTED) |
Stefan Kost | 7d9ed16 | 2009-12-27 23:32:58 +0200 | [diff] [blame] | 3601 | goto too_late; |
| 3602 | |
Wim Taymans | a95acb7 | 2011-11-04 11:58:22 +0100 | [diff] [blame] | 3603 | if (templ == gst_element_class_get_pad_template (klass, "audio_%u")) { |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3604 | setcaps_func = gst_qt_mux_audio_sink_set_caps; |
Wim Taymans | a95acb7 | 2011-11-04 11:58:22 +0100 | [diff] [blame] | 3605 | if (req_name != NULL && sscanf (req_name, "audio_%u", &pad_id) == 1) { |
Mark Nauwelaerts | 611c950 | 2011-07-04 11:07:13 +0200 | [diff] [blame] | 3606 | name = g_strdup (req_name); |
| 3607 | } else { |
Wim Taymans | a95acb7 | 2011-11-04 11:58:22 +0100 | [diff] [blame] | 3608 | name = g_strdup_printf ("audio_%u", qtmux->audio_pads++); |
Mark Nauwelaerts | 611c950 | 2011-07-04 11:07:13 +0200 | [diff] [blame] | 3609 | } |
Wim Taymans | a95acb7 | 2011-11-04 11:58:22 +0100 | [diff] [blame] | 3610 | } else if (templ == gst_element_class_get_pad_template (klass, "video_%u")) { |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3611 | setcaps_func = gst_qt_mux_video_sink_set_caps; |
Wim Taymans | a95acb7 | 2011-11-04 11:58:22 +0100 | [diff] [blame] | 3612 | if (req_name != NULL && sscanf (req_name, "video_%u", &pad_id) == 1) { |
Mark Nauwelaerts | 611c950 | 2011-07-04 11:07:13 +0200 | [diff] [blame] | 3613 | name = g_strdup (req_name); |
| 3614 | } else { |
Wim Taymans | a95acb7 | 2011-11-04 11:58:22 +0100 | [diff] [blame] | 3615 | name = g_strdup_printf ("video_%u", qtmux->video_pads++); |
Mark Nauwelaerts | 611c950 | 2011-07-04 11:07:13 +0200 | [diff] [blame] | 3616 | } |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3617 | } else if (templ == gst_element_class_get_pad_template (klass, "subtitle_%u")) { |
| 3618 | setcaps_func = gst_qt_mux_subtitle_sink_set_caps; |
| 3619 | if (req_name != NULL && sscanf (req_name, "subtitle_%u", &pad_id) == 1) { |
| 3620 | name = g_strdup (req_name); |
| 3621 | } else { |
| 3622 | name = g_strdup_printf ("subtitle_%u", qtmux->subtitle_pads++); |
| 3623 | } |
Matej Knopp | fd3e8c5 | 2014-09-23 19:08:48 +0200 | [diff] [blame] | 3624 | lock = FALSE; |
Stefan Kost | 7d9ed16 | 2009-12-27 23:32:58 +0200 | [diff] [blame] | 3625 | } else |
| 3626 | goto wrong_template; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3627 | |
Stefan Kost | 05257fe | 2009-12-27 23:51:50 +0200 | [diff] [blame] | 3628 | GST_DEBUG_OBJECT (qtmux, "Requested pad: %s", name); |
| 3629 | |
| 3630 | /* create pad and add to collections */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3631 | newpad = gst_pad_new_from_template (templ, name); |
Stefan Kost | 05257fe | 2009-12-27 23:51:50 +0200 | [diff] [blame] | 3632 | g_free (name); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3633 | collect_pad = (GstQTPad *) |
Stefan Sauer | f874922 | 2012-09-12 21:05:44 +0200 | [diff] [blame] | 3634 | gst_collect_pads_add_pad (qtmux->collect, newpad, sizeof (GstQTPad), |
Matej Knopp | fd3e8c5 | 2014-09-23 19:08:48 +0200 | [diff] [blame] | 3635 | (GstCollectDataDestroyNotify) (gst_qt_mux_pad_reset), lock); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3636 | /* set up pad */ |
| 3637 | gst_qt_mux_pad_reset (collect_pad); |
Mark Nauwelaerts | ce865cc | 2010-11-05 12:08:15 +0100 | [diff] [blame] | 3638 | collect_pad->trak = atom_trak_new (qtmux->context); |
| 3639 | atom_moov_add_trak (qtmux->moov, collect_pad->trak); |
Marc-André Lureau | 2618cb0 | 2009-09-28 16:11:35 +0200 | [diff] [blame] | 3640 | |
Thiago Santos | c92785e | 2010-02-22 10:48:11 -0300 | [diff] [blame] | 3641 | qtmux->sinkpads = g_slist_append (qtmux->sinkpads, collect_pad); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3642 | |
| 3643 | /* set up pad functions */ |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3644 | collect_pad->set_caps = setcaps_func; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3645 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3646 | gst_pad_set_active (newpad, TRUE); |
| 3647 | gst_element_add_pad (element, newpad); |
| 3648 | |
| 3649 | return newpad; |
Stefan Kost | 7d9ed16 | 2009-12-27 23:32:58 +0200 | [diff] [blame] | 3650 | |
| 3651 | /* ERRORS */ |
| 3652 | wrong_direction: |
| 3653 | { |
| 3654 | GST_WARNING_OBJECT (qtmux, "Request pad that is not a SINK pad."); |
| 3655 | return NULL; |
| 3656 | } |
| 3657 | too_late: |
| 3658 | { |
| 3659 | GST_WARNING_OBJECT (qtmux, "Not providing request pad after stream start."); |
| 3660 | return NULL; |
| 3661 | } |
| 3662 | wrong_template: |
| 3663 | { |
| 3664 | GST_WARNING_OBJECT (qtmux, "This is not our template!"); |
| 3665 | return NULL; |
| 3666 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | static void |
| 3670 | gst_qt_mux_get_property (GObject * object, |
| 3671 | guint prop_id, GValue * value, GParamSpec * pspec) |
| 3672 | { |
| 3673 | GstQTMux *qtmux = GST_QT_MUX_CAST (object); |
| 3674 | |
| 3675 | GST_OBJECT_LOCK (qtmux); |
| 3676 | switch (prop_id) { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3677 | case PROP_MOVIE_TIMESCALE: |
| 3678 | g_value_set_uint (value, qtmux->timescale); |
| 3679 | break; |
Marc-André Lureau | bee00aa | 2010-07-30 12:48:29 +0200 | [diff] [blame] | 3680 | case PROP_TRAK_TIMESCALE: |
| 3681 | g_value_set_uint (value, qtmux->trak_timescale); |
| 3682 | break; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3683 | case PROP_DO_CTTS: |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 3684 | g_value_set_boolean (value, qtmux->guess_pts); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3685 | break; |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 3686 | #ifndef GST_REMOVE_DEPRECATED |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 3687 | case PROP_DTS_METHOD: |
| 3688 | g_value_set_enum (value, qtmux->dts_method); |
| 3689 | break; |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 3690 | #endif |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3691 | case PROP_FAST_START: |
| 3692 | g_value_set_boolean (value, qtmux->fast_start); |
| 3693 | break; |
| 3694 | case PROP_FAST_START_TEMP_FILE: |
| 3695 | g_value_set_string (value, qtmux->fast_start_file_path); |
| 3696 | break; |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 3697 | case PROP_MOOV_RECOV_FILE: |
| 3698 | g_value_set_string (value, qtmux->moov_recov_file_path); |
| 3699 | break; |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 3700 | case PROP_FRAGMENT_DURATION: |
| 3701 | g_value_set_uint (value, qtmux->fragment_duration); |
| 3702 | break; |
Marc-André Lureau | 61964eb | 2010-08-06 13:26:27 +0200 | [diff] [blame] | 3703 | case PROP_STREAMABLE: |
| 3704 | g_value_set_boolean (value, qtmux->streamable); |
| 3705 | break; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3706 | default: |
| 3707 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 3708 | break; |
| 3709 | } |
| 3710 | GST_OBJECT_UNLOCK (qtmux); |
| 3711 | } |
| 3712 | |
| 3713 | static void |
| 3714 | gst_qt_mux_generate_fast_start_file_path (GstQTMux * qtmux) |
| 3715 | { |
| 3716 | gchar *tmp; |
| 3717 | |
Thiago Santos | 6dc515b | 2010-01-26 13:44:04 -0300 | [diff] [blame] | 3718 | g_free (qtmux->fast_start_file_path); |
| 3719 | qtmux->fast_start_file_path = NULL; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3720 | |
| 3721 | tmp = g_strdup_printf ("%s%d", "qtmux", g_random_int ()); |
| 3722 | qtmux->fast_start_file_path = g_build_filename (g_get_tmp_dir (), tmp, NULL); |
| 3723 | g_free (tmp); |
| 3724 | } |
| 3725 | |
| 3726 | static void |
| 3727 | gst_qt_mux_set_property (GObject * object, |
| 3728 | guint prop_id, const GValue * value, GParamSpec * pspec) |
| 3729 | { |
| 3730 | GstQTMux *qtmux = GST_QT_MUX_CAST (object); |
| 3731 | |
| 3732 | GST_OBJECT_LOCK (qtmux); |
| 3733 | switch (prop_id) { |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3734 | case PROP_MOVIE_TIMESCALE: |
| 3735 | qtmux->timescale = g_value_get_uint (value); |
| 3736 | break; |
Marc-André Lureau | bee00aa | 2010-07-30 12:48:29 +0200 | [diff] [blame] | 3737 | case PROP_TRAK_TIMESCALE: |
| 3738 | qtmux->trak_timescale = g_value_get_uint (value); |
| 3739 | break; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3740 | case PROP_DO_CTTS: |
David Schleef | b11186e | 2008-11-15 02:56:31 +0000 | [diff] [blame] | 3741 | qtmux->guess_pts = g_value_get_boolean (value); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3742 | break; |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 3743 | #ifndef GST_REMOVE_DEPRECATED |
Mark Nauwelaerts | ae64493 | 2011-01-03 17:24:23 +0100 | [diff] [blame] | 3744 | case PROP_DTS_METHOD: |
| 3745 | qtmux->dts_method = g_value_get_enum (value); |
| 3746 | break; |
David Schleef | 6571e38 | 2013-03-22 13:24:33 -0700 | [diff] [blame] | 3747 | #endif |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3748 | case PROP_FAST_START: |
| 3749 | qtmux->fast_start = g_value_get_boolean (value); |
| 3750 | break; |
| 3751 | case PROP_FAST_START_TEMP_FILE: |
Thiago Santos | 6dc515b | 2010-01-26 13:44:04 -0300 | [diff] [blame] | 3752 | g_free (qtmux->fast_start_file_path); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3753 | qtmux->fast_start_file_path = g_value_dup_string (value); |
| 3754 | /* NULL means to generate a random one */ |
| 3755 | if (!qtmux->fast_start_file_path) { |
| 3756 | gst_qt_mux_generate_fast_start_file_path (qtmux); |
| 3757 | } |
| 3758 | break; |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 3759 | case PROP_MOOV_RECOV_FILE: |
| 3760 | g_free (qtmux->moov_recov_file_path); |
| 3761 | qtmux->moov_recov_file_path = g_value_dup_string (value); |
| 3762 | break; |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 3763 | case PROP_FRAGMENT_DURATION: |
| 3764 | qtmux->fragment_duration = g_value_get_uint (value); |
| 3765 | break; |
Andoni Morales Alastruey | 5732684 | 2013-09-17 12:01:30 +0200 | [diff] [blame] | 3766 | case PROP_STREAMABLE:{ |
| 3767 | GstQTMuxClass *qtmux_klass = |
| 3768 | (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux)); |
| 3769 | if (qtmux_klass->format == GST_QT_MUX_FORMAT_ISML) { |
| 3770 | qtmux->streamable = g_value_get_boolean (value); |
| 3771 | } |
Marc-André Lureau | 61964eb | 2010-08-06 13:26:27 +0200 | [diff] [blame] | 3772 | break; |
Andoni Morales Alastruey | 5732684 | 2013-09-17 12:01:30 +0200 | [diff] [blame] | 3773 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3774 | default: |
| 3775 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 3776 | break; |
| 3777 | } |
| 3778 | GST_OBJECT_UNLOCK (qtmux); |
| 3779 | } |
| 3780 | |
| 3781 | static GstStateChangeReturn |
| 3782 | gst_qt_mux_change_state (GstElement * element, GstStateChange transition) |
| 3783 | { |
| 3784 | GstStateChangeReturn ret; |
| 3785 | GstQTMux *qtmux = GST_QT_MUX_CAST (element); |
| 3786 | |
| 3787 | switch (transition) { |
| 3788 | case GST_STATE_CHANGE_NULL_TO_READY: |
| 3789 | break; |
| 3790 | case GST_STATE_CHANGE_READY_TO_PAUSED: |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 3791 | gst_collect_pads_start (qtmux->collect); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3792 | qtmux->state = GST_QT_MUX_STATE_STARTED; |
| 3793 | break; |
| 3794 | case GST_STATE_CHANGE_PAUSED_TO_PLAYING: |
| 3795 | break; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3796 | case GST_STATE_CHANGE_PAUSED_TO_READY: |
Mark Nauwelaerts | 67e168a | 2012-04-17 15:14:27 +0200 | [diff] [blame] | 3797 | gst_collect_pads_stop (qtmux->collect); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3798 | break; |
| 3799 | default: |
| 3800 | break; |
| 3801 | } |
| 3802 | |
| 3803 | ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); |
| 3804 | |
| 3805 | switch (transition) { |
| 3806 | case GST_STATE_CHANGE_PLAYING_TO_PAUSED: |
| 3807 | break; |
| 3808 | case GST_STATE_CHANGE_PAUSED_TO_READY: |
| 3809 | gst_qt_mux_reset (qtmux, TRUE); |
| 3810 | break; |
| 3811 | case GST_STATE_CHANGE_READY_TO_NULL: |
| 3812 | break; |
| 3813 | default: |
| 3814 | break; |
| 3815 | } |
| 3816 | |
| 3817 | return ret; |
| 3818 | } |
| 3819 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3820 | gboolean |
| 3821 | gst_qt_mux_register (GstPlugin * plugin) |
| 3822 | { |
| 3823 | GTypeInfo typeinfo = { |
| 3824 | sizeof (GstQTMuxClass), |
| 3825 | (GBaseInitFunc) gst_qt_mux_base_init, |
| 3826 | NULL, |
| 3827 | (GClassInitFunc) gst_qt_mux_class_init, |
| 3828 | NULL, |
| 3829 | NULL, |
| 3830 | sizeof (GstQTMux), |
| 3831 | 0, |
| 3832 | (GInstanceInitFunc) gst_qt_mux_init, |
| 3833 | }; |
| 3834 | static const GInterfaceInfo tag_setter_info = { |
| 3835 | NULL, NULL, NULL |
| 3836 | }; |
Thiago Santos | aba8000 | 2011-03-21 10:56:51 -0300 | [diff] [blame] | 3837 | static const GInterfaceInfo tag_xmp_writer_info = { |
| 3838 | NULL, NULL, NULL |
| 3839 | }; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3840 | GType type; |
| 3841 | GstQTMuxFormat format; |
| 3842 | GstQTMuxClassParams *params; |
| 3843 | guint i = 0; |
| 3844 | |
Tim-Philipp Müller | 1663c51 | 2010-03-25 00:20:54 +0000 | [diff] [blame] | 3845 | GST_DEBUG_CATEGORY_INIT (gst_qt_mux_debug, "qtmux", 0, "QT Muxer"); |
| 3846 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3847 | GST_LOG ("Registering muxers"); |
| 3848 | |
| 3849 | while (TRUE) { |
| 3850 | GstQTMuxFormatProp *prop; |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3851 | GstCaps *subtitle_caps; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3852 | |
| 3853 | prop = &gst_qt_mux_format_list[i]; |
| 3854 | format = prop->format; |
| 3855 | if (format == GST_QT_MUX_FORMAT_NONE) |
| 3856 | break; |
| 3857 | |
| 3858 | /* create a cache for these properties */ |
| 3859 | params = g_new0 (GstQTMuxClassParams, 1); |
| 3860 | params->prop = prop; |
| 3861 | params->src_caps = gst_static_caps_get (&prop->src_caps); |
| 3862 | params->video_sink_caps = gst_static_caps_get (&prop->video_sink_caps); |
| 3863 | params->audio_sink_caps = gst_static_caps_get (&prop->audio_sink_caps); |
Thiago Santos | 2ae1897 | 2014-02-05 10:27:54 -0300 | [diff] [blame] | 3864 | subtitle_caps = gst_static_caps_get (&prop->subtitle_sink_caps); |
| 3865 | if (!gst_caps_is_equal (subtitle_caps, GST_CAPS_NONE)) { |
| 3866 | params->subtitle_sink_caps = subtitle_caps; |
| 3867 | } else { |
| 3868 | gst_caps_unref (subtitle_caps); |
| 3869 | } |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3870 | |
| 3871 | /* create the type now */ |
| 3872 | type = g_type_register_static (GST_TYPE_ELEMENT, prop->type_name, &typeinfo, |
| 3873 | 0); |
| 3874 | g_type_set_qdata (type, GST_QT_MUX_PARAMS_QDATA, (gpointer) params); |
| 3875 | g_type_add_interface_static (type, GST_TYPE_TAG_SETTER, &tag_setter_info); |
Thiago Santos | aba8000 | 2011-03-21 10:56:51 -0300 | [diff] [blame] | 3876 | g_type_add_interface_static (type, GST_TYPE_TAG_XMP_WRITER, |
| 3877 | &tag_xmp_writer_info); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3878 | |
Tim-Philipp Müller | 0671b23 | 2011-04-21 22:51:52 +0100 | [diff] [blame] | 3879 | if (!gst_element_register (plugin, prop->name, prop->rank, type)) |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3880 | return FALSE; |
| 3881 | |
| 3882 | i++; |
| 3883 | } |
| 3884 | |
| 3885 | GST_LOG ("Finished registering muxers"); |
| 3886 | |
Thiago Santos | 083f825 | 2009-12-10 16:53:19 -0300 | [diff] [blame] | 3887 | /* FIXME: ideally classification tag should be added and |
| 3888 | registered in gstreamer core gsttaglist |
| 3889 | */ |
| 3890 | |
| 3891 | GST_LOG ("Registering tags"); |
| 3892 | |
| 3893 | gst_tag_register (GST_TAG_3GP_CLASSIFICATION, GST_TAG_FLAG_META, |
| 3894 | G_TYPE_STRING, GST_TAG_3GP_CLASSIFICATION, "content classification", |
| 3895 | gst_tag_merge_use_first); |
| 3896 | |
| 3897 | GST_LOG ("Finished registering tags"); |
| 3898 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3899 | return TRUE; |
| 3900 | } |