2008-11-08 02:00:58 +00:00
|
|
|
/* Quicktime muxer plugin for GStreamer
|
2009-12-12 19:07:15 +00:00
|
|
|
* Copyright (C) 2008-2010 Thiago Santos <thiagoss@embedded.ufcg.edu.br>
|
2008-11-08 02:00:58 +00:00
|
|
|
* Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.net>
|
2011-01-03 09:43:15 +00:00
|
|
|
* Copyright (C) 2010 Nokia Corporation. All rights reserved.
|
2015-04-01 00:15:38 +00:00
|
|
|
* Copyright (C) 2014 Jan Schmidt <jan@centricular.com>
|
2011-01-03 09:43:15 +00:00
|
|
|
* Contact: Stefan Kost <stefan.kost@nokia.com>
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-11-08 02:00:58 +00:00
|
|
|
*/
|
2008-12-19 18:33:47 +00:00
|
|
|
/*
|
|
|
|
* Unless otherwise indicated, Source Code is licensed under MIT license.
|
|
|
|
* See further explanation attached in License Statement (distributed in the file
|
|
|
|
* LICENSE).
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
* so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-12-03 17:09:41 +00:00
|
|
|
* SECTION:element-qtmux
|
2018-10-22 09:39:24 +00:00
|
|
|
* @title: qtmux
|
2008-11-08 02:00:58 +00:00
|
|
|
* @short_description: Muxer for quicktime(.mov) files
|
|
|
|
*
|
2010-12-03 17:09:41 +00:00
|
|
|
* This element merges streams (audio and video) into QuickTime(.mov) files.
|
|
|
|
*
|
|
|
|
* The following background intends to explain why various similar muxers
|
|
|
|
* are present in this plugin.
|
|
|
|
*
|
2019-08-23 16:56:01 +00:00
|
|
|
* The [QuickTime file format specification](http://www.apple.com/quicktime/resources/qtfileformat.pdf)
|
|
|
|
* served as basis for the MP4 file format specification (mp4mux), and as such
|
|
|
|
* the QuickTime file structure is nearly identical to the so-called ISO Base
|
|
|
|
* Media file format defined in ISO 14496-12 (except for some media specific
|
|
|
|
* parts).
|
|
|
|
*
|
2010-12-03 17:09:41 +00:00
|
|
|
* In turn, the latter ISO Base Media format was further specialized as a
|
|
|
|
* Motion JPEG-2000 file format in ISO 15444-3 (mj2mux)
|
|
|
|
* and in various 3GPP(2) specs (gppmux).
|
|
|
|
* The fragmented file features defined (only) in ISO Base Media are used by
|
|
|
|
* ISMV files making up (a.o.) Smooth Streaming (ismlmux).
|
|
|
|
*
|
2018-01-18 16:36:27 +00:00
|
|
|
* A few properties (#GstQTMux:movie-timescale, #GstQTMux:trak-timescale,
|
|
|
|
* #GstQTMuxPad:trak-timescale) allow adjusting some technical parameters,
|
|
|
|
* which might be useful in (rare) cases to resolve compatibility issues in
|
|
|
|
* some situations.
|
2011-01-03 09:43:15 +00:00
|
|
|
*
|
|
|
|
* Some other properties influence the result more fundamentally.
|
2014-02-18 20:44:24 +00:00
|
|
|
* A typical mov/mp4 file's metadata (aka moov) is located at the end of the
|
|
|
|
* file, somewhat contrary to this usually being called "the header".
|
|
|
|
* However, a #GstQTMux:faststart file will (with some effort) arrange this to
|
|
|
|
* be located near start of the file, which then allows it e.g. to be played
|
|
|
|
* while downloading. Alternatively, rather than having one chunk of metadata at
|
|
|
|
* start (or end), there can be some metadata at start and most of the other
|
|
|
|
* data can be spread out into fragments of #GstQTMux:fragment-duration.
|
2011-01-03 09:43:15 +00:00
|
|
|
* If such fragmented layout is intended for streaming purposes, then
|
2014-02-18 20:44:24 +00:00
|
|
|
* #GstQTMux:streamable allows foregoing to add index metadata (at the end of
|
|
|
|
* file).
|
2011-01-03 09:43:15 +00:00
|
|
|
*
|
2015-04-01 00:15:38 +00:00
|
|
|
* When the maximum duration to be recorded can be known in advance, #GstQTMux
|
|
|
|
* also supports a 'Robust Muxing' mode. In robust muxing mode, space for the
|
|
|
|
* headers are reserved at the start of muxing, and rewritten at a configurable
|
|
|
|
* interval, so that the output file is always playable, even if the recording
|
|
|
|
* is interrupted uncleanly by a crash. Robust muxing mode requires a seekable
|
|
|
|
* output, such as filesink, because it needs to rewrite the start of the file.
|
|
|
|
*
|
2019-05-25 14:56:32 +00:00
|
|
|
* To enable robust muxing mode, set the #GstQTMux:reserved-moov-update-period
|
|
|
|
* and #GstQTMux:reserved-max-duration property. Also present is the
|
|
|
|
* #GstQTMux:reserved-bytes-per-sec property, which can be increased if
|
2015-04-01 00:15:38 +00:00
|
|
|
* for some reason the default is not large enough and the initial reserved
|
|
|
|
* space for headers is too small. Applications can monitor the
|
2019-05-25 14:56:32 +00:00
|
|
|
* #GstQTMux:reserved-duration-remaining property to see how close to full
|
2015-04-01 00:15:38 +00:00
|
|
|
* the reserved space is becoming.
|
|
|
|
*
|
2018-03-08 09:10:01 +00:00
|
|
|
* Applications that wish to be able to use/edit a file while it is being
|
|
|
|
* written to by live content, can use the "Robust Prefill Muxing" mode. That
|
|
|
|
* mode is a variant of the "Robust Muxing" mode in that it will pre-allocate a
|
|
|
|
* completely valid header from the start for all tracks (i.e. it appears as
|
|
|
|
* though the file is "reserved-max-duration" long with all samples
|
|
|
|
* present). This mode can be enabled by setting the
|
2019-05-25 14:56:32 +00:00
|
|
|
* #GstQTMux:reserved-moov-update-period and #GstQTMux:reserved-prefill
|
2018-03-08 09:10:01 +00:00
|
|
|
* properties. Note that this mode is only possible with input streams that have
|
|
|
|
* a fixed sample size (such as raw audio and Prores Video) and that don't
|
|
|
|
* have reordered samples.
|
|
|
|
*
|
2018-10-22 09:39:24 +00:00
|
|
|
* ## Example pipelines
|
2010-12-03 17:09:41 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 v4l2src num-buffers=500 ! video/x-raw,width=320,height=240 ! videoconvert ! qtmux ! filesink location=video.mov
|
2010-12-03 17:09:41 +00:00
|
|
|
* ]|
|
2008-11-08 02:00:58 +00:00
|
|
|
* Records a video stream captured from a v4l2 device and muxes it into a qt file.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2008-11-08 02:00:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Based on avimux
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2015-06-11 01:27:27 +00:00
|
|
|
#include <gst/base/gstbytereader.h>
|
|
|
|
#include <gst/base/gstbitreader.h>
|
2012-01-04 10:29:26 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2011-06-29 10:46:20 +00:00
|
|
|
#include <gst/video/video.h>
|
2013-03-22 01:24:01 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2015-11-16 13:26:50 +00:00
|
|
|
#include <gst/pbutils/pbutils.h>
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2009-03-23 10:17:39 +00:00
|
|
|
#include <sys/types.h>
|
2009-03-20 13:20:16 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h> /* lseek, open, close, read */
|
|
|
|
#undef lseek
|
|
|
|
#define lseek _lseeki64
|
|
|
|
#undef off_t
|
|
|
|
#define off_t guint64
|
|
|
|
#endif
|
|
|
|
|
2010-12-01 09:45:49 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define ftruncate g_win32_ftruncate
|
|
|
|
#endif
|
|
|
|
|
2009-03-23 10:17:39 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
#include "gstqtmux.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_qt_mux_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_qt_mux_debug
|
|
|
|
|
2017-03-29 11:01:25 +00:00
|
|
|
#ifndef ABSDIFF
|
|
|
|
#define ABSDIFF(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))
|
|
|
|
#endif
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Hacker notes.
|
|
|
|
*
|
|
|
|
* The basic building blocks of MP4 files are:
|
|
|
|
* - an 'ftyp' box at the very start
|
|
|
|
* - an 'mdat' box which contains the raw audio/video/subtitle data;
|
|
|
|
* this is just a bunch of bytes, completely unframed and possibly
|
|
|
|
* unordered with no additional meta-information
|
|
|
|
* - a 'moov' box that contains information about the different streams
|
|
|
|
* and what they contain, as well as sample tables for each stream
|
|
|
|
* that tell the demuxer where in the mdat box each buffer/sample is
|
|
|
|
* and what its duration/timestamp etc. is, and whether it's a
|
|
|
|
* keyframe etc.
|
|
|
|
* Additionally, fragmented MP4 works by writing chunks of data in
|
|
|
|
* pairs of 'moof' and 'mdat' boxes:
|
|
|
|
* - 'moof' boxes, header preceding each mdat fragment describing the
|
|
|
|
* contents, like a moov but only for that fragment.
|
|
|
|
* - a 'mfra' box for Fragmented MP4, which is written at the end and
|
|
|
|
* contains a summary of all fragments and seek tables.
|
|
|
|
*
|
2015-04-01 00:15:38 +00:00
|
|
|
* Currently mp4mux can work in 4 different modes / generate 4 types
|
2015-04-01 00:15:38 +00:00
|
|
|
* of output files/streams:
|
|
|
|
*
|
|
|
|
* - Normal mp4: mp4mux will write a little ftyp identifier at the
|
|
|
|
* beginning, then start an mdat box into which it will write all the
|
|
|
|
* sample data. At EOS it will then write the moov header with track
|
|
|
|
* headers and sample tables at the end of the file, and rewrite the
|
|
|
|
* start of the file to fix up the mdat box size at the beginning.
|
|
|
|
* It has to wait for EOS to write the moov (which includes the
|
|
|
|
* sample tables) because it doesn't know how much space those
|
|
|
|
* tables will be. The output downstream must be seekable to rewrite
|
|
|
|
* the mdat box at EOS.
|
|
|
|
*
|
|
|
|
* - Fragmented mp4: moov header with track headers at start
|
2015-04-07 15:41:18 +00:00
|
|
|
* but no sample table, followed by N fragments, each containing
|
2015-04-01 00:15:38 +00:00
|
|
|
* track headers with sample tables followed by some data. Downstream
|
|
|
|
* does not need to be seekable if the 'streamable' flag is TRUE,
|
|
|
|
* as the final mfra and total duration will be omitted.
|
|
|
|
*
|
|
|
|
* - Fast-start mp4: the goal here is to create a file where the moov
|
|
|
|
* headers are at the beginning; what mp4mux will do is write all
|
|
|
|
* sample data into a temp file and build moov header plus sample
|
|
|
|
* tables in memory and then when EOS comes, it will push out the
|
|
|
|
* moov header plus sample tables at the beginning, followed by the
|
|
|
|
* mdat sample data at the end which is read in from the temp file
|
|
|
|
* Files created in this mode are better for streaming over the
|
|
|
|
* network, since the client doesn't have to seek to the end of the
|
|
|
|
* file to get the headers, but it requires copying all sample data
|
|
|
|
* out of the temp file at EOS, which can be expensive. Downstream does
|
|
|
|
* not need to be seekable, because of the use of the temp file.
|
|
|
|
*
|
2015-04-01 00:15:38 +00:00
|
|
|
* - Robust Muxing mode: In this mode, qtmux uses the reserved-max-duration
|
|
|
|
* and reserved-moov-update-period properties to reserve free space
|
|
|
|
* at the start of the file and periodically write the MOOV atom out
|
|
|
|
* to it. That means that killing the muxing at any point still
|
|
|
|
* results in a playable file, at the cost of wasting some amount of
|
|
|
|
* free space at the start of file. The approximate recording duration
|
|
|
|
* has to be known in advance to estimate how much free space to reserve
|
|
|
|
* for the moov, and the downstream must be seekable.
|
|
|
|
* If the moov header grows larger than the reserved space, an error
|
|
|
|
* is generated - so it's better to over-estimate the amount of space
|
|
|
|
* to reserve. To ensure the file is playable at any point, the moov
|
|
|
|
* is updated using a 'ping-pong' strategy, so the output is never in
|
|
|
|
* an invalid state.
|
2015-04-01 00:15:38 +00:00
|
|
|
*/
|
|
|
|
|
2013-03-22 20:24:33 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2011-01-03 16:24:23 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
DTS_METHOD_DD,
|
|
|
|
DTS_METHOD_REORDER,
|
|
|
|
DTS_METHOD_ASC
|
|
|
|
};
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gst_qt_mux_dts_method_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gst_qt_mux_dts_method = 0;
|
|
|
|
|
|
|
|
if (!gst_qt_mux_dts_method) {
|
|
|
|
static const GEnumValue dts_methods[] = {
|
|
|
|
{DTS_METHOD_DD, "delta/duration", "dd"},
|
|
|
|
{DTS_METHOD_REORDER, "reorder", "reorder"},
|
|
|
|
{DTS_METHOD_ASC, "ascending", "asc"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
gst_qt_mux_dts_method =
|
|
|
|
g_enum_register_static ("GstQTMuxDtsMethods", dts_methods);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_qt_mux_dts_method;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_TYPE_QT_MUX_DTS_METHOD \
|
|
|
|
(gst_qt_mux_dts_method_get_type ())
|
2013-03-22 20:24:33 +00:00
|
|
|
#endif
|
2011-01-03 16:24:23 +00:00
|
|
|
|
2018-01-18 16:36:27 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_PAD_0,
|
|
|
|
PROP_PAD_TRAK_TIMESCALE,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_PAD_TRAK_TIMESCALE 0
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
G_DEFINE_TYPE (GstQTMuxPad, gst_qt_mux_pad, GST_TYPE_AGGREGATOR_PAD);
|
2018-01-18 16:36:27 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_pad_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstQTMuxPad *pad = GST_QT_MUX_PAD_CAST (object);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pad);
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PAD_TRAK_TIMESCALE:
|
|
|
|
pad->trak_timescale = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_pad_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstQTMuxPad *pad = GST_QT_MUX_PAD_CAST (object);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pad);
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PAD_TRAK_TIMESCALE:
|
|
|
|
g_value_set_uint (value, pad->trak_timescale);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_pad_class_init (GstQTMuxPadClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->get_property = gst_qt_mux_pad_get_property;
|
|
|
|
gobject_class->set_property = gst_qt_mux_pad_set_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PAD_TRAK_TIMESCALE,
|
|
|
|
g_param_spec_uint ("trak-timescale", "Track timescale",
|
|
|
|
"Timescale to use for this pad's trak (units per second, 0 is automatic)",
|
|
|
|
0, G_MAXUINT32, DEFAULT_PAD_TRAK_TIMESCALE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_pad_init (GstQTMuxPad * pad)
|
|
|
|
{
|
|
|
|
pad->trak_timescale = DEFAULT_PAD_TRAK_TIMESCALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint32
|
|
|
|
gst_qt_mux_pad_get_timescale (GstQTMuxPad * pad)
|
|
|
|
{
|
|
|
|
guint32 timescale;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (pad);
|
|
|
|
timescale = pad->trak_timescale;
|
|
|
|
GST_OBJECT_UNLOCK (pad);
|
|
|
|
|
|
|
|
return timescale;
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* QTMux signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_MOVIE_TIMESCALE,
|
2010-07-30 10:48:29 +00:00
|
|
|
PROP_TRAK_TIMESCALE,
|
2008-11-08 02:00:58 +00:00
|
|
|
PROP_FAST_START,
|
2009-12-12 19:07:15 +00:00
|
|
|
PROP_FAST_START_TEMP_FILE,
|
2010-11-15 14:17:59 +00:00
|
|
|
PROP_MOOV_RECOV_FILE,
|
2010-08-06 11:26:27 +00:00
|
|
|
PROP_FRAGMENT_DURATION,
|
2011-01-03 16:24:23 +00:00
|
|
|
PROP_STREAMABLE,
|
2015-04-01 00:15:38 +00:00
|
|
|
PROP_RESERVED_MAX_DURATION,
|
|
|
|
PROP_RESERVED_DURATION_REMAINING,
|
|
|
|
PROP_RESERVED_MOOV_UPDATE_PERIOD,
|
|
|
|
PROP_RESERVED_BYTES_PER_SEC,
|
2017-03-09 08:15:34 +00:00
|
|
|
PROP_RESERVED_PREFILL,
|
2013-03-22 20:24:33 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2011-01-03 16:24:23 +00:00
|
|
|
PROP_DTS_METHOD,
|
2013-03-22 20:24:33 +00:00
|
|
|
#endif
|
2011-01-03 16:24:23 +00:00
|
|
|
PROP_DO_CTTS,
|
2016-10-19 11:25:28 +00:00
|
|
|
PROP_INTERLEAVE_BYTES,
|
|
|
|
PROP_INTERLEAVE_TIME,
|
2017-03-29 11:01:25 +00:00
|
|
|
PROP_MAX_RAW_AUDIO_DRIFT,
|
2018-10-19 14:02:11 +00:00
|
|
|
PROP_START_GAP_THRESHOLD,
|
2008-11-08 02:00:58 +00:00
|
|
|
};
|
|
|
|
|
2009-06-11 13:54:42 +00:00
|
|
|
/* some spare for header size as well */
|
|
|
|
#define MDAT_LARGE_FILE_LIMIT ((guint64) 1024 * 1024 * 1024 * 2)
|
|
|
|
|
2016-10-20 17:41:07 +00:00
|
|
|
#define DEFAULT_MOVIE_TIMESCALE 0
|
2010-07-30 10:48:29 +00:00
|
|
|
#define DEFAULT_TRAK_TIMESCALE 0
|
2011-04-13 11:37:09 +00:00
|
|
|
#define DEFAULT_DO_CTTS TRUE
|
2008-11-08 02:00:58 +00:00
|
|
|
#define DEFAULT_FAST_START FALSE
|
|
|
|
#define DEFAULT_FAST_START_TEMP_FILE NULL
|
2009-12-12 19:07:15 +00:00
|
|
|
#define DEFAULT_MOOV_RECOV_FILE NULL
|
2010-11-15 14:17:59 +00:00
|
|
|
#define DEFAULT_FRAGMENT_DURATION 0
|
2013-09-17 10:06:06 +00:00
|
|
|
#define DEFAULT_STREAMABLE TRUE
|
2013-03-22 20:24:33 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2011-04-13 11:37:09 +00:00
|
|
|
#define DEFAULT_DTS_METHOD DTS_METHOD_REORDER
|
2013-03-22 20:24:33 +00:00
|
|
|
#endif
|
2015-04-01 00:15:38 +00:00
|
|
|
#define DEFAULT_RESERVED_MAX_DURATION GST_CLOCK_TIME_NONE
|
|
|
|
#define DEFAULT_RESERVED_MOOV_UPDATE_PERIOD GST_CLOCK_TIME_NONE
|
|
|
|
#define DEFAULT_RESERVED_BYTES_PER_SEC_PER_TRAK 550
|
2017-03-09 08:15:34 +00:00
|
|
|
#define DEFAULT_RESERVED_PREFILL FALSE
|
2016-10-19 11:25:28 +00:00
|
|
|
#define DEFAULT_INTERLEAVE_BYTES 0
|
2016-10-20 14:40:59 +00:00
|
|
|
#define DEFAULT_INTERLEAVE_TIME 250*GST_MSECOND
|
2017-03-29 11:01:25 +00:00
|
|
|
#define DEFAULT_MAX_RAW_AUDIO_DRIFT 40 * GST_MSECOND
|
2018-10-19 14:02:11 +00:00
|
|
|
#define DEFAULT_START_GAP_THRESHOLD 0
|
2010-11-15 14:17:59 +00:00
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static void gst_qt_mux_finalize (GObject * object);
|
|
|
|
|
|
|
|
/* property functions */
|
|
|
|
static void gst_qt_mux_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_qt_mux_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
/* pad functions */
|
|
|
|
static GstPad *gst_qt_mux_request_new_pad (GstElement * element,
|
2011-06-29 10:46:20 +00:00
|
|
|
GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
|
2008-11-08 02:00:58 +00:00
|
|
|
static void gst_qt_mux_release_pad (GstElement * element, GstPad * pad);
|
|
|
|
|
|
|
|
/* event */
|
2019-12-03 14:30:06 +00:00
|
|
|
static gboolean gst_qt_mux_sink_event (GstAggregator * agg,
|
|
|
|
GstAggregatorPad * agg_pad, GstEvent * event);
|
|
|
|
|
|
|
|
/* aggregator */
|
|
|
|
static GstAggregatorPad *gst_qt_mux_create_new_pad (GstAggregator * self,
|
|
|
|
GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps);
|
|
|
|
static GstFlowReturn gst_qt_mux_aggregate (GstAggregator * agg,
|
|
|
|
gboolean timeout);
|
|
|
|
static GstBuffer *gst_qt_mux_clip_running_time (GstAggregator * agg,
|
|
|
|
GstAggregatorPad * agg_pad, GstBuffer * buf);
|
|
|
|
static gboolean gst_qt_mux_start (GstAggregator * agg);
|
|
|
|
static gboolean gst_qt_mux_stop (GstAggregator * agg);
|
|
|
|
|
|
|
|
/* internal */
|
|
|
|
|
|
|
|
static GstFlowReturn gst_qt_mux_add_buffer (GstQTMux * qtmux, GstQTMuxPad * pad,
|
2008-11-08 02:00:58 +00:00
|
|
|
GstBuffer * buf);
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_robust_recording_rewrite_moov (GstQTMux * qtmux);
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
static void gst_qt_mux_update_global_statistics (GstQTMux * qtmux);
|
|
|
|
static void gst_qt_mux_update_edit_lists (GstQTMux * qtmux);
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
GstQTMuxClass *klass = (GstQTMuxClass *) g_class;
|
|
|
|
GstQTMuxClassParams *params;
|
2018-02-07 10:00:18 +00:00
|
|
|
GstPadTemplate *videosinktempl, *audiosinktempl, *subtitlesinktempl,
|
|
|
|
*captionsinktempl;
|
2014-02-05 13:27:54 +00:00
|
|
|
GstPadTemplate *srctempl;
|
2010-03-18 16:30:26 +00:00
|
|
|
gchar *longname, *description;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
params =
|
|
|
|
(GstQTMuxClassParams *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class),
|
|
|
|
GST_QT_MUX_PARAMS_QDATA);
|
|
|
|
g_assert (params != NULL);
|
|
|
|
|
|
|
|
/* construct the element details struct */
|
2010-03-18 16:30:26 +00:00
|
|
|
longname = g_strdup_printf ("%s Muxer", params->prop->long_name);
|
2012-07-06 11:54:02 +00:00
|
|
|
description = g_strdup_printf ("Multiplex audio and video into a %s file",
|
|
|
|
params->prop->long_name);
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class, longname,
|
2010-03-18 16:30:26 +00:00
|
|
|
"Codec/Muxer", description,
|
|
|
|
"Thiago Sousa Santos <thiagoss@embedded.ufcg.edu.br>");
|
|
|
|
g_free (longname);
|
|
|
|
g_free (description);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/* pad templates */
|
2019-12-03 14:30:06 +00:00
|
|
|
srctempl = gst_pad_template_new_with_gtype ("src", GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS, params->src_caps, GST_TYPE_AGGREGATOR_PAD);
|
2008-11-08 02:00:58 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, srctempl);
|
|
|
|
|
|
|
|
if (params->audio_sink_caps) {
|
2018-01-18 16:36:27 +00:00
|
|
|
audiosinktempl = gst_pad_template_new_with_gtype ("audio_%u",
|
|
|
|
GST_PAD_SINK, GST_PAD_REQUEST, params->audio_sink_caps,
|
|
|
|
GST_TYPE_QT_MUX_PAD);
|
2008-11-08 02:00:58 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, audiosinktempl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params->video_sink_caps) {
|
2018-01-18 16:36:27 +00:00
|
|
|
videosinktempl = gst_pad_template_new_with_gtype ("video_%u",
|
|
|
|
GST_PAD_SINK, GST_PAD_REQUEST, params->video_sink_caps,
|
|
|
|
GST_TYPE_QT_MUX_PAD);
|
2008-11-08 02:00:58 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, videosinktempl);
|
|
|
|
}
|
|
|
|
|
2014-02-05 13:27:54 +00:00
|
|
|
if (params->subtitle_sink_caps) {
|
2018-01-18 16:36:27 +00:00
|
|
|
subtitlesinktempl = gst_pad_template_new_with_gtype ("subtitle_%u",
|
|
|
|
GST_PAD_SINK, GST_PAD_REQUEST, params->subtitle_sink_caps,
|
|
|
|
GST_TYPE_QT_MUX_PAD);
|
2014-02-05 13:27:54 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, subtitlesinktempl);
|
|
|
|
}
|
|
|
|
|
2018-02-07 10:00:18 +00:00
|
|
|
if (params->caption_sink_caps) {
|
|
|
|
captionsinktempl = gst_pad_template_new_with_gtype ("caption_%u",
|
|
|
|
GST_PAD_SINK, GST_PAD_REQUEST, params->caption_sink_caps,
|
|
|
|
GST_TYPE_QT_MUX_PAD);
|
|
|
|
gst_element_class_add_pad_template (element_class, captionsinktempl);
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
klass->format = params->prop->format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_class_init (GstQTMuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2019-12-03 14:30:06 +00:00
|
|
|
GstAggregatorClass *gstagg_class = GST_AGGREGATOR_CLASS (klass);
|
2014-11-02 16:51:23 +00:00
|
|
|
GParamFlags streamable_flags;
|
2013-09-17 10:01:30 +00:00
|
|
|
const gchar *streamable_desc;
|
2013-09-17 10:06:06 +00:00
|
|
|
gboolean streamable;
|
2013-09-17 10:01:30 +00:00
|
|
|
#define STREAMABLE_DESC "If set to true, the output should be as if it is to "\
|
|
|
|
"be streamed and hence no indexes written or duration written."
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_qt_mux_finalize;
|
|
|
|
gobject_class->get_property = gst_qt_mux_get_property;
|
|
|
|
gobject_class->set_property = gst_qt_mux_set_property;
|
|
|
|
|
2014-11-02 16:51:23 +00:00
|
|
|
streamable_flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
|
2013-09-17 10:01:30 +00:00
|
|
|
if (klass->format == GST_QT_MUX_FORMAT_ISML) {
|
|
|
|
streamable_desc = STREAMABLE_DESC;
|
2013-09-17 10:06:06 +00:00
|
|
|
streamable = DEFAULT_STREAMABLE;
|
2013-09-17 10:01:30 +00:00
|
|
|
} else {
|
|
|
|
streamable_desc =
|
|
|
|
STREAMABLE_DESC " (DEPRECATED, only valid for fragmented MP4)";
|
2014-11-02 16:51:23 +00:00
|
|
|
streamable_flags |= G_PARAM_DEPRECATED;
|
2013-09-17 10:06:06 +00:00
|
|
|
streamable = FALSE;
|
2013-09-17 10:01:30 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MOVIE_TIMESCALE,
|
|
|
|
g_param_spec_uint ("movie-timescale", "Movie timescale",
|
2016-10-20 17:41:07 +00:00
|
|
|
"Timescale to use in the movie (units per second, 0 == default)",
|
|
|
|
0, G_MAXUINT32, DEFAULT_MOVIE_TIMESCALE,
|
2010-10-04 02:45:46 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2010-07-30 10:48:29 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_TRAK_TIMESCALE,
|
|
|
|
g_param_spec_uint ("trak-timescale", "Track timescale",
|
|
|
|
"Timescale to use for the tracks (units per second, 0 is automatic)",
|
|
|
|
0, G_MAXUINT32, DEFAULT_TRAK_TIMESCALE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2008-11-08 02:00:58 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DO_CTTS,
|
|
|
|
g_param_spec_boolean ("presentation-time",
|
|
|
|
"Include presentation-time info",
|
2009-11-17 12:26:05 +00:00
|
|
|
"Calculate and include presentation/composition time "
|
2011-04-13 11:37:09 +00:00
|
|
|
"(in addition to decoding time)", DEFAULT_DO_CTTS,
|
2010-10-04 02:45:46 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2013-03-22 20:24:33 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2011-01-03 16:24:23 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DTS_METHOD,
|
|
|
|
g_param_spec_enum ("dts-method", "dts-method",
|
2014-11-02 16:51:23 +00:00
|
|
|
"Method to determine DTS time (DEPRECATED)",
|
2011-01-03 16:24:23 +00:00
|
|
|
GST_TYPE_QT_MUX_DTS_METHOD, DEFAULT_DTS_METHOD,
|
2013-03-22 20:24:33 +00:00
|
|
|
G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
#endif
|
2008-11-08 02:00:58 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FAST_START,
|
|
|
|
g_param_spec_boolean ("faststart", "Format file to faststart",
|
2011-04-13 11:37:09 +00:00
|
|
|
"If the file should be formatted for faststart (headers first)",
|
2010-10-04 02:45:46 +00:00
|
|
|
DEFAULT_FAST_START, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-11-08 02:00:58 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FAST_START_TEMP_FILE,
|
|
|
|
g_param_spec_string ("faststart-file", "File to use for storing buffers",
|
2009-11-17 12:26:05 +00:00
|
|
|
"File that will be used temporarily to store data from the stream "
|
|
|
|
"when creating a faststart file. If null a filepath will be "
|
|
|
|
"created automatically", DEFAULT_FAST_START_TEMP_FILE,
|
2018-11-12 11:05:45 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS |
|
|
|
|
GST_PARAM_DOC_SHOW_DEFAULT));
|
2009-12-12 19:07:15 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MOOV_RECOV_FILE,
|
2010-10-04 02:45:46 +00:00
|
|
|
g_param_spec_string ("moov-recovery-file",
|
|
|
|
"File to store data for posterior moov atom recovery",
|
|
|
|
"File to be used to store "
|
2009-12-12 19:07:15 +00:00
|
|
|
"data for moov atom making movie file recovery possible in case "
|
|
|
|
"of a crash during muxing. Null for disabled. (Experimental)",
|
2010-10-04 02:45:46 +00:00
|
|
|
DEFAULT_MOOV_RECOV_FILE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2010-11-15 14:17:59 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FRAGMENT_DURATION,
|
|
|
|
g_param_spec_uint ("fragment-duration", "Fragment duration",
|
|
|
|
"Fragment durations in ms (produce a fragmented file if > 0)",
|
2010-11-19 18:17:45 +00:00
|
|
|
0, G_MAXUINT32, klass->format == GST_QT_MUX_FORMAT_ISML ?
|
|
|
|
2000 : DEFAULT_FRAGMENT_DURATION,
|
2010-11-15 14:17:59 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2010-08-06 11:26:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_STREAMABLE,
|
2013-09-17 10:01:30 +00:00
|
|
|
g_param_spec_boolean ("streamable", "Streamable", streamable_desc,
|
2014-11-02 16:51:23 +00:00
|
|
|
streamable, streamable_flags | G_PARAM_STATIC_STRINGS));
|
2015-04-01 00:15:38 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RESERVED_MAX_DURATION,
|
|
|
|
g_param_spec_uint64 ("reserved-max-duration",
|
|
|
|
"Reserved maximum file duration (ns)",
|
|
|
|
"When set to a value > 0, reserves space for index tables at the "
|
|
|
|
"beginning of the file.",
|
|
|
|
0, G_MAXUINT64, DEFAULT_RESERVED_MAX_DURATION,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_RESERVED_DURATION_REMAINING,
|
|
|
|
g_param_spec_uint64 ("reserved-duration-remaining",
|
|
|
|
"Report the approximate amount of remaining recording space (ns)",
|
|
|
|
"Reports the approximate amount of remaining moov header space "
|
|
|
|
"reserved using reserved-max-duration", 0, G_MAXUINT64, 0,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_RESERVED_MOOV_UPDATE_PERIOD,
|
|
|
|
g_param_spec_uint64 ("reserved-moov-update-period",
|
|
|
|
"Interval at which to update index tables (ns)",
|
|
|
|
"When used with reserved-max-duration, periodically updates the "
|
|
|
|
"index tables with information muxed so far.", 0, G_MAXUINT64,
|
|
|
|
DEFAULT_RESERVED_MOOV_UPDATE_PERIOD,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_RESERVED_BYTES_PER_SEC,
|
|
|
|
g_param_spec_uint ("reserved-bytes-per-sec",
|
|
|
|
"Reserved MOOV bytes per second, per track",
|
|
|
|
"Multiplier for converting reserved-max-duration into bytes of header to reserve, per second, per track",
|
|
|
|
0, 10000, DEFAULT_RESERVED_BYTES_PER_SEC_PER_TRAK,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2017-03-09 08:15:34 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RESERVED_PREFILL,
|
|
|
|
g_param_spec_boolean ("reserved-prefill",
|
|
|
|
"Reserved Prefill Samples Table",
|
|
|
|
"Prefill samples table of reserved duration",
|
|
|
|
DEFAULT_RESERVED_PREFILL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2016-10-19 11:25:28 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_INTERLEAVE_BYTES,
|
|
|
|
g_param_spec_uint64 ("interleave-bytes", "Interleave (bytes)",
|
|
|
|
"Interleave between streams in bytes",
|
|
|
|
0, G_MAXUINT64, DEFAULT_INTERLEAVE_BYTES,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_INTERLEAVE_TIME,
|
|
|
|
g_param_spec_uint64 ("interleave-time", "Interleave (time)",
|
|
|
|
"Interleave between streams in nanoseconds",
|
|
|
|
0, G_MAXUINT64, DEFAULT_INTERLEAVE_TIME,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2017-03-29 11:01:25 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_RAW_AUDIO_DRIFT,
|
|
|
|
g_param_spec_uint64 ("max-raw-audio-drift", "Max Raw Audio Drift",
|
|
|
|
"Maximum allowed drift of raw audio samples vs. timestamps in nanoseconds",
|
|
|
|
0, G_MAXUINT64, DEFAULT_MAX_RAW_AUDIO_DRIFT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2018-10-19 14:02:11 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_START_GAP_THRESHOLD,
|
|
|
|
g_param_spec_uint64 ("start-gap-threshold", "Start Gap Threshold",
|
|
|
|
"Threshold for creating an edit list for gaps at the start in nanoseconds",
|
|
|
|
0, G_MAXUINT64, DEFAULT_START_GAP_THRESHOLD,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
gstelement_class->request_new_pad =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_qt_mux_request_new_pad);
|
|
|
|
gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_qt_mux_release_pad);
|
2019-12-03 14:30:06 +00:00
|
|
|
|
|
|
|
gstagg_class->sink_event = gst_qt_mux_sink_event;
|
|
|
|
gstagg_class->aggregate = gst_qt_mux_aggregate;
|
|
|
|
gstagg_class->clip = gst_qt_mux_clip_running_time;
|
|
|
|
gstagg_class->start = gst_qt_mux_start;
|
|
|
|
gstagg_class->stop = gst_qt_mux_stop;
|
|
|
|
gstagg_class->create_new_pad = gst_qt_mux_create_new_pad;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_pad_reset (GstQTMuxPad * qtpad)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
|
|
|
qtpad->fourcc = 0;
|
|
|
|
qtpad->is_out_of_order = FALSE;
|
|
|
|
qtpad->sample_size = 0;
|
|
|
|
qtpad->sync = FALSE;
|
|
|
|
qtpad->last_dts = 0;
|
2017-03-29 11:01:25 +00:00
|
|
|
qtpad->sample_offset = 0;
|
2015-04-04 00:34:42 +00:00
|
|
|
qtpad->dts_adjustment = GST_CLOCK_TIME_NONE;
|
2009-11-06 13:34:39 +00:00
|
|
|
qtpad->first_ts = GST_CLOCK_TIME_NONE;
|
2015-06-23 21:54:31 +00:00
|
|
|
qtpad->first_dts = GST_CLOCK_TIME_NONE;
|
2009-12-11 01:20:45 +00:00
|
|
|
qtpad->prepare_buf_func = NULL;
|
2014-02-07 04:49:26 +00:00
|
|
|
qtpad->create_empty_buffer = NULL;
|
2010-07-05 08:39:50 +00:00
|
|
|
qtpad->avg_bitrate = 0;
|
|
|
|
qtpad->max_bitrate = 0;
|
2011-09-28 14:41:49 +00:00
|
|
|
qtpad->total_duration = 0;
|
|
|
|
qtpad->total_bytes = 0;
|
2014-02-07 04:49:26 +00:00
|
|
|
qtpad->sparse = FALSE;
|
2018-09-05 18:10:51 +00:00
|
|
|
qtpad->first_cc_sample_size = 0;
|
2019-07-30 10:07:18 +00:00
|
|
|
qtpad->flow_status = GST_FLOW_OK;
|
2011-01-03 16:24:23 +00:00
|
|
|
|
2015-02-18 13:10:53 +00:00
|
|
|
gst_buffer_replace (&qtpad->last_buf, NULL);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-01-31 17:32:34 +00:00
|
|
|
if (qtpad->tags) {
|
|
|
|
gst_tag_list_unref (qtpad->tags);
|
|
|
|
qtpad->tags = NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* reference owned elsewhere */
|
|
|
|
qtpad->trak = NULL;
|
2017-03-08 13:27:32 +00:00
|
|
|
qtpad->tc_trak = NULL;
|
2010-11-15 14:17:59 +00:00
|
|
|
|
|
|
|
if (qtpad->traf) {
|
|
|
|
atom_traf_free (qtpad->traf);
|
|
|
|
qtpad->traf = NULL;
|
|
|
|
}
|
|
|
|
atom_array_clear (&qtpad->fragment_buffers);
|
2017-03-09 08:15:34 +00:00
|
|
|
if (qtpad->samples)
|
|
|
|
g_array_unref (qtpad->samples);
|
|
|
|
qtpad->samples = NULL;
|
2010-11-18 15:48:06 +00:00
|
|
|
|
|
|
|
/* reference owned elsewhere */
|
|
|
|
qtpad->tfra = NULL;
|
2017-03-22 16:52:51 +00:00
|
|
|
|
|
|
|
qtpad->first_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
qtpad->tc_pos = -1;
|
|
|
|
if (qtpad->first_tc)
|
|
|
|
gst_video_time_code_free (qtpad->first_tc);
|
|
|
|
qtpad->first_tc = NULL;
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
if (qtpad->raw_audio_adapter)
|
|
|
|
gst_object_unref (qtpad->raw_audio_adapter);
|
|
|
|
qtpad->raw_audio_adapter = NULL;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Takes GstQTMux back to its initial state
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_qt_mux_reset (GstQTMux * qtmux, gboolean alloc)
|
|
|
|
{
|
|
|
|
GSList *walk;
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
qtmux->state = GST_QT_MUX_STATE_NONE;
|
|
|
|
qtmux->header_size = 0;
|
|
|
|
qtmux->mdat_size = 0;
|
2015-04-01 00:15:38 +00:00
|
|
|
qtmux->moov_pos = 0;
|
2008-11-08 02:00:58 +00:00
|
|
|
qtmux->mdat_pos = 0;
|
2009-10-16 13:47:32 +00:00
|
|
|
qtmux->longest_chunk = GST_CLOCK_TIME_NONE;
|
2010-11-15 14:17:59 +00:00
|
|
|
qtmux->fragment_sequence = 0;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
if (qtmux->ftyp) {
|
|
|
|
atom_ftyp_free (qtmux->ftyp);
|
|
|
|
qtmux->ftyp = NULL;
|
|
|
|
}
|
|
|
|
if (qtmux->moov) {
|
|
|
|
atom_moov_free (qtmux->moov);
|
|
|
|
qtmux->moov = NULL;
|
|
|
|
}
|
2010-11-18 15:48:06 +00:00
|
|
|
if (qtmux->mfra) {
|
|
|
|
atom_mfra_free (qtmux->mfra);
|
|
|
|
qtmux->mfra = NULL;
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
if (qtmux->fast_start_file) {
|
|
|
|
fclose (qtmux->fast_start_file);
|
2009-09-28 14:53:51 +00:00
|
|
|
g_remove (qtmux->fast_start_file_path);
|
2008-11-08 02:00:58 +00:00
|
|
|
qtmux->fast_start_file = NULL;
|
|
|
|
}
|
2009-12-12 19:07:15 +00:00
|
|
|
if (qtmux->moov_recov_file) {
|
|
|
|
fclose (qtmux->moov_recov_file);
|
|
|
|
qtmux->moov_recov_file = NULL;
|
|
|
|
}
|
2010-09-15 20:54:49 +00:00
|
|
|
for (walk = qtmux->extra_atoms; walk; walk = g_slist_next (walk)) {
|
|
|
|
AtomInfo *ainfo = (AtomInfo *) walk->data;
|
|
|
|
ainfo->free_func (ainfo->atom);
|
2010-12-19 11:53:34 +00:00
|
|
|
g_free (ainfo);
|
2010-09-15 20:54:49 +00:00
|
|
|
}
|
|
|
|
g_slist_free (qtmux->extra_atoms);
|
|
|
|
qtmux->extra_atoms = NULL;
|
2010-02-26 19:50:25 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2008-12-16 16:26:52 +00:00
|
|
|
gst_tag_setter_reset_tags (GST_TAG_SETTER (qtmux));
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/* reset pad data */
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2008-11-08 02:00:58 +00:00
|
|
|
gst_qt_mux_pad_reset (qtpad);
|
|
|
|
|
|
|
|
/* hm, moov_free above yanked the traks away from us,
|
|
|
|
* so do not free, but do clear */
|
|
|
|
qtpad->trak = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alloc) {
|
|
|
|
qtmux->moov = atom_moov_new (qtmux->context);
|
2009-03-25 20:24:44 +00:00
|
|
|
/* ensure all is as nice and fresh as request_new_pad would provide it */
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2009-03-25 20:24:44 +00:00
|
|
|
|
2010-11-05 11:08:15 +00:00
|
|
|
qtpad->trak = atom_trak_new (qtmux->context);
|
|
|
|
atom_moov_add_trak (qtmux->moov, qtpad->trak);
|
2009-03-25 20:24:44 +00:00
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
2016-10-19 11:25:28 +00:00
|
|
|
qtmux->current_pad = NULL;
|
|
|
|
qtmux->current_chunk_size = 0;
|
|
|
|
qtmux->current_chunk_duration = 0;
|
|
|
|
qtmux->current_chunk_offset = -1;
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
qtmux->reserved_moov_size = 0;
|
|
|
|
qtmux->last_moov_update = GST_CLOCK_TIME_NONE;
|
|
|
|
qtmux->muxed_since_last_update = 0;
|
|
|
|
qtmux->reserved_duration_remaining = GST_CLOCK_TIME_NONE;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
static GstBuffer *
|
|
|
|
gst_qt_mux_clip_running_time (GstAggregator * agg,
|
|
|
|
GstAggregatorPad * agg_pad, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstQTMuxPad *qtpad = GST_QT_MUX_PAD (agg_pad);
|
|
|
|
GstBuffer *outbuf = buf;
|
|
|
|
|
|
|
|
/* invalid left alone and passed */
|
|
|
|
if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS_OR_PTS (buf)))) {
|
|
|
|
GstClockTime time;
|
|
|
|
GstClockTime buf_dts, abs_dts;
|
|
|
|
gint dts_sign;
|
|
|
|
|
|
|
|
time = GST_BUFFER_PTS (buf);
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (time)) {
|
|
|
|
time =
|
|
|
|
gst_segment_to_running_time (&agg_pad->segment, GST_FORMAT_TIME,
|
|
|
|
time);
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (time))) {
|
|
|
|
GST_DEBUG_OBJECT (agg_pad, "clipping buffer on pad outside segment %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_PTS (buf)));
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (agg_pad, "buffer pts %" GST_TIME_FORMAT " -> %"
|
|
|
|
GST_TIME_FORMAT " running time",
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buf)), GST_TIME_ARGS (time));
|
|
|
|
outbuf = gst_buffer_make_writable (buf);
|
|
|
|
GST_BUFFER_PTS (outbuf) = time;
|
|
|
|
|
|
|
|
dts_sign = gst_segment_to_running_time_full (&agg_pad->segment,
|
|
|
|
GST_FORMAT_TIME, GST_BUFFER_DTS (outbuf), &abs_dts);
|
|
|
|
buf_dts = GST_BUFFER_DTS (outbuf);
|
|
|
|
if (dts_sign > 0) {
|
|
|
|
GST_BUFFER_DTS (outbuf) = abs_dts;
|
|
|
|
qtpad->dts = abs_dts;
|
|
|
|
} else if (dts_sign < 0) {
|
|
|
|
GST_BUFFER_DTS (outbuf) = GST_CLOCK_TIME_NONE;
|
|
|
|
qtpad->dts = -((gint64) abs_dts);
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_DTS (outbuf) = GST_CLOCK_TIME_NONE;
|
|
|
|
qtpad->dts = GST_CLOCK_STIME_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (agg_pad, "buffer dts %" GST_TIME_FORMAT " -> %"
|
|
|
|
GST_STIME_FORMAT " running time", GST_TIME_ARGS (buf_dts),
|
|
|
|
GST_STIME_ARGS (qtpad->dts));
|
|
|
|
}
|
|
|
|
|
|
|
|
return outbuf;
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static void
|
|
|
|
gst_qt_mux_init (GstQTMux * qtmux, GstQTMuxClass * qtmux_klass)
|
|
|
|
{
|
|
|
|
/* properties set to default upon construction */
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
qtmux->reserved_max_duration = DEFAULT_RESERVED_MAX_DURATION;
|
|
|
|
qtmux->reserved_moov_update_period = DEFAULT_RESERVED_MOOV_UPDATE_PERIOD;
|
|
|
|
qtmux->reserved_bytes_per_sec_per_trak =
|
|
|
|
DEFAULT_RESERVED_BYTES_PER_SEC_PER_TRAK;
|
2016-10-19 11:25:28 +00:00
|
|
|
qtmux->interleave_bytes = DEFAULT_INTERLEAVE_BYTES;
|
|
|
|
qtmux->interleave_time = DEFAULT_INTERLEAVE_TIME;
|
2017-03-29 11:01:25 +00:00
|
|
|
qtmux->max_raw_audio_drift = DEFAULT_MAX_RAW_AUDIO_DRIFT;
|
2018-10-19 14:02:11 +00:00
|
|
|
qtmux->start_gap_threshold = DEFAULT_START_GAP_THRESHOLD;
|
2015-04-01 00:15:38 +00:00
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* always need this */
|
|
|
|
qtmux->context =
|
|
|
|
atoms_context_new (gst_qt_mux_map_format_to_flavor (qtmux_klass->format));
|
|
|
|
|
|
|
|
/* internals to initial state */
|
|
|
|
gst_qt_mux_reset (qtmux, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (object);
|
|
|
|
|
|
|
|
gst_qt_mux_reset (qtmux, FALSE);
|
|
|
|
|
2010-01-26 16:44:04 +00:00
|
|
|
g_free (qtmux->fast_start_file_path);
|
2009-12-12 19:07:15 +00:00
|
|
|
g_free (qtmux->moov_recov_file_path);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
atoms_context_free (qtmux->context);
|
2010-11-19 13:44:45 +00:00
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2009-12-11 01:20:45 +00:00
|
|
|
static GstBuffer *
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_prepare_jpc_buffer (GstQTMuxPad * qtpad, GstBuffer * buf,
|
2009-12-11 01:20:45 +00:00
|
|
|
GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
GstBuffer *newbuf;
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2011-06-29 10:46:20 +00:00
|
|
|
gsize size;
|
2009-12-11 01:20:45 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux, "Preparing jpc buffer");
|
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-29 10:46:20 +00:00
|
|
|
size = gst_buffer_get_size (buf);
|
|
|
|
newbuf = gst_buffer_new_and_alloc (size + 8);
|
|
|
|
gst_buffer_copy_into (newbuf, buf, GST_BUFFER_COPY_ALL, 8, size);
|
2009-12-11 01:20:45 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (newbuf, &map, GST_MAP_WRITE);
|
|
|
|
GST_WRITE_UINT32_BE (map.data, map.size);
|
|
|
|
GST_WRITE_UINT32_LE (map.data + 4, FOURCC_jp2c);
|
2009-12-11 01:20:45 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2009-12-11 01:20:45 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
2018-02-07 10:00:18 +00:00
|
|
|
static gsize
|
2018-12-10 15:34:03 +00:00
|
|
|
extract_608_field_from_s334_1a (const guint8 * ccdata, gsize ccdata_size,
|
2018-02-07 10:00:18 +00:00
|
|
|
guint field, guint8 ** res)
|
|
|
|
{
|
|
|
|
guint8 *storage;
|
|
|
|
gsize storage_size = 128;
|
|
|
|
gsize i, res_size = 0;
|
|
|
|
|
|
|
|
storage = g_malloc0 (storage_size);
|
|
|
|
|
|
|
|
/* Iterate over the ccdata and put the corresponding tuples for the given field
|
|
|
|
* in the storage */
|
|
|
|
for (i = 0; i < ccdata_size; i += 3) {
|
2018-12-10 15:34:03 +00:00
|
|
|
if ((field == 1 && (ccdata[i * 3] & 0x80)) ||
|
|
|
|
(field == 2 && !(ccdata[i * 3] & 0x80))) {
|
2018-02-07 10:00:18 +00:00
|
|
|
GST_DEBUG ("Storing matching cc for field %d : 0x%02x 0x%02x", field,
|
|
|
|
ccdata[i * 3 + 1], ccdata[i * 3 + 2]);
|
|
|
|
if (res_size >= storage_size) {
|
|
|
|
storage_size += 128;
|
|
|
|
storage = g_realloc (storage, storage_size);
|
|
|
|
}
|
|
|
|
storage[res_size] = ccdata[i * 3 + 1];
|
|
|
|
storage[res_size + 1] = ccdata[i * 3 + 2];
|
|
|
|
res_size += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res_size == 0) {
|
|
|
|
g_free (storage);
|
|
|
|
*res = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*res = storage;
|
|
|
|
return res_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstBuffer *
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_prepare_caption_buffer (GstQTMuxPad * qtpad, GstBuffer * buf,
|
2018-02-07 10:00:18 +00:00
|
|
|
GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
GstBuffer *newbuf = NULL;
|
|
|
|
GstMapInfo map, inmap;
|
|
|
|
gsize size;
|
|
|
|
gboolean in_prefill;
|
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
in_prefill = (qtmux->mux_mode == GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL);
|
|
|
|
|
|
|
|
size = gst_buffer_get_size (buf);
|
|
|
|
gst_buffer_map (buf, &inmap, GST_MAP_READ);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux,
|
|
|
|
"Preparing caption buffer %" GST_FOURCC_FORMAT " size:%" G_GSIZE_FORMAT,
|
|
|
|
GST_FOURCC_ARGS (qtpad->fourcc), size);
|
|
|
|
|
|
|
|
switch (qtpad->fourcc) {
|
|
|
|
case FOURCC_c608:
|
|
|
|
{
|
|
|
|
guint8 *cdat, *cdt2;
|
|
|
|
gsize cdat_size, cdt2_size, total_size = 0;
|
|
|
|
gsize write_offs = 0;
|
|
|
|
|
2018-04-25 08:37:40 +00:00
|
|
|
cdat_size =
|
2018-12-10 15:34:03 +00:00
|
|
|
extract_608_field_from_s334_1a (inmap.data, inmap.size, 1, &cdat);
|
2018-04-25 08:37:40 +00:00
|
|
|
cdt2_size =
|
2018-12-10 15:34:03 +00:00
|
|
|
extract_608_field_from_s334_1a (inmap.data, inmap.size, 2, &cdt2);
|
2018-02-07 10:00:18 +00:00
|
|
|
|
|
|
|
if (cdat_size)
|
|
|
|
total_size += cdat_size + 8;
|
|
|
|
if (cdt2_size)
|
|
|
|
total_size += cdt2_size + 8;
|
|
|
|
if (total_size == 0) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "No 608 data ?");
|
|
|
|
/* FIXME : We might want to *always* store something, even if
|
|
|
|
* it's "empty" CC (i.e. 0x80 0x80) */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
newbuf = gst_buffer_new_and_alloc (in_prefill ? 20 : total_size);
|
|
|
|
/* Let's copy over all metadata and not the memory */
|
|
|
|
gst_buffer_copy_into (newbuf, buf, GST_BUFFER_COPY_METADATA, 0, size);
|
|
|
|
|
|
|
|
gst_buffer_map (newbuf, &map, GST_MAP_WRITE);
|
|
|
|
if (cdat_size || in_prefill) {
|
|
|
|
GST_WRITE_UINT32_BE (map.data, in_prefill ? 10 : cdat_size + 8);
|
|
|
|
GST_WRITE_UINT32_LE (map.data + 4, FOURCC_cdat);
|
|
|
|
if (cdat_size)
|
|
|
|
memcpy (map.data + 8, cdat, in_prefill ? 2 : cdat_size);
|
|
|
|
else {
|
|
|
|
/* Write 'empty' CC */
|
|
|
|
map.data[8] = 0x80;
|
|
|
|
map.data[9] = 0x80;
|
|
|
|
}
|
|
|
|
write_offs = in_prefill ? 10 : cdat_size + 8;
|
|
|
|
if (cdat_size)
|
|
|
|
g_free (cdat);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cdt2_size || in_prefill) {
|
|
|
|
GST_WRITE_UINT32_BE (map.data + write_offs,
|
|
|
|
in_prefill ? 10 : cdt2_size + 8);
|
|
|
|
GST_WRITE_UINT32_LE (map.data + write_offs + 4, FOURCC_cdt2);
|
|
|
|
if (cdt2_size)
|
|
|
|
memcpy (map.data + write_offs + 8, cdt2, in_prefill ? 2 : cdt2_size);
|
|
|
|
else {
|
|
|
|
/* Write 'empty' CC */
|
|
|
|
map.data[write_offs + 8] = 0x80;
|
|
|
|
map.data[write_offs + 9] = 0x80;
|
|
|
|
}
|
|
|
|
if (cdt2_size)
|
|
|
|
g_free (cdt2);
|
|
|
|
}
|
|
|
|
gst_buffer_unmap (newbuf, &map);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FOURCC_c708:
|
|
|
|
{
|
2018-09-05 18:10:51 +00:00
|
|
|
gsize actual_size;
|
|
|
|
|
2018-02-07 10:00:18 +00:00
|
|
|
/* Take the whole CDP */
|
2018-09-05 18:10:51 +00:00
|
|
|
if (in_prefill) {
|
|
|
|
if (size > qtpad->first_cc_sample_size) {
|
|
|
|
GST_ELEMENT_WARNING (qtmux, RESOURCE, WRITE,
|
|
|
|
("Truncating too big CEA708 sample (%" G_GSIZE_FORMAT " > %u)",
|
|
|
|
size, qtpad->first_cc_sample_size), (NULL));
|
|
|
|
} else if (size < qtpad->first_cc_sample_size) {
|
|
|
|
GST_ELEMENT_WARNING (qtmux, RESOURCE, WRITE,
|
|
|
|
("Padding too small CEA708 sample (%" G_GSIZE_FORMAT " < %u)",
|
|
|
|
size, qtpad->first_cc_sample_size), (NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
actual_size = MIN (qtpad->first_cc_sample_size, size);
|
|
|
|
} else {
|
|
|
|
actual_size = size;
|
2018-02-07 10:00:18 +00:00
|
|
|
}
|
2018-09-05 18:10:51 +00:00
|
|
|
|
|
|
|
newbuf = gst_buffer_new_and_alloc (actual_size + 8);
|
2018-02-07 10:00:18 +00:00
|
|
|
|
|
|
|
/* Let's copy over all metadata and not the memory */
|
2018-09-05 18:10:51 +00:00
|
|
|
gst_buffer_copy_into (newbuf, buf, GST_BUFFER_COPY_METADATA, 0, -1);
|
2018-02-07 10:00:18 +00:00
|
|
|
|
|
|
|
gst_buffer_map (newbuf, &map, GST_MAP_WRITE);
|
|
|
|
|
2018-09-05 18:10:51 +00:00
|
|
|
GST_WRITE_UINT32_BE (map.data, actual_size + 8);
|
2018-02-07 10:00:18 +00:00
|
|
|
GST_WRITE_UINT32_LE (map.data + 4, FOURCC_ccdp);
|
2018-09-05 18:10:51 +00:00
|
|
|
memcpy (map.data + 8, inmap.data, actual_size);
|
2018-02-07 10:00:18 +00:00
|
|
|
|
|
|
|
gst_buffer_unmap (newbuf, &map);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
/* theoretically this should never happen, but let's keep this here in case */
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Unknown caption format");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_unmap (buf, &inmap);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
2014-02-06 15:15:22 +00:00
|
|
|
static GstBuffer *
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_prepare_tx3g_buffer (GstQTMuxPad * qtpad, GstBuffer * buf,
|
2014-02-06 15:15:22 +00:00
|
|
|
GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
GstBuffer *newbuf;
|
|
|
|
GstMapInfo frommap;
|
|
|
|
GstMapInfo tomap;
|
|
|
|
gsize size;
|
2015-10-19 12:36:37 +00:00
|
|
|
const guint8 *dataend;
|
2014-02-06 15:15:22 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux, "Preparing tx3g buffer %" GST_PTR_FORMAT, buf);
|
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2014-09-23 17:07:25 +00:00
|
|
|
gst_buffer_map (buf, &frommap, GST_MAP_READ);
|
|
|
|
|
2015-10-19 12:36:37 +00:00
|
|
|
dataend = memchr (frommap.data, 0, frommap.size);
|
|
|
|
size = dataend ? dataend - frommap.data : frommap.size;
|
2014-02-06 15:15:22 +00:00
|
|
|
newbuf = gst_buffer_new_and_alloc (size + 2);
|
|
|
|
|
|
|
|
gst_buffer_map (newbuf, &tomap, GST_MAP_WRITE);
|
|
|
|
|
|
|
|
GST_WRITE_UINT16_BE (tomap.data, size);
|
|
|
|
memcpy (tomap.data + 2, frommap.data, size);
|
|
|
|
|
|
|
|
gst_buffer_unmap (newbuf, &tomap);
|
|
|
|
gst_buffer_unmap (buf, &frommap);
|
|
|
|
|
|
|
|
gst_buffer_copy_into (newbuf, buf, GST_BUFFER_COPY_METADATA, 0, size);
|
|
|
|
|
2014-09-23 17:07:25 +00:00
|
|
|
/* gst_buffer_copy_into is trying to be too clever and
|
|
|
|
* won't copy duration when size is different */
|
|
|
|
GST_BUFFER_DURATION (newbuf) = GST_BUFFER_DURATION (buf);
|
|
|
|
|
2014-02-06 15:15:22 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
2015-06-11 01:27:27 +00:00
|
|
|
static void
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_pad_add_ac3_extension (GstQTMux * qtmux, GstQTMuxPad * qtpad,
|
2015-06-11 01:27:27 +00:00
|
|
|
guint8 fscod, guint8 frmsizcod, guint8 bsid, guint8 bsmod, guint8 acmod,
|
|
|
|
guint8 lfe_on)
|
|
|
|
{
|
|
|
|
AtomInfo *ext;
|
|
|
|
|
|
|
|
g_return_if_fail (qtpad->trak_ste);
|
|
|
|
|
|
|
|
ext = build_ac3_extension (fscod, bsid, bsmod, acmod, lfe_on, frmsizcod >> 1); /* bitrate_code is inside frmsizcod */
|
|
|
|
|
|
|
|
sample_table_entry_add_ext_atom (qtpad->trak_ste, ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstBuffer *
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_prepare_parse_ac3_frame (GstQTMuxPad * qtpad, GstBuffer * buf,
|
2015-06-11 01:27:27 +00:00
|
|
|
GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
GstMapInfo map;
|
|
|
|
GstByteReader reader;
|
|
|
|
guint off;
|
|
|
|
|
|
|
|
if (!gst_buffer_map (buf, &map, GST_MAP_READ)) {
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_WARNING_OBJECT (qtpad, "Failed to map buffer");
|
2015-06-11 01:27:27 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (map.size < 8))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
gst_byte_reader_init (&reader, map.data, map.size);
|
|
|
|
off = gst_byte_reader_masked_scan_uint32 (&reader, 0xffff0000, 0x0b770000,
|
|
|
|
0, map.size);
|
|
|
|
|
|
|
|
if (off != -1) {
|
|
|
|
GstBitReader bits;
|
|
|
|
guint8 fscod, frmsizcod, bsid, bsmod, acmod, lfe_on;
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_OBJECT (qtpad, "Found ac3 sync point at offset: %u", off);
|
2015-06-11 01:27:27 +00:00
|
|
|
|
|
|
|
gst_bit_reader_init (&bits, map.data, map.size);
|
|
|
|
|
|
|
|
/* off + sync + crc */
|
|
|
|
gst_bit_reader_skip_unchecked (&bits, off * 8 + 16 + 16);
|
|
|
|
|
|
|
|
fscod = gst_bit_reader_get_bits_uint8_unchecked (&bits, 2);
|
|
|
|
frmsizcod = gst_bit_reader_get_bits_uint8_unchecked (&bits, 6);
|
|
|
|
bsid = gst_bit_reader_get_bits_uint8_unchecked (&bits, 5);
|
|
|
|
bsmod = gst_bit_reader_get_bits_uint8_unchecked (&bits, 3);
|
|
|
|
acmod = gst_bit_reader_get_bits_uint8_unchecked (&bits, 3);
|
|
|
|
|
|
|
|
if ((acmod & 0x1) && (acmod != 0x1)) /* 3 front channels */
|
|
|
|
gst_bit_reader_skip_unchecked (&bits, 2);
|
|
|
|
if ((acmod & 0x4)) /* if a surround channel exists */
|
|
|
|
gst_bit_reader_skip_unchecked (&bits, 2);
|
|
|
|
if (acmod == 0x2) /* if in 2/0 mode */
|
|
|
|
gst_bit_reader_skip_unchecked (&bits, 2);
|
|
|
|
|
|
|
|
lfe_on = gst_bit_reader_get_bits_uint8_unchecked (&bits, 1);
|
|
|
|
|
|
|
|
gst_qt_mux_pad_add_ac3_extension (qtmux, qtpad, fscod, frmsizcod, bsid,
|
|
|
|
bsmod, acmod, lfe_on);
|
|
|
|
|
|
|
|
/* AC-3 spec says that those values should be constant for the
|
|
|
|
* whole stream when muxed in mp4. We trust the input follows it */
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_OBJECT (qtpad, "Data parsed, removing "
|
2015-06-11 01:27:27 +00:00
|
|
|
"prepare buffer function");
|
|
|
|
qtpad->prepare_buf_func = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2014-02-07 04:49:26 +00:00
|
|
|
static GstBuffer *
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_create_empty_tx3g_buffer (GstQTMuxPad * qtpad, gint64 duration)
|
2014-02-07 04:49:26 +00:00
|
|
|
{
|
|
|
|
guint8 *data;
|
|
|
|
|
|
|
|
data = g_malloc (2);
|
|
|
|
GST_WRITE_UINT16_BE (data, 0);
|
|
|
|
|
2014-09-23 17:07:25 +00:00
|
|
|
return gst_buffer_new_wrapped (data, 2);
|
2014-02-07 04:49:26 +00:00
|
|
|
}
|
|
|
|
|
2009-06-10 10:42:44 +00:00
|
|
|
static void
|
|
|
|
gst_qt_mux_add_mp4_tag (GstQTMux * qtmux, const GstTagList * list,
|
2015-01-31 16:14:44 +00:00
|
|
|
AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc)
|
2009-06-10 10:42:44 +00:00
|
|
|
{
|
|
|
|
switch (gst_tag_get_type (tag)) {
|
|
|
|
/* strings */
|
|
|
|
case G_TYPE_STRING:
|
|
|
|
{
|
|
|
|
gchar *str = NULL;
|
|
|
|
|
|
|
|
if (!gst_tag_list_get_string (list, tag, &str) || !str)
|
|
|
|
break;
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
|
|
|
|
GST_FOURCC_ARGS (fourcc), str);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_str_tag (udta, fourcc, str);
|
2009-06-10 10:42:44 +00:00
|
|
|
g_free (str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* double */
|
|
|
|
case G_TYPE_DOUBLE:
|
|
|
|
{
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
if (!gst_tag_list_get_double (list, tag, &value))
|
|
|
|
break;
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %u",
|
|
|
|
GST_FOURCC_ARGS (fourcc), (gint) value);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_uint_tag (udta, fourcc, 21, (gint) value);
|
2009-06-10 10:42:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case G_TYPE_UINT:
|
|
|
|
{
|
2010-06-25 23:19:20 +00:00
|
|
|
guint value = 0;
|
2009-12-21 16:58:30 +00:00
|
|
|
if (tag2) {
|
|
|
|
/* paired unsigned integers */
|
2010-06-25 23:19:20 +00:00
|
|
|
guint count = 0;
|
2011-10-31 15:18:32 +00:00
|
|
|
gboolean got_tag;
|
2009-12-21 16:58:30 +00:00
|
|
|
|
2011-10-31 15:18:32 +00:00
|
|
|
got_tag = gst_tag_list_get_uint (list, tag, &value);
|
|
|
|
got_tag = gst_tag_list_get_uint (list, tag2, &count) || got_tag;
|
|
|
|
if (!got_tag)
|
2009-12-21 16:58:30 +00:00
|
|
|
break;
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %u/%u",
|
|
|
|
GST_FOURCC_ARGS (fourcc), value, count);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_uint_tag (udta, fourcc, 0,
|
2009-12-21 16:58:30 +00:00
|
|
|
value << 16 | (count & 0xFFFF));
|
|
|
|
} else {
|
|
|
|
/* unpaired unsigned integers */
|
|
|
|
if (!gst_tag_list_get_uint (list, tag, &value))
|
|
|
|
break;
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %u",
|
|
|
|
GST_FOURCC_ARGS (fourcc), value);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_uint_tag (udta, fourcc, 1, value);
|
2009-12-21 16:58:30 +00:00
|
|
|
}
|
2009-06-10 10:42:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_add_mp4_date (GstQTMux * qtmux, const GstTagList * list,
|
2015-01-31 16:14:44 +00:00
|
|
|
AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc)
|
2009-06-10 10:42:44 +00:00
|
|
|
{
|
|
|
|
GDate *date = NULL;
|
|
|
|
GDateYear year;
|
|
|
|
GDateMonth month;
|
|
|
|
GDateDay day;
|
|
|
|
gchar *str;
|
|
|
|
|
2012-01-12 23:55:31 +00:00
|
|
|
g_return_if_fail (gst_tag_get_type (tag) == G_TYPE_DATE);
|
2009-06-10 10:42:44 +00:00
|
|
|
|
|
|
|
if (!gst_tag_list_get_date (list, tag, &date) || !date)
|
|
|
|
return;
|
|
|
|
|
|
|
|
year = g_date_get_year (date);
|
|
|
|
month = g_date_get_month (date);
|
|
|
|
day = g_date_get_day (date);
|
|
|
|
|
2011-06-29 10:05:04 +00:00
|
|
|
g_date_free (date);
|
|
|
|
|
2009-06-10 10:42:44 +00:00
|
|
|
if (year == G_DATE_BAD_YEAR && month == G_DATE_BAD_MONTH &&
|
|
|
|
day == G_DATE_BAD_DAY) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "invalid date in tag");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = g_strdup_printf ("%u-%u-%u", year, month, day);
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
|
|
|
|
GST_FOURCC_ARGS (fourcc), str);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_str_tag (udta, fourcc, str);
|
2009-11-17 12:26:05 +00:00
|
|
|
g_free (str);
|
2009-06-10 10:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_add_mp4_cover (GstQTMux * qtmux, const GstTagList * list,
|
2015-01-31 16:14:44 +00:00
|
|
|
AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc)
|
2009-06-10 10:42:44 +00:00
|
|
|
{
|
|
|
|
GValue value = { 0, };
|
|
|
|
GstBuffer *buf;
|
2012-03-07 09:20:00 +00:00
|
|
|
GstSample *sample;
|
2009-06-10 10:42:44 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstStructure *structure;
|
|
|
|
gint flags = 0;
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2009-06-10 10:42:44 +00:00
|
|
|
|
2012-03-07 09:20:00 +00:00
|
|
|
g_return_if_fail (gst_tag_get_type (tag) == GST_TYPE_SAMPLE);
|
2009-06-10 10:42:44 +00:00
|
|
|
|
|
|
|
if (!gst_tag_list_copy_value (&value, list, tag))
|
|
|
|
return;
|
|
|
|
|
2012-03-07 09:20:00 +00:00
|
|
|
sample = gst_value_get_sample (&value);
|
|
|
|
|
|
|
|
if (!sample)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
buf = gst_sample_get_buffer (sample);
|
2009-06-10 10:42:44 +00:00
|
|
|
if (!buf)
|
|
|
|
goto done;
|
|
|
|
|
2012-03-07 09:20:00 +00:00
|
|
|
caps = gst_sample_get_caps (sample);
|
2009-06-10 10:42:44 +00:00
|
|
|
if (!caps) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "preview image without caps");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "preview image caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
if (gst_structure_has_name (structure, "image/jpeg"))
|
|
|
|
flags = 13;
|
|
|
|
else if (gst_structure_has_name (structure, "image/png"))
|
|
|
|
flags = 14;
|
|
|
|
|
|
|
|
if (!flags) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "preview image format not supported");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
2009-06-10 10:42:44 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT
|
2012-01-23 16:25:37 +00:00
|
|
|
" -> image size %" G_GSIZE_FORMAT "", GST_FOURCC_ARGS (fourcc), map.size);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_tag (udta, fourcc, flags, map.data, map.size);
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2009-06-10 10:42:44 +00:00
|
|
|
done:
|
|
|
|
g_value_unset (&value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_add_3gp_str (GstQTMux * qtmux, const GstTagList * list,
|
2015-01-31 16:14:44 +00:00
|
|
|
AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc)
|
2009-06-10 10:42:44 +00:00
|
|
|
{
|
|
|
|
gchar *str = NULL;
|
|
|
|
guint number;
|
|
|
|
|
|
|
|
g_return_if_fail (gst_tag_get_type (tag) == G_TYPE_STRING);
|
|
|
|
g_return_if_fail (!tag2 || gst_tag_get_type (tag2) == G_TYPE_UINT);
|
|
|
|
|
|
|
|
if (!gst_tag_list_get_string (list, tag, &str) || !str)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tag2)
|
|
|
|
if (!gst_tag_list_get_uint (list, tag2, &number))
|
|
|
|
tag2 = NULL;
|
|
|
|
|
|
|
|
if (!tag2) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
|
|
|
|
GST_FOURCC_ARGS (fourcc), str);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_3gp_str_tag (udta, fourcc, str);
|
2009-06-10 10:42:44 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s/%d",
|
|
|
|
GST_FOURCC_ARGS (fourcc), str, number);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_3gp_str_int_tag (udta, fourcc, str, number);
|
2009-06-10 10:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_add_3gp_date (GstQTMux * qtmux, const GstTagList * list,
|
2015-01-31 16:14:44 +00:00
|
|
|
AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc)
|
2009-06-10 10:42:44 +00:00
|
|
|
{
|
|
|
|
GDate *date = NULL;
|
|
|
|
GDateYear year;
|
|
|
|
|
2012-01-12 23:55:31 +00:00
|
|
|
g_return_if_fail (gst_tag_get_type (tag) == G_TYPE_DATE);
|
2009-06-10 10:42:44 +00:00
|
|
|
|
|
|
|
if (!gst_tag_list_get_date (list, tag, &date) || !date)
|
|
|
|
return;
|
|
|
|
|
|
|
|
year = g_date_get_year (date);
|
2015-10-07 08:14:57 +00:00
|
|
|
g_date_free (date);
|
2009-06-10 10:42:44 +00:00
|
|
|
|
|
|
|
if (year == G_DATE_BAD_YEAR) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "invalid date in tag");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-25 06:38:10 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %d",
|
|
|
|
GST_FOURCC_ARGS (fourcc), year);
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_3gp_uint_tag (udta, fourcc, year);
|
2009-06-10 10:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_add_3gp_location (GstQTMux * qtmux, const GstTagList * list,
|
2015-01-31 16:14:44 +00:00
|
|
|
AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc)
|
2009-06-10 10:42:44 +00:00
|
|
|
{
|
|
|
|
gdouble latitude = -360, longitude = -360, altitude = 0;
|
|
|
|
gchar *location = NULL;
|
|
|
|
guint8 *data, *ddata;
|
|
|
|
gint size = 0, len = 0;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
g_return_if_fail (strcmp (tag, GST_TAG_GEO_LOCATION_NAME) == 0);
|
|
|
|
|
|
|
|
ret = gst_tag_list_get_string (list, tag, &location);
|
|
|
|
ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_LONGITUDE,
|
|
|
|
&longitude);
|
|
|
|
ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_LATITUDE,
|
|
|
|
&latitude);
|
|
|
|
ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_ELEVATION,
|
|
|
|
&altitude);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (location)
|
|
|
|
len = strlen (location);
|
|
|
|
size += len + 1 + 2;
|
|
|
|
|
|
|
|
/* role + (long, lat, alt) + body + notes */
|
|
|
|
size += 1 + 3 * 4 + 1 + 1;
|
|
|
|
|
|
|
|
data = ddata = g_malloc (size);
|
|
|
|
|
|
|
|
/* language tag */
|
|
|
|
GST_WRITE_UINT16_BE (data, language_code (GST_QT_MUX_DEFAULT_TAG_LANGUAGE));
|
|
|
|
/* location */
|
|
|
|
if (location)
|
|
|
|
memcpy (data + 2, location, len);
|
|
|
|
GST_WRITE_UINT8 (data + 2 + len, 0);
|
|
|
|
data += len + 1 + 2;
|
|
|
|
/* role */
|
|
|
|
GST_WRITE_UINT8 (data, 0);
|
|
|
|
/* long, lat, alt */
|
2011-05-05 11:24:23 +00:00
|
|
|
#define QT_WRITE_SFP32(data, fp) GST_WRITE_UINT32_BE(data, (guint32) ((gint) (fp * 65536.0)))
|
|
|
|
QT_WRITE_SFP32 (data + 1, longitude);
|
|
|
|
QT_WRITE_SFP32 (data + 5, latitude);
|
|
|
|
QT_WRITE_SFP32 (data + 9, altitude);
|
2009-06-10 10:42:44 +00:00
|
|
|
/* neither astronomical body nor notes */
|
|
|
|
GST_WRITE_UINT16_BE (data + 13, 0);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag 'loci'");
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_3gp_tag (udta, fourcc, ddata, size);
|
2009-06-10 10:42:44 +00:00
|
|
|
g_free (ddata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_add_3gp_keywords (GstQTMux * qtmux, const GstTagList * list,
|
2015-01-31 16:14:44 +00:00
|
|
|
AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc)
|
2009-06-10 10:42:44 +00:00
|
|
|
{
|
|
|
|
gchar *keywords = NULL;
|
|
|
|
guint8 *data, *ddata;
|
|
|
|
gint size = 0, i;
|
|
|
|
gchar **kwds;
|
|
|
|
|
|
|
|
g_return_if_fail (strcmp (tag, GST_TAG_KEYWORDS) == 0);
|
|
|
|
|
|
|
|
if (!gst_tag_list_get_string (list, tag, &keywords) || !keywords)
|
|
|
|
return;
|
|
|
|
|
|
|
|
kwds = g_strsplit (keywords, ",", 0);
|
2010-12-19 11:50:30 +00:00
|
|
|
g_free (keywords);
|
2009-06-10 10:42:44 +00:00
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for (i = 0; kwds[i]; i++) {
|
|
|
|
/* size byte + null-terminator */
|
|
|
|
size += strlen (kwds[i]) + 1 + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* language tag + count + keywords */
|
|
|
|
size += 2 + 1;
|
|
|
|
|
|
|
|
data = ddata = g_malloc (size);
|
|
|
|
|
|
|
|
/* language tag */
|
|
|
|
GST_WRITE_UINT16_BE (data, language_code (GST_QT_MUX_DEFAULT_TAG_LANGUAGE));
|
|
|
|
/* count */
|
|
|
|
GST_WRITE_UINT8 (data + 2, i);
|
|
|
|
data += 3;
|
|
|
|
/* keywords */
|
|
|
|
for (i = 0; kwds[i]; ++i) {
|
|
|
|
gint len = strlen (kwds[i]);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
|
|
|
|
GST_FOURCC_ARGS (fourcc), kwds[i]);
|
|
|
|
/* size */
|
|
|
|
GST_WRITE_UINT8 (data, len + 1);
|
|
|
|
memcpy (data + 1, kwds[i], len + 1);
|
|
|
|
data += len + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (kwds);
|
|
|
|
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_3gp_tag (udta, fourcc, ddata, size);
|
2009-06-10 10:42:44 +00:00
|
|
|
g_free (ddata);
|
|
|
|
}
|
|
|
|
|
2009-12-10 19:53:19 +00:00
|
|
|
static gboolean
|
|
|
|
gst_qt_mux_parse_classification_string (GstQTMux * qtmux, const gchar * input,
|
|
|
|
guint32 * p_fourcc, guint16 * p_table, gchar ** p_content)
|
|
|
|
{
|
|
|
|
guint32 fourcc;
|
|
|
|
gint table;
|
|
|
|
gint size;
|
|
|
|
const gchar *data;
|
|
|
|
|
|
|
|
data = input;
|
|
|
|
size = strlen (input);
|
|
|
|
|
|
|
|
if (size < 4 + 3 + 1 + 1 + 1) {
|
|
|
|
/* at least the minimum xxxx://y/z */
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Classification tag input (%s) too short, "
|
|
|
|
"ignoring", input);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the fourcc */
|
|
|
|
memcpy (&fourcc, data, 4);
|
|
|
|
size -= 4;
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
if (strncmp (data, "://", 3) != 0) {
|
|
|
|
goto mismatch;
|
|
|
|
}
|
|
|
|
data += 3;
|
|
|
|
size -= 3;
|
|
|
|
|
|
|
|
/* read the table number */
|
|
|
|
if (sscanf (data, "%d", &table) != 1) {
|
|
|
|
goto mismatch;
|
|
|
|
}
|
|
|
|
if (table < 0) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Invalid table number in classification tag (%d)"
|
|
|
|
", table numbers should be positive, ignoring tag", table);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the next / */
|
|
|
|
while (size > 0 && data[0] != '/') {
|
|
|
|
data += 1;
|
|
|
|
size -= 1;
|
|
|
|
}
|
|
|
|
if (size == 0) {
|
|
|
|
goto mismatch;
|
|
|
|
}
|
|
|
|
g_assert (data[0] == '/');
|
|
|
|
|
|
|
|
/* skip the '/' */
|
|
|
|
data += 1;
|
|
|
|
size -= 1;
|
|
|
|
if (size == 0) {
|
|
|
|
goto mismatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read up the rest of the string */
|
|
|
|
*p_content = g_strdup (data);
|
|
|
|
*p_table = (guint16) table;
|
|
|
|
*p_fourcc = fourcc;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
mismatch:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Ignoring classification tag as "
|
|
|
|
"input (%s) didn't match the expected entitycode://table/content",
|
|
|
|
input);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_add_3gp_classification (GstQTMux * qtmux, const GstTagList * list,
|
2015-01-31 16:14:44 +00:00
|
|
|
AtomUDTA * udta, const char *tag, const char *tag2, guint32 fourcc)
|
2009-12-10 19:53:19 +00:00
|
|
|
{
|
|
|
|
gchar *clsf_data = NULL;
|
|
|
|
gint size = 0;
|
|
|
|
guint32 entity = 0;
|
|
|
|
guint16 table = 0;
|
|
|
|
gchar *content = NULL;
|
|
|
|
guint8 *data;
|
|
|
|
|
|
|
|
g_return_if_fail (strcmp (tag, GST_TAG_3GP_CLASSIFICATION) == 0);
|
|
|
|
|
|
|
|
if (!gst_tag_list_get_string (list, tag, &clsf_data) || !clsf_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
|
|
|
|
GST_FOURCC_ARGS (fourcc), clsf_data);
|
|
|
|
|
|
|
|
/* parse the string, format is:
|
|
|
|
* entityfourcc://table/content
|
|
|
|
*/
|
|
|
|
gst_qt_mux_parse_classification_string (qtmux, clsf_data, &entity, &table,
|
|
|
|
&content);
|
|
|
|
g_free (clsf_data);
|
|
|
|
/* +1 for the \0 */
|
|
|
|
size = strlen (content) + 1;
|
|
|
|
|
|
|
|
/* now we have everything, build the atom
|
|
|
|
* atom description is at 3GPP TS 26.244 V8.2.0 (2009-09) */
|
|
|
|
data = g_malloc (4 + 2 + 2 + size);
|
|
|
|
GST_WRITE_UINT32_LE (data, entity);
|
|
|
|
GST_WRITE_UINT16_BE (data + 4, (guint16) table);
|
|
|
|
GST_WRITE_UINT16_BE (data + 6, 0);
|
|
|
|
memcpy (data + 8, content, size);
|
|
|
|
g_free (content);
|
|
|
|
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_3gp_tag (udta, fourcc, data, 4 + 2 + 2 + size);
|
2009-12-10 19:53:19 +00:00
|
|
|
g_free (data);
|
|
|
|
}
|
2009-06-10 10:42:44 +00:00
|
|
|
|
2015-01-31 16:14:44 +00:00
|
|
|
typedef void (*GstQTMuxAddUdtaTagFunc) (GstQTMux * mux,
|
|
|
|
const GstTagList * list, AtomUDTA * udta, const char *tag,
|
|
|
|
const char *tag2, guint32 fourcc);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Struct to record mappings from gstreamer tags to fourcc codes
|
|
|
|
*/
|
|
|
|
typedef struct _GstTagToFourcc
|
|
|
|
{
|
|
|
|
guint32 fourcc;
|
|
|
|
const gchar *gsttag;
|
|
|
|
const gchar *gsttag2;
|
2015-01-31 16:14:44 +00:00
|
|
|
const GstQTMuxAddUdtaTagFunc func;
|
2008-11-08 02:00:58 +00:00
|
|
|
} GstTagToFourcc;
|
|
|
|
|
|
|
|
/* tag list tags to fourcc matching */
|
2009-06-10 10:42:44 +00:00
|
|
|
static const GstTagToFourcc tag_matches_mp4[] = {
|
|
|
|
{FOURCC__alb, GST_TAG_ALBUM, NULL, gst_qt_mux_add_mp4_tag},
|
2009-12-21 15:05:37 +00:00
|
|
|
{FOURCC_soal, GST_TAG_ALBUM_SORTNAME, NULL, gst_qt_mux_add_mp4_tag},
|
2009-06-10 10:42:44 +00:00
|
|
|
{FOURCC__ART, GST_TAG_ARTIST, NULL, gst_qt_mux_add_mp4_tag},
|
2009-12-21 15:05:37 +00:00
|
|
|
{FOURCC_soar, GST_TAG_ARTIST_SORTNAME, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_aART, GST_TAG_ALBUM_ARTIST, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_soaa, GST_TAG_ALBUM_ARTIST_SORTNAME, NULL, gst_qt_mux_add_mp4_tag},
|
2015-01-31 13:47:40 +00:00
|
|
|
{FOURCC__swr, GST_TAG_APPLICATION_NAME, NULL, gst_qt_mux_add_mp4_tag},
|
2009-06-10 10:42:44 +00:00
|
|
|
{FOURCC__cmt, GST_TAG_COMMENT, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC__wrt, GST_TAG_COMPOSER, NULL, gst_qt_mux_add_mp4_tag},
|
2009-12-21 15:05:37 +00:00
|
|
|
{FOURCC_soco, GST_TAG_COMPOSER_SORTNAME, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_tvsh, GST_TAG_SHOW_NAME, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_sosn, GST_TAG_SHOW_SORTNAME, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_tvsn, GST_TAG_SHOW_SEASON_NUMBER, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_tves, GST_TAG_SHOW_EPISODE_NUMBER, NULL, gst_qt_mux_add_mp4_tag},
|
2009-06-10 10:42:44 +00:00
|
|
|
{FOURCC__gen, GST_TAG_GENRE, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC__nam, GST_TAG_TITLE, NULL, gst_qt_mux_add_mp4_tag},
|
2009-12-21 15:05:37 +00:00
|
|
|
{FOURCC_sonm, GST_TAG_TITLE_SORTNAME, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_perf, GST_TAG_PERFORMER, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC__grp, GST_TAG_GROUPING, NULL, gst_qt_mux_add_mp4_tag},
|
2009-06-10 10:42:44 +00:00
|
|
|
{FOURCC__des, GST_TAG_DESCRIPTION, NULL, gst_qt_mux_add_mp4_tag},
|
2009-12-21 15:05:37 +00:00
|
|
|
{FOURCC__lyr, GST_TAG_LYRICS, NULL, gst_qt_mux_add_mp4_tag},
|
2009-06-10 10:42:44 +00:00
|
|
|
{FOURCC__too, GST_TAG_ENCODER, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_cprt, GST_TAG_COPYRIGHT, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_keyw, GST_TAG_KEYWORDS, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC__day, GST_TAG_DATE, NULL, gst_qt_mux_add_mp4_date},
|
|
|
|
{FOURCC_tmpo, GST_TAG_BEATS_PER_MINUTE, NULL, gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_trkn, GST_TAG_TRACK_NUMBER, GST_TAG_TRACK_COUNT,
|
|
|
|
gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_disk, GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_ALBUM_VOLUME_COUNT,
|
|
|
|
gst_qt_mux_add_mp4_tag},
|
|
|
|
{FOURCC_covr, GST_TAG_PREVIEW_IMAGE, NULL, gst_qt_mux_add_mp4_cover},
|
2011-05-30 10:09:31 +00:00
|
|
|
{FOURCC_covr, GST_TAG_IMAGE, NULL, gst_qt_mux_add_mp4_cover},
|
2009-06-10 10:42:44 +00:00
|
|
|
{0, NULL,}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GstTagToFourcc tag_matches_3gp[] = {
|
|
|
|
{FOURCC_titl, GST_TAG_TITLE, NULL, gst_qt_mux_add_3gp_str},
|
|
|
|
{FOURCC_dscp, GST_TAG_DESCRIPTION, NULL, gst_qt_mux_add_3gp_str},
|
|
|
|
{FOURCC_cprt, GST_TAG_COPYRIGHT, NULL, gst_qt_mux_add_3gp_str},
|
|
|
|
{FOURCC_perf, GST_TAG_ARTIST, NULL, gst_qt_mux_add_3gp_str},
|
|
|
|
{FOURCC_auth, GST_TAG_COMPOSER, NULL, gst_qt_mux_add_3gp_str},
|
|
|
|
{FOURCC_gnre, GST_TAG_GENRE, NULL, gst_qt_mux_add_3gp_str},
|
|
|
|
{FOURCC_kywd, GST_TAG_KEYWORDS, NULL, gst_qt_mux_add_3gp_keywords},
|
|
|
|
{FOURCC_yrrc, GST_TAG_DATE, NULL, gst_qt_mux_add_3gp_date},
|
|
|
|
{FOURCC_albm, GST_TAG_ALBUM, GST_TAG_TRACK_NUMBER, gst_qt_mux_add_3gp_str},
|
|
|
|
{FOURCC_loci, GST_TAG_GEO_LOCATION_NAME, NULL, gst_qt_mux_add_3gp_location},
|
2009-12-10 19:53:19 +00:00
|
|
|
{FOURCC_clsf, GST_TAG_3GP_CLASSIFICATION, NULL,
|
|
|
|
gst_qt_mux_add_3gp_classification},
|
2008-11-08 02:00:58 +00:00
|
|
|
{0, NULL,}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* qtdemux produces these for atoms it cannot parse */
|
|
|
|
#define GST_QT_DEMUX_PRIVATE_TAG "private-qt-tag"
|
|
|
|
|
2010-02-22 19:45:34 +00:00
|
|
|
static void
|
|
|
|
gst_qt_mux_add_xmp_tags (GstQTMux * qtmux, const GstTagList * list)
|
|
|
|
{
|
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
2011-03-21 13:56:51 +00:00
|
|
|
GstBuffer *xmp = NULL;
|
2010-02-22 19:45:34 +00:00
|
|
|
|
2010-09-15 20:54:49 +00:00
|
|
|
/* adobe specs only have 'quicktime' and 'mp4',
|
|
|
|
* but I guess we can extrapolate to gpp.
|
|
|
|
* Keep mj2 out for now as we don't add any tags for it yet.
|
2010-03-12 13:53:36 +00:00
|
|
|
* If you have further info about xmp on these formats, please share */
|
|
|
|
if (qtmux_klass->format == GST_QT_MUX_FORMAT_MJ2)
|
|
|
|
return;
|
2010-02-22 19:45:34 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding xmp tags");
|
|
|
|
|
2010-09-15 20:54:49 +00:00
|
|
|
if (qtmux_klass->format == GST_QT_MUX_FORMAT_QT) {
|
2011-03-21 13:56:51 +00:00
|
|
|
xmp = gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER (qtmux),
|
|
|
|
list, TRUE);
|
|
|
|
if (xmp)
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_xmp_tags (&qtmux->moov->udta, xmp);
|
2010-09-15 20:54:49 +00:00
|
|
|
} else {
|
2011-03-21 13:56:51 +00:00
|
|
|
AtomInfo *ainfo;
|
2010-09-15 20:54:49 +00:00
|
|
|
/* for isom/mp4, it is a top level uuid atom */
|
2011-03-21 13:56:51 +00:00
|
|
|
xmp = gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER (qtmux),
|
|
|
|
list, TRUE);
|
|
|
|
if (xmp) {
|
|
|
|
ainfo = build_uuid_xmp_atom (xmp);
|
|
|
|
if (ainfo) {
|
|
|
|
qtmux->extra_atoms = g_slist_prepend (qtmux->extra_atoms, ainfo);
|
|
|
|
}
|
2010-09-15 20:54:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-21 13:56:51 +00:00
|
|
|
if (xmp)
|
|
|
|
gst_buffer_unref (xmp);
|
2010-02-22 19:45:34 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static void
|
2015-01-31 16:14:44 +00:00
|
|
|
gst_qt_mux_add_metadata_tags (GstQTMux * qtmux, const GstTagList * list,
|
|
|
|
AtomUDTA * udta)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2009-06-10 10:42:44 +00:00
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
2008-11-08 02:00:58 +00:00
|
|
|
guint32 fourcc;
|
|
|
|
gint i;
|
|
|
|
const gchar *tag, *tag2;
|
2009-06-10 10:42:44 +00:00
|
|
|
const GstTagToFourcc *tag_matches;
|
|
|
|
|
|
|
|
switch (qtmux_klass->format) {
|
|
|
|
case GST_QT_MUX_FORMAT_3GP:
|
|
|
|
tag_matches = tag_matches_3gp;
|
|
|
|
break;
|
|
|
|
case GST_QT_MUX_FORMAT_MJ2:
|
|
|
|
tag_matches = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* sort of iTunes style for mp4 and QT (?) */
|
|
|
|
tag_matches = tag_matches_mp4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tag_matches)
|
|
|
|
return;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Clear existing tags so we don't add them over and over */
|
|
|
|
atom_udta_clear_tags (udta);
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
for (i = 0; tag_matches[i].fourcc; i++) {
|
|
|
|
fourcc = tag_matches[i].fourcc;
|
|
|
|
tag = tag_matches[i].gsttag;
|
|
|
|
tag2 = tag_matches[i].gsttag2;
|
|
|
|
|
2009-06-10 10:42:44 +00:00
|
|
|
g_assert (tag_matches[i].func);
|
2015-01-31 16:14:44 +00:00
|
|
|
tag_matches[i].func (qtmux, list, udta, tag, tag2, fourcc);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add unparsed blobs if present */
|
|
|
|
if (gst_tag_exists (GST_QT_DEMUX_PRIVATE_TAG)) {
|
|
|
|
guint num_tags;
|
|
|
|
|
|
|
|
num_tags = gst_tag_list_get_tag_size (list, GST_QT_DEMUX_PRIVATE_TAG);
|
|
|
|
for (i = 0; i < num_tags; ++i) {
|
2012-07-27 10:05:44 +00:00
|
|
|
GstSample *sample = NULL;
|
2008-11-08 02:00:58 +00:00
|
|
|
GstBuffer *buf;
|
2012-07-27 10:05:44 +00:00
|
|
|
const GstStructure *s;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2012-07-27 10:05:44 +00:00
|
|
|
if (!gst_tag_list_get_sample_index (list, GST_QT_DEMUX_PRIVATE_TAG, i,
|
|
|
|
&sample))
|
|
|
|
continue;
|
|
|
|
buf = gst_sample_get_buffer (sample);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2012-07-27 10:05:44 +00:00
|
|
|
if (buf && (s = gst_sample_get_info (sample))) {
|
2008-11-08 02:00:58 +00:00
|
|
|
const gchar *style = NULL;
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
2011-11-21 19:31:31 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux,
|
2012-07-27 10:05:44 +00:00
|
|
|
"Found private tag %d/%d; size %" G_GSIZE_FORMAT ", info %"
|
|
|
|
GST_PTR_FORMAT, i, num_tags, map.size, s);
|
2008-11-08 02:00:58 +00:00
|
|
|
if (s && (style = gst_structure_get_string (s, "style"))) {
|
2009-06-10 10:42:44 +00:00
|
|
|
/* try to prevent some style tag ending up into another variant
|
|
|
|
* (todo: make into a list if more cases) */
|
|
|
|
if ((strcmp (style, "itunes") == 0 &&
|
|
|
|
qtmux_klass->format == GST_QT_MUX_FORMAT_MP4) ||
|
|
|
|
(strcmp (style, "iso") == 0 &&
|
|
|
|
qtmux_klass->format == GST_QT_MUX_FORMAT_3GP)) {
|
2008-11-08 02:00:58 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Adding private tag");
|
2015-01-31 16:14:44 +00:00
|
|
|
atom_udta_add_blob_tag (udta, map.data, map.size);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
2015-10-05 02:03:38 +00:00
|
|
|
gst_sample_unref (sample);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the tagsetter iface taglist and puts the known tags
|
|
|
|
* into the output stream
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_qt_mux_setup_metadata (GstQTMux * qtmux)
|
|
|
|
{
|
2015-04-01 00:15:38 +00:00
|
|
|
const GstTagList *tags = NULL;
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2010-02-26 19:50:25 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (qtmux->tags_changed) {
|
|
|
|
tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (qtmux));
|
|
|
|
qtmux->tags_changed = FALSE;
|
|
|
|
}
|
2010-02-26 19:50:25 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2008-12-16 16:26:52 +00:00
|
|
|
GST_LOG_OBJECT (qtmux, "tags: %" GST_PTR_FORMAT, tags);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2008-12-16 16:26:52 +00:00
|
|
|
if (tags && !gst_tag_list_is_empty (tags)) {
|
2010-07-02 10:45:20 +00:00
|
|
|
GstTagList *copy = gst_tag_list_copy (tags);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Removing bogus tags");
|
|
|
|
gst_tag_list_remove_tag (copy, GST_TAG_VIDEO_CODEC);
|
|
|
|
gst_tag_list_remove_tag (copy, GST_TAG_AUDIO_CODEC);
|
|
|
|
gst_tag_list_remove_tag (copy, GST_TAG_CONTAINER_FORMAT);
|
|
|
|
|
2008-12-16 16:26:52 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Formatting tags");
|
2015-01-31 16:14:44 +00:00
|
|
|
gst_qt_mux_add_metadata_tags (qtmux, copy, &qtmux->moov->udta);
|
2010-07-02 10:45:20 +00:00
|
|
|
gst_qt_mux_add_xmp_tags (qtmux, copy);
|
2012-08-04 15:10:16 +00:00
|
|
|
gst_tag_list_unref (copy);
|
2008-11-08 02:00:58 +00:00
|
|
|
} else {
|
2015-04-01 00:15:38 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "No new tags received");
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
2015-01-31 16:14:44 +00:00
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qpad = GST_QT_MUX_PAD (l->data);
|
2015-01-31 17:32:34 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
if (qpad->tags_changed && qpad->tags) {
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_OBJECT (qpad, "Adding tags");
|
2015-01-31 17:32:34 +00:00
|
|
|
gst_tag_list_remove_tag (qpad->tags, GST_TAG_CONTAINER_FORMAT);
|
|
|
|
gst_qt_mux_add_metadata_tags (qtmux, qpad->tags, &qpad->trak->udta);
|
2015-04-01 00:15:38 +00:00
|
|
|
qpad->tags_changed = FALSE;
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_OBJECT (qpad, "Tags added");
|
2015-01-31 17:32:34 +00:00
|
|
|
} else {
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_OBJECT (qpad, "No new tags received");
|
2015-01-31 17:32:34 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 14:01:15 +00:00
|
|
|
static inline GstBuffer *
|
|
|
|
_gst_buffer_new_take_data (guint8 * data, guint size)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
buf = gst_buffer_new ();
|
2012-03-30 16:13:08 +00:00
|
|
|
gst_buffer_append_memory (buf,
|
2012-02-22 01:06:17 +00:00
|
|
|
gst_memory_new_wrapped (0, data, size, 0, size, data, g_free));
|
2010-11-09 14:01:15 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_send_buffer (GstQTMux * qtmux, GstBuffer * buf, guint64 * offset,
|
|
|
|
gboolean mind_fast)
|
|
|
|
{
|
|
|
|
GstFlowReturn res;
|
2011-06-29 10:46:20 +00:00
|
|
|
gsize size;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
|
|
|
|
|
2011-06-29 10:46:20 +00:00
|
|
|
size = gst_buffer_get_size (buf);
|
2011-11-21 19:31:31 +00:00
|
|
|
GST_LOG_OBJECT (qtmux, "sending buffer size %" G_GSIZE_FORMAT, size);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
if (mind_fast && qtmux->fast_start_file) {
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2008-11-08 02:00:58 +00:00
|
|
|
gint ret;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux, "to temporary file");
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
|
|
|
ret = fwrite (map.data, sizeof (guint8), map.size, qtmux->fast_start_file);
|
|
|
|
gst_buffer_unmap (buf, &map);
|
2008-11-08 02:00:58 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
if (ret != size)
|
|
|
|
goto write_error;
|
|
|
|
else
|
|
|
|
res = GST_FLOW_OK;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (qtmux, "downstream");
|
2019-12-03 14:30:06 +00:00
|
|
|
res = gst_aggregator_finish_buffer (GST_AGGREGATOR (qtmux), buf);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:18 +00:00
|
|
|
if (res != GST_FLOW_OK)
|
|
|
|
GST_WARNING_OBJECT (qtmux,
|
|
|
|
"Failed to send buffer (%p) size %" G_GSIZE_FORMAT, buf, size);
|
|
|
|
|
2009-06-11 13:54:42 +00:00
|
|
|
if (G_LIKELY (offset))
|
2008-11-08 02:00:58 +00:00
|
|
|
*offset += size;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
write_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, RESOURCE, WRITE,
|
|
|
|
("Failed to write to temporary file"), GST_ERROR_SYSTEM);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-30 15:16:30 +00:00
|
|
|
static gboolean
|
|
|
|
gst_qt_mux_seek_to_beginning (FILE * f)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_FSEEKO
|
|
|
|
if (fseeko (f, (off_t) 0, SEEK_SET) != 0)
|
|
|
|
return FALSE;
|
|
|
|
#elif defined (G_OS_UNIX) || defined (G_OS_WIN32)
|
|
|
|
if (lseek (fileno (f), (off_t) 0, SEEK_SET) == (off_t) - 1)
|
|
|
|
return FALSE;
|
|
|
|
#else
|
|
|
|
if (fseek (f, (long) 0, SEEK_SET) != 0)
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_send_buffered_data (GstQTMux * qtmux, guint64 * offset)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
|
|
|
|
if (fflush (qtmux->fast_start_file))
|
|
|
|
goto flush_failed;
|
|
|
|
|
2009-09-30 15:16:30 +00:00
|
|
|
if (!gst_qt_mux_seek_to_beginning (qtmux->fast_start_file))
|
2009-03-20 13:20:16 +00:00
|
|
|
goto seek_failed;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/* hm, this could all take a really really long time,
|
|
|
|
* but there may not be another way to get moov atom first
|
|
|
|
* (somehow optimize copy?) */
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Sending buffered data");
|
|
|
|
while (ret == GST_FLOW_OK) {
|
|
|
|
const int bufsize = 4096;
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2011-06-29 10:46:20 +00:00
|
|
|
gsize size;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
buf = gst_buffer_new_and_alloc (bufsize);
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (buf, &map, GST_MAP_WRITE);
|
|
|
|
size = fread (map.data, sizeof (guint8), bufsize, qtmux->fast_start_file);
|
2011-06-29 10:46:20 +00:00
|
|
|
if (size == 0) {
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
2011-06-29 10:46:20 +00:00
|
|
|
}
|
2013-03-20 01:09:31 +00:00
|
|
|
GST_LOG_OBJECT (qtmux, "Pushing buffered buffer of size %d", (gint) size);
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2013-03-20 01:09:31 +00:00
|
|
|
if (size != bufsize)
|
|
|
|
gst_buffer_set_size (buf, size);
|
2008-11-08 02:00:58 +00:00
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, buf, offset, FALSE);
|
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
2009-09-30 15:16:30 +00:00
|
|
|
if (ftruncate (fileno (qtmux->fast_start_file), 0))
|
|
|
|
goto seek_failed;
|
|
|
|
if (!gst_qt_mux_seek_to_beginning (qtmux->fast_start_file))
|
|
|
|
goto seek_failed;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
flush_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, RESOURCE, WRITE,
|
|
|
|
("Failed to flush temporary file"), GST_ERROR_SYSTEM);
|
|
|
|
ret = GST_FLOW_ERROR;
|
2010-11-05 10:08:01 +00:00
|
|
|
goto fail;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
seek_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, RESOURCE, SEEK,
|
|
|
|
("Failed to seek temporary file"), GST_ERROR_SYSTEM);
|
|
|
|
ret = GST_FLOW_ERROR;
|
2010-11-05 10:08:01 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
fail:
|
|
|
|
{
|
|
|
|
/* clear descriptor so we don't remove temp file later on,
|
|
|
|
* might be possible to recover */
|
|
|
|
fclose (qtmux->fast_start_file);
|
|
|
|
qtmux->fast_start_file = NULL;
|
2009-09-28 14:53:51 +00:00
|
|
|
return ret;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sends the initial mdat atom fields (size fields and fourcc type),
|
|
|
|
* the subsequent buffers are considered part of it's data.
|
|
|
|
* As we can't predict the amount of data that we are going to place in mdat
|
|
|
|
* we need to record the position of the size field in the stream so we can
|
|
|
|
* seek back to it later and update when the streams have finished.
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2009-06-11 13:54:42 +00:00
|
|
|
gst_qt_mux_send_mdat_header (GstQTMux * qtmux, guint64 * off, guint64 size,
|
2015-04-16 00:44:49 +00:00
|
|
|
gboolean extended, gboolean fsync_after)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
2015-04-01 00:15:38 +00:00
|
|
|
GstMapInfo map;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Sending mdat's atom header, "
|
|
|
|
"size %" G_GUINT64_FORMAT, size);
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* if the qtmux state is EOS, really write the mdat, otherwise
|
|
|
|
* allow size == 0 for a placeholder atom */
|
|
|
|
if (qtmux->state == GST_QT_MUX_STATE_EOS || size > 0)
|
|
|
|
size += 8;
|
|
|
|
|
2009-06-11 13:54:42 +00:00
|
|
|
if (extended) {
|
2015-04-01 00:15:38 +00:00
|
|
|
gboolean large_file = (size > MDAT_LARGE_FILE_LIMIT);
|
|
|
|
/* Always write 16-bytes, but put a free atom first
|
|
|
|
* if the size is < 4GB. */
|
|
|
|
buf = gst_buffer_new_and_alloc (16);
|
|
|
|
gst_buffer_map (buf, &map, GST_MAP_WRITE);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
if (large_file) {
|
|
|
|
/* Write extended mdat header and large_size field */
|
|
|
|
GST_WRITE_UINT32_BE (map.data, 1);
|
|
|
|
GST_WRITE_UINT32_LE (map.data + 4, FOURCC_mdat);
|
|
|
|
GST_WRITE_UINT64_BE (map.data + 8, size + 8);
|
|
|
|
} else {
|
|
|
|
/* Write an empty free atom, then standard 32-bit mdat */
|
|
|
|
GST_WRITE_UINT32_BE (map.data, 8);
|
|
|
|
GST_WRITE_UINT32_LE (map.data + 4, FOURCC_free);
|
|
|
|
GST_WRITE_UINT32_BE (map.data + 8, size);
|
|
|
|
GST_WRITE_UINT32_LE (map.data + 12, FOURCC_mdat);
|
|
|
|
}
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
} else {
|
|
|
|
buf = gst_buffer_new_and_alloc (8);
|
|
|
|
gst_buffer_map (buf, &map, GST_MAP_WRITE);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Vanilla 32-bit mdat */
|
|
|
|
GST_WRITE_UINT32_BE (map.data, size);
|
|
|
|
GST_WRITE_UINT32_LE (map.data + 4, FOURCC_mdat);
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
GST_LOG_OBJECT (qtmux, "Pushing mdat header");
|
2015-04-16 00:44:49 +00:00
|
|
|
if (fsync_after)
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_SYNC_AFTER);
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
return gst_qt_mux_send_buffer (qtmux, buf, off, FALSE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We get the position of the mdat size field, seek back to it
|
|
|
|
* and overwrite with the real value
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_update_mdat_size (GstQTMux * qtmux, guint64 mdat_pos,
|
2015-04-16 00:44:49 +00:00
|
|
|
guint64 mdat_size, guint64 * offset, gboolean fsync_after)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2011-06-29 10:46:20 +00:00
|
|
|
GstSegment segment;
|
2009-06-11 13:54:42 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* We must have recorded the mdat position for this to work */
|
|
|
|
g_assert (mdat_pos != 0);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/* seek and rewrite the header */
|
2011-06-29 10:46:20 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = mdat_pos;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-16 00:44:49 +00:00
|
|
|
return gst_qt_mux_send_mdat_header (qtmux, offset, mdat_size, TRUE,
|
|
|
|
fsync_after);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2009-10-16 00:11:16 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_send_ftyp (GstQTMux * qtmux, guint64 * off)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
guint64 size = 0, offset = 0;
|
|
|
|
guint8 *data = NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Sending ftyp atom");
|
|
|
|
|
|
|
|
if (!atom_ftyp_copy_data (qtmux->ftyp, &data, &size, &offset))
|
|
|
|
goto serialize_error;
|
|
|
|
|
2010-11-09 14:01:15 +00:00
|
|
|
buf = _gst_buffer_new_take_data (data, offset);
|
2009-10-16 00:11:16 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux, "Pushing ftyp");
|
|
|
|
return gst_qt_mux_send_buffer (qtmux, buf, off, FALSE);
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
serialize_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Failed to serialize ftyp"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-12 19:07:15 +00:00
|
|
|
static void
|
|
|
|
gst_qt_mux_prepare_ftyp (GstQTMux * qtmux, AtomFTYP ** p_ftyp,
|
|
|
|
GstBuffer ** p_prefix)
|
2009-10-16 00:11:16 +00:00
|
|
|
{
|
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
|
|
|
guint32 major, version;
|
|
|
|
GList *comp;
|
2009-12-12 19:07:15 +00:00
|
|
|
GstBuffer *prefix = NULL;
|
|
|
|
AtomFTYP *ftyp = NULL;
|
2009-10-16 00:11:16 +00:00
|
|
|
|
2009-12-12 19:07:15 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Preparing ftyp and possible prefix atom");
|
2009-10-16 00:11:16 +00:00
|
|
|
|
|
|
|
/* init and send context and ftyp based on current property state */
|
|
|
|
gst_qt_mux_map_format_to_header (qtmux_klass->format, &prefix, &major,
|
2009-10-16 13:47:32 +00:00
|
|
|
&version, &comp, qtmux->moov, qtmux->longest_chunk,
|
|
|
|
qtmux->fast_start_file != NULL);
|
2009-12-12 19:07:15 +00:00
|
|
|
ftyp = atom_ftyp_new (qtmux->context, major, version, comp);
|
2009-10-16 00:11:16 +00:00
|
|
|
if (comp)
|
|
|
|
g_list_free (comp);
|
2009-12-12 19:07:15 +00:00
|
|
|
if (prefix) {
|
|
|
|
if (p_prefix)
|
|
|
|
*p_prefix = prefix;
|
|
|
|
else
|
|
|
|
gst_buffer_unref (prefix);
|
|
|
|
}
|
|
|
|
*p_ftyp = ftyp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_prepare_and_send_ftyp (GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
GstBuffer *prefix = NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Preparing to send ftyp atom");
|
|
|
|
|
|
|
|
/* init and send context and ftyp based on current property state */
|
|
|
|
if (qtmux->ftyp) {
|
|
|
|
atom_ftyp_free (qtmux->ftyp);
|
|
|
|
qtmux->ftyp = NULL;
|
|
|
|
}
|
|
|
|
gst_qt_mux_prepare_ftyp (qtmux, &qtmux->ftyp, &prefix);
|
2009-10-16 00:11:16 +00:00
|
|
|
if (prefix) {
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, prefix, &qtmux->header_size, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return gst_qt_mux_send_ftyp (qtmux, &qtmux->header_size);
|
|
|
|
}
|
|
|
|
|
2010-07-22 17:40:07 +00:00
|
|
|
static void
|
|
|
|
gst_qt_mux_set_header_on_caps (GstQTMux * mux, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
GValue array = { 0 };
|
|
|
|
GValue value = { 0 };
|
2011-06-29 10:46:20 +00:00
|
|
|
GstCaps *caps, *tcaps;
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
tcaps = gst_pad_get_current_caps (GST_AGGREGATOR_SRC_PAD (mux));
|
2011-06-29 10:46:20 +00:00
|
|
|
caps = gst_caps_copy (tcaps);
|
|
|
|
gst_caps_unref (tcaps);
|
2010-07-22 17:40:07 +00:00
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
g_value_init (&array, GST_TYPE_ARRAY);
|
|
|
|
|
2012-01-30 16:16:51 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER);
|
2010-07-22 17:40:07 +00:00
|
|
|
g_value_init (&value, GST_TYPE_BUFFER);
|
|
|
|
gst_value_take_buffer (&value, gst_buffer_ref (buf));
|
|
|
|
gst_value_array_append_value (&array, &value);
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
gst_structure_set_value (structure, "streamheader", &array);
|
|
|
|
g_value_unset (&array);
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_set_src_caps (GST_AGGREGATOR (mux), caps);
|
2010-07-22 17:40:07 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/*
|
|
|
|
* Write out a free space atom. The offset is adjusted by the full
|
|
|
|
* size, but a smaller buffer is sent
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2015-04-16 00:44:49 +00:00
|
|
|
gst_qt_mux_send_free_atom (GstQTMux * qtmux, guint64 * off, guint32 size,
|
|
|
|
gboolean fsync_after)
|
2015-04-01 00:15:38 +00:00
|
|
|
{
|
|
|
|
Atom *node_header;
|
|
|
|
GstBuffer *buf;
|
|
|
|
guint8 *data = NULL;
|
|
|
|
guint64 offset = 0, bsize = 0;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Sending free atom header of size %u", size);
|
|
|
|
|
|
|
|
/* We can't make a free space atom smaller than the header */
|
|
|
|
if (size < 8)
|
|
|
|
goto too_small;
|
|
|
|
|
|
|
|
node_header = g_malloc0 (sizeof (Atom));
|
|
|
|
node_header->type = FOURCC_free;
|
|
|
|
node_header->size = size;
|
|
|
|
|
|
|
|
bsize = offset = 0;
|
|
|
|
if (atom_copy_data (node_header, &data, &bsize, &offset) == 0)
|
|
|
|
goto serialize_error;
|
|
|
|
|
|
|
|
buf = _gst_buffer_new_take_data (data, offset);
|
|
|
|
g_free (node_header);
|
|
|
|
|
2015-04-16 00:44:49 +00:00
|
|
|
if (fsync_after)
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_SYNC_AFTER);
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
GST_LOG_OBJECT (qtmux, "Pushing free atom");
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, buf, off, FALSE);
|
|
|
|
|
|
|
|
if (off) {
|
|
|
|
GstSegment segment;
|
|
|
|
|
|
|
|
*off += size - 8;
|
|
|
|
|
|
|
|
/* Make sure downstream position ends up at the end of this free box */
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = *off;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
too_small:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Not enough free reserved space"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
serialize_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Failed to serialize mdat"));
|
|
|
|
g_free (node_header);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 15:49:07 +00:00
|
|
|
static void
|
2015-04-01 00:15:38 +00:00
|
|
|
gst_qt_mux_configure_moov (GstQTMux * qtmux)
|
2010-11-09 15:49:07 +00:00
|
|
|
{
|
2015-04-01 00:15:38 +00:00
|
|
|
gboolean fragmented = FALSE;
|
2010-11-09 15:49:07 +00:00
|
|
|
guint32 timescale;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2010-11-15 14:17:59 +00:00
|
|
|
timescale = qtmux->timescale;
|
2015-04-01 00:15:38 +00:00
|
|
|
if (qtmux->mux_mode == GST_QT_MUX_MODE_FRAGMENTED ||
|
|
|
|
qtmux->mux_mode == GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE)
|
|
|
|
fragmented = TRUE;
|
2010-11-09 15:49:07 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
|
|
|
/* inform lower layers of our property wishes, and determine duration.
|
|
|
|
* Let moov take care of this using its list of traks;
|
|
|
|
* so that released pads are also included */
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Updating timescale to %" G_GUINT32_FORMAT,
|
|
|
|
timescale);
|
|
|
|
atom_moov_update_timescale (qtmux->moov, timescale);
|
2010-11-15 14:17:59 +00:00
|
|
|
atom_moov_set_fragmented (qtmux->moov, fragmented);
|
2010-11-09 15:49:07 +00:00
|
|
|
|
|
|
|
atom_moov_update_duration (qtmux->moov);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2015-04-01 00:15:38 +00:00
|
|
|
gst_qt_mux_send_moov (GstQTMux * qtmux, guint64 * _offset,
|
2015-04-16 00:44:49 +00:00
|
|
|
guint64 padded_moov_size, gboolean mind_fast, gboolean fsync_after)
|
2010-11-09 15:49:07 +00:00
|
|
|
{
|
|
|
|
guint64 offset = 0, size = 0;
|
|
|
|
guint8 *data;
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2017-02-27 11:55:58 +00:00
|
|
|
guint64 current_time = atoms_get_current_qt_time ();
|
|
|
|
|
|
|
|
/* update modification times */
|
|
|
|
qtmux->moov->mvhd.time_info.modification_time = current_time;
|
2019-12-12 19:20:35 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2017-02-27 11:55:58 +00:00
|
|
|
|
|
|
|
qtpad->trak->mdia.mdhd.time_info.modification_time = current_time;
|
|
|
|
qtpad->trak->tkhd.modification_time = current_time;
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2010-11-09 15:49:07 +00:00
|
|
|
|
|
|
|
/* serialize moov */
|
|
|
|
offset = size = 0;
|
|
|
|
data = NULL;
|
|
|
|
GST_LOG_OBJECT (qtmux, "Copying movie header into buffer");
|
|
|
|
if (!atom_moov_copy_data (qtmux->moov, &data, &size, &offset))
|
|
|
|
goto serialize_error;
|
2015-04-01 00:15:38 +00:00
|
|
|
qtmux->last_moov_size = offset;
|
2010-11-09 15:49:07 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Check we have enough reserved space for this and a Free atom */
|
|
|
|
if (padded_moov_size > 0 && offset + 8 > padded_moov_size)
|
|
|
|
goto too_small_reserved;
|
2010-11-09 15:49:07 +00:00
|
|
|
buf = _gst_buffer_new_take_data (data, offset);
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Pushing moov atoms");
|
2015-04-02 13:57:20 +00:00
|
|
|
|
|
|
|
/* If at EOS, this is the final moov, put in the streamheader
|
|
|
|
* (apparently used by a flumotion util) */
|
|
|
|
if (qtmux->state == GST_QT_MUX_STATE_EOS)
|
|
|
|
gst_qt_mux_set_header_on_caps (qtmux, buf);
|
2015-04-16 00:44:49 +00:00
|
|
|
|
|
|
|
if (fsync_after)
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_SYNC_AFTER);
|
2010-11-09 15:49:07 +00:00
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, buf, _offset, mind_fast);
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Write out a free atom if needed */
|
|
|
|
if (ret == GST_FLOW_OK && offset < padded_moov_size) {
|
|
|
|
GST_LOG_OBJECT (qtmux, "Writing out free atom of size %u",
|
|
|
|
(guint32) (padded_moov_size - offset));
|
2015-04-16 00:44:49 +00:00
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_free_atom (qtmux, _offset, padded_moov_size - offset,
|
|
|
|
fsync_after);
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
2010-11-09 15:49:07 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
return ret;
|
|
|
|
too_small_reserved:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX,
|
|
|
|
("Not enough free reserved header space"),
|
|
|
|
("Needed %" G_GUINT64_FORMAT " bytes, reserved %" G_GUINT64_FORMAT,
|
|
|
|
offset, padded_moov_size));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2010-11-09 15:49:07 +00:00
|
|
|
serialize_error:
|
|
|
|
{
|
|
|
|
g_free (data);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 14:54:44 +00:00
|
|
|
/* either calculates size of extra atoms or pushes them */
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_send_extra_atoms (GstQTMux * qtmux, gboolean send, guint64 * offset,
|
|
|
|
gboolean mind_fast)
|
|
|
|
{
|
|
|
|
GSList *walk;
|
|
|
|
guint64 loffset = 0, size = 0;
|
|
|
|
guint8 *data;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
for (walk = qtmux->extra_atoms; walk; walk = g_slist_next (walk)) {
|
|
|
|
AtomInfo *ainfo = (AtomInfo *) walk->data;
|
|
|
|
|
|
|
|
loffset = size = 0;
|
|
|
|
data = NULL;
|
|
|
|
if (!ainfo->copy_data_func (ainfo->atom,
|
|
|
|
send ? &data : NULL, &size, &loffset))
|
|
|
|
goto serialize_error;
|
|
|
|
|
|
|
|
if (send) {
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux,
|
|
|
|
"Pushing extra top-level atom %" GST_FOURCC_FORMAT,
|
|
|
|
GST_FOURCC_ARGS (ainfo->atom->type));
|
|
|
|
buf = _gst_buffer_new_take_data (data, loffset);
|
2010-11-09 15:49:07 +00:00
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, buf, offset, FALSE);
|
2010-11-09 14:54:44 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (offset)
|
|
|
|
*offset += loffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
serialize_error:
|
|
|
|
{
|
|
|
|
g_free (data);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 12:46:13 +00:00
|
|
|
static gboolean
|
|
|
|
gst_qt_mux_downstream_is_seekable (GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
gboolean seekable = FALSE;
|
|
|
|
GstQuery *query = gst_query_new_seeking (GST_FORMAT_BYTES);
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
if (gst_pad_peer_query (GST_AGGREGATOR_SRC_PAD (qtmux), query)) {
|
2015-04-01 12:46:13 +00:00
|
|
|
gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL);
|
|
|
|
GST_INFO_OBJECT (qtmux, "downstream is %sseekable", seekable ? "" : "not ");
|
|
|
|
} else {
|
|
|
|
/* have to assume seeking is not supported if query not handled downstream */
|
|
|
|
GST_WARNING_OBJECT (qtmux, "downstream did not handle seeking query");
|
|
|
|
seekable = FALSE;
|
|
|
|
}
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
|
|
|
return seekable;
|
|
|
|
}
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
static void
|
|
|
|
gst_qt_mux_prepare_moov_recovery (GstQTMux * qtmux)
|
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2015-04-01 00:15:38 +00:00
|
|
|
gboolean fail = FALSE;
|
|
|
|
AtomFTYP *ftyp = NULL;
|
|
|
|
GstBuffer *prefix = NULL;
|
|
|
|
|
2017-01-25 18:43:00 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Opening moov recovery file: %s",
|
2015-04-01 00:15:38 +00:00
|
|
|
qtmux->moov_recov_file_path);
|
|
|
|
|
|
|
|
qtmux->moov_recov_file = g_fopen (qtmux->moov_recov_file_path, "wb+");
|
|
|
|
if (qtmux->moov_recov_file == NULL) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Failed to open moov recovery file in %s",
|
|
|
|
qtmux->moov_recov_file_path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_qt_mux_prepare_ftyp (qtmux, &ftyp, &prefix);
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (!atoms_recov_write_headers (qtmux->moov_recov_file, ftyp, prefix,
|
2019-12-03 14:30:06 +00:00
|
|
|
qtmux->moov, qtmux->timescale,
|
|
|
|
g_list_length (GST_ELEMENT (qtmux)->sinkpads))) {
|
2015-04-01 00:15:38 +00:00
|
|
|
GST_WARNING_OBJECT (qtmux, "Failed to write moov recovery file " "headers");
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
atom_ftyp_free (ftyp);
|
|
|
|
if (prefix)
|
|
|
|
gst_buffer_unref (prefix);
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qpad = (GstQTMuxPad *) l->data;
|
2015-04-01 00:15:38 +00:00
|
|
|
/* write info for each stream */
|
|
|
|
fail = atoms_recov_write_trak_info (qtmux->moov_recov_file, qpad->trak);
|
|
|
|
if (fail) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Failed to write trak info to recovery "
|
|
|
|
"file");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
2017-03-11 20:56:33 +00:00
|
|
|
return;
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
fail:
|
|
|
|
/* cleanup */
|
|
|
|
fclose (qtmux->moov_recov_file);
|
|
|
|
qtmux->moov_recov_file = NULL;
|
|
|
|
}
|
2015-04-01 12:46:13 +00:00
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
static guint64
|
2019-12-03 14:30:06 +00:00
|
|
|
prefill_get_block_index (GstQTMux * qtmux, GstQTMuxPad * qpad)
|
2017-03-09 08:15:34 +00:00
|
|
|
{
|
|
|
|
switch (qpad->fourcc) {
|
|
|
|
case FOURCC_apch:
|
|
|
|
case FOURCC_apcn:
|
|
|
|
case FOURCC_apcs:
|
|
|
|
case FOURCC_apco:
|
|
|
|
case FOURCC_ap4h:
|
|
|
|
case FOURCC_ap4x:
|
2018-02-07 10:00:18 +00:00
|
|
|
case FOURCC_c608:
|
|
|
|
case FOURCC_c708:
|
2017-03-09 08:15:34 +00:00
|
|
|
return qpad->sample_offset;
|
|
|
|
case FOURCC_sowt:
|
|
|
|
case FOURCC_twos:
|
|
|
|
return gst_util_uint64_scale_ceil (qpad->sample_offset,
|
|
|
|
qpad->expected_sample_duration_n,
|
|
|
|
qpad->expected_sample_duration_d *
|
|
|
|
atom_trak_get_timescale (qpad->trak));
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
2019-12-03 14:30:06 +00:00
|
|
|
prefill_get_sample_size (GstQTMux * qtmux, GstQTMuxPad * qpad)
|
2017-03-09 08:15:34 +00:00
|
|
|
{
|
|
|
|
switch (qpad->fourcc) {
|
|
|
|
case FOURCC_apch:
|
|
|
|
if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 480) {
|
|
|
|
return 300000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 576) {
|
|
|
|
return 350000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 720) {
|
|
|
|
return 525000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 1080) {
|
|
|
|
return 1050000;
|
2020-02-24 13:25:07 +00:00
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 2160) {
|
2017-03-09 08:15:34 +00:00
|
|
|
return 4150000;
|
2020-02-24 13:25:07 +00:00
|
|
|
} else {
|
|
|
|
return 16600000;
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FOURCC_apcn:
|
|
|
|
if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 480) {
|
|
|
|
return 200000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 576) {
|
|
|
|
return 250000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 720) {
|
|
|
|
return 350000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 1080) {
|
|
|
|
return 700000;
|
2020-02-24 13:25:07 +00:00
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 2160) {
|
2017-03-09 08:15:34 +00:00
|
|
|
return 2800000;
|
2020-02-24 13:25:07 +00:00
|
|
|
} else {
|
|
|
|
return 11200000;
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FOURCC_apcs:
|
|
|
|
if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 480) {
|
|
|
|
return 150000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 576) {
|
|
|
|
return 200000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 720) {
|
|
|
|
return 250000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 1080) {
|
|
|
|
return 500000;
|
2020-02-24 13:25:07 +00:00
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 2160) {
|
2017-03-09 08:15:34 +00:00
|
|
|
return 2800000;
|
2020-02-24 13:25:07 +00:00
|
|
|
} else {
|
|
|
|
return 11200000;
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FOURCC_apco:
|
|
|
|
if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 480) {
|
|
|
|
return 80000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 576) {
|
|
|
|
return 100000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 720) {
|
|
|
|
return 150000;
|
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 1080) {
|
|
|
|
return 250000;
|
2020-02-24 13:25:07 +00:00
|
|
|
} else if (((SampleTableEntryMP4V *) qpad->trak_ste)->height <= 2160) {
|
2017-03-09 08:15:34 +00:00
|
|
|
return 900000;
|
2020-02-24 13:25:07 +00:00
|
|
|
} else {
|
|
|
|
return 3600000;
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-02-07 10:00:18 +00:00
|
|
|
case FOURCC_c608:
|
|
|
|
/* We always write both cdat and cdt2 atom in prefill mode */
|
|
|
|
return 20;
|
2018-09-05 18:10:51 +00:00
|
|
|
case FOURCC_c708:{
|
|
|
|
if (qpad->first_cc_sample_size == 0) {
|
|
|
|
GstBuffer *buf =
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_pad_peek_buffer (GST_AGGREGATOR_PAD (qpad));
|
2018-09-05 18:10:51 +00:00
|
|
|
g_assert (buf != NULL);
|
|
|
|
qpad->first_cc_sample_size = gst_buffer_get_size (buf);
|
|
|
|
g_assert (qpad->first_cc_sample_size != 0);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
return qpad->first_cc_sample_size + 8;
|
|
|
|
}
|
2017-03-09 08:15:34 +00:00
|
|
|
case FOURCC_sowt:
|
|
|
|
case FOURCC_twos:{
|
|
|
|
guint64 block_idx;
|
|
|
|
guint64 next_sample_offset;
|
|
|
|
|
|
|
|
block_idx = prefill_get_block_index (qtmux, qpad);
|
|
|
|
next_sample_offset =
|
|
|
|
gst_util_uint64_scale (block_idx + 1,
|
|
|
|
qpad->expected_sample_duration_d *
|
|
|
|
atom_trak_get_timescale (qpad->trak),
|
|
|
|
qpad->expected_sample_duration_n);
|
|
|
|
|
|
|
|
return (next_sample_offset - qpad->sample_offset) * qpad->sample_size;
|
|
|
|
}
|
|
|
|
case FOURCC_ap4h:
|
|
|
|
case FOURCC_ap4x:
|
|
|
|
default:
|
|
|
|
GST_ERROR_OBJECT (qtmux, "unsupported codec for pre-filling");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstClockTime
|
2019-12-03 14:30:06 +00:00
|
|
|
prefill_get_next_timestamp (GstQTMux * qtmux, GstQTMuxPad * qpad)
|
2017-03-09 08:15:34 +00:00
|
|
|
{
|
|
|
|
switch (qpad->fourcc) {
|
|
|
|
case FOURCC_apch:
|
|
|
|
case FOURCC_apcn:
|
|
|
|
case FOURCC_apcs:
|
|
|
|
case FOURCC_apco:
|
|
|
|
case FOURCC_ap4h:
|
|
|
|
case FOURCC_ap4x:
|
2018-02-07 10:00:18 +00:00
|
|
|
case FOURCC_c608:
|
|
|
|
case FOURCC_c708:
|
2017-03-09 08:15:34 +00:00
|
|
|
return gst_util_uint64_scale (qpad->sample_offset + 1,
|
|
|
|
qpad->expected_sample_duration_d * GST_SECOND,
|
|
|
|
qpad->expected_sample_duration_n);
|
|
|
|
case FOURCC_sowt:
|
|
|
|
case FOURCC_twos:{
|
|
|
|
guint64 block_idx;
|
|
|
|
guint64 next_sample_offset;
|
|
|
|
|
|
|
|
block_idx = prefill_get_block_index (qtmux, qpad);
|
|
|
|
next_sample_offset =
|
|
|
|
gst_util_uint64_scale (block_idx + 1,
|
|
|
|
qpad->expected_sample_duration_d *
|
|
|
|
atom_trak_get_timescale (qpad->trak),
|
|
|
|
qpad->expected_sample_duration_n);
|
|
|
|
|
|
|
|
return gst_util_uint64_scale (next_sample_offset, GST_SECOND,
|
|
|
|
atom_trak_get_timescale (qpad->trak));
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
GST_ERROR_OBJECT (qtmux, "unsupported codec for pre-filling");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstBuffer *
|
2019-12-03 14:30:06 +00:00
|
|
|
prefill_raw_audio_prepare_buf_func (GstQTMuxPad * qtpad, GstBuffer * buf,
|
2017-03-09 08:15:34 +00:00
|
|
|
GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
guint64 block_idx;
|
|
|
|
guint64 nsamples;
|
|
|
|
GstClockTime input_timestamp;
|
|
|
|
guint64 input_timestamp_distance;
|
|
|
|
|
|
|
|
if (buf)
|
|
|
|
gst_adapter_push (qtpad->raw_audio_adapter, buf);
|
|
|
|
|
|
|
|
block_idx = gst_util_uint64_scale_ceil (qtpad->raw_audio_adapter_offset,
|
|
|
|
qtpad->expected_sample_duration_n,
|
|
|
|
qtpad->expected_sample_duration_d *
|
|
|
|
atom_trak_get_timescale (qtpad->trak));
|
|
|
|
nsamples =
|
|
|
|
gst_util_uint64_scale (block_idx + 1,
|
|
|
|
qtpad->expected_sample_duration_d * atom_trak_get_timescale (qtpad->trak),
|
|
|
|
qtpad->expected_sample_duration_n) - qtpad->raw_audio_adapter_offset;
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
if ((!gst_aggregator_pad_is_eos (GST_AGGREGATOR_PAD (qtpad))
|
2017-03-09 08:15:34 +00:00
|
|
|
&& gst_adapter_available (qtpad->raw_audio_adapter) <
|
|
|
|
nsamples * qtpad->sample_size)
|
|
|
|
|| gst_adapter_available (qtpad->raw_audio_adapter) == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_timestamp =
|
|
|
|
gst_adapter_prev_pts (qtpad->raw_audio_adapter,
|
|
|
|
&input_timestamp_distance);
|
|
|
|
if (input_timestamp != GST_CLOCK_TIME_NONE)
|
|
|
|
input_timestamp +=
|
|
|
|
gst_util_uint64_scale (input_timestamp_distance, GST_SECOND,
|
|
|
|
qtpad->sample_size * atom_trak_get_timescale (qtpad->trak));
|
|
|
|
|
|
|
|
buf =
|
|
|
|
gst_adapter_take_buffer (qtpad->raw_audio_adapter,
|
2019-12-03 14:30:06 +00:00
|
|
|
!gst_aggregator_pad_is_eos (GST_AGGREGATOR_PAD (qtpad)) ? nsamples *
|
2017-03-09 08:15:34 +00:00
|
|
|
qtpad->sample_size : gst_adapter_available (qtpad->raw_audio_adapter));
|
|
|
|
GST_BUFFER_PTS (buf) = input_timestamp;
|
|
|
|
GST_BUFFER_DTS (buf) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
qtpad->raw_audio_adapter_offset += nsamples;
|
|
|
|
|
|
|
|
/* Check if we have yet another block of raw audio in the adapter */
|
|
|
|
nsamples =
|
|
|
|
gst_util_uint64_scale (block_idx + 2,
|
|
|
|
qtpad->expected_sample_duration_d * atom_trak_get_timescale (qtpad->trak),
|
|
|
|
qtpad->expected_sample_duration_n) - qtpad->raw_audio_adapter_offset;
|
|
|
|
if (gst_adapter_available (qtpad->raw_audio_adapter) >=
|
|
|
|
nsamples * qtpad->sample_size) {
|
|
|
|
input_timestamp =
|
|
|
|
gst_adapter_prev_pts (qtpad->raw_audio_adapter,
|
|
|
|
&input_timestamp_distance);
|
|
|
|
if (input_timestamp != GST_CLOCK_TIME_NONE)
|
|
|
|
input_timestamp +=
|
|
|
|
gst_util_uint64_scale (input_timestamp_distance, GST_SECOND,
|
|
|
|
qtpad->sample_size * atom_trak_get_timescale (qtpad->trak));
|
|
|
|
qtpad->raw_audio_adapter_pts = input_timestamp;
|
|
|
|
} else {
|
|
|
|
qtpad->raw_audio_adapter_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2018-02-07 10:00:18 +00:00
|
|
|
static void
|
|
|
|
find_video_sample_duration (GstQTMux * qtmux, guint * dur_n, guint * dur_d)
|
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2018-02-07 10:00:18 +00:00
|
|
|
|
|
|
|
/* Find the (first) video track and assume that we have to output
|
|
|
|
* in that size */
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *tmp_qpad = (GstQTMuxPad *) l->data;
|
2018-02-07 10:00:18 +00:00
|
|
|
|
|
|
|
if (tmp_qpad->trak->is_video) {
|
|
|
|
*dur_n = tmp_qpad->expected_sample_duration_n;
|
|
|
|
*dur_d = tmp_qpad->expected_sample_duration_d;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2018-02-07 10:00:18 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
if (l == NULL) {
|
2018-02-07 10:00:18 +00:00
|
|
|
GST_INFO_OBJECT (qtmux,
|
|
|
|
"Found no video framerate, using 40ms audio buffers");
|
|
|
|
*dur_n = 25;
|
|
|
|
*dur_d = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when all pads are prerolled to adjust and */
|
2017-03-09 08:15:34 +00:00
|
|
|
static gboolean
|
2019-12-03 14:30:06 +00:00
|
|
|
prefill_update_sample_size (GstQTMux * qtmux, GstQTMuxPad * qpad)
|
2017-03-09 08:15:34 +00:00
|
|
|
{
|
|
|
|
switch (qpad->fourcc) {
|
|
|
|
case FOURCC_apch:
|
|
|
|
case FOURCC_apcn:
|
|
|
|
case FOURCC_apcs:
|
|
|
|
case FOURCC_apco:
|
|
|
|
case FOURCC_ap4h:
|
2018-02-07 10:00:18 +00:00
|
|
|
case FOURCC_ap4x:
|
|
|
|
{
|
|
|
|
guint sample_size = prefill_get_sample_size (qtmux, qpad);
|
|
|
|
atom_trak_set_constant_size_samples (qpad->trak, sample_size);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case FOURCC_c608:
|
|
|
|
case FOURCC_c708:
|
|
|
|
{
|
2017-03-09 08:15:34 +00:00
|
|
|
guint sample_size = prefill_get_sample_size (qtmux, qpad);
|
2018-02-07 10:00:18 +00:00
|
|
|
/* We need a "valid" duration */
|
|
|
|
find_video_sample_duration (qtmux, &qpad->expected_sample_duration_n,
|
|
|
|
&qpad->expected_sample_duration_d);
|
2017-03-09 08:15:34 +00:00
|
|
|
atom_trak_set_constant_size_samples (qpad->trak, sample_size);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case FOURCC_sowt:
|
|
|
|
case FOURCC_twos:{
|
2018-02-07 10:00:18 +00:00
|
|
|
find_video_sample_duration (qtmux, &qpad->expected_sample_duration_n,
|
|
|
|
&qpad->expected_sample_duration_d);
|
2017-03-09 08:15:34 +00:00
|
|
|
/* Set a prepare_buf_func that ensures this */
|
|
|
|
qpad->prepare_buf_func = prefill_raw_audio_prepare_buf_func;
|
|
|
|
qpad->raw_audio_adapter = gst_adapter_new ();
|
|
|
|
qpad->raw_audio_adapter_offset = 0;
|
|
|
|
qpad->raw_audio_adapter_pts = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 09:10:01 +00:00
|
|
|
/* Only called at startup when doing the "fake" iteration of all tracks in order
|
|
|
|
* to prefill the sample tables in the header. */
|
2019-12-03 14:30:06 +00:00
|
|
|
static GstQTMuxPad *
|
2018-03-08 09:10:01 +00:00
|
|
|
find_best_pad_prefill_start (GstQTMux * qtmux)
|
2017-03-09 08:15:34 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstQTMuxPad *best_pad = NULL;
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2018-03-08 09:10:01 +00:00
|
|
|
/* If interleave limits have been specified and the current pad is within
|
|
|
|
* those interleave limits, pick that one, otherwise let's try to figure out
|
|
|
|
* the next best one. */
|
2019-12-12 19:20:35 +00:00
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
if (qtmux->current_pad &&
|
|
|
|
(qtmux->interleave_bytes != 0 || qtmux->interleave_time != 0) &&
|
|
|
|
(qtmux->interleave_bytes == 0
|
|
|
|
|| qtmux->current_chunk_size <= qtmux->interleave_bytes)
|
|
|
|
&& (qtmux->interleave_time == 0
|
|
|
|
|| qtmux->current_chunk_duration <= qtmux->interleave_time)
|
|
|
|
&& qtmux->mux_mode != GST_QT_MUX_MODE_FRAGMENTED
|
|
|
|
&& qtmux->mux_mode != GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE) {
|
|
|
|
|
|
|
|
if (qtmux->current_pad->total_duration < qtmux->reserved_max_duration) {
|
|
|
|
best_pad = qtmux->current_pad;
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
} else {
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
if (GST_ELEMENT_CAST (qtmux)->sinkpads->next) {
|
|
|
|
/* Attempt to try another pad if we have one. Otherwise use the only pad
|
|
|
|
* present */
|
|
|
|
best_pad = qtmux->current_pad = NULL;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 09:10:01 +00:00
|
|
|
/* The next best pad is the one which has the lowest timestamp and hasn't
|
|
|
|
* exceeded the reserved max duration */
|
2017-03-09 08:15:34 +00:00
|
|
|
if (!best_pad) {
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2017-03-09 08:15:34 +00:00
|
|
|
GstClockTime best_time = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2017-03-09 08:15:34 +00:00
|
|
|
GstClockTime timestamp;
|
|
|
|
|
|
|
|
if (qtpad->total_duration >= qtmux->reserved_max_duration)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
timestamp = qtpad->total_duration;
|
|
|
|
|
|
|
|
if (best_pad == NULL ||
|
|
|
|
!GST_CLOCK_TIME_IS_VALID (best_time) || timestamp < best_time) {
|
|
|
|
best_pad = qtpad;
|
|
|
|
best_time = timestamp;
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return best_pad;
|
|
|
|
}
|
|
|
|
|
2018-03-08 09:10:01 +00:00
|
|
|
/* Called when starting the file in prefill_mode to figure out all the entries
|
|
|
|
* of the header based on the input stream and reserved maximum duration.
|
|
|
|
*
|
|
|
|
* The _actual_ header (i.e. with the proper duration and trimmed sample tables)
|
|
|
|
* will be updated and written on EOS. */
|
2017-03-09 08:15:34 +00:00
|
|
|
static gboolean
|
|
|
|
gst_qt_mux_prefill_samples (GstQTMux * qtmux)
|
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstQTMuxPad *qpad;
|
|
|
|
GList *l;
|
2017-05-16 09:56:15 +00:00
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
/* Update expected sample sizes/durations as needed, this is for raw
|
|
|
|
* audio where samples are actual audio samples. */
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qpad = (GstQTMuxPad *) l->data;
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
if (!prefill_update_sample_size (qtmux, qpad)) {
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2017-03-09 08:15:34 +00:00
|
|
|
return FALSE;
|
2019-12-12 19:20:35 +00:00
|
|
|
}
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2017-05-16 09:56:15 +00:00
|
|
|
if (qtmux_klass->format == GST_QT_MUX_FORMAT_QT) {
|
|
|
|
/* For the first sample check/update timecode as needed. We do that before
|
|
|
|
* all actual samples as the code in gst_qt_mux_add_buffer() does it with
|
|
|
|
* initial buffer directly, not with last_buf */
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qpad = (GstQTMuxPad *) l->data;
|
2017-05-16 09:56:15 +00:00
|
|
|
GstBuffer *buffer =
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_pad_peek_buffer (GST_AGGREGATOR_PAD (qpad));
|
2017-05-16 09:56:15 +00:00
|
|
|
GstVideoTimeCodeMeta *tc_meta;
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2019-02-08 11:59:19 +00:00
|
|
|
if (buffer && (tc_meta = gst_buffer_get_video_time_code_meta (buffer))
|
|
|
|
&& qpad->trak->is_video) {
|
2017-05-16 09:56:15 +00:00
|
|
|
GstVideoTimeCode *tc = &tc_meta->tc;
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2017-05-16 09:56:15 +00:00
|
|
|
qpad->tc_trak = atom_trak_new (qtmux->context);
|
|
|
|
atom_moov_add_trak (qtmux->moov, qpad->tc_trak);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2017-05-16 09:56:15 +00:00
|
|
|
qpad->trak->tref = atom_tref_new (FOURCC_tmcd);
|
|
|
|
atom_tref_add_entry (qpad->trak->tref, qpad->tc_trak->tkhd.track_ID);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2018-01-19 13:05:26 +00:00
|
|
|
atom_trak_set_timecode_type (qpad->tc_trak, qtmux->context,
|
|
|
|
qpad->trak->mdia.mdhd.time_info.timescale, tc);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2017-05-16 09:56:15 +00:00
|
|
|
atom_trak_add_samples (qpad->tc_trak, 1, 1, 4,
|
|
|
|
qtmux->mdat_size, FALSE, 0);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2017-05-16 09:56:15 +00:00
|
|
|
qpad->tc_pos = qtmux->mdat_size;
|
|
|
|
qpad->first_tc = gst_video_time_code_copy (tc);
|
|
|
|
qpad->first_pts = GST_BUFFER_PTS (buffer);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
2017-05-16 09:56:15 +00:00
|
|
|
qtmux->current_chunk_offset = -1;
|
|
|
|
qtmux->current_chunk_size = 0;
|
|
|
|
qtmux->current_chunk_duration = 0;
|
|
|
|
qtmux->mdat_size += 4;
|
|
|
|
}
|
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 09:10:01 +00:00
|
|
|
while ((qpad = find_best_pad_prefill_start (qtmux))) {
|
2017-03-09 08:15:34 +00:00
|
|
|
GstClockTime timestamp, next_timestamp, duration;
|
|
|
|
guint nsamples, sample_size;
|
|
|
|
guint64 chunk_offset;
|
|
|
|
gint64 scaled_duration;
|
|
|
|
gint64 pts_offset = 0;
|
|
|
|
gboolean sync = FALSE;
|
|
|
|
TrakBufferEntryInfo sample_entry;
|
|
|
|
|
|
|
|
sample_size = prefill_get_sample_size (qtmux, qpad);
|
|
|
|
|
|
|
|
if (sample_size == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!qpad->samples)
|
|
|
|
qpad->samples = g_array_new (FALSE, FALSE, sizeof (TrakBufferEntryInfo));
|
|
|
|
|
|
|
|
timestamp = qpad->total_duration;
|
|
|
|
next_timestamp = prefill_get_next_timestamp (qtmux, qpad);
|
|
|
|
duration = next_timestamp - timestamp;
|
|
|
|
|
|
|
|
if (qpad->first_ts == GST_CLOCK_TIME_NONE)
|
|
|
|
qpad->first_ts = timestamp;
|
|
|
|
if (qpad->first_dts == GST_CLOCK_TIME_NONE)
|
|
|
|
qpad->first_dts = timestamp;
|
|
|
|
|
|
|
|
if (qtmux->current_pad != qpad || qtmux->current_chunk_offset == -1) {
|
|
|
|
qtmux->current_pad = qpad;
|
|
|
|
if (qtmux->current_chunk_offset == -1)
|
|
|
|
qtmux->current_chunk_offset = qtmux->mdat_size;
|
|
|
|
else
|
|
|
|
qtmux->current_chunk_offset += qtmux->current_chunk_size;
|
|
|
|
qtmux->current_chunk_size = 0;
|
|
|
|
qtmux->current_chunk_duration = 0;
|
|
|
|
}
|
|
|
|
if (qpad->sample_size)
|
|
|
|
nsamples = sample_size / qpad->sample_size;
|
|
|
|
else
|
|
|
|
nsamples = 1;
|
|
|
|
qpad->last_dts = timestamp;
|
|
|
|
scaled_duration = gst_util_uint64_scale_round (timestamp + duration,
|
|
|
|
atom_trak_get_timescale (qpad->trak),
|
|
|
|
GST_SECOND) - gst_util_uint64_scale_round (timestamp,
|
|
|
|
atom_trak_get_timescale (qpad->trak), GST_SECOND);
|
|
|
|
|
|
|
|
qtmux->current_chunk_size += sample_size;
|
|
|
|
qtmux->current_chunk_duration += duration;
|
|
|
|
qpad->total_bytes += sample_size;
|
|
|
|
|
|
|
|
chunk_offset = qtmux->current_chunk_offset;
|
|
|
|
|
|
|
|
/* I-frame only, no frame reordering */
|
|
|
|
sync = FALSE;
|
|
|
|
pts_offset = 0;
|
|
|
|
|
|
|
|
if (qtmux->current_chunk_duration > qtmux->longest_chunk
|
|
|
|
|| !GST_CLOCK_TIME_IS_VALID (qtmux->longest_chunk)) {
|
|
|
|
qtmux->longest_chunk = qtmux->current_chunk_duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
sample_entry.track_id = qpad->trak->tkhd.track_ID;
|
|
|
|
sample_entry.nsamples = nsamples;
|
|
|
|
sample_entry.delta = scaled_duration / nsamples;
|
|
|
|
sample_entry.size = sample_size / nsamples;
|
|
|
|
sample_entry.chunk_offset = chunk_offset;
|
|
|
|
sample_entry.pts_offset = pts_offset;
|
|
|
|
sample_entry.sync = sync;
|
|
|
|
sample_entry.do_pts = TRUE;
|
|
|
|
g_array_append_val (qpad->samples, sample_entry);
|
|
|
|
atom_trak_add_samples (qpad->trak, nsamples, scaled_duration / nsamples,
|
|
|
|
sample_size / nsamples, chunk_offset, sync, pts_offset);
|
|
|
|
|
|
|
|
qpad->total_duration = next_timestamp;
|
|
|
|
qtmux->mdat_size += sample_size;
|
|
|
|
qpad->sample_offset += nsamples;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-10-16 00:11:16 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_start_file (GstQTMux * qtmux)
|
|
|
|
{
|
2015-04-01 00:15:38 +00:00
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
2009-10-16 00:11:16 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2011-01-13 14:27:36 +00:00
|
|
|
GstCaps *caps;
|
2015-04-01 00:15:38 +00:00
|
|
|
GstClockTime reserved_max_duration;
|
|
|
|
guint reserved_bytes_per_sec_per_trak;
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2009-10-16 00:11:16 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "starting file");
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
reserved_max_duration = qtmux->reserved_max_duration;
|
|
|
|
reserved_bytes_per_sec_per_trak = qtmux->reserved_bytes_per_sec_per_trak;
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
caps =
|
|
|
|
gst_caps_copy (gst_pad_get_pad_template_caps (GST_AGGREGATOR_SRC_PAD
|
|
|
|
(qtmux)));
|
2011-04-13 14:18:11 +00:00
|
|
|
/* qtmux has structure with and without variant, remove all but the first */
|
2019-12-03 14:30:06 +00:00
|
|
|
g_assert (gst_caps_truncate (caps));
|
|
|
|
gst_aggregator_set_src_caps (GST_AGGREGATOR (qtmux), caps);
|
2011-01-13 14:27:36 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Default is 'normal' mode */
|
|
|
|
qtmux->mux_mode = GST_QT_MUX_MODE_MOOV_AT_END;
|
|
|
|
|
|
|
|
/* Require a sensible fragment duration when muxing
|
|
|
|
* using the ISML muxer */
|
|
|
|
if (qtmux_klass->format == GST_QT_MUX_FORMAT_ISML &&
|
|
|
|
qtmux->fragment_duration == 0)
|
|
|
|
goto invalid_isml;
|
|
|
|
|
|
|
|
if (qtmux->fragment_duration > 0) {
|
|
|
|
if (qtmux->streamable)
|
|
|
|
qtmux->mux_mode = GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE;
|
|
|
|
else
|
|
|
|
qtmux->mux_mode = GST_QT_MUX_MODE_FRAGMENTED;
|
|
|
|
} else if (qtmux->fast_start) {
|
|
|
|
qtmux->mux_mode = GST_QT_MUX_MODE_FAST_START;
|
2015-04-01 00:15:38 +00:00
|
|
|
} else if (reserved_max_duration != GST_CLOCK_TIME_NONE) {
|
2017-03-09 08:15:34 +00:00
|
|
|
if (qtmux->reserved_prefill)
|
|
|
|
qtmux->mux_mode = GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL;
|
|
|
|
else
|
|
|
|
qtmux->mux_mode = GST_QT_MUX_MODE_ROBUST_RECORDING;
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (qtmux->mux_mode) {
|
|
|
|
case GST_QT_MUX_MODE_MOOV_AT_END:
|
2015-04-01 00:15:38 +00:00
|
|
|
case GST_QT_MUX_MODE_ROBUST_RECORDING:
|
2015-04-01 00:15:38 +00:00
|
|
|
/* We have to be able to seek to rewrite the mdat header, or any
|
|
|
|
* moov atom we write will not be visible in the file, because an
|
|
|
|
* MDAT with 0 as the size covers the rest of the file. A file
|
|
|
|
* with no moov is not playable, so error out now. */
|
|
|
|
if (!gst_qt_mux_downstream_is_seekable (qtmux)) {
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX,
|
|
|
|
("Downstream is not seekable - will not be able to create a playable file"),
|
|
|
|
(NULL));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2018-08-16 16:55:29 +00:00
|
|
|
if (qtmux->reserved_moov_update_period == GST_CLOCK_TIME_NONE) {
|
|
|
|
GST_WARNING_OBJECT (qtmux,
|
|
|
|
"Robust muxing requires reserved-moov-update-period to be set");
|
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
break;
|
|
|
|
case GST_QT_MUX_MODE_FAST_START:
|
|
|
|
case GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE:
|
|
|
|
break; /* Don't need seekability, ignore */
|
|
|
|
case GST_QT_MUX_MODE_FRAGMENTED:
|
|
|
|
if (!gst_qt_mux_downstream_is_seekable (qtmux)) {
|
2013-09-17 10:17:54 +00:00
|
|
|
GST_WARNING_OBJECT (qtmux, "downstream is not seekable, but "
|
|
|
|
"streamable=false. Will ignore that and create streamable output "
|
|
|
|
"instead");
|
|
|
|
qtmux->streamable = TRUE;
|
|
|
|
g_object_notify (G_OBJECT (qtmux), "streamable");
|
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
break;
|
2017-03-09 08:15:34 +00:00
|
|
|
case GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL:
|
|
|
|
if (!gst_qt_mux_downstream_is_seekable (qtmux)) {
|
|
|
|
GST_WARNING_OBJECT (qtmux,
|
|
|
|
"downstream is not seekable, will not be able "
|
|
|
|
"to trim samples table at the end if less than reserved-duration is "
|
|
|
|
"recorded");
|
|
|
|
}
|
|
|
|
break;
|
2012-02-25 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
2009-12-12 19:07:15 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2016-10-20 17:41:07 +00:00
|
|
|
|
|
|
|
if (qtmux->timescale == 0) {
|
|
|
|
guint32 suggested_timescale = 0;
|
|
|
|
|
|
|
|
/* Calculate a reasonable timescale for the moov:
|
|
|
|
* If there is video, it is the biggest video track timescale or an even
|
|
|
|
* multiple of it if it's smaller than 1800.
|
|
|
|
* Otherwise it is 1800 */
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qpad = (GstQTMuxPad *) l->data;
|
2016-10-20 17:41:07 +00:00
|
|
|
|
|
|
|
if (!qpad->trak)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* not video */
|
|
|
|
if (!qpad->trak->mdia.minf.vmhd)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
suggested_timescale =
|
|
|
|
MAX (qpad->trak->mdia.mdhd.time_info.timescale, suggested_timescale);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (suggested_timescale == 0)
|
|
|
|
suggested_timescale = 1800;
|
|
|
|
|
|
|
|
while (suggested_timescale < 1800)
|
|
|
|
suggested_timescale *= 2;
|
|
|
|
|
|
|
|
qtmux->timescale = suggested_timescale;
|
|
|
|
}
|
|
|
|
|
2018-12-05 17:31:25 +00:00
|
|
|
/* Set width/height/timescale of any closed caption tracks to that of the
|
|
|
|
* first video track */
|
2018-09-18 15:13:52 +00:00
|
|
|
{
|
|
|
|
guint video_width = 0, video_height = 0;
|
2018-12-05 17:31:25 +00:00
|
|
|
guint32 video_timescale = 0;
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2018-09-18 15:13:52 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qpad = (GstQTMuxPad *) l->data;
|
2018-09-18 15:13:52 +00:00
|
|
|
|
|
|
|
if (!qpad->trak)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Not closed caption */
|
|
|
|
if (qpad->trak->mdia.hdlr.handler_type != FOURCC_clcp)
|
|
|
|
continue;
|
|
|
|
|
2018-12-05 17:31:25 +00:00
|
|
|
if (video_width == 0 || video_height == 0 || video_timescale == 0) {
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l2;
|
2018-09-18 15:13:52 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l2 = GST_ELEMENT_CAST (qtmux)->sinkpads; l2; l2 = l2->next) {
|
|
|
|
GstQTMuxPad *qpad2 = (GstQTMuxPad *) l2->data;
|
2018-09-18 15:13:52 +00:00
|
|
|
|
|
|
|
if (!qpad2->trak)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* not video */
|
|
|
|
if (!qpad2->trak->mdia.minf.vmhd)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
video_width = qpad2->trak->tkhd.width;
|
|
|
|
video_height = qpad2->trak->tkhd.height;
|
2018-12-05 17:31:25 +00:00
|
|
|
video_timescale = qpad2->trak->mdia.mdhd.time_info.timescale;
|
2018-09-18 15:13:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qpad->trak->tkhd.width = video_width << 16;
|
|
|
|
qpad->trak->tkhd.height = video_height << 16;
|
2018-12-05 17:31:25 +00:00
|
|
|
qpad->trak->mdia.mdhd.time_info.timescale = video_timescale;
|
2018-09-18 15:13:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 17:41:07 +00:00
|
|
|
/* initialize our moov recovery file */
|
2009-12-12 19:07:15 +00:00
|
|
|
if (qtmux->moov_recov_file_path) {
|
2015-04-01 00:15:38 +00:00
|
|
|
gst_qt_mux_prepare_moov_recovery (qtmux);
|
2009-12-12 19:07:15 +00:00
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
/* Make sure the first time we update the moov, we'll
|
|
|
|
* include any tagsetter tags */
|
|
|
|
qtmux->tags_changed = TRUE;
|
|
|
|
|
2009-12-12 19:07:15 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/*
|
2009-10-16 00:11:16 +00:00
|
|
|
* send mdat header if already needed, and mark position for later update.
|
|
|
|
* We don't send ftyp now if we are on fast start mode, because we can
|
|
|
|
* better fine tune using the information we gather to create the whole moov
|
|
|
|
* atom.
|
|
|
|
*/
|
2015-04-01 00:15:38 +00:00
|
|
|
switch (qtmux->mux_mode) {
|
|
|
|
case GST_QT_MUX_MODE_MOOV_AT_END:
|
|
|
|
ret = gst_qt_mux_prepare_and_send_ftyp (qtmux);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
break;
|
2010-11-15 14:17:59 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Store this as the mdat offset for later updating
|
|
|
|
* when we write the moov */
|
|
|
|
qtmux->mdat_pos = qtmux->header_size;
|
|
|
|
/* extended atom in case we go over 4GB while writing and need
|
|
|
|
* the full 64-bit atom */
|
2015-04-16 00:44:49 +00:00
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_mdat_header (qtmux, &qtmux->header_size, 0, TRUE,
|
|
|
|
FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
break;
|
|
|
|
case GST_QT_MUX_MODE_ROBUST_RECORDING:
|
|
|
|
ret = gst_qt_mux_prepare_and_send_ftyp (qtmux);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Pad ftyp out to an 8-byte boundary before starting the moov
|
|
|
|
* ping pong region. It should be well less than 1 disk sector,
|
|
|
|
* unless there's a bajillion compatible types listed,
|
|
|
|
* but let's be sure the free atom doesn't cross a sector
|
|
|
|
* boundary anyway */
|
|
|
|
if (qtmux->header_size % 8) {
|
|
|
|
/* Extra 8 bytes for the padding free atom header */
|
|
|
|
guint padding = (guint) (16 - (qtmux->header_size % 8));
|
|
|
|
GST_LOG_OBJECT (qtmux, "Rounding ftyp by %u bytes", padding);
|
2015-04-16 00:44:49 +00:00
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_free_atom (qtmux, &qtmux->header_size, padding,
|
|
|
|
FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store this as the moov offset for later updating.
|
|
|
|
* We record mdat position below */
|
|
|
|
qtmux->moov_pos = qtmux->header_size;
|
|
|
|
|
|
|
|
/* Set up the initial 'ping' state of the ping-pong buffers */
|
|
|
|
qtmux->reserved_moov_first_active = TRUE;
|
|
|
|
|
|
|
|
gst_qt_mux_configure_moov (qtmux);
|
|
|
|
gst_qt_mux_setup_metadata (qtmux);
|
|
|
|
/* Empty free atom to begin, starting on an 8-byte boundary */
|
2015-04-16 00:44:49 +00:00
|
|
|
ret = gst_qt_mux_send_free_atom (qtmux, &qtmux->header_size, 8, FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
/* Moov header, not padded yet */
|
2015-04-16 00:44:49 +00:00
|
|
|
ret = gst_qt_mux_send_moov (qtmux, &qtmux->header_size, 0, FALSE, FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
/* The moov we just sent contains the 'base' size of the moov, before
|
|
|
|
* we put in any time-dependent per-trak data. Use that to make
|
|
|
|
* a good estimate of how much extra to reserve */
|
|
|
|
/* Calculate how much space to reserve for our MOOV atom.
|
|
|
|
* We actually reserve twice that, for ping-pong buffers */
|
|
|
|
qtmux->base_moov_size = qtmux->last_moov_size;
|
|
|
|
GST_LOG_OBJECT (qtmux, "Base moov size is %u before any indexes",
|
|
|
|
qtmux->base_moov_size);
|
|
|
|
qtmux->reserved_moov_size = qtmux->base_moov_size +
|
|
|
|
gst_util_uint64_scale (reserved_max_duration,
|
|
|
|
reserved_bytes_per_sec_per_trak *
|
|
|
|
atom_moov_get_trak_count (qtmux->moov), GST_SECOND);
|
|
|
|
|
|
|
|
/* Need space for at least 4 atom headers. More really, but
|
|
|
|
* this as an absolute minimum */
|
|
|
|
if (qtmux->reserved_moov_size < 4 * 8)
|
|
|
|
goto reserved_moov_too_small;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "reserving header area of size %u",
|
|
|
|
2 * qtmux->reserved_moov_size + 16);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
qtmux->reserved_duration_remaining =
|
|
|
|
gst_util_uint64_scale (qtmux->reserved_moov_size -
|
|
|
|
qtmux->base_moov_size, GST_SECOND,
|
|
|
|
reserved_bytes_per_sec_per_trak *
|
|
|
|
atom_moov_get_trak_count (qtmux->moov));
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
2019-09-02 12:27:35 +00:00
|
|
|
/* Now that we know how much reserved space is targeted,
|
2015-04-01 00:15:38 +00:00
|
|
|
* output a free atom to fill the extra reserved */
|
|
|
|
ret = gst_qt_mux_send_free_atom (qtmux, &qtmux->header_size,
|
2015-04-16 00:44:49 +00:00
|
|
|
qtmux->reserved_moov_size - qtmux->base_moov_size, FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Then a free atom containing 'pong' buffer, with an
|
|
|
|
* extra 8 bytes to account for the free atom header itself */
|
|
|
|
ret = gst_qt_mux_send_free_atom (qtmux, &qtmux->header_size,
|
2015-04-16 00:44:49 +00:00
|
|
|
qtmux->reserved_moov_size + 8, FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* extra atoms go after the free/moov(s), before the mdat */
|
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_extra_atoms (qtmux, TRUE, &qtmux->header_size, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
qtmux->mdat_pos = qtmux->header_size;
|
|
|
|
/* extended atom in case we go over 4GB while writing and need
|
|
|
|
* the full 64-bit atom */
|
2015-04-16 00:44:49 +00:00
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_mdat_header (qtmux, &qtmux->header_size, 0, TRUE,
|
|
|
|
FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
break;
|
2017-03-09 08:15:34 +00:00
|
|
|
case GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL:
|
2019-12-12 19:20:35 +00:00
|
|
|
{
|
|
|
|
guint32 atom_size;
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
ret = gst_qt_mux_prepare_and_send_ftyp (qtmux);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Store this as the moov offset for later updating.
|
|
|
|
* We record mdat position below */
|
|
|
|
qtmux->moov_pos = qtmux->header_size;
|
|
|
|
|
|
|
|
if (!gst_qt_mux_prefill_samples (qtmux)) {
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX,
|
|
|
|
("Unsupported codecs or configuration for prefill mode"), (NULL));
|
|
|
|
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_qt_mux_update_global_statistics (qtmux);
|
|
|
|
gst_qt_mux_configure_moov (qtmux);
|
|
|
|
gst_qt_mux_update_edit_lists (qtmux);
|
|
|
|
gst_qt_mux_setup_metadata (qtmux);
|
|
|
|
|
|
|
|
/* Moov header with pre-filled samples */
|
|
|
|
ret = gst_qt_mux_send_moov (qtmux, &qtmux->header_size, 0, FALSE, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
atom_size = 12 * g_list_length (GST_ELEMENT (qtmux)->sinkpads) + 8;
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
/* last_moov_size now contains the full size of the moov, moov_pos the
|
|
|
|
* position. This allows us to rewrite it in the very end as needed */
|
2019-12-12 19:20:35 +00:00
|
|
|
qtmux->reserved_moov_size = qtmux->last_moov_size + atom_size;
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
/* Send an additional free atom at the end so we definitely have space
|
|
|
|
* to rewrite the moov header at the end and remove the samples that
|
|
|
|
* were not actually written */
|
|
|
|
ret =
|
2019-12-12 19:20:35 +00:00
|
|
|
gst_qt_mux_send_free_atom (qtmux, &qtmux->header_size, atom_size,
|
|
|
|
FALSE);
|
2017-03-09 08:15:34 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* extra atoms go after the free/moov(s), before the mdat */
|
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_extra_atoms (qtmux, TRUE, &qtmux->header_size, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
qtmux->mdat_pos = qtmux->header_size;
|
|
|
|
|
|
|
|
/* And now send the mdat header */
|
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_mdat_header (qtmux, &qtmux->header_size,
|
|
|
|
qtmux->mdat_size, TRUE, FALSE);
|
|
|
|
|
|
|
|
/* chunks position is set relative to the first byte of the
|
|
|
|
* MDAT atom payload. Set the overall offset into the file */
|
|
|
|
atom_moov_chunks_set_offset (qtmux->moov, qtmux->header_size);
|
|
|
|
|
|
|
|
{
|
|
|
|
GstSegment segment;
|
|
|
|
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = qtmux->moov_pos;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
ret = gst_qt_mux_send_moov (qtmux, NULL, 0, FALSE, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
segment.start = qtmux->header_size;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qtmux->current_chunk_size = 0;
|
|
|
|
qtmux->current_chunk_duration = 0;
|
|
|
|
qtmux->current_chunk_offset = -1;
|
|
|
|
qtmux->mdat_size = 0;
|
|
|
|
qtmux->current_pad = NULL;
|
|
|
|
qtmux->longest_chunk = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
qtpad->total_bytes = 0;
|
|
|
|
qtpad->total_duration = 0;
|
|
|
|
qtpad->first_dts = qtpad->first_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
qtpad->last_dts = GST_CLOCK_TIME_NONE;
|
|
|
|
qtpad->sample_offset = 0;
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
break;
|
2019-12-12 19:20:35 +00:00
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
case GST_QT_MUX_MODE_FAST_START:
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
qtmux->fast_start_file = g_fopen (qtmux->fast_start_file_path, "wb+");
|
|
|
|
if (!qtmux->fast_start_file)
|
|
|
|
goto open_failed;
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
/* send a dummy buffer for preroll */
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, gst_buffer_new (), NULL, FALSE);
|
|
|
|
break;
|
|
|
|
case GST_QT_MUX_MODE_FRAGMENTED:
|
|
|
|
case GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE:
|
|
|
|
ret = gst_qt_mux_prepare_and_send_ftyp (qtmux);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
break;
|
2015-04-01 00:15:38 +00:00
|
|
|
/* store the moov pos so we can update the duration later
|
|
|
|
* in non-streamable mode */
|
|
|
|
qtmux->moov_pos = qtmux->header_size;
|
|
|
|
|
2010-11-15 14:17:59 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "fragment duration %d ms, writing headers",
|
|
|
|
qtmux->fragment_duration);
|
|
|
|
/* also used as snapshot marker to indicate fragmented file */
|
|
|
|
qtmux->fragment_sequence = 1;
|
|
|
|
/* prepare moov and/or tags */
|
2015-04-01 00:15:38 +00:00
|
|
|
gst_qt_mux_configure_moov (qtmux);
|
2010-11-15 14:17:59 +00:00
|
|
|
gst_qt_mux_setup_metadata (qtmux);
|
2015-04-16 00:44:49 +00:00
|
|
|
ret = gst_qt_mux_send_moov (qtmux, &qtmux->header_size, 0, FALSE, FALSE);
|
2010-11-15 14:17:59 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
/* extra atoms */
|
2010-11-18 15:48:06 +00:00
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_extra_atoms (qtmux, TRUE, &qtmux->header_size, FALSE);
|
2010-11-15 14:17:59 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
2015-04-01 00:15:38 +00:00
|
|
|
break;
|
|
|
|
/* prepare index if not streamable */
|
|
|
|
if (qtmux->mux_mode == GST_QT_MUX_MODE_FRAGMENTED)
|
2010-08-06 11:26:27 +00:00
|
|
|
qtmux->mfra = atom_mfra_new (qtmux->context);
|
2015-04-01 00:15:38 +00:00
|
|
|
break;
|
2009-10-16 00:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
/* ERRORS */
|
2015-04-01 00:15:38 +00:00
|
|
|
invalid_isml:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX,
|
|
|
|
("Cannot create an ISML file with 0 fragment duration"), (NULL));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
reserved_moov_too_small:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX,
|
|
|
|
("Not enough reserved space for creating headers"), (NULL));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2009-10-16 00:11:16 +00:00
|
|
|
open_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, RESOURCE, OPEN_READ_WRITE,
|
2015-04-01 00:15:38 +00:00
|
|
|
(("Could not open temporary file \"%s\""),
|
|
|
|
qtmux->fast_start_file_path), GST_ERROR_SYSTEM);
|
2009-10-16 00:11:16 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static GstFlowReturn
|
2015-04-01 00:15:38 +00:00
|
|
|
gst_qt_mux_send_last_buffers (GstQTMux * qtmux)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2015-04-01 00:15:38 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2019-12-12 19:20:35 +00:00
|
|
|
GList *sinkpads, *l;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
sinkpads = g_list_copy_deep (GST_ELEMENT_CAST (qtmux)->sinkpads,
|
|
|
|
(GCopyFunc) gst_object_ref, NULL);
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
|
|
|
for (l = sinkpads; l; l = l->next) {
|
2019-12-03 14:30:06 +00:00
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-09-16 13:53:22 +00:00
|
|
|
/* avoid add_buffer complaining if not negotiated
|
|
|
|
* in which case no buffers either, so skipping */
|
|
|
|
if (!qtpad->fourcc) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Pad %s has never had buffers",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (qtpad));
|
2011-09-16 13:53:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send last buffer; also flushes possibly queued buffers/ts */
|
2008-11-08 02:00:58 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Sending the last buffer for pad %s",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (qtpad));
|
2008-11-08 02:00:58 +00:00
|
|
|
ret = gst_qt_mux_add_buffer (qtmux, qtpad, NULL);
|
2011-09-16 13:53:22 +00:00
|
|
|
if (ret != GST_FLOW_OK) {
|
2009-11-06 03:46:12 +00:00
|
|
|
GST_WARNING_OBJECT (qtmux, "Failed to send last buffer for %s, "
|
2019-12-03 14:30:06 +00:00
|
|
|
"flow return: %s", GST_PAD_NAME (qtpad), gst_flow_get_name (ret));
|
2011-09-16 13:53:22 +00:00
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
2011-04-15 10:34:05 +00:00
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
g_list_free_full (sinkpads, gst_object_unref);
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_update_global_statistics (GstQTMux * qtmux)
|
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
/* for setting some subtitles fields */
|
|
|
|
guint max_width = 0;
|
|
|
|
guint max_height = 0;
|
|
|
|
|
|
|
|
qtmux->first_ts = qtmux->last_dts = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
if (!qtpad->fourcc) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Pad %s has never had buffers",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (qtpad));
|
2011-04-15 10:34:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* having flushed above, can check for buffers now */
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (qtpad->first_ts)) {
|
2017-06-19 19:13:42 +00:00
|
|
|
GstClockTime first_pts_in = qtpad->first_ts;
|
|
|
|
/* it should be, since we got first_ts by adding adjustment
|
|
|
|
* to a positive incoming PTS */
|
|
|
|
if (qtpad->dts_adjustment <= first_pts_in)
|
|
|
|
first_pts_in -= qtpad->dts_adjustment;
|
2015-04-01 00:15:38 +00:00
|
|
|
/* determine max stream duration */
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (qtmux->last_dts)
|
|
|
|
|| qtpad->last_dts > qtmux->last_dts) {
|
|
|
|
qtmux->last_dts = qtpad->last_dts;
|
|
|
|
}
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (qtmux->first_ts)
|
2017-06-19 19:13:42 +00:00
|
|
|
|| first_pts_in < qtmux->first_ts) {
|
|
|
|
/* we need the original incoming PTS here, as this first_ts
|
|
|
|
* is used in update_edit_lists to construct the edit list that arrange
|
|
|
|
* for sync'ed streams. The first_ts is most likely obtained from
|
|
|
|
* some (audio) stream with 0 dts_adjustment and initial 0 PTS,
|
|
|
|
* so it makes no difference, though it matters in other cases */
|
|
|
|
qtmux->first_ts = first_pts_in;
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
2010-11-15 14:17:59 +00:00
|
|
|
}
|
2011-09-28 14:41:49 +00:00
|
|
|
|
2014-02-06 15:15:22 +00:00
|
|
|
/* subtitles need to know the video width/height,
|
|
|
|
* it is stored shifted 16 bits to the left according to the
|
|
|
|
* spec */
|
|
|
|
max_width = MAX (max_width, (qtpad->trak->tkhd.width >> 16));
|
|
|
|
max_height = MAX (max_height, (qtpad->trak->tkhd.height >> 16));
|
|
|
|
|
2011-09-28 14:41:49 +00:00
|
|
|
/* update average bitrate of streams if needed */
|
|
|
|
{
|
|
|
|
guint32 avgbitrate = 0;
|
|
|
|
guint32 maxbitrate = qtpad->max_bitrate;
|
|
|
|
|
|
|
|
if (qtpad->avg_bitrate)
|
|
|
|
avgbitrate = qtpad->avg_bitrate;
|
|
|
|
else if (qtpad->total_duration > 0)
|
|
|
|
avgbitrate = (guint32) gst_util_uint64_scale_round (qtpad->total_bytes,
|
|
|
|
8 * GST_SECOND, qtpad->total_duration);
|
|
|
|
|
|
|
|
atom_trak_update_bitrates (qtpad->trak, avgbitrate, maxbitrate);
|
|
|
|
}
|
2010-11-15 14:17:59 +00:00
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2010-11-15 14:17:59 +00:00
|
|
|
|
2014-02-06 15:15:22 +00:00
|
|
|
/* need to update values on subtitle traks now that we know the
|
|
|
|
* max width and height */
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2014-02-06 15:15:22 +00:00
|
|
|
|
|
|
|
if (!qtpad->fourcc) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Pad %s has never had buffers",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (qtpad));
|
2014-02-06 15:15:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qtpad->fourcc == FOURCC_tx3g) {
|
|
|
|
atom_trak_tx3g_update_dimension (qtpad->trak, max_width, max_height);
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
2014-02-06 15:15:22 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Called after gst_qt_mux_update_global_statistics() updates the
|
|
|
|
* first_ts tracking, to create/set edit lists for delayed streams */
|
|
|
|
static void
|
|
|
|
gst_qt_mux_update_edit_lists (GstQTMux * qtmux)
|
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Media first ts selected: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (qtmux->first_ts));
|
|
|
|
/* add/update EDTSs for late streams. configure_moov will have
|
|
|
|
* set the trak durations above by summing the sample tables,
|
|
|
|
* here we extend that if needing to insert an empty segment */
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2015-06-19 20:45:02 +00:00
|
|
|
|
2017-02-08 15:24:26 +00:00
|
|
|
atom_trak_edts_clear (qtpad->trak);
|
|
|
|
|
2015-06-19 20:45:02 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (qtpad->first_ts)) {
|
|
|
|
guint32 lateness = 0;
|
|
|
|
guint32 duration = qtpad->trak->tkhd.duration;
|
|
|
|
gboolean has_gap;
|
|
|
|
|
|
|
|
has_gap = (qtpad->first_ts > (qtmux->first_ts + qtpad->dts_adjustment));
|
|
|
|
|
|
|
|
if (has_gap) {
|
2018-10-19 14:02:11 +00:00
|
|
|
GstClockTime diff, trak_lateness;
|
2015-06-19 20:45:02 +00:00
|
|
|
|
|
|
|
diff = qtpad->first_ts - (qtmux->first_ts + qtpad->dts_adjustment);
|
|
|
|
lateness = gst_util_uint64_scale_round (diff,
|
|
|
|
qtmux->timescale, GST_SECOND);
|
2018-10-19 14:02:11 +00:00
|
|
|
|
2018-09-12 14:24:00 +00:00
|
|
|
/* Allow up to 1 trak timescale unit of lateness, Such a small
|
|
|
|
* timestamp/duration can't be represented by the trak-specific parts
|
|
|
|
* of the headers anyway, so it's irrelevantly small */
|
|
|
|
trak_lateness = gst_util_uint64_scale (diff,
|
|
|
|
atom_trak_get_timescale (qtpad->trak), GST_SECOND);
|
2015-06-19 20:45:02 +00:00
|
|
|
|
2018-10-19 14:02:11 +00:00
|
|
|
if (trak_lateness > 0 && diff > qtmux->start_gap_threshold) {
|
2016-11-22 13:58:37 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux,
|
|
|
|
"Pad %s is a late stream by %" GST_TIME_FORMAT,
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (qtpad), GST_TIME_ARGS (diff));
|
2015-06-19 20:45:02 +00:00
|
|
|
|
2016-11-22 13:58:37 +00:00
|
|
|
atom_trak_set_elst_entry (qtpad->trak, 0, lateness, (guint32) - 1,
|
|
|
|
(guint32) (1 * 65536.0));
|
|
|
|
}
|
2015-06-19 20:45:02 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 12:44:11 +00:00
|
|
|
/* Always write an edit list for the whole track. In general this is not
|
|
|
|
* necessary except for the case of having a gap or DTS adjustment but
|
|
|
|
* it allows to give the whole track's duration in the usually more
|
|
|
|
* accurate media timescale
|
|
|
|
*/
|
|
|
|
{
|
2015-12-17 18:17:15 +00:00
|
|
|
GstClockTime ctts = 0;
|
2015-06-23 21:54:31 +00:00
|
|
|
guint32 media_start;
|
|
|
|
|
2015-12-17 18:17:15 +00:00
|
|
|
if (qtpad->first_ts > qtpad->first_dts)
|
|
|
|
ctts = qtpad->first_ts - qtpad->first_dts;
|
|
|
|
|
2015-06-23 21:54:31 +00:00
|
|
|
media_start = gst_util_uint64_scale_round (ctts,
|
2015-06-19 20:45:02 +00:00
|
|
|
atom_trak_get_timescale (qtpad->trak), GST_SECOND);
|
|
|
|
|
2017-02-09 00:29:43 +00:00
|
|
|
/* atom_trak_set_elst_entry() has a quirk - if the edit list
|
|
|
|
* is empty because there's no gap added above, this call
|
|
|
|
* will not replace index 1, it will create the entry at index 0.
|
|
|
|
* Luckily, that's exactly what we want here */
|
2015-06-23 21:54:31 +00:00
|
|
|
atom_trak_set_elst_entry (qtpad->trak, 1, duration, media_start,
|
2015-06-19 20:45:02 +00:00
|
|
|
(guint32) (1 * 65536.0));
|
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
/* need to add the empty time to the trak duration */
|
|
|
|
duration += lateness;
|
|
|
|
qtpad->trak->tkhd.duration = duration;
|
2016-06-24 13:32:37 +00:00
|
|
|
if (qtpad->tc_trak) {
|
|
|
|
qtpad->tc_trak->tkhd.duration = duration;
|
|
|
|
qtpad->tc_trak->mdia.mdhd.time_info.duration = duration;
|
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
/* And possibly grow the moov duration */
|
|
|
|
if (duration > qtmux->moov->mvhd.time_info.duration) {
|
|
|
|
qtmux->moov->mvhd.time_info.duration = duration;
|
|
|
|
qtmux->moov->mvex.mehd.fragment_duration = duration;
|
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 13:32:37 +00:00
|
|
|
static GstFlowReturn
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_update_timecode (GstQTMux * qtmux, GstQTMuxPad * qtpad)
|
2016-06-24 13:32:37 +00:00
|
|
|
{
|
|
|
|
GstSegment segment;
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstMapInfo map;
|
2017-03-22 16:52:51 +00:00
|
|
|
guint64 offset = qtpad->tc_pos;
|
2017-05-16 09:56:15 +00:00
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
|
|
|
|
|
|
|
if (qtmux_klass->format != GST_QT_MUX_FORMAT_QT)
|
|
|
|
return GST_FLOW_OK;
|
2016-06-24 13:32:37 +00:00
|
|
|
|
2017-03-22 16:52:51 +00:00
|
|
|
g_assert (qtpad->tc_pos != -1);
|
2016-06-24 13:32:37 +00:00
|
|
|
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = offset;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2016-06-24 13:32:37 +00:00
|
|
|
|
|
|
|
buf = gst_buffer_new_and_alloc (4);
|
|
|
|
gst_buffer_map (buf, &map, GST_MAP_WRITE);
|
|
|
|
|
|
|
|
GST_WRITE_UINT32_BE (map.data,
|
2017-03-22 16:52:51 +00:00
|
|
|
gst_video_time_code_frames_since_daily_jam (qtpad->first_tc));
|
2016-06-24 13:32:37 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
|
|
|
|
/* Reset this value, so the timecode won't be re-rewritten */
|
2017-03-22 16:52:51 +00:00
|
|
|
qtpad->tc_pos = -1;
|
2016-06-24 13:32:37 +00:00
|
|
|
|
|
|
|
return gst_qt_mux_send_buffer (qtmux, buf, &offset, FALSE);
|
|
|
|
}
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
static GstFlowReturn
|
2015-04-02 13:57:20 +00:00
|
|
|
gst_qt_mux_stop_file (GstQTMux * qtmux)
|
2015-04-01 00:15:38 +00:00
|
|
|
{
|
|
|
|
gboolean ret = GST_FLOW_OK;
|
|
|
|
guint64 offset = 0, size = 0;
|
|
|
|
gboolean large_file;
|
2019-12-12 19:20:35 +00:00
|
|
|
GList *sinkpads, *l;
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Updating remaining values and sending last data");
|
|
|
|
|
|
|
|
/* pushing last buffers for each pad */
|
2015-04-02 13:57:20 +00:00
|
|
|
if ((ret = gst_qt_mux_send_last_buffers (qtmux)) != GST_FLOW_OK)
|
2015-04-01 00:15:38 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (qtmux->mux_mode == GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE) {
|
|
|
|
/* Streamable mode; no need to write duration or MFRA */
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "streamable file; nothing to stop");
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_qt_mux_update_global_statistics (qtmux);
|
2019-12-12 19:20:35 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
sinkpads = g_list_copy_deep (GST_ELEMENT_CAST (qtmux)->sinkpads,
|
|
|
|
(GCopyFunc) gst_object_ref, NULL);
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
|
|
|
for (l = sinkpads; l; l = l->next) {
|
2019-12-03 14:30:06 +00:00
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2017-03-22 16:52:51 +00:00
|
|
|
|
|
|
|
if (qtpad->tc_pos != -1) {
|
|
|
|
/* File is being stopped and timecode hasn't been updated. Update it now
|
|
|
|
* with whatever we have */
|
|
|
|
ret = gst_qt_mux_update_timecode (qtmux, qtpad);
|
2019-12-12 19:20:35 +00:00
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
g_list_free_full (sinkpads, gst_object_unref);
|
2017-03-22 16:52:51 +00:00
|
|
|
return ret;
|
2019-12-12 19:20:35 +00:00
|
|
|
}
|
2017-03-22 16:52:51 +00:00
|
|
|
}
|
2016-06-24 13:32:37 +00:00
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
g_list_free_full (sinkpads, gst_object_unref);
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
switch (qtmux->mux_mode) {
|
|
|
|
case GST_QT_MUX_MODE_FRAGMENTED:{
|
2015-04-01 00:15:38 +00:00
|
|
|
GstSegment segment;
|
2010-11-18 15:48:06 +00:00
|
|
|
guint8 *data = NULL;
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
size = offset = 0;
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "adding mfra");
|
|
|
|
if (!atom_mfra_copy_data (qtmux->mfra, &data, &size, &offset))
|
|
|
|
goto serialize_error;
|
|
|
|
buf = _gst_buffer_new_take_data (data, offset);
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, buf, NULL, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* only mvex duration is updated,
|
|
|
|
* mvhd should be consistent with empty moov
|
|
|
|
* (but TODO maybe some clients do not handle that well ?) */
|
|
|
|
qtmux->moov->mvex.mehd.fragment_duration =
|
qtmux: round to nearest when computing mehd and tkhd duration
This fixes a bug where in some files mehd.fragment_duration is one unit
less than the actual duration of the fragmented movie, as explained below:
mehd.fragment_duration is computed by scaling the end timestamp of
the last frame of the movie in (in nanoseconds) by the movie timescale.
In some situations, the end timestamp is innacurate due to lossy conversion to
fixed point required by GstBuffer upstream.
Take for instance a movie with 3 frames at exactly 3 fps.
$ gst-launch-1.0 -v videotestsrc num-buffers=3 \
! video/x-raw, framerate="(fraction)3/1" \
! x264enc \
! fakesink silent=false
dts: 999:59:59.333333334, pts: 1000:00:00.000000000, duration: 0:00:00.333333333
dts: 999:59:59.666666667, pts: 1000:00:00.666666666, duration: 0:00:00.333333334
dts: 1000:00:00.000000000, pts: 1000:00:00.333333333, duration: 0:00:00.333333333
The end timestamp is calculated by qtmux in this way:
end timestamp = last frame DTS + last frame DUR - first frame DTS =
= 1000:00:00.000000000 + 0:00:00.333333333 - 999:59:59.333333334 =
= 0:00:00.999999999
qtmux needs to round this timestamp to the declared movie timescale, which can
ameliorate this distortion, but it's important that round-neareast is used;
otherwise it would backfire badly.
Take for example a movie with a timescale of 30 units/s.
0.999999999 s * 30 units/s = 29.999999970 units
A round-floor (as it was done before this patch) would set fragment_duration to
29 units, amplifying the original distorsion from 1 nanosecond up to 33
milliseconds less than the correct value. The greatest distortion would occur
in the case where timescale = framerate, where an entire frame duration would
be subtracted.
Also, rounding is added to tkhd duration computation too, which
potentially has the same problem.
https://bugzilla.gnome.org/show_bug.cgi?id=793959
2018-03-01 16:25:07 +00:00
|
|
|
gst_util_uint64_scale_round (qtmux->last_dts, qtmux->timescale,
|
|
|
|
GST_SECOND);
|
|
|
|
GST_DEBUG_OBJECT (qtmux,
|
|
|
|
"rewriting moov with mvex duration %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (qtmux->last_dts));
|
2015-04-01 00:15:38 +00:00
|
|
|
/* seek and rewrite the header */
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
2015-04-01 00:15:38 +00:00
|
|
|
segment.start = qtmux->moov_pos;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2015-04-01 00:15:38 +00:00
|
|
|
/* no need to seek back */
|
2015-04-16 00:44:49 +00:00
|
|
|
return gst_qt_mux_send_moov (qtmux, NULL, 0, FALSE, FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
|
|
|
case GST_QT_MUX_MODE_ROBUST_RECORDING:{
|
|
|
|
ret = gst_qt_mux_robust_recording_rewrite_moov (qtmux);
|
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK))
|
|
|
|
return ret;
|
|
|
|
/* Finalise by writing the final size into the mdat. Up until now
|
|
|
|
* it's been 0, which means 'rest of the file'
|
|
|
|
* No need to seek back after this, we won't write any more */
|
|
|
|
return gst_qt_mux_update_mdat_size (qtmux, qtmux->mdat_pos,
|
2015-04-16 00:44:49 +00:00
|
|
|
qtmux->mdat_size, NULL, TRUE);
|
2015-04-01 00:15:38 +00:00
|
|
|
}
|
2017-03-09 08:15:34 +00:00
|
|
|
case GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL:{
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
2017-03-09 08:15:34 +00:00
|
|
|
guint32 next_track_id = qtmux->moov->mvhd.next_track_id;
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qpad = (GstQTMuxPad *) l->data;
|
2017-03-09 08:15:34 +00:00
|
|
|
guint64 block_idx;
|
|
|
|
AtomSTBL *stbl = &qpad->trak->mdia.minf.stbl;
|
|
|
|
|
|
|
|
/* Get the block index of the last sample we wrote, not of the next
|
|
|
|
* sample we would write */
|
|
|
|
block_idx = prefill_get_block_index (qtmux, qpad);
|
|
|
|
|
|
|
|
/* stts */
|
2018-07-31 09:47:47 +00:00
|
|
|
if (block_idx > 0) {
|
2017-03-09 08:15:34 +00:00
|
|
|
STTSEntry *entry;
|
|
|
|
guint64 nsamples = 0;
|
|
|
|
gint i, n;
|
|
|
|
|
|
|
|
n = atom_array_get_len (&stbl->stts.entries);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
entry = &atom_array_index (&stbl->stts.entries, i);
|
|
|
|
if (nsamples + entry->sample_count >= qpad->sample_offset) {
|
|
|
|
entry->sample_count = qpad->sample_offset - nsamples;
|
|
|
|
stbl->stts.entries.len = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsamples += entry->sample_count;
|
|
|
|
}
|
|
|
|
g_assert (i < n);
|
2018-07-31 09:47:47 +00:00
|
|
|
} else {
|
|
|
|
stbl->stts.entries.len = 0;
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stsz */
|
|
|
|
{
|
|
|
|
g_assert (stbl->stsz.entries.len == 0);
|
|
|
|
stbl->stsz.table_size = qpad->sample_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stco/stsc */
|
|
|
|
{
|
|
|
|
gint i, n;
|
|
|
|
guint64 nsamples = 0;
|
|
|
|
gint chunk_index = 0;
|
2018-07-31 09:47:47 +00:00
|
|
|
const TrakBufferEntryInfo *sample_entry;
|
|
|
|
|
|
|
|
if (block_idx > 0) {
|
|
|
|
sample_entry =
|
|
|
|
&g_array_index (qpad->samples, TrakBufferEntryInfo,
|
|
|
|
block_idx - 1);
|
|
|
|
|
|
|
|
n = stbl->stco64.entries.len;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
guint64 *entry = &atom_array_index (&stbl->stco64.entries, i);
|
|
|
|
|
|
|
|
if (*entry == sample_entry->chunk_offset) {
|
|
|
|
stbl->stco64.entries.len = i + 1;
|
|
|
|
chunk_index = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
2018-07-31 09:47:47 +00:00
|
|
|
g_assert (i < n);
|
|
|
|
g_assert (chunk_index > 0);
|
|
|
|
|
|
|
|
n = stbl->stsc.entries.len;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
STSCEntry *entry = &atom_array_index (&stbl->stsc.entries, i);
|
|
|
|
|
|
|
|
if (entry->first_chunk >= chunk_index)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
nsamples +=
|
|
|
|
(entry->first_chunk - atom_array_index (&stbl->stsc.entries,
|
|
|
|
i -
|
|
|
|
1).first_chunk) * atom_array_index (&stbl->stsc.entries,
|
|
|
|
i - 1).samples_per_chunk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_assert (i <= n);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
if (i > 0) {
|
2018-07-31 09:47:47 +00:00
|
|
|
STSCEntry *prev_entry =
|
|
|
|
&atom_array_index (&stbl->stsc.entries, i - 1);
|
2017-03-09 08:15:34 +00:00
|
|
|
nsamples +=
|
2018-07-31 09:47:47 +00:00
|
|
|
(chunk_index -
|
|
|
|
prev_entry->first_chunk) * prev_entry->samples_per_chunk;
|
|
|
|
if (qpad->sample_offset - nsamples > 0) {
|
|
|
|
stbl->stsc.entries.len = i;
|
|
|
|
atom_stsc_add_new_entry (&stbl->stsc, chunk_index,
|
|
|
|
qpad->sample_offset - nsamples);
|
|
|
|
} else {
|
|
|
|
stbl->stsc.entries.len = i;
|
|
|
|
stbl->stco64.entries.len--;
|
|
|
|
}
|
2017-03-09 08:15:34 +00:00
|
|
|
} else {
|
2018-07-31 09:47:47 +00:00
|
|
|
/* Everything in a single chunk */
|
|
|
|
stbl->stsc.entries.len = 0;
|
|
|
|
atom_stsc_add_new_entry (&stbl->stsc, chunk_index,
|
|
|
|
qpad->sample_offset);
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
2017-05-09 14:02:43 +00:00
|
|
|
} else {
|
2018-07-31 09:47:47 +00:00
|
|
|
stbl->stco64.entries.len = 0;
|
2017-05-09 14:02:43 +00:00
|
|
|
stbl->stsc.entries.len = 0;
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
GList *walk2;
|
|
|
|
|
|
|
|
for (walk2 = qtmux->moov->mvex.trexs; walk2; walk2 = walk2->next) {
|
|
|
|
AtomTREX *trex = walk2->data;
|
|
|
|
|
|
|
|
if (trex->track_ID == qpad->trak->tkhd.track_ID) {
|
|
|
|
trex->track_ID = next_track_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qpad->trak->tkhd.track_ID = next_track_id++;
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
qtmux->moov->mvhd.next_track_id = next_track_id;
|
|
|
|
|
|
|
|
gst_qt_mux_update_global_statistics (qtmux);
|
|
|
|
gst_qt_mux_configure_moov (qtmux);
|
|
|
|
|
|
|
|
gst_qt_mux_update_edit_lists (qtmux);
|
|
|
|
|
2017-05-10 12:31:40 +00:00
|
|
|
/* Check if any gap edit lists were added. We don't have any space
|
|
|
|
* reserved for this in the moov and the pre-finalized moov would have
|
|
|
|
* broken A/V synchronization. Error out here now
|
|
|
|
*/
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qpad = (GstQTMuxPad *) l->data;
|
2017-05-10 12:31:40 +00:00
|
|
|
|
|
|
|
if (qpad->trak->edts
|
|
|
|
&& g_slist_length (qpad->trak->edts->elst.entries) > 1) {
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Can't support gaps in prefill mode"));
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
2017-05-10 12:31:40 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2017-05-10 12:31:40 +00:00
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
gst_qt_mux_setup_metadata (qtmux);
|
|
|
|
atom_moov_chunks_set_offset (qtmux->moov, qtmux->header_size);
|
|
|
|
|
|
|
|
{
|
|
|
|
GstSegment segment;
|
|
|
|
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = qtmux->moov_pos;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_moov (qtmux, NULL, qtmux->reserved_moov_size, FALSE,
|
|
|
|
FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
2017-05-10 09:42:09 +00:00
|
|
|
if (qtmux->reserved_moov_size > qtmux->last_moov_size) {
|
2017-03-09 08:15:34 +00:00
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_free_atom (qtmux, NULL,
|
2017-05-10 09:42:09 +00:00
|
|
|
qtmux->reserved_moov_size - qtmux->last_moov_size, TRUE);
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_qt_mux_update_mdat_size (qtmux, qtmux->mdat_pos,
|
|
|
|
qtmux->mdat_size, NULL, FALSE);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Moov-at-end or fast-start mode from here down */
|
2015-04-01 00:15:38 +00:00
|
|
|
gst_qt_mux_configure_moov (qtmux);
|
2014-08-07 17:58:14 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
gst_qt_mux_update_edit_lists (qtmux);
|
2009-11-06 13:34:39 +00:00
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* tags into file metadata */
|
|
|
|
gst_qt_mux_setup_metadata (qtmux);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
2009-06-11 13:54:42 +00:00
|
|
|
large_file = (qtmux->mdat_size > MDAT_LARGE_FILE_LIMIT);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
switch (qtmux->mux_mode) {
|
|
|
|
case GST_QT_MUX_MODE_FAST_START:{
|
|
|
|
/* if faststart, update the offset of the atoms in the movie with the offset
|
|
|
|
* that the movie headers before mdat will cause.
|
|
|
|
* Also, send the ftyp */
|
|
|
|
offset = size = 0;
|
2009-10-16 00:11:16 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
ret = gst_qt_mux_prepare_and_send_ftyp (qtmux);
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
goto ftyp_error;
|
|
|
|
}
|
|
|
|
/* copy into NULL to obtain size */
|
|
|
|
if (!atom_moov_copy_data (qtmux->moov, NULL, &size, &offset))
|
|
|
|
goto serialize_error;
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "calculated moov atom size %" G_GUINT64_FORMAT,
|
|
|
|
offset);
|
|
|
|
offset += qtmux->header_size + (large_file ? 16 : 8);
|
2010-09-15 20:54:49 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* sum up with the extra atoms size */
|
|
|
|
ret = gst_qt_mux_send_extra_atoms (qtmux, FALSE, &offset, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
offset = qtmux->header_size;
|
|
|
|
break;
|
2010-11-09 14:54:44 +00:00
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
/* Now that we know the size of moov + extra atoms, we can adjust
|
|
|
|
* the chunk offsets stored into the moov */
|
2015-04-01 00:15:38 +00:00
|
|
|
atom_moov_chunks_set_offset (qtmux->moov, offset);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* write out moov and extra atoms */
|
2008-11-08 02:00:58 +00:00
|
|
|
/* note: as of this point, we no longer care about tracking written data size,
|
|
|
|
* since there is no more use for it anyway */
|
2015-04-16 00:44:49 +00:00
|
|
|
ret = gst_qt_mux_send_moov (qtmux, NULL, 0, FALSE, FALSE);
|
2010-11-09 14:54:44 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
2010-09-15 20:54:49 +00:00
|
|
|
|
2010-11-09 14:54:44 +00:00
|
|
|
/* extra atoms */
|
|
|
|
ret = gst_qt_mux_send_extra_atoms (qtmux, TRUE, NULL, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
2010-09-15 20:54:49 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
switch (qtmux->mux_mode) {
|
|
|
|
case GST_QT_MUX_MODE_MOOV_AT_END:
|
|
|
|
{
|
|
|
|
/* mdat needs update iff not using faststart */
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "updating mdat size");
|
|
|
|
ret = gst_qt_mux_update_mdat_size (qtmux, qtmux->mdat_pos,
|
2015-04-16 00:44:49 +00:00
|
|
|
qtmux->mdat_size, NULL, FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
/* note; no seeking back to the end of file is done,
|
|
|
|
* since we no longer write anything anyway */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QT_MUX_MODE_FAST_START:
|
|
|
|
{
|
|
|
|
/* send mdat atom and move buffered data into it */
|
|
|
|
/* mdat_size = accumulated (buffered data) */
|
|
|
|
ret = gst_qt_mux_send_mdat_header (qtmux, NULL, qtmux->mdat_size,
|
2015-04-16 00:44:49 +00:00
|
|
|
large_file, FALSE);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
ret = gst_qt_mux_send_buffered_data (qtmux, NULL);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
serialize_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Failed to serialize moov"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2009-10-16 00:11:16 +00:00
|
|
|
ftyp_error:
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2009-10-16 00:11:16 +00:00
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), ("Failed to send ftyp"));
|
2008-11-08 02:00:58 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-15 14:17:59 +00:00
|
|
|
static GstFlowReturn
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_pad_fragment_add_buffer (GstQTMux * qtmux, GstQTMuxPad * pad,
|
2010-11-18 15:48:06 +00:00
|
|
|
GstBuffer * buf, gboolean force, guint32 nsamples, gint64 dts,
|
2011-01-03 15:56:57 +00:00
|
|
|
guint32 delta, guint32 size, gboolean sync, gint64 pts_offset)
|
2010-11-15 14:17:59 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2019-07-30 10:07:18 +00:00
|
|
|
guint index = 0;
|
2010-11-15 14:17:59 +00:00
|
|
|
|
|
|
|
/* setup if needed */
|
|
|
|
if (G_UNLIKELY (!pad->traf || force))
|
|
|
|
goto init;
|
|
|
|
|
|
|
|
flush:
|
|
|
|
/* flush pad fragment if threshold reached,
|
|
|
|
* or at new keyframe if we should be minding those in the first place */
|
|
|
|
if (G_UNLIKELY (force || (sync && pad->sync) ||
|
|
|
|
pad->fragment_duration < (gint64) delta)) {
|
|
|
|
AtomMOOF *moof;
|
|
|
|
guint64 size = 0, offset = 0;
|
|
|
|
guint8 *data = NULL;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
guint i, total_size;
|
|
|
|
|
2010-11-18 15:48:06 +00:00
|
|
|
/* now we know where moof ends up, update offset in tfra */
|
|
|
|
if (pad->tfra)
|
|
|
|
atom_tfra_update_offset (pad->tfra, qtmux->header_size);
|
|
|
|
|
2010-11-15 14:17:59 +00:00
|
|
|
moof = atom_moof_new (qtmux->context, qtmux->fragment_sequence);
|
|
|
|
/* takes ownership */
|
|
|
|
atom_moof_add_traf (moof, pad->traf);
|
|
|
|
pad->traf = NULL;
|
|
|
|
atom_moof_copy_data (moof, &data, &size, &offset);
|
|
|
|
buffer = _gst_buffer_new_take_data (data, offset);
|
2011-11-21 19:31:31 +00:00
|
|
|
GST_LOG_OBJECT (qtmux, "writing moof size %" G_GSIZE_FORMAT,
|
2011-06-29 10:46:20 +00:00
|
|
|
gst_buffer_get_size (buffer));
|
2010-11-18 15:48:06 +00:00
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, buffer, &qtmux->header_size, FALSE);
|
2010-11-15 14:17:59 +00:00
|
|
|
|
2019-07-30 10:07:18 +00:00
|
|
|
atom_moof_free (moof);
|
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto moof_send_error;
|
|
|
|
|
2010-11-15 14:17:59 +00:00
|
|
|
/* and actual data */
|
|
|
|
total_size = 0;
|
|
|
|
for (i = 0; i < atom_array_get_len (&pad->fragment_buffers); i++) {
|
|
|
|
total_size +=
|
2011-06-29 10:46:20 +00:00
|
|
|
gst_buffer_get_size (atom_array_index (&pad->fragment_buffers, i));
|
2010-11-15 14:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux, "writing %d buffers, total_size %d",
|
|
|
|
atom_array_get_len (&pad->fragment_buffers), total_size);
|
2019-07-30 10:07:18 +00:00
|
|
|
ret = gst_qt_mux_send_mdat_header (qtmux, &qtmux->header_size, total_size,
|
|
|
|
FALSE, FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto mdat_header_send_error;
|
|
|
|
|
|
|
|
for (index = 0; index < atom_array_get_len (&pad->fragment_buffers);
|
|
|
|
index++) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "sending fragment %p",
|
|
|
|
atom_array_index (&pad->fragment_buffers, index));
|
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_buffer (qtmux,
|
|
|
|
atom_array_index (&pad->fragment_buffers, index), &qtmux->header_size,
|
|
|
|
FALSE);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto fragment_buf_send_error;
|
2010-11-15 14:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
atom_array_clear (&pad->fragment_buffers);
|
|
|
|
qtmux->fragment_sequence++;
|
|
|
|
force = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
init:
|
|
|
|
if (G_UNLIKELY (!pad->traf)) {
|
|
|
|
GST_LOG_OBJECT (qtmux, "setting up new fragment");
|
|
|
|
pad->traf = atom_traf_new (qtmux->context, atom_trak_get_id (pad->trak));
|
|
|
|
atom_array_init (&pad->fragment_buffers, 512);
|
|
|
|
pad->fragment_duration = gst_util_uint64_scale (qtmux->fragment_duration,
|
|
|
|
atom_trak_get_timescale (pad->trak), 1000);
|
2010-11-18 15:48:06 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (qtmux->mfra && !pad->tfra)) {
|
|
|
|
pad->tfra = atom_tfra_new (qtmux->context, atom_trak_get_id (pad->trak));
|
|
|
|
atom_mfra_add_tfra (qtmux->mfra, pad->tfra);
|
|
|
|
}
|
2017-01-07 14:13:32 +00:00
|
|
|
atom_traf_set_base_decode_time (pad->traf, dts);
|
2010-11-15 14:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add buffer and metadata */
|
2011-01-03 15:56:57 +00:00
|
|
|
atom_traf_add_samples (pad->traf, delta, size, sync, pts_offset,
|
2010-11-19 16:41:41 +00:00
|
|
|
pad->sync && sync);
|
2019-07-30 10:07:18 +00:00
|
|
|
GST_LOG_OBJECT (qtmux, "adding buffer %p to fragments", buf);
|
|
|
|
atom_array_append (&pad->fragment_buffers, g_steal_pointer (&buf), 256);
|
2010-11-15 14:17:59 +00:00
|
|
|
pad->fragment_duration -= delta;
|
|
|
|
|
2010-11-18 15:48:06 +00:00
|
|
|
if (pad->tfra) {
|
|
|
|
guint32 sn = atom_traf_get_sample_num (pad->traf);
|
|
|
|
|
|
|
|
if ((sync && pad->sync) || (sn == 1 && !pad->sync))
|
|
|
|
atom_tfra_add_entry (pad->tfra, dts, sn);
|
|
|
|
}
|
|
|
|
|
2010-11-15 14:17:59 +00:00
|
|
|
if (G_UNLIKELY (force))
|
|
|
|
goto flush;
|
|
|
|
|
|
|
|
return ret;
|
2019-07-30 10:07:18 +00:00
|
|
|
|
|
|
|
moof_send_error:
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
GST_ERROR_OBJECT (qtmux, "Failed to send moof buffer");
|
|
|
|
for (i = 0; i < atom_array_get_len (&pad->fragment_buffers); i++)
|
|
|
|
gst_buffer_unref (atom_array_index (&pad->fragment_buffers, i));
|
|
|
|
atom_array_clear (&pad->fragment_buffers);
|
|
|
|
gst_clear_buffer (&buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdat_header_send_error:
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
GST_ERROR_OBJECT (qtmux, "Failed to send mdat header");
|
|
|
|
for (i = 0; i < atom_array_get_len (&pad->fragment_buffers); i++)
|
|
|
|
gst_buffer_unref (atom_array_index (&pad->fragment_buffers, i));
|
|
|
|
atom_array_clear (&pad->fragment_buffers);
|
|
|
|
gst_clear_buffer (&buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment_buf_send_error:
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
GST_ERROR_OBJECT (qtmux, "Failed to send fragment");
|
|
|
|
for (i = index + 1; i < atom_array_get_len (&pad->fragment_buffers); i++) {
|
|
|
|
gst_buffer_unref (atom_array_index (&pad->fragment_buffers, i));
|
|
|
|
}
|
|
|
|
atom_array_clear (&pad->fragment_buffers);
|
|
|
|
gst_clear_buffer (&buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-11-15 14:17:59 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Here's the clever bit of robust recording: Updating the moov
|
|
|
|
* header is done using a ping-pong scheme inside 2 blocks of size
|
|
|
|
* 'reserved_moov_size' at the start of the file, in such a way that the
|
|
|
|
* file on-disk is always valid if interrupted.
|
|
|
|
* Inside the reserved space, we have 2 pairs of free + moov atoms
|
|
|
|
* (in that order), free-A + moov-A @ offset 0 and free-B + moov-B at
|
|
|
|
* at offset "reserved_moov_size".
|
|
|
|
*
|
|
|
|
* 1. Free-A has 0 size payload, moov-A immediately after is
|
|
|
|
* active/current, and is padded with an internal Free atom to
|
|
|
|
* end at reserved_space/2. Free-B is at reserved_space/2, sized
|
|
|
|
* to cover the remaining free space (including moov-B).
|
|
|
|
* 2. We write moov-B (which is invisible inside free-B), and pad it to
|
|
|
|
* end at the end of free space. Then, we update free-A to size
|
|
|
|
* reserved_space/2 + sizeof(free-B), which hides moov-A and the
|
|
|
|
* free-B header, and makes moov-B active.
|
|
|
|
* 3. Rewrite moov-A inside free-A, with padding out to free-B.
|
|
|
|
* Change the size of free-A to make moov-A active again.
|
|
|
|
* 4. Rinse and repeat.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_robust_recording_rewrite_moov (GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
GstSegment segment;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
guint64 freeA_offset;
|
|
|
|
guint32 new_freeA_size;
|
|
|
|
guint64 new_moov_offset;
|
|
|
|
|
|
|
|
/* Update moov info, then seek and rewrite the MOOV atom */
|
|
|
|
gst_qt_mux_update_global_statistics (qtmux);
|
|
|
|
gst_qt_mux_configure_moov (qtmux);
|
|
|
|
|
|
|
|
gst_qt_mux_update_edit_lists (qtmux);
|
|
|
|
|
|
|
|
/* tags into file metadata */
|
|
|
|
gst_qt_mux_setup_metadata (qtmux);
|
|
|
|
|
|
|
|
/* chunks position is set relative to the first byte of the
|
|
|
|
* MDAT atom payload. Set the overall offset into the file */
|
|
|
|
atom_moov_chunks_set_offset (qtmux->moov, qtmux->header_size);
|
|
|
|
|
|
|
|
/* Calculate which moov to rewrite. qtmux->moov_pos points to
|
|
|
|
* the start of the free-A header */
|
|
|
|
freeA_offset = qtmux->moov_pos;
|
|
|
|
if (qtmux->reserved_moov_first_active) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Updating pong moov header");
|
|
|
|
/* After this, freeA will include itself, moovA, plus the freeB
|
|
|
|
* header */
|
|
|
|
new_freeA_size = qtmux->reserved_moov_size + 16;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Updating ping moov header");
|
|
|
|
new_freeA_size = 8;
|
|
|
|
}
|
|
|
|
/* the moov we update is after free-A, calculate its offset */
|
|
|
|
new_moov_offset = freeA_offset + new_freeA_size;
|
|
|
|
|
|
|
|
/* Swap ping-pong cadence marker */
|
|
|
|
qtmux->reserved_moov_first_active = !qtmux->reserved_moov_first_active;
|
|
|
|
|
|
|
|
/* seek and rewrite the MOOV atom */
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = new_moov_offset;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
2015-04-16 00:44:49 +00:00
|
|
|
ret =
|
|
|
|
gst_qt_mux_send_moov (qtmux, NULL, qtmux->reserved_moov_size, FALSE,
|
|
|
|
TRUE);
|
2015-04-01 00:15:38 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Update the estimated recording space remaining, based on amount used so
|
|
|
|
* far and duration muxed so far */
|
|
|
|
if (qtmux->last_moov_size > qtmux->base_moov_size && qtmux->last_dts > 0) {
|
|
|
|
GstClockTime remain;
|
|
|
|
GstClockTime time_muxed = qtmux->last_dts;
|
|
|
|
|
|
|
|
remain =
|
|
|
|
gst_util_uint64_scale (qtmux->reserved_moov_size -
|
|
|
|
qtmux->last_moov_size, time_muxed,
|
|
|
|
qtmux->last_moov_size - qtmux->base_moov_size);
|
|
|
|
/* Always under-estimate slightly, so users
|
|
|
|
* have time to stop muxing before we run out */
|
|
|
|
if (remain < GST_SECOND / 2)
|
|
|
|
remain = 0;
|
|
|
|
else
|
|
|
|
remain -= GST_SECOND / 2;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (qtmux,
|
|
|
|
"Reserved %u header bytes. Used %u in %" GST_TIME_FORMAT
|
|
|
|
". Remaining now %u or approx %" G_GUINT64_FORMAT " ns\n",
|
|
|
|
qtmux->reserved_moov_size, qtmux->last_moov_size,
|
|
|
|
GST_TIME_ARGS (qtmux->last_dts),
|
|
|
|
qtmux->reserved_moov_size - qtmux->last_moov_size, remain);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
qtmux->reserved_duration_remaining = remain;
|
|
|
|
qtmux->muxed_since_last_update = 0;
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "reserved remaining duration now %"
|
|
|
|
G_GUINT64_FORMAT, qtmux->reserved_duration_remaining);
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Now update the moov-A size. Don't pass offset, since we don't need
|
|
|
|
* send_free_atom() to seek for us - all our callers seek back to
|
|
|
|
* where they need after this, or they don't need it */
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = freeA_offset;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
2015-04-16 00:44:49 +00:00
|
|
|
ret = gst_qt_mux_send_free_atom (qtmux, NULL, new_freeA_size, TRUE);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_qt_mux_robust_recording_update (GstQTMux * qtmux, GstClockTime position)
|
|
|
|
{
|
|
|
|
GstSegment segment;
|
|
|
|
GstFlowReturn flow_ret;
|
|
|
|
|
|
|
|
guint64 mdat_offset = qtmux->mdat_pos + 16 + qtmux->mdat_size;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2017-11-24 13:53:42 +00:00
|
|
|
|
|
|
|
/* Update the offset of how much we've muxed, so the
|
|
|
|
* report of remaining space keeps counting down */
|
|
|
|
if (position > qtmux->last_moov_update &&
|
|
|
|
position - qtmux->last_moov_update > qtmux->muxed_since_last_update) {
|
|
|
|
GST_LOG_OBJECT (qtmux,
|
|
|
|
"Muxed time %" G_GUINT64_FORMAT " since last moov update",
|
|
|
|
qtmux->muxed_since_last_update);
|
|
|
|
qtmux->muxed_since_last_update = position - qtmux->last_moov_update;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next, check if we're supposed to send periodic moov updates downstream */
|
2015-04-01 00:15:38 +00:00
|
|
|
if (qtmux->reserved_moov_update_period == GST_CLOCK_TIME_NONE) {
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update if position is > the threshold or there's been no update yet */
|
|
|
|
if (qtmux->last_moov_update != GST_CLOCK_TIME_NONE &&
|
|
|
|
(position <= qtmux->last_moov_update ||
|
|
|
|
(position - qtmux->last_moov_update) <
|
|
|
|
qtmux->reserved_moov_update_period)) {
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
return GST_FLOW_OK; /* No update needed yet */
|
|
|
|
}
|
|
|
|
|
|
|
|
qtmux->last_moov_update = position;
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Update moov atom, position %" GST_TIME_FORMAT
|
|
|
|
" mdat starts @ %" G_GUINT64_FORMAT " we were a %" G_GUINT64_FORMAT,
|
|
|
|
GST_TIME_ARGS (position), qtmux->mdat_pos, mdat_offset);
|
|
|
|
|
|
|
|
flow_ret = gst_qt_mux_robust_recording_rewrite_moov (qtmux);
|
|
|
|
if (G_UNLIKELY (flow_ret != GST_FLOW_OK))
|
|
|
|
return flow_ret;
|
|
|
|
|
|
|
|
/* Seek back to previous position */
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = mdat_offset;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
return flow_ret;
|
|
|
|
}
|
|
|
|
|
2014-02-07 04:49:26 +00:00
|
|
|
static GstFlowReturn
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_register_and_push_sample (GstQTMux * qtmux, GstQTMuxPad * pad,
|
2014-02-07 04:49:26 +00:00
|
|
|
GstBuffer * buffer, gboolean is_last_buffer, guint nsamples,
|
|
|
|
gint64 last_dts, gint64 scaled_duration, guint sample_size,
|
2014-12-09 01:43:00 +00:00
|
|
|
guint64 chunk_offset, gboolean sync, gboolean do_pts, gint64 pts_offset)
|
2014-02-07 04:49:26 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* note that a new chunk is started each time (not fancy but works) */
|
|
|
|
if (qtmux->moov_recov_file) {
|
|
|
|
if (!atoms_recov_write_trak_samples (qtmux->moov_recov_file, pad->trak,
|
|
|
|
nsamples, (gint32) scaled_duration, sample_size, chunk_offset, sync,
|
|
|
|
do_pts, pts_offset)) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Failed to write sample information to "
|
|
|
|
"recovery file, disabling recovery");
|
|
|
|
fclose (qtmux->moov_recov_file);
|
|
|
|
qtmux->moov_recov_file = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
switch (qtmux->mux_mode) {
|
2017-03-09 08:15:34 +00:00
|
|
|
case GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL:{
|
|
|
|
const TrakBufferEntryInfo *sample_entry;
|
|
|
|
guint64 block_idx = prefill_get_block_index (qtmux, pad);
|
|
|
|
|
|
|
|
if (block_idx >= pad->samples->len) {
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Unexpected sample %" G_GUINT64_FORMAT ", expected up to %u",
|
|
|
|
block_idx, pad->samples->len));
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if all values are as expected */
|
|
|
|
sample_entry =
|
|
|
|
&g_array_index (pad->samples, TrakBufferEntryInfo, block_idx);
|
|
|
|
|
|
|
|
/* Allow +/- 1 difference for the scaled_duration to allow
|
|
|
|
* for some rounding errors
|
|
|
|
*/
|
|
|
|
if (sample_entry->nsamples != nsamples
|
|
|
|
|| ABSDIFF (sample_entry->delta, scaled_duration) > 1
|
|
|
|
|| sample_entry->size != sample_size
|
|
|
|
|| sample_entry->chunk_offset != chunk_offset
|
|
|
|
|| sample_entry->pts_offset != pts_offset
|
|
|
|
|| sample_entry->sync != sync) {
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Unexpected values in sample %" G_GUINT64_FORMAT,
|
|
|
|
pad->sample_offset + 1));
|
2018-05-14 18:06:55 +00:00
|
|
|
GST_ERROR_OBJECT (qtmux, "Expected: samples %u, delta %u, size %u, "
|
|
|
|
"chunk offset %" G_GUINT64_FORMAT ", "
|
|
|
|
"pts offset %" G_GUINT64_FORMAT ", sync %d",
|
|
|
|
sample_entry->nsamples,
|
|
|
|
sample_entry->delta,
|
|
|
|
sample_entry->size,
|
|
|
|
sample_entry->chunk_offset,
|
|
|
|
sample_entry->pts_offset, sample_entry->sync);
|
|
|
|
GST_ERROR_OBJECT (qtmux, "Got: samples %u, delta %u, size %u, "
|
|
|
|
"chunk offset %" G_GUINT64_FORMAT ", "
|
|
|
|
"pts offset %" G_GUINT64_FORMAT ", sync %d",
|
|
|
|
nsamples,
|
|
|
|
(guint) scaled_duration,
|
|
|
|
sample_size, chunk_offset, pts_offset, sync);
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, buffer, &qtmux->mdat_size, TRUE);
|
|
|
|
break;
|
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
case GST_QT_MUX_MODE_MOOV_AT_END:
|
|
|
|
case GST_QT_MUX_MODE_FAST_START:
|
2015-04-01 00:15:38 +00:00
|
|
|
case GST_QT_MUX_MODE_ROBUST_RECORDING:
|
2015-04-01 00:15:38 +00:00
|
|
|
atom_trak_add_samples (pad->trak, nsamples, (gint32) scaled_duration,
|
|
|
|
sample_size, chunk_offset, sync, pts_offset);
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, buffer, &qtmux->mdat_size, TRUE);
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Check if it's time to re-write the headers in robust-recording mode */
|
|
|
|
if (ret == GST_FLOW_OK
|
|
|
|
&& qtmux->mux_mode == GST_QT_MUX_MODE_ROBUST_RECORDING)
|
|
|
|
ret = gst_qt_mux_robust_recording_update (qtmux, pad->total_duration);
|
2015-04-01 00:15:38 +00:00
|
|
|
break;
|
|
|
|
case GST_QT_MUX_MODE_FRAGMENTED:
|
|
|
|
case GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE:
|
|
|
|
/* ensure that always sync samples are marked as such */
|
|
|
|
ret = gst_qt_mux_pad_fragment_add_buffer (qtmux, pad, buffer,
|
|
|
|
is_last_buffer, nsamples, last_dts, (gint32) scaled_duration,
|
|
|
|
sample_size, !pad->sync || sync, pts_offset);
|
|
|
|
break;
|
2014-02-07 04:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-01 16:59:07 +00:00
|
|
|
static void
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_register_buffer_in_chunk (GstQTMux * qtmux, GstQTMuxPad * pad,
|
2017-07-01 16:59:07 +00:00
|
|
|
guint buffer_size, GstClockTime duration)
|
|
|
|
{
|
|
|
|
/* not that much happens here,
|
|
|
|
* but updating any of this very likely needs to happen all in sync,
|
|
|
|
* unless there is a very good reason not to */
|
|
|
|
|
|
|
|
/* for computing the avg bitrate */
|
|
|
|
pad->total_bytes += buffer_size;
|
|
|
|
pad->total_duration += duration;
|
|
|
|
/* for keeping track of where we are in chunk;
|
|
|
|
* ensures that data really is located as recorded in atoms */
|
|
|
|
qtmux->current_chunk_size += buffer_size;
|
|
|
|
qtmux->current_chunk_duration += duration;
|
|
|
|
}
|
|
|
|
|
2016-06-24 13:32:37 +00:00
|
|
|
static GstFlowReturn
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_check_and_update_timecode (GstQTMux * qtmux, GstQTMuxPad * pad,
|
2016-06-24 13:32:37 +00:00
|
|
|
GstBuffer * buf, GstFlowReturn ret)
|
|
|
|
{
|
2017-03-23 13:01:16 +00:00
|
|
|
GstVideoTimeCodeMeta *tc_meta;
|
|
|
|
GstVideoTimeCode *tc;
|
|
|
|
GstBuffer *tc_buf;
|
|
|
|
gsize szret;
|
|
|
|
guint32 frames_since_daily_jam;
|
2017-05-16 09:56:15 +00:00
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
|
|
|
|
2019-02-08 11:59:19 +00:00
|
|
|
if (!pad->trak->is_video)
|
|
|
|
return ret;
|
|
|
|
|
2017-05-16 09:56:15 +00:00
|
|
|
if (qtmux_klass->format != GST_QT_MUX_FORMAT_QT)
|
|
|
|
return ret;
|
2017-03-23 13:01:16 +00:00
|
|
|
|
|
|
|
if (buf == NULL || (pad->tc_trak != NULL && pad->tc_pos == -1))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
tc_meta = gst_buffer_get_video_time_code_meta (buf);
|
|
|
|
if (!tc_meta)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
tc = &tc_meta->tc;
|
|
|
|
|
|
|
|
/* This means we never got a timecode before */
|
|
|
|
if (pad->first_tc == NULL) {
|
2016-06-24 13:32:37 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2017-03-23 13:01:16 +00:00
|
|
|
gchar *tc_str = gst_video_time_code_to_string (tc);
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Found first timecode %s", tc_str);
|
|
|
|
g_free (tc_str);
|
2016-06-24 13:32:37 +00:00
|
|
|
#endif
|
2017-03-23 13:01:16 +00:00
|
|
|
g_assert (pad->tc_trak == NULL);
|
|
|
|
pad->first_tc = gst_video_time_code_copy (tc);
|
|
|
|
/* If frames are out of order, the frame we're currently getting might
|
|
|
|
* not be the first one. Just write a 0 timecode for now and wait
|
|
|
|
* until we receive a timecode that's lower than the current one */
|
|
|
|
if (pad->is_out_of_order) {
|
|
|
|
pad->first_pts = GST_BUFFER_PTS (buf);
|
|
|
|
frames_since_daily_jam = 0;
|
|
|
|
/* Position to rewrite */
|
|
|
|
pad->tc_pos = qtmux->mdat_size;
|
|
|
|
} else {
|
|
|
|
frames_since_daily_jam =
|
|
|
|
gst_video_time_code_frames_since_daily_jam (pad->first_tc);
|
|
|
|
frames_since_daily_jam = GUINT32_TO_BE (frames_since_daily_jam);
|
|
|
|
}
|
|
|
|
/* Write the timecode trak now */
|
|
|
|
pad->tc_trak = atom_trak_new (qtmux->context);
|
|
|
|
atom_moov_add_trak (qtmux->moov, pad->tc_trak);
|
|
|
|
|
|
|
|
pad->trak->tref = atom_tref_new (FOURCC_tmcd);
|
|
|
|
atom_tref_add_entry (pad->trak->tref, pad->tc_trak->tkhd.track_ID);
|
|
|
|
|
2018-01-19 13:05:26 +00:00
|
|
|
atom_trak_set_timecode_type (pad->tc_trak, qtmux->context,
|
|
|
|
pad->trak->mdia.mdhd.time_info.timescale, pad->first_tc);
|
2017-03-23 13:01:16 +00:00
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
tc_buf = gst_buffer_new_allocate (NULL, 4, NULL);
|
2017-03-23 13:01:16 +00:00
|
|
|
szret = gst_buffer_fill (tc_buf, 0, &frames_since_daily_jam, 4);
|
|
|
|
g_assert (szret == 4);
|
|
|
|
|
|
|
|
atom_trak_add_samples (pad->tc_trak, 1, 1, 4, qtmux->mdat_size, FALSE, 0);
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, tc_buf, &qtmux->mdat_size, TRUE);
|
|
|
|
|
|
|
|
/* Need to reset the current chunk (of the previous pad) here because
|
|
|
|
* some other data was written now above, and the pad has to start a
|
|
|
|
* new chunk now */
|
|
|
|
qtmux->current_chunk_offset = -1;
|
|
|
|
qtmux->current_chunk_size = 0;
|
|
|
|
qtmux->current_chunk_duration = 0;
|
2017-03-09 08:15:34 +00:00
|
|
|
} else if (qtmux->mux_mode == GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL) {
|
|
|
|
frames_since_daily_jam =
|
|
|
|
gst_video_time_code_frames_since_daily_jam (pad->first_tc);
|
|
|
|
frames_since_daily_jam = GUINT32_TO_BE (frames_since_daily_jam);
|
|
|
|
|
|
|
|
tc_buf = gst_buffer_new_allocate (NULL, 4, NULL);
|
|
|
|
szret = gst_buffer_fill (tc_buf, 0, &frames_since_daily_jam, 4);
|
|
|
|
g_assert (szret == 4);
|
|
|
|
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, tc_buf, &qtmux->mdat_size, TRUE);
|
|
|
|
pad->tc_pos = -1;
|
|
|
|
|
|
|
|
qtmux->current_chunk_offset = -1;
|
|
|
|
qtmux->current_chunk_size = 0;
|
|
|
|
qtmux->current_chunk_duration = 0;
|
2017-03-23 13:01:16 +00:00
|
|
|
} else if (pad->is_out_of_order) {
|
|
|
|
/* Check for a lower timecode than the one stored */
|
|
|
|
g_assert (pad->tc_trak != NULL);
|
|
|
|
if (GST_BUFFER_DTS (buf) <= pad->first_pts) {
|
|
|
|
if (gst_video_time_code_compare (tc, pad->first_tc) == -1) {
|
|
|
|
gst_video_time_code_free (pad->first_tc);
|
2017-03-22 16:52:51 +00:00
|
|
|
pad->first_tc = gst_video_time_code_copy (tc);
|
2016-06-24 13:32:37 +00:00
|
|
|
}
|
2017-03-23 13:01:16 +00:00
|
|
|
} else {
|
|
|
|
guint64 bk_size = qtmux->mdat_size;
|
|
|
|
GstSegment segment;
|
|
|
|
/* If this frame's DTS is after the first PTS received, it means
|
|
|
|
* we've already received the first frame to be presented. Otherwise
|
|
|
|
* the decoder would need to go back in time */
|
|
|
|
gst_qt_mux_update_timecode (qtmux, pad);
|
|
|
|
|
|
|
|
/* Reset writing position */
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
segment.start = bk_size;
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_update_segment (GST_AGGREGATOR (qtmux), &segment);
|
2016-06-24 13:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-23 13:01:16 +00:00
|
|
|
|
2016-06-24 13:32:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/*
|
|
|
|
* Here we push the buffer and update the tables in the track atoms
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_add_buffer (GstQTMux * qtmux, GstQTMuxPad * pad, GstBuffer * buf)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
|
|
|
GstBuffer *last_buf = NULL;
|
|
|
|
GstClockTime duration;
|
|
|
|
guint nsamples, sample_size;
|
2011-01-03 16:24:23 +00:00
|
|
|
guint64 chunk_offset;
|
|
|
|
gint64 last_dts, scaled_duration;
|
2008-11-08 02:00:58 +00:00
|
|
|
gint64 pts_offset = 0;
|
2015-04-07 19:12:40 +00:00
|
|
|
gboolean sync = FALSE;
|
2011-04-15 10:34:05 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2017-03-09 08:15:34 +00:00
|
|
|
guint buffer_size;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
/* GAP event, nothing to do */
|
|
|
|
if (buf && gst_buffer_get_size (buf) == 0 &&
|
|
|
|
GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP)) {
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
if (!pad->fourcc)
|
|
|
|
goto not_negotiated;
|
|
|
|
|
2009-12-11 01:20:45 +00:00
|
|
|
/* if this pad has a prepare function, call it */
|
|
|
|
if (pad->prepare_buf_func != NULL) {
|
2017-03-09 08:15:34 +00:00
|
|
|
GstBuffer *new_buf;
|
|
|
|
|
|
|
|
new_buf = pad->prepare_buf_func (pad, buf, qtmux);
|
|
|
|
if (buf && !new_buf)
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
buf = new_buf;
|
2009-12-11 01:20:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 13:32:37 +00:00
|
|
|
ret = gst_qt_mux_check_and_update_timecode (qtmux, pad, buf, ret);
|
2017-04-04 12:22:25 +00:00
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
2017-04-04 12:07:40 +00:00
|
|
|
return ret;
|
2017-04-04 12:22:25 +00:00
|
|
|
}
|
2017-04-04 12:07:40 +00:00
|
|
|
|
|
|
|
last_buf = pad->last_buf;
|
2017-04-04 12:22:25 +00:00
|
|
|
pad->last_buf = buf;
|
2016-06-24 13:32:37 +00:00
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
if (last_buf == NULL) {
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if (buf == NULL) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Pad %s has no previous buffer stored and "
|
2019-12-03 14:30:06 +00:00
|
|
|
"received NULL buffer, doing nothing", GST_PAD_NAME (pad));
|
2008-11-08 02:00:58 +00:00
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (qtmux,
|
|
|
|
"Pad %s has no previous buffer stored, storing now",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (pad));
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-04-15 10:34:05 +00:00
|
|
|
goto exit;
|
2016-11-22 13:59:19 +00:00
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2016-11-22 14:42:26 +00:00
|
|
|
if (!GST_BUFFER_PTS_IS_VALID (last_buf))
|
|
|
|
goto no_pts;
|
|
|
|
|
2011-09-09 12:12:56 +00:00
|
|
|
/* if this is the first buffer, store the timestamp */
|
2017-04-04 12:22:25 +00:00
|
|
|
if (G_UNLIKELY (pad->first_ts == GST_CLOCK_TIME_NONE)) {
|
2015-06-19 22:40:43 +00:00
|
|
|
if (GST_BUFFER_PTS_IS_VALID (last_buf)) {
|
2013-02-15 00:34:34 +00:00
|
|
|
pad->first_ts = GST_BUFFER_PTS (last_buf);
|
2015-06-19 22:40:43 +00:00
|
|
|
} else if (GST_BUFFER_DTS_IS_VALID (last_buf)) {
|
|
|
|
pad->first_ts = GST_BUFFER_DTS (last_buf);
|
2013-09-14 13:56:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 01:22:09 +00:00
|
|
|
if (GST_BUFFER_DTS_IS_VALID (last_buf)) {
|
2015-06-23 21:54:31 +00:00
|
|
|
pad->first_dts = pad->last_dts = GST_BUFFER_DTS (last_buf);
|
2015-06-23 01:22:09 +00:00
|
|
|
} else if (GST_BUFFER_PTS_IS_VALID (last_buf)) {
|
2015-06-23 21:54:31 +00:00
|
|
|
pad->first_dts = pad->last_dts = GST_BUFFER_PTS (last_buf);
|
2015-06-23 01:22:09 +00:00
|
|
|
}
|
|
|
|
|
2013-09-14 13:56:04 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (pad->first_ts)) {
|
2013-03-14 00:08:03 +00:00
|
|
|
GST_DEBUG ("setting first_ts to %" G_GUINT64_FORMAT, pad->first_ts);
|
2011-09-09 12:12:56 +00:00
|
|
|
} else {
|
2015-04-07 03:53:35 +00:00
|
|
|
GST_WARNING_OBJECT (qtmux, "First buffer for pad %s has no timestamp, "
|
2019-12-03 14:30:06 +00:00
|
|
|
"using 0 as first timestamp", GST_PAD_NAME (pad));
|
2015-06-23 21:54:31 +00:00
|
|
|
pad->first_ts = pad->first_dts = 0;
|
2011-09-09 12:12:56 +00:00
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Stored first timestamp for pad %s %"
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_TIME_FORMAT, GST_PAD_NAME (pad), GST_TIME_ARGS (pad->first_ts));
|
2011-09-09 12:12:56 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 12:22:25 +00:00
|
|
|
if (buf && GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (buf)) &&
|
2013-03-14 00:08:03 +00:00
|
|
|
GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (last_buf)) &&
|
|
|
|
GST_BUFFER_DTS (buf) < GST_BUFFER_DTS (last_buf)) {
|
|
|
|
GST_ERROR ("decreasing DTS value %" GST_TIME_FORMAT " < %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (buf)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (last_buf)));
|
2017-04-12 11:26:59 +00:00
|
|
|
pad->last_buf = buf = gst_buffer_make_writable (buf);
|
2013-03-14 00:08:03 +00:00
|
|
|
GST_BUFFER_DTS (buf) = GST_BUFFER_DTS (last_buf);
|
|
|
|
}
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
buffer_size = gst_buffer_get_size (last_buf);
|
|
|
|
|
|
|
|
if (qtmux->mux_mode == GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL) {
|
|
|
|
guint required_buffer_size = prefill_get_sample_size (qtmux, pad);
|
|
|
|
guint fill_size = required_buffer_size - buffer_size;
|
|
|
|
GstMemory *mem;
|
|
|
|
GstMapInfo map;
|
|
|
|
|
|
|
|
if (required_buffer_size < buffer_size) {
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Sample size %u bigger than expected maximum %u", buffer_size,
|
|
|
|
required_buffer_size));
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2017-05-11 17:21:22 +00:00
|
|
|
if (fill_size > 0) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux,
|
|
|
|
"Padding buffer by %u bytes to reach required %u bytes", fill_size,
|
|
|
|
required_buffer_size);
|
|
|
|
mem = gst_allocator_alloc (NULL, fill_size, NULL);
|
|
|
|
gst_memory_map (mem, &map, GST_MAP_WRITE);
|
|
|
|
memset (map.data, 0, map.size);
|
|
|
|
gst_memory_unmap (mem, &map);
|
|
|
|
last_buf = gst_buffer_make_writable (last_buf);
|
|
|
|
gst_buffer_append_memory (last_buf, mem);
|
|
|
|
buffer_size = required_buffer_size;
|
|
|
|
}
|
2017-03-09 08:15:34 +00:00
|
|
|
}
|
|
|
|
|
2013-03-23 04:22:23 +00:00
|
|
|
/* duration actually means time delta between samples, so we calculate
|
|
|
|
* the duration based on the difference in DTS or PTS, falling back
|
|
|
|
* to DURATION if the other two don't exist, such as with the last
|
2016-11-22 14:18:41 +00:00
|
|
|
* sample before EOS. Or use 0 if nothing else is available */
|
|
|
|
if (GST_BUFFER_DURATION_IS_VALID (last_buf))
|
|
|
|
duration = GST_BUFFER_DURATION (last_buf);
|
|
|
|
else
|
|
|
|
duration = 0;
|
2014-02-07 04:49:26 +00:00
|
|
|
if (!pad->sparse) {
|
2017-04-04 12:22:25 +00:00
|
|
|
if (buf && GST_BUFFER_DTS_IS_VALID (buf)
|
2014-02-07 04:49:26 +00:00
|
|
|
&& GST_BUFFER_DTS_IS_VALID (last_buf))
|
|
|
|
duration = GST_BUFFER_DTS (buf) - GST_BUFFER_DTS (last_buf);
|
2017-04-04 12:22:25 +00:00
|
|
|
else if (buf && GST_BUFFER_PTS_IS_VALID (buf)
|
2014-02-07 04:49:26 +00:00
|
|
|
&& GST_BUFFER_PTS_IS_VALID (last_buf))
|
|
|
|
duration = GST_BUFFER_PTS (buf) - GST_BUFFER_PTS (last_buf);
|
|
|
|
}
|
|
|
|
|
2016-10-19 11:25:28 +00:00
|
|
|
if (qtmux->current_pad != pad || qtmux->current_chunk_offset == -1) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux,
|
|
|
|
"Switching to next chunk for pad %s:%s: offset %" G_GUINT64_FORMAT
|
|
|
|
", size %" G_GUINT64_FORMAT ", duration %" GST_TIME_FORMAT,
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad), qtmux->current_chunk_offset,
|
2016-10-19 11:25:28 +00:00
|
|
|
qtmux->current_chunk_size,
|
|
|
|
GST_TIME_ARGS (qtmux->current_chunk_duration));
|
|
|
|
qtmux->current_pad = pad;
|
|
|
|
if (qtmux->current_chunk_offset == -1)
|
|
|
|
qtmux->current_chunk_offset = qtmux->mdat_size;
|
|
|
|
else
|
|
|
|
qtmux->current_chunk_offset += qtmux->current_chunk_size;
|
|
|
|
qtmux->current_chunk_size = 0;
|
|
|
|
qtmux->current_chunk_duration = 0;
|
|
|
|
}
|
|
|
|
|
2009-11-26 00:41:27 +00:00
|
|
|
last_dts = gst_util_uint64_scale_round (pad->last_dts,
|
2008-11-08 02:00:58 +00:00
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND);
|
|
|
|
|
2010-11-15 14:17:59 +00:00
|
|
|
/* fragments only deal with 1 buffer == 1 chunk (== 1 sample) */
|
|
|
|
if (pad->sample_size && !qtmux->fragment_sequence) {
|
2017-03-29 11:01:25 +00:00
|
|
|
GstClockTime expected_timestamp;
|
|
|
|
|
2010-01-27 23:37:37 +00:00
|
|
|
/* Constant size packets: usually raw audio (with many samples per
|
|
|
|
buffer (= chunk)), but can also be fixed-packet-size codecs like ADPCM
|
|
|
|
*/
|
2008-11-08 02:00:58 +00:00
|
|
|
sample_size = pad->sample_size;
|
2017-03-09 08:15:34 +00:00
|
|
|
if (buffer_size % sample_size != 0)
|
2008-11-08 02:00:58 +00:00
|
|
|
goto fragmented_sample;
|
2017-03-29 11:01:25 +00:00
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* note: qt raw audio storage warps it implicitly into a timewise
|
2017-03-29 11:01:25 +00:00
|
|
|
* perfect stream, discarding buffer times.
|
|
|
|
* If the difference between the current PTS and the expected one
|
|
|
|
* becomes too big, we error out: there was a gap and we have no way to
|
|
|
|
* represent that, causing A/V sync to be off */
|
|
|
|
expected_timestamp =
|
|
|
|
gst_util_uint64_scale (pad->sample_offset, GST_SECOND,
|
|
|
|
atom_trak_get_timescale (pad->trak)) + pad->first_ts;
|
|
|
|
if (ABSDIFF (GST_BUFFER_DTS_OR_PTS (last_buf),
|
|
|
|
expected_timestamp) > qtmux->max_raw_audio_drift)
|
|
|
|
goto raw_audio_timestamp_drift;
|
|
|
|
|
2010-01-27 23:37:37 +00:00
|
|
|
if (GST_BUFFER_DURATION (last_buf) != GST_CLOCK_TIME_NONE) {
|
|
|
|
nsamples = gst_util_uint64_scale_round (GST_BUFFER_DURATION (last_buf),
|
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND);
|
2016-11-22 14:18:41 +00:00
|
|
|
duration = GST_BUFFER_DURATION (last_buf);
|
2010-01-27 23:37:37 +00:00
|
|
|
} else {
|
2017-03-09 08:15:34 +00:00
|
|
|
nsamples = buffer_size / sample_size;
|
2016-11-22 14:18:41 +00:00
|
|
|
duration =
|
|
|
|
gst_util_uint64_scale_round (nsamples, GST_SECOND,
|
|
|
|
atom_trak_get_timescale (pad->trak));
|
2010-01-27 23:37:37 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* timescale = samplerate */
|
|
|
|
scaled_duration = 1;
|
2017-03-29 11:01:25 +00:00
|
|
|
pad->last_dts =
|
|
|
|
pad->first_dts + gst_util_uint64_scale_round (pad->sample_offset +
|
|
|
|
nsamples, GST_SECOND, atom_trak_get_timescale (pad->trak));
|
2008-11-08 02:00:58 +00:00
|
|
|
} else {
|
|
|
|
nsamples = 1;
|
2017-03-09 08:15:34 +00:00
|
|
|
sample_size = buffer_size;
|
2017-07-01 16:59:14 +00:00
|
|
|
if (!pad->sparse && ((buf && GST_BUFFER_DTS_IS_VALID (buf))
|
|
|
|
|| GST_BUFFER_DTS_IS_VALID (last_buf))) {
|
2008-11-15 02:56:31 +00:00
|
|
|
gint64 scaled_dts;
|
2016-11-22 14:18:41 +00:00
|
|
|
if (buf && GST_BUFFER_DTS_IS_VALID (buf)) {
|
|
|
|
pad->last_dts = GST_BUFFER_DTS (buf);
|
2013-03-14 00:08:03 +00:00
|
|
|
} else {
|
2016-11-22 14:18:41 +00:00
|
|
|
pad->last_dts = GST_BUFFER_DTS (last_buf) + duration;
|
2013-03-14 00:08:03 +00:00
|
|
|
}
|
2008-11-15 02:56:31 +00:00
|
|
|
if ((gint64) (pad->last_dts) < 0) {
|
2009-11-26 00:41:27 +00:00
|
|
|
scaled_dts = -gst_util_uint64_scale_round (-pad->last_dts,
|
2008-11-15 02:56:31 +00:00
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND);
|
|
|
|
} else {
|
2009-11-26 00:41:27 +00:00
|
|
|
scaled_dts = gst_util_uint64_scale_round (pad->last_dts,
|
2008-11-15 02:56:31 +00:00
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND);
|
|
|
|
}
|
|
|
|
scaled_duration = scaled_dts - last_dts;
|
|
|
|
last_dts = scaled_dts;
|
|
|
|
} else {
|
|
|
|
/* first convert intended timestamp (in GstClockTime resolution) to
|
|
|
|
* trak timescale, then derive delta;
|
|
|
|
* this ensures sums of (scale)delta add up to converted timestamp,
|
|
|
|
* which only deviates at most 1/scale from timestamp itself */
|
2009-11-26 00:41:27 +00:00
|
|
|
scaled_duration = gst_util_uint64_scale_round (pad->last_dts + duration,
|
2008-11-15 02:56:31 +00:00
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND) - last_dts;
|
|
|
|
pad->last_dts += duration;
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
2016-10-19 11:25:28 +00:00
|
|
|
|
2017-07-01 16:59:07 +00:00
|
|
|
gst_qt_mux_register_buffer_in_chunk (qtmux, pad, buffer_size, duration);
|
2016-11-22 14:18:41 +00:00
|
|
|
|
2016-10-19 11:25:28 +00:00
|
|
|
chunk_offset = qtmux->current_chunk_offset;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux,
|
|
|
|
"Pad (%s) dts updated to %" GST_TIME_FORMAT,
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (pad), GST_TIME_ARGS (pad->last_dts));
|
2008-11-08 02:00:58 +00:00
|
|
|
GST_LOG_OBJECT (qtmux,
|
|
|
|
"Adding %d samples to track, duration: %" G_GUINT64_FORMAT
|
|
|
|
" size: %" G_GUINT32_FORMAT " chunk offset: %" G_GUINT64_FORMAT,
|
|
|
|
nsamples, scaled_duration, sample_size, chunk_offset);
|
|
|
|
|
|
|
|
/* might be a sync sample */
|
|
|
|
if (pad->sync &&
|
|
|
|
!GST_BUFFER_FLAG_IS_SET (last_buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
|
|
|
|
GST_LOG_OBJECT (qtmux, "Adding new sync sample entry for track of pad %s",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (pad));
|
2008-11-08 02:00:58 +00:00
|
|
|
sync = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-09-28 20:03:58 +00:00
|
|
|
if (GST_BUFFER_DTS_IS_VALID (last_buf)) {
|
2013-02-15 00:34:34 +00:00
|
|
|
last_dts = gst_util_uint64_scale_round (GST_BUFFER_DTS (last_buf),
|
2008-11-08 02:00:58 +00:00
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND);
|
2013-02-15 00:34:34 +00:00
|
|
|
pts_offset =
|
|
|
|
(gint64) (gst_util_uint64_scale_round (GST_BUFFER_PTS (last_buf),
|
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND) - last_dts);
|
|
|
|
} else {
|
|
|
|
pts_offset = 0;
|
|
|
|
last_dts = gst_util_uint64_scale_round (GST_BUFFER_PTS (last_buf),
|
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
2013-02-15 00:34:34 +00:00
|
|
|
GST_DEBUG ("dts: %" GST_TIME_FORMAT " pts: %" GST_TIME_FORMAT
|
|
|
|
" timebase_dts: %d pts_offset: %d",
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (last_buf)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (last_buf)),
|
|
|
|
(int) (last_dts), (int) (pts_offset));
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2016-10-19 11:25:28 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration)
|
|
|
|
&& (qtmux->current_chunk_duration > qtmux->longest_chunk
|
|
|
|
|| !GST_CLOCK_TIME_IS_VALID (qtmux->longest_chunk))) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux,
|
|
|
|
"New longest chunk found: %" GST_TIME_FORMAT ", pad %s",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_TIME_ARGS (qtmux->current_chunk_duration), GST_PAD_NAME (pad));
|
2016-10-19 11:25:28 +00:00
|
|
|
qtmux->longest_chunk = qtmux->current_chunk_duration;
|
2009-10-16 13:47:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
if (qtmux->mux_mode == GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL) {
|
|
|
|
const TrakBufferEntryInfo *sample_entry;
|
|
|
|
guint64 block_idx = prefill_get_block_index (qtmux, pad);
|
|
|
|
|
|
|
|
if (block_idx >= pad->samples->len) {
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Unexpected sample %" G_GUINT64_FORMAT ", expected up to %u",
|
|
|
|
block_idx, pad->samples->len));
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if all values are as expected */
|
|
|
|
sample_entry =
|
|
|
|
&g_array_index (pad->samples, TrakBufferEntryInfo, block_idx);
|
|
|
|
|
|
|
|
if (chunk_offset < sample_entry->chunk_offset) {
|
|
|
|
guint fill_size = sample_entry->chunk_offset - chunk_offset;
|
|
|
|
GstBuffer *fill_buf;
|
|
|
|
|
|
|
|
fill_buf = gst_buffer_new_allocate (NULL, fill_size, NULL);
|
|
|
|
gst_buffer_memset (fill_buf, 0, 0, fill_size);
|
|
|
|
|
|
|
|
ret = gst_qt_mux_send_buffer (qtmux, fill_buf, &qtmux->mdat_size, TRUE);
|
2017-05-10 09:12:23 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto bail;
|
2017-03-09 08:15:34 +00:00
|
|
|
qtmux->current_chunk_offset = chunk_offset = sample_entry->chunk_offset;
|
|
|
|
qtmux->current_chunk_size = buffer_size;
|
|
|
|
qtmux->current_chunk_duration = duration;
|
|
|
|
} else if (chunk_offset != sample_entry->chunk_offset) {
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Unexpected chunk offset %" G_GUINT64_FORMAT ", expected up to %"
|
|
|
|
G_GUINT64_FORMAT, chunk_offset, sample_entry->chunk_offset));
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* now we go and register this buffer/sample all over */
|
2019-07-30 10:07:18 +00:00
|
|
|
pad->flow_status = gst_qt_mux_register_and_push_sample (qtmux, pad, last_buf,
|
2014-02-07 04:49:26 +00:00
|
|
|
buf == NULL, nsamples, last_dts, scaled_duration, sample_size,
|
2015-04-07 19:12:40 +00:00
|
|
|
chunk_offset, sync, TRUE, pts_offset);
|
2019-07-30 10:07:18 +00:00
|
|
|
if (pad->flow_status != GST_FLOW_OK)
|
|
|
|
goto sample_error;
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
pad->sample_offset += nsamples;
|
2014-02-07 04:49:26 +00:00
|
|
|
|
|
|
|
/* if this is sparse and we have a next buffer, check if there is any gap
|
|
|
|
* between them to insert an empty sample */
|
|
|
|
if (pad->sparse && buf) {
|
|
|
|
if (pad->create_empty_buffer) {
|
|
|
|
GstBuffer *empty_buf;
|
|
|
|
gint64 empty_duration =
|
2016-11-22 14:42:55 +00:00
|
|
|
GST_BUFFER_PTS (buf) - (GST_BUFFER_PTS (last_buf) + duration);
|
2014-02-07 04:49:26 +00:00
|
|
|
gint64 empty_duration_scaled;
|
2017-07-01 16:59:07 +00:00
|
|
|
guint empty_size;
|
2014-02-07 04:49:26 +00:00
|
|
|
|
|
|
|
empty_buf = pad->create_empty_buffer (pad, empty_duration);
|
|
|
|
|
2017-07-01 16:59:14 +00:00
|
|
|
pad->last_dts = GST_BUFFER_PTS (buf);
|
|
|
|
empty_duration_scaled = gst_util_uint64_scale_round (pad->last_dts,
|
|
|
|
atom_trak_get_timescale (pad->trak), GST_SECOND)
|
|
|
|
- (last_dts + scaled_duration);
|
2017-07-01 16:59:07 +00:00
|
|
|
empty_size = gst_buffer_get_size (empty_buf);
|
2014-02-07 04:49:26 +00:00
|
|
|
|
2017-07-01 16:59:07 +00:00
|
|
|
gst_qt_mux_register_buffer_in_chunk (qtmux, pad, empty_size,
|
|
|
|
empty_duration);
|
2014-02-07 04:49:26 +00:00
|
|
|
|
|
|
|
ret =
|
|
|
|
gst_qt_mux_register_and_push_sample (qtmux, pad, empty_buf, FALSE, 1,
|
|
|
|
last_dts + scaled_duration, empty_duration_scaled,
|
2017-07-01 16:59:07 +00:00
|
|
|
empty_size, chunk_offset, sync, TRUE, 0);
|
2018-02-07 10:00:18 +00:00
|
|
|
} else if (pad->fourcc != FOURCC_c608 && pad->fourcc != FOURCC_c708) {
|
|
|
|
/* This assert is kept here to make sure implementors of new
|
|
|
|
* sparse input format decide whether there needs to be special
|
|
|
|
* gap handling or not */
|
2014-02-07 04:49:26 +00:00
|
|
|
g_assert_not_reached ();
|
|
|
|
GST_WARNING_OBJECT (qtmux,
|
|
|
|
"no empty buffer creation function found for pad %s",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (pad));
|
2009-12-12 19:07:15 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-04-15 10:34:05 +00:00
|
|
|
exit:
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-01-03 16:24:23 +00:00
|
|
|
return ret;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* ERRORS */
|
|
|
|
bail:
|
|
|
|
{
|
|
|
|
gst_buffer_unref (last_buf);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
fragmented_sample:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Audio buffer contains fragmented sample."));
|
|
|
|
goto bail;
|
|
|
|
}
|
2017-03-29 11:01:25 +00:00
|
|
|
raw_audio_timestamp_drift:
|
|
|
|
{
|
|
|
|
/* TODO: Could in theory be implemented with edit lists */
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
|
|
|
|
("Audio stream timestamps are drifting (got %" GST_TIME_FORMAT
|
|
|
|
", expected %" GST_TIME_FORMAT "). This is not supported yet!",
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS_OR_PTS (last_buf)),
|
|
|
|
GST_TIME_ARGS (gst_util_uint64_scale (pad->sample_offset,
|
|
|
|
GST_SECOND,
|
|
|
|
atom_trak_get_timescale (pad->trak)) + pad->first_ts)));
|
|
|
|
goto bail;
|
|
|
|
}
|
2016-09-28 20:03:58 +00:00
|
|
|
no_pts:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), ("Buffer has no PTS."));
|
|
|
|
goto bail;
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
not_negotiated:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, CORE, NEGOTIATION, (NULL),
|
|
|
|
("format wasn't negotiated before buffer flow on pad %s",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_PAD_NAME (pad)));
|
2009-11-06 03:46:12 +00:00
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
2008-11-08 02:00:58 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
2019-07-30 10:07:18 +00:00
|
|
|
sample_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), ("Failed to push sample."));
|
|
|
|
return pad->flow_status;
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2015-04-04 00:34:42 +00:00
|
|
|
/*
|
|
|
|
* DTS running time can be negative. There is no way to represent that in
|
|
|
|
* MP4 however, thus we need to offset DTS so that it starts from 0.
|
|
|
|
*/
|
|
|
|
static void
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_pad_adjust_buffer_dts (GstQTMux * qtmux, GstQTMuxPad * pad,
|
|
|
|
GstBuffer ** buf)
|
2015-04-04 00:34:42 +00:00
|
|
|
{
|
|
|
|
GstClockTime pts;
|
|
|
|
gint64 dts;
|
|
|
|
|
|
|
|
pts = GST_BUFFER_PTS (*buf);
|
2019-12-03 14:30:06 +00:00
|
|
|
dts = pad->dts;
|
2015-04-04 00:34:42 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux, "selected pad %s with PTS %" GST_TIME_FORMAT
|
2019-12-03 14:30:06 +00:00
|
|
|
" and DTS %" GST_STIME_FORMAT, GST_PAD_NAME (pad),
|
2015-04-04 00:34:42 +00:00
|
|
|
GST_TIME_ARGS (pts), GST_STIME_ARGS (dts));
|
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (pad->dts_adjustment)) {
|
|
|
|
if (GST_CLOCK_STIME_IS_VALID (dts) && dts < 0)
|
|
|
|
pad->dts_adjustment = -dts;
|
|
|
|
else
|
|
|
|
pad->dts_adjustment = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pad->dts_adjustment > 0) {
|
|
|
|
*buf = gst_buffer_make_writable (*buf);
|
|
|
|
|
|
|
|
dts += pad->dts_adjustment;
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (pts))
|
|
|
|
pts += pad->dts_adjustment;
|
|
|
|
|
|
|
|
if (GST_CLOCK_STIME_IS_VALID (dts) && dts < 0) {
|
|
|
|
GST_WARNING_OBJECT (pad, "Decreasing DTS.");
|
|
|
|
dts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pts < dts) {
|
|
|
|
GST_WARNING_OBJECT (pad, "DTS is bigger then PTS");
|
|
|
|
pts = dts;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_PTS (*buf) = pts;
|
|
|
|
GST_BUFFER_DTS (*buf) = dts;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (qtmux, "time adjusted to PTS %" GST_TIME_FORMAT
|
|
|
|
" and DTS %" GST_TIME_FORMAT, GST_TIME_ARGS (pts), GST_TIME_ARGS (dts));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
static GstQTMuxPad *
|
|
|
|
find_best_pad (GstQTMux * qtmux)
|
2016-10-19 11:25:28 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GList *l;
|
|
|
|
GstQTMuxPad *best_pad = NULL;
|
2016-10-19 11:25:28 +00:00
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
if (qtmux->mux_mode == GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL) {
|
|
|
|
guint64 smallest_offset = G_MAXUINT64;
|
|
|
|
guint64 chunk_offset = 0;
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2017-03-09 08:15:34 +00:00
|
|
|
const TrakBufferEntryInfo *sample_entry;
|
|
|
|
guint64 block_idx, current_block_idx;
|
|
|
|
guint64 chunk_offset_offset = 0;
|
|
|
|
GstBuffer *tmp_buf =
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_pad_peek_buffer (GST_AGGREGATOR_PAD (qtpad));
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
/* Check for EOS pads and just skip them */
|
|
|
|
if (!tmp_buf && !qtpad->last_buf && (!qtpad->raw_audio_adapter
|
|
|
|
|| gst_adapter_available (qtpad->raw_audio_adapter) == 0))
|
|
|
|
continue;
|
|
|
|
if (tmp_buf)
|
|
|
|
gst_buffer_unref (tmp_buf);
|
|
|
|
|
|
|
|
/* Find the exact offset where the next sample of this track is supposed
|
|
|
|
* to be written at */
|
|
|
|
block_idx = current_block_idx = prefill_get_block_index (qtmux, qtpad);
|
|
|
|
sample_entry =
|
|
|
|
&g_array_index (qtpad->samples, TrakBufferEntryInfo, block_idx);
|
|
|
|
while (block_idx > 0) {
|
|
|
|
const TrakBufferEntryInfo *tmp =
|
|
|
|
&g_array_index (qtpad->samples, TrakBufferEntryInfo, block_idx - 1);
|
|
|
|
|
|
|
|
if (tmp->chunk_offset != sample_entry->chunk_offset)
|
|
|
|
break;
|
|
|
|
chunk_offset_offset += tmp->size * tmp->nsamples;
|
|
|
|
block_idx--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Except for the previously selected pad being EOS we always have
|
|
|
|
* qtmux->current_chunk_offset + qtmux->current_chunk_size
|
|
|
|
* ==
|
|
|
|
* sample_entry->chunk_offset + chunk_offset_offset
|
|
|
|
* for the best pad. Instead of checking that, we just return the
|
|
|
|
* pad that has the smallest offset for the next to-be-written sample.
|
|
|
|
*/
|
|
|
|
if (sample_entry->chunk_offset + chunk_offset_offset < smallest_offset) {
|
|
|
|
smallest_offset = sample_entry->chunk_offset + chunk_offset_offset;
|
|
|
|
best_pad = qtpad;
|
|
|
|
chunk_offset = sample_entry->chunk_offset;
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
if (chunk_offset != qtmux->current_chunk_offset) {
|
|
|
|
qtmux->current_pad = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return best_pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qtmux->current_pad && (qtmux->interleave_bytes != 0
|
|
|
|
|| qtmux->interleave_time != 0) && (qtmux->interleave_bytes == 0
|
2016-10-19 11:25:28 +00:00
|
|
|
|| qtmux->current_chunk_size <= qtmux->interleave_bytes)
|
|
|
|
&& (qtmux->interleave_time == 0
|
|
|
|
|| qtmux->current_chunk_duration <= qtmux->interleave_time)
|
|
|
|
&& qtmux->mux_mode != GST_QT_MUX_MODE_FRAGMENTED
|
|
|
|
&& qtmux->mux_mode != GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE) {
|
|
|
|
GstBuffer *tmp_buf =
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_aggregator_pad_peek_buffer (GST_AGGREGATOR_PAD
|
|
|
|
(qtmux->current_pad));
|
2016-10-19 11:25:28 +00:00
|
|
|
|
|
|
|
if (tmp_buf || qtmux->current_pad->last_buf) {
|
|
|
|
best_pad = qtmux->current_pad;
|
|
|
|
if (tmp_buf)
|
|
|
|
gst_buffer_unref (tmp_buf);
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Reusing pad %s:%s",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_PAD_NAME (best_pad));
|
2016-10-19 11:25:28 +00:00
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
} else {
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
if (GST_ELEMENT (qtmux)->sinkpads->next) {
|
|
|
|
/* Only switch pads if we have more than one, otherwise
|
|
|
|
* we can just put everything into a single chunk and save
|
|
|
|
* a few bytes of offsets
|
|
|
|
*/
|
|
|
|
if (qtmux->current_pad)
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Switching from pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (qtmux->current_pad));
|
|
|
|
best_pad = qtmux->current_pad = NULL;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2016-10-19 11:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!best_pad) {
|
|
|
|
GstClockTime best_time = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (qtmux)->sinkpads; l; l = l->next) {
|
|
|
|
GstQTMuxPad *qtpad = (GstQTMuxPad *) l->data;
|
2016-10-19 11:25:28 +00:00
|
|
|
GstBuffer *tmp_buf;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
tmp_buf = gst_aggregator_pad_peek_buffer (GST_AGGREGATOR_PAD (qtpad));;
|
2016-10-19 11:25:28 +00:00
|
|
|
if (!tmp_buf) {
|
|
|
|
/* This one is newly EOS now, finish it for real */
|
|
|
|
if (qtpad->last_buf) {
|
|
|
|
timestamp = GST_BUFFER_DTS_OR_PTS (qtpad->last_buf);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2017-04-04 12:08:33 +00:00
|
|
|
if (qtpad->last_buf)
|
|
|
|
timestamp = GST_BUFFER_DTS_OR_PTS (qtpad->last_buf);
|
|
|
|
else
|
|
|
|
timestamp = GST_BUFFER_DTS_OR_PTS (tmp_buf);
|
2016-10-19 11:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (best_pad == NULL ||
|
|
|
|
!GST_CLOCK_TIME_IS_VALID (best_time) || timestamp < best_time) {
|
|
|
|
best_pad = qtpad;
|
|
|
|
best_time = timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp_buf)
|
|
|
|
gst_buffer_unref (tmp_buf);
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2016-10-19 11:25:28 +00:00
|
|
|
|
2016-11-02 12:33:28 +00:00
|
|
|
if (best_pad) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Choosing pad %s:%s",
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_PAD_NAME (best_pad));
|
2016-11-02 12:33:28 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "No best pad: EOS");
|
|
|
|
}
|
2016-10-19 11:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return best_pad;
|
|
|
|
}
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
static gboolean
|
|
|
|
gst_qt_mux_are_all_pads_eos (GstQTMux * mux)
|
|
|
|
{
|
|
|
|
GList *l;
|
2019-12-12 19:20:35 +00:00
|
|
|
gboolean ret = TRUE;
|
2019-12-03 14:30:06 +00:00
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
2019-12-03 14:30:06 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
2019-12-12 19:20:35 +00:00
|
|
|
if (!gst_aggregator_pad_is_eos (GST_AGGREGATOR_PAD (l->data))) {
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2019-12-03 14:30:06 +00:00
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
|
|
|
|
|
|
|
return ret;
|
2019-12-03 14:30:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static GstFlowReturn
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_aggregate (GstAggregator * agg, gboolean timeout)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2019-12-03 14:30:06 +00:00
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (agg);
|
|
|
|
GstQTMuxPad *best_pad = NULL;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (qtmux->state == GST_QT_MUX_STATE_STARTED)) {
|
|
|
|
if ((ret = gst_qt_mux_start_file (qtmux)) != GST_FLOW_OK)
|
|
|
|
return ret;
|
2015-04-01 00:15:38 +00:00
|
|
|
|
|
|
|
qtmux->state = GST_QT_MUX_STATE_DATA;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (qtmux->state == GST_QT_MUX_STATE_EOS))
|
2012-01-03 14:26:21 +00:00
|
|
|
return GST_FLOW_EOS;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
best_pad = find_best_pad (qtmux);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-12-16 17:03:01 +00:00
|
|
|
/* clipping already converted to running time */
|
2008-11-08 02:00:58 +00:00
|
|
|
if (best_pad != NULL) {
|
2017-03-09 08:15:34 +00:00
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
|
2019-07-30 10:07:18 +00:00
|
|
|
/* FIXME: the function should always return flow_status information, that
|
|
|
|
* is supposed to be stored each time buffers (collected from the pads)
|
|
|
|
* are pushed. */
|
|
|
|
if (best_pad->flow_status != GST_FLOW_OK)
|
|
|
|
return best_pad->flow_status;
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
if (qtmux->mux_mode != GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL ||
|
|
|
|
best_pad->raw_audio_adapter == NULL ||
|
|
|
|
best_pad->raw_audio_adapter_pts == GST_CLOCK_TIME_NONE)
|
2019-12-03 14:30:06 +00:00
|
|
|
buf = gst_aggregator_pad_pop_buffer (GST_AGGREGATOR_PAD (best_pad));
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
g_assert (buf || best_pad->last_buf || (best_pad->raw_audio_adapter
|
|
|
|
&& gst_adapter_available (best_pad->raw_audio_adapter) > 0));
|
2016-10-19 11:25:28 +00:00
|
|
|
|
|
|
|
if (buf)
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_pad_adjust_buffer_dts (qtmux, best_pad, &buf);
|
2016-10-19 11:25:28 +00:00
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
ret = gst_qt_mux_add_buffer (qtmux, best_pad, buf);
|
2019-12-03 14:30:06 +00:00
|
|
|
} else if (gst_qt_mux_are_all_pads_eos (qtmux)) {
|
|
|
|
|
2015-04-02 13:57:20 +00:00
|
|
|
qtmux->state = GST_QT_MUX_STATE_EOS;
|
|
|
|
ret = gst_qt_mux_stop_file (qtmux);
|
2008-11-08 02:00:58 +00:00
|
|
|
if (ret == GST_FLOW_OK) {
|
2019-12-03 14:30:06 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "We are eos");
|
2012-01-03 14:26:21 +00:00
|
|
|
ret = GST_FLOW_EOS;
|
2010-09-15 20:54:49 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Failed to stop file: %s",
|
|
|
|
gst_flow_get_name (ret));
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-14 02:33:51 +00:00
|
|
|
static gboolean
|
|
|
|
check_field (GQuark field_id, const GValue * value, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstStructure *structure = (GstStructure *) user_data;
|
|
|
|
const GValue *other = gst_structure_id_get_value (structure, field_id);
|
|
|
|
if (other == NULL)
|
|
|
|
return FALSE;
|
|
|
|
return gst_value_compare (value, other) == GST_VALUE_EQUAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_qtmux_caps_is_subset_full (GstQTMux * qtmux, GstCaps * subset,
|
|
|
|
GstCaps * superset)
|
|
|
|
{
|
|
|
|
GstStructure *sub_s = gst_caps_get_structure (subset, 0);
|
|
|
|
GstStructure *sup_s = gst_caps_get_structure (superset, 0);
|
|
|
|
|
|
|
|
return gst_structure_foreach (sub_s, check_field, sup_s);
|
|
|
|
}
|
|
|
|
|
2018-04-13 20:49:43 +00:00
|
|
|
/* will unref @qtmux */
|
2018-02-06 13:36:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_qt_mux_can_renegotiate (GstQTMux * qtmux, GstPad * pad, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstCaps *current_caps;
|
|
|
|
|
|
|
|
/* does not go well to renegotiate stream mid-way, unless
|
|
|
|
* the old caps are a subset of the new one (this means upstream
|
|
|
|
* added more info to the caps, as both should be 'fixed' caps) */
|
|
|
|
current_caps = gst_pad_get_current_caps (pad);
|
|
|
|
g_assert (caps != NULL);
|
|
|
|
|
|
|
|
if (!gst_qtmux_caps_is_subset_full (qtmux, current_caps, caps)) {
|
|
|
|
gst_caps_unref (current_caps);
|
|
|
|
GST_WARNING_OBJECT (qtmux,
|
|
|
|
"pad %s refused renegotiation to %" GST_PTR_FORMAT,
|
|
|
|
GST_PAD_NAME (pad), caps);
|
|
|
|
gst_object_unref (qtmux);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux,
|
|
|
|
"pad %s accepted renegotiation to %" GST_PTR_FORMAT " from %"
|
|
|
|
GST_PTR_FORMAT, GST_PAD_NAME (pad), caps, current_caps);
|
2018-04-13 20:49:43 +00:00
|
|
|
gst_object_unref (qtmux);
|
2018-02-06 13:36:50 +00:00
|
|
|
gst_caps_unref (current_caps);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static gboolean
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_audio_sink_set_caps (GstQTMuxPad * qtpad, GstCaps * caps)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstPad *pad = GST_PAD (qtpad);
|
2008-11-08 02:00:58 +00:00
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad));
|
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
|
|
|
GstStructure *structure;
|
|
|
|
const gchar *mimetype;
|
|
|
|
gint rate, channels;
|
|
|
|
const GValue *value = NULL;
|
|
|
|
const GstBuffer *codec_data = NULL;
|
|
|
|
GstQTMuxFormat format;
|
|
|
|
AudioSampleEntry entry = { 0, };
|
|
|
|
AtomInfo *ext_atom = NULL;
|
|
|
|
gint constant_size = 0;
|
2010-01-11 13:34:32 +00:00
|
|
|
const gchar *stream_format;
|
2018-01-18 16:36:27 +00:00
|
|
|
guint32 timescale;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2018-02-06 13:36:50 +00:00
|
|
|
if (qtpad->fourcc)
|
|
|
|
return gst_qt_mux_can_renegotiate (qtmux, pad, caps);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT,
|
|
|
|
GST_DEBUG_PAD_NAME (pad), caps);
|
|
|
|
|
2017-05-11 18:01:15 +00:00
|
|
|
qtpad->prepare_buf_func = NULL;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
format = qtmux_klass->format;
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
mimetype = gst_structure_get_name (structure);
|
|
|
|
|
|
|
|
/* common info */
|
|
|
|
if (!gst_structure_get_int (structure, "channels", &channels) ||
|
|
|
|
!gst_structure_get_int (structure, "rate", &rate)) {
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* optional */
|
|
|
|
value = gst_structure_get_value (structure, "codec_data");
|
|
|
|
if (value != NULL)
|
|
|
|
codec_data = gst_value_get_buffer (value);
|
|
|
|
|
|
|
|
qtpad->is_out_of_order = FALSE;
|
|
|
|
|
|
|
|
/* set common properties */
|
|
|
|
entry.sample_rate = rate;
|
|
|
|
entry.channels = channels;
|
|
|
|
/* default */
|
|
|
|
entry.sample_size = 16;
|
|
|
|
/* this is the typical compressed case */
|
|
|
|
if (format == GST_QT_MUX_FORMAT_QT) {
|
|
|
|
entry.version = 1;
|
|
|
|
entry.compression_id = -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now map onto a fourcc, and some extra properties */
|
|
|
|
if (strcmp (mimetype, "audio/mpeg") == 0) {
|
2016-04-28 13:24:52 +00:00
|
|
|
gint mpegversion = 0, mpegaudioversion = 0;
|
2008-11-08 02:00:58 +00:00
|
|
|
gint layer = -1;
|
|
|
|
|
|
|
|
gst_structure_get_int (structure, "mpegversion", &mpegversion);
|
|
|
|
switch (mpegversion) {
|
|
|
|
case 1:
|
|
|
|
gst_structure_get_int (structure, "layer", &layer);
|
2016-04-28 13:24:52 +00:00
|
|
|
gst_structure_get_int (structure, "mpegaudioversion",
|
|
|
|
&mpegaudioversion);
|
|
|
|
|
|
|
|
/* mp1/2/3 */
|
|
|
|
/* note: QuickTime player does not like mp3 either way in iso/mp4 */
|
|
|
|
if (format == GST_QT_MUX_FORMAT_QT)
|
|
|
|
entry.fourcc = FOURCC__mp3;
|
|
|
|
else {
|
|
|
|
entry.fourcc = FOURCC_mp4a;
|
|
|
|
ext_atom =
|
|
|
|
build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG1_P3,
|
|
|
|
ESDS_STREAM_TYPE_AUDIO, codec_data, qtpad->avg_bitrate,
|
|
|
|
qtpad->max_bitrate);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
2016-04-28 13:24:52 +00:00
|
|
|
if (layer == 1) {
|
2017-09-06 13:55:38 +00:00
|
|
|
g_warn_if_fail (format == GST_QT_MUX_FORMAT_MP4
|
|
|
|
|| format == GST_QT_MUX_FORMAT_QT);
|
2016-04-28 13:24:52 +00:00
|
|
|
entry.samples_per_packet = 384;
|
|
|
|
} else if (layer == 2) {
|
2017-09-06 13:55:38 +00:00
|
|
|
g_warn_if_fail (format == GST_QT_MUX_FORMAT_MP4
|
|
|
|
|| format == GST_QT_MUX_FORMAT_QT);
|
2016-04-28 13:24:52 +00:00
|
|
|
entry.samples_per_packet = 1152;
|
|
|
|
} else {
|
|
|
|
g_warn_if_fail (layer == 3);
|
|
|
|
entry.samples_per_packet = (mpegaudioversion <= 1) ? 1152 : 576;
|
|
|
|
}
|
|
|
|
entry.bytes_per_sample = 2;
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2010-01-11 13:34:32 +00:00
|
|
|
|
|
|
|
/* check stream-format */
|
|
|
|
stream_format = gst_structure_get_string (structure, "stream-format");
|
|
|
|
if (stream_format) {
|
2010-01-11 16:13:41 +00:00
|
|
|
if (strcmp (stream_format, "raw") != 0) {
|
2010-01-11 13:34:32 +00:00
|
|
|
GST_WARNING_OBJECT (qtmux, "Unsupported AAC stream-format %s, "
|
2010-01-11 16:13:41 +00:00
|
|
|
"please use 'raw'", stream_format);
|
2010-01-11 13:34:32 +00:00
|
|
|
goto refuse_caps;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "No stream-format present in caps, "
|
2010-01-11 16:13:41 +00:00
|
|
|
"assuming 'raw'");
|
2010-01-11 13:34:32 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 12:54:13 +00:00
|
|
|
if (!codec_data || gst_buffer_get_size ((GstBuffer *) codec_data) < 2) {
|
2008-11-08 02:00:58 +00:00
|
|
|
GST_WARNING_OBJECT (qtmux, "no (valid) codec_data for AAC audio");
|
2016-07-04 12:54:13 +00:00
|
|
|
goto refuse_caps;
|
|
|
|
} else {
|
2011-06-29 10:46:20 +00:00
|
|
|
guint8 profile;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-06-29 10:46:20 +00:00
|
|
|
gst_buffer_extract ((GstBuffer *) codec_data, 0, &profile, 1);
|
2008-11-08 02:00:58 +00:00
|
|
|
/* warn if not Low Complexity profile */
|
|
|
|
profile >>= 3;
|
|
|
|
if (profile != 2)
|
|
|
|
GST_WARNING_OBJECT (qtmux,
|
|
|
|
"non-LC AAC may not run well on (Apple) QuickTime/iTunes");
|
|
|
|
}
|
2010-01-11 13:34:32 +00:00
|
|
|
|
|
|
|
/* AAC */
|
|
|
|
entry.fourcc = FOURCC_mp4a;
|
|
|
|
|
2008-11-14 20:17:10 +00:00
|
|
|
if (format == GST_QT_MUX_FORMAT_QT)
|
2010-07-05 08:39:50 +00:00
|
|
|
ext_atom = build_mov_aac_extension (qtpad->trak, codec_data,
|
|
|
|
qtpad->avg_bitrate, qtpad->max_bitrate);
|
2008-11-14 20:17:10 +00:00
|
|
|
else
|
|
|
|
ext_atom =
|
|
|
|
build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG4_P3,
|
2010-07-05 08:39:50 +00:00
|
|
|
ESDS_STREAM_TYPE_AUDIO, codec_data, qtpad->avg_bitrate,
|
|
|
|
qtpad->max_bitrate);
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (strcmp (mimetype, "audio/AMR") == 0) {
|
|
|
|
entry.fourcc = FOURCC_samr;
|
|
|
|
entry.sample_size = 16;
|
|
|
|
entry.samples_per_packet = 160;
|
|
|
|
entry.bytes_per_sample = 2;
|
2009-01-28 12:25:14 +00:00
|
|
|
ext_atom = build_amr_extension ();
|
|
|
|
} else if (strcmp (mimetype, "audio/AMR-WB") == 0) {
|
|
|
|
entry.fourcc = FOURCC_sawb;
|
|
|
|
entry.sample_size = 16;
|
|
|
|
entry.samples_per_packet = 320;
|
|
|
|
entry.bytes_per_sample = 2;
|
|
|
|
ext_atom = build_amr_extension ();
|
2012-01-04 10:29:26 +00:00
|
|
|
} else if (strcmp (mimetype, "audio/x-raw") == 0) {
|
|
|
|
GstAudioInfo info;
|
2009-08-04 10:58:35 +00:00
|
|
|
|
2012-01-04 10:29:26 +00:00
|
|
|
gst_audio_info_init (&info);
|
|
|
|
if (!gst_audio_info_from_caps (&info, caps))
|
2008-11-08 02:00:58 +00:00
|
|
|
goto refuse_caps;
|
|
|
|
|
|
|
|
/* spec has no place for a distinction in these */
|
2012-01-04 10:29:26 +00:00
|
|
|
if (info.finfo->width != info.finfo->depth) {
|
2008-11-08 02:00:58 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "width must be same as depth!");
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
|
|
|
|
2012-01-04 10:29:26 +00:00
|
|
|
if ((info.finfo->flags & GST_AUDIO_FORMAT_FLAG_SIGNED)) {
|
|
|
|
if (info.finfo->endianness == G_LITTLE_ENDIAN)
|
2008-11-08 02:00:58 +00:00
|
|
|
entry.fourcc = FOURCC_sowt;
|
2012-01-04 10:29:26 +00:00
|
|
|
else if (info.finfo->endianness == G_BIG_ENDIAN)
|
2008-11-08 02:00:58 +00:00
|
|
|
entry.fourcc = FOURCC_twos;
|
2015-10-11 11:06:26 +00:00
|
|
|
else
|
|
|
|
entry.fourcc = FOURCC_sowt;
|
2008-11-08 02:00:58 +00:00
|
|
|
/* maximum backward compatibility; only new version for > 16 bit */
|
2012-01-04 10:29:26 +00:00
|
|
|
if (info.finfo->depth <= 16)
|
2008-11-08 02:00:58 +00:00
|
|
|
entry.version = 0;
|
|
|
|
/* not compressed in any case */
|
|
|
|
entry.compression_id = 0;
|
|
|
|
/* QT spec says: max at 16 bit even if sample size were actually larger,
|
|
|
|
* however, most players (e.g. QuickTime!) seem to disagree, so ... */
|
2012-01-04 10:29:26 +00:00
|
|
|
entry.sample_size = info.finfo->depth;
|
|
|
|
entry.bytes_per_sample = info.finfo->depth / 8;
|
2008-11-08 02:00:58 +00:00
|
|
|
entry.samples_per_packet = 1;
|
2012-01-04 10:29:26 +00:00
|
|
|
entry.bytes_per_packet = info.finfo->depth / 8;
|
|
|
|
entry.bytes_per_frame = entry.bytes_per_packet * info.channels;
|
2008-11-08 02:00:58 +00:00
|
|
|
} else {
|
2012-01-04 10:29:26 +00:00
|
|
|
if (info.finfo->width == 8 && info.finfo->depth == 8) {
|
2008-11-08 02:00:58 +00:00
|
|
|
/* fall back to old 8-bit version */
|
|
|
|
entry.fourcc = FOURCC_raw_;
|
|
|
|
entry.version = 0;
|
|
|
|
entry.compression_id = 0;
|
|
|
|
entry.sample_size = 8;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "non 8-bit PCM must be signed");
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
|
|
|
}
|
2012-01-04 10:29:26 +00:00
|
|
|
constant_size = (info.finfo->depth / 8) * info.channels;
|
2008-11-08 02:00:58 +00:00
|
|
|
} else if (strcmp (mimetype, "audio/x-alaw") == 0) {
|
|
|
|
entry.fourcc = FOURCC_alaw;
|
|
|
|
entry.samples_per_packet = 1023;
|
|
|
|
entry.bytes_per_sample = 2;
|
|
|
|
} else if (strcmp (mimetype, "audio/x-mulaw") == 0) {
|
|
|
|
entry.fourcc = FOURCC_ulaw;
|
|
|
|
entry.samples_per_packet = 1023;
|
|
|
|
entry.bytes_per_sample = 2;
|
2009-12-09 01:55:56 +00:00
|
|
|
} else if (strcmp (mimetype, "audio/x-adpcm") == 0) {
|
|
|
|
gint blocksize;
|
|
|
|
if (!gst_structure_get_int (structure, "block_align", &blocksize)) {
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "broken caps, block_align missing");
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
2009-12-09 01:59:04 +00:00
|
|
|
/* Currently only supports WAV-style IMA ADPCM, for which the codec id is
|
|
|
|
0x11 */
|
2009-12-09 01:55:56 +00:00
|
|
|
entry.fourcc = MS_WAVE_FOURCC (0x11);
|
2009-12-09 01:59:04 +00:00
|
|
|
/* 4 byte header per channel (including one sample). 2 samples per byte
|
|
|
|
remaining. Simplifying gives the following (samples per block per
|
|
|
|
channel) */
|
2009-12-09 01:55:56 +00:00
|
|
|
entry.samples_per_packet = 2 * blocksize / channels - 7;
|
|
|
|
entry.bytes_per_sample = 2;
|
|
|
|
|
2010-01-27 23:37:37 +00:00
|
|
|
entry.bytes_per_frame = blocksize;
|
|
|
|
entry.bytes_per_packet = blocksize / channels;
|
|
|
|
/* ADPCM has constant size packets */
|
|
|
|
constant_size = 1;
|
|
|
|
/* TODO: I don't really understand why this helps, but it does! Constant
|
|
|
|
* size and compression_id of -2 seem to be incompatible, and other files
|
|
|
|
* in the wild use this too. */
|
|
|
|
entry.compression_id = -1;
|
|
|
|
|
2009-12-09 01:55:56 +00:00
|
|
|
ext_atom = build_ima_adpcm_extension (channels, rate, blocksize);
|
2010-02-16 15:24:12 +00:00
|
|
|
} else if (strcmp (mimetype, "audio/x-alac") == 0) {
|
|
|
|
GstBuffer *codec_config;
|
|
|
|
gint len;
|
2012-01-23 16:25:37 +00:00
|
|
|
GstMapInfo map;
|
2010-02-16 15:24:12 +00:00
|
|
|
|
|
|
|
entry.fourcc = FOURCC_alac;
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map ((GstBuffer *) codec_data, &map, GST_MAP_READ);
|
2010-02-16 15:24:12 +00:00
|
|
|
/* let's check if codec data already comes with 'alac' atom prefix */
|
2012-01-23 16:25:37 +00:00
|
|
|
if (!codec_data || (len = map.size) < 28) {
|
2010-02-16 15:24:12 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "broken caps, codec data missing");
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap ((GstBuffer *) codec_data, &map);
|
2010-02-16 15:24:12 +00:00
|
|
|
goto refuse_caps;
|
|
|
|
}
|
2012-01-23 16:25:37 +00:00
|
|
|
if (GST_READ_UINT32_LE (map.data + 4) == FOURCC_alac) {
|
2010-02-16 15:24:12 +00:00
|
|
|
len -= 8;
|
2011-06-29 10:46:20 +00:00
|
|
|
codec_config =
|
2014-12-25 21:32:40 +00:00
|
|
|
gst_buffer_copy_region ((GstBuffer *) codec_data,
|
|
|
|
GST_BUFFER_COPY_MEMORY, 8, len);
|
2010-02-16 15:24:12 +00:00
|
|
|
} else {
|
|
|
|
codec_config = gst_buffer_ref ((GstBuffer *) codec_data);
|
|
|
|
}
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_unmap ((GstBuffer *) codec_data, &map);
|
2010-02-16 15:24:12 +00:00
|
|
|
if (len != 28) {
|
|
|
|
/* does not look good, but perhaps some trailing unneeded stuff */
|
|
|
|
GST_WARNING_OBJECT (qtmux, "unexpected codec-data size, possibly broken");
|
|
|
|
}
|
|
|
|
if (format == GST_QT_MUX_FORMAT_QT)
|
2015-12-10 17:41:46 +00:00
|
|
|
ext_atom = build_mov_alac_extension (codec_config);
|
2010-02-16 15:24:12 +00:00
|
|
|
else
|
|
|
|
ext_atom = build_codec_data_extension (FOURCC_alac, codec_config);
|
|
|
|
/* set some more info */
|
2012-01-23 16:25:37 +00:00
|
|
|
gst_buffer_map (codec_config, &map, GST_MAP_READ);
|
2010-02-16 15:24:12 +00:00
|
|
|
entry.bytes_per_sample = 2;
|
2012-01-23 16:25:37 +00:00
|
|
|
entry.samples_per_packet = GST_READ_UINT32_BE (map.data + 4);
|
|
|
|
gst_buffer_unmap (codec_config, &map);
|
2010-02-16 15:24:12 +00:00
|
|
|
gst_buffer_unref (codec_config);
|
2015-06-11 01:27:27 +00:00
|
|
|
} else if (strcmp (mimetype, "audio/x-ac3") == 0) {
|
|
|
|
entry.fourcc = FOURCC_ac_3;
|
|
|
|
|
|
|
|
/* Fixed values according to TS 102 366 but it also mentions that
|
|
|
|
* they should be ignored */
|
|
|
|
entry.channels = 2;
|
|
|
|
entry.sample_size = 16;
|
|
|
|
|
|
|
|
/* AC-3 needs an extension atom but its data can only be obtained from
|
|
|
|
* the stream itself. Abuse the prepare_buf_func so we parse a frame
|
|
|
|
* and get the needed data */
|
|
|
|
qtpad->prepare_buf_func = gst_qt_mux_prepare_parse_ac3_frame;
|
2015-11-16 13:26:50 +00:00
|
|
|
} else if (strcmp (mimetype, "audio/x-opus") == 0) {
|
|
|
|
/* Based on the specification defined in:
|
|
|
|
* https://www.opus-codec.org/docs/opus_in_isobmff.html */
|
|
|
|
guint8 channels, mapping_family, stream_count, coupled_count;
|
|
|
|
guint16 pre_skip;
|
|
|
|
gint16 output_gain;
|
|
|
|
guint32 rate;
|
|
|
|
guint8 channel_mapping[256];
|
|
|
|
const GValue *streamheader;
|
|
|
|
const GValue *first_element;
|
|
|
|
GstBuffer *header;
|
|
|
|
|
|
|
|
entry.fourcc = FOURCC_opus;
|
|
|
|
entry.sample_size = 16;
|
|
|
|
|
|
|
|
streamheader = gst_structure_get_value (structure, "streamheader");
|
|
|
|
if (streamheader && GST_VALUE_HOLDS_ARRAY (streamheader) &&
|
|
|
|
gst_value_array_get_size (streamheader) != 0) {
|
|
|
|
first_element = gst_value_array_get_value (streamheader, 0);
|
|
|
|
header = gst_value_get_buffer (first_element);
|
|
|
|
if (!gst_codec_utils_opus_parse_header (header, &rate, &channels,
|
|
|
|
&mapping_family, &stream_count, &coupled_count, channel_mapping,
|
|
|
|
&pre_skip, &output_gain)) {
|
|
|
|
GST_ERROR_OBJECT (qtmux, "Incomplete OpusHead");
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (qtmux,
|
|
|
|
"no streamheader field in caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
if (!gst_codec_utils_opus_parse_caps (caps, &rate, &channels,
|
|
|
|
&mapping_family, &stream_count, &coupled_count,
|
|
|
|
channel_mapping)) {
|
|
|
|
GST_ERROR_OBJECT (qtmux, "Incomplete Opus caps");
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
|
|
|
pre_skip = 0;
|
|
|
|
output_gain = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry.channels = channels;
|
|
|
|
ext_atom = build_opus_extension (rate, channels, mapping_family,
|
|
|
|
stream_count, coupled_count, channel_mapping, pre_skip, output_gain);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!entry.fourcc)
|
|
|
|
goto refuse_caps;
|
|
|
|
|
2018-01-18 16:36:27 +00:00
|
|
|
timescale = gst_qt_mux_pad_get_timescale (GST_QT_MUX_PAD_CAST (pad));
|
|
|
|
if (!timescale && qtmux->trak_timescale)
|
|
|
|
timescale = qtmux->trak_timescale;
|
|
|
|
else if (!timescale)
|
|
|
|
timescale = entry.sample_rate;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* ok, set the pad info accordingly */
|
|
|
|
qtpad->fourcc = entry.fourcc;
|
|
|
|
qtpad->sample_size = constant_size;
|
2015-06-11 01:27:27 +00:00
|
|
|
qtpad->trak_ste =
|
|
|
|
(SampleTableEntry *) atom_trak_set_audio_type (qtpad->trak,
|
2018-01-18 16:36:27 +00:00
|
|
|
qtmux->context, &entry, timescale, ext_atom, constant_size);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
gst_object_unref (qtmux);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
refuse_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT,
|
|
|
|
GST_PAD_NAME (pad), caps);
|
|
|
|
gst_object_unref (qtmux);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_video_sink_set_caps (GstQTMuxPad * qtpad, GstCaps * caps)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstPad *pad = GST_PAD (qtpad);
|
2008-11-08 02:00:58 +00:00
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad));
|
|
|
|
GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
|
|
|
GstStructure *structure;
|
|
|
|
const gchar *mimetype;
|
|
|
|
gint width, height, depth = -1;
|
|
|
|
gint framerate_num, framerate_den;
|
|
|
|
guint32 rate;
|
|
|
|
const GValue *value = NULL;
|
|
|
|
const GstBuffer *codec_data = NULL;
|
|
|
|
VisualSampleEntry entry = { 0, };
|
|
|
|
GstQTMuxFormat format;
|
|
|
|
AtomInfo *ext_atom = NULL;
|
2009-10-29 11:36:02 +00:00
|
|
|
GList *ext_atom_list = NULL;
|
2008-11-08 02:00:58 +00:00
|
|
|
gboolean sync = FALSE;
|
2008-11-18 01:09:09 +00:00
|
|
|
int par_num, par_den;
|
2018-02-02 11:51:49 +00:00
|
|
|
const gchar *multiview_mode;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2018-02-06 13:36:50 +00:00
|
|
|
if (qtpad->fourcc)
|
|
|
|
return gst_qt_mux_can_renegotiate (qtmux, pad, caps);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT,
|
|
|
|
GST_DEBUG_PAD_NAME (pad), caps);
|
|
|
|
|
2017-05-11 18:01:15 +00:00
|
|
|
qtpad->prepare_buf_func = NULL;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
format = qtmux_klass->format;
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
mimetype = gst_structure_get_name (structure);
|
|
|
|
|
|
|
|
/* required parts */
|
|
|
|
if (!gst_structure_get_int (structure, "width", &width) ||
|
2008-11-14 20:17:10 +00:00
|
|
|
!gst_structure_get_int (structure, "height", &height))
|
2008-11-08 02:00:58 +00:00
|
|
|
goto refuse_caps;
|
|
|
|
|
|
|
|
/* optional */
|
2008-11-14 20:17:10 +00:00
|
|
|
depth = -1;
|
|
|
|
/* works as a default timebase */
|
|
|
|
framerate_num = 10000;
|
|
|
|
framerate_den = 1;
|
|
|
|
gst_structure_get_fraction (structure, "framerate", &framerate_num,
|
|
|
|
&framerate_den);
|
2008-11-08 02:00:58 +00:00
|
|
|
gst_structure_get_int (structure, "depth", &depth);
|
|
|
|
value = gst_structure_get_value (structure, "codec_data");
|
|
|
|
if (value != NULL)
|
|
|
|
codec_data = gst_value_get_buffer (value);
|
|
|
|
|
2008-11-18 01:09:09 +00:00
|
|
|
par_num = 1;
|
|
|
|
par_den = 1;
|
|
|
|
gst_structure_get_fraction (structure, "pixel-aspect-ratio", &par_num,
|
|
|
|
&par_den);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
qtpad->is_out_of_order = FALSE;
|
|
|
|
|
|
|
|
/* bring frame numerator into a range that ensures both reasonable resolution
|
|
|
|
* as well as a fair duration */
|
2017-03-09 08:15:34 +00:00
|
|
|
qtpad->expected_sample_duration_n = framerate_num;
|
|
|
|
qtpad->expected_sample_duration_d = framerate_den;
|
2018-01-18 16:36:27 +00:00
|
|
|
|
|
|
|
rate = gst_qt_mux_pad_get_timescale (GST_QT_MUX_PAD_CAST (pad));
|
|
|
|
if (!rate && qtmux->trak_timescale)
|
|
|
|
rate = qtmux->trak_timescale;
|
|
|
|
else if (!rate)
|
|
|
|
rate = atom_framerate_to_timescale (framerate_num, framerate_den);
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Rate of video track selected: %" G_GUINT32_FORMAT,
|
|
|
|
rate);
|
|
|
|
|
2018-02-02 11:51:49 +00:00
|
|
|
multiview_mode = gst_structure_get_string (structure, "multiview-mode");
|
|
|
|
if (multiview_mode && !qtpad->trak->mdia.minf.stbl.svmi) {
|
|
|
|
GstVideoMultiviewMode mode;
|
|
|
|
GstVideoMultiviewFlags flags = 0;
|
|
|
|
|
|
|
|
mode = gst_video_multiview_mode_from_caps_string (multiview_mode);
|
2019-08-29 13:11:02 +00:00
|
|
|
gst_structure_get_flagset (structure,
|
|
|
|
"multiview-flags", (guint *) & flags, NULL);
|
2018-02-02 11:51:49 +00:00
|
|
|
switch (mode) {
|
2020-03-03 16:43:51 +00:00
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_MONO:
|
|
|
|
/* Nothing to do for mono, just don't warn about it */
|
|
|
|
break;
|
2018-02-02 11:51:49 +00:00
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE:
|
|
|
|
qtpad->trak->mdia.minf.stbl.svmi =
|
|
|
|
atom_svmi_new (0,
|
|
|
|
flags & GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED:
|
|
|
|
qtpad->trak->mdia.minf.stbl.svmi =
|
|
|
|
atom_svmi_new (1,
|
|
|
|
flags & GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME:
|
|
|
|
qtpad->trak->mdia.minf.stbl.svmi =
|
|
|
|
atom_svmi_new (2,
|
|
|
|
flags & GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "Unsupported multiview-mode %s",
|
|
|
|
multiview_mode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* set common properties */
|
|
|
|
entry.width = width;
|
|
|
|
entry.height = height;
|
2009-06-01 21:00:44 +00:00
|
|
|
entry.par_n = par_num;
|
|
|
|
entry.par_d = par_den;
|
2008-11-08 02:00:58 +00:00
|
|
|
/* should be OK according to qt and iso spec, override if really needed */
|
|
|
|
entry.color_table_id = -1;
|
|
|
|
entry.frame_count = 1;
|
|
|
|
entry.depth = 24;
|
|
|
|
|
|
|
|
/* sync entries by default */
|
|
|
|
sync = TRUE;
|
|
|
|
|
|
|
|
/* now map onto a fourcc, and some extra properties */
|
2011-06-29 10:46:20 +00:00
|
|
|
if (strcmp (mimetype, "video/x-raw") == 0) {
|
|
|
|
const gchar *format;
|
|
|
|
GstVideoFormat fmt;
|
2011-08-05 06:59:59 +00:00
|
|
|
const GstVideoFormatInfo *vinfo;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-06-29 10:46:20 +00:00
|
|
|
format = gst_structure_get_string (structure, "format");
|
|
|
|
fmt = gst_video_format_from_string (format);
|
2011-08-05 06:59:59 +00:00
|
|
|
vinfo = gst_video_format_get_info (fmt);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-06-29 10:46:20 +00:00
|
|
|
switch (fmt) {
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
2008-11-08 02:00:58 +00:00
|
|
|
if (depth == -1)
|
|
|
|
depth = 24;
|
|
|
|
entry.fourcc = FOURCC_2vuy;
|
|
|
|
entry.depth = depth;
|
2011-06-29 10:46:20 +00:00
|
|
|
sync = FALSE;
|
|
|
|
break;
|
2015-01-13 18:05:20 +00:00
|
|
|
case GST_VIDEO_FORMAT_v210:
|
|
|
|
if (depth == -1)
|
|
|
|
depth = 24;
|
|
|
|
entry.fourcc = FOURCC_v210;
|
|
|
|
entry.depth = depth;
|
|
|
|
sync = FALSE;
|
|
|
|
break;
|
2011-06-29 10:46:20 +00:00
|
|
|
default:
|
2011-08-05 06:59:59 +00:00
|
|
|
if (GST_VIDEO_FORMAT_INFO_FLAGS (vinfo) & GST_VIDEO_FORMAT_FLAG_RGB) {
|
2011-06-29 10:46:20 +00:00
|
|
|
entry.fourcc = FOURCC_raw_;
|
2011-08-05 06:59:59 +00:00
|
|
|
entry.depth = GST_VIDEO_FORMAT_INFO_PSTRIDE (vinfo, 0) * 8;
|
2011-06-29 10:46:20 +00:00
|
|
|
sync = FALSE;
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (strcmp (mimetype, "video/x-h263") == 0) {
|
2009-10-29 11:36:02 +00:00
|
|
|
ext_atom = NULL;
|
2009-05-28 11:56:10 +00:00
|
|
|
if (format == GST_QT_MUX_FORMAT_QT)
|
|
|
|
entry.fourcc = FOURCC_h263;
|
|
|
|
else
|
|
|
|
entry.fourcc = FOURCC_s263;
|
2009-01-28 12:25:14 +00:00
|
|
|
ext_atom = build_h263_extension ();
|
2009-10-29 11:36:02 +00:00
|
|
|
if (ext_atom != NULL)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
2008-11-08 02:00:58 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-divx") == 0 ||
|
|
|
|
strcmp (mimetype, "video/mpeg") == 0) {
|
|
|
|
gint version = 0;
|
|
|
|
|
|
|
|
if (strcmp (mimetype, "video/x-divx") == 0) {
|
|
|
|
gst_structure_get_int (structure, "divxversion", &version);
|
|
|
|
version = version == 5 ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
gst_structure_get_int (structure, "mpegversion", &version);
|
|
|
|
version = version == 4 ? 1 : 0;
|
|
|
|
}
|
|
|
|
if (version) {
|
|
|
|
entry.fourcc = FOURCC_mp4v;
|
2008-11-14 20:17:10 +00:00
|
|
|
ext_atom =
|
|
|
|
build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG4_P2,
|
2010-07-05 08:39:50 +00:00
|
|
|
ESDS_STREAM_TYPE_VISUAL, codec_data, qtpad->avg_bitrate,
|
|
|
|
qtpad->max_bitrate);
|
2009-10-29 11:36:02 +00:00
|
|
|
if (ext_atom != NULL)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
2008-11-08 02:00:58 +00:00
|
|
|
if (!codec_data)
|
|
|
|
GST_WARNING_OBJECT (qtmux, "no codec_data for MPEG4 video; "
|
|
|
|
"output might not play in Apple QuickTime (try global-headers?)");
|
|
|
|
}
|
|
|
|
} else if (strcmp (mimetype, "video/x-h264") == 0) {
|
2011-04-13 15:37:07 +00:00
|
|
|
if (!codec_data) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "no codec_data in h264 caps");
|
2011-04-16 17:17:01 +00:00
|
|
|
goto refuse_caps;
|
2011-04-13 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
entry.fourcc = FOURCC_avc1;
|
2017-01-12 16:45:35 +00:00
|
|
|
|
2010-07-06 09:18:08 +00:00
|
|
|
ext_atom = build_btrt_extension (0, qtpad->avg_bitrate, qtpad->max_bitrate);
|
|
|
|
if (ext_atom != NULL)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
2008-11-14 20:17:10 +00:00
|
|
|
ext_atom = build_codec_data_extension (FOURCC_avcC, codec_data);
|
2009-10-29 11:36:02 +00:00
|
|
|
if (ext_atom != NULL)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
2016-12-08 16:02:22 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-h265") == 0) {
|
|
|
|
const gchar *format;
|
|
|
|
|
|
|
|
if (!codec_data) {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "no codec_data in h265 caps");
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
format = gst_structure_get_string (structure, "stream-format");
|
|
|
|
if (strcmp (format, "hvc1") == 0)
|
|
|
|
entry.fourcc = FOURCC_hvc1;
|
|
|
|
else if (strcmp (format, "hev1") == 0)
|
|
|
|
entry.fourcc = FOURCC_hev1;
|
|
|
|
|
|
|
|
ext_atom = build_btrt_extension (0, qtpad->avg_bitrate, qtpad->max_bitrate);
|
|
|
|
if (ext_atom != NULL)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
|
|
|
|
|
|
|
ext_atom = build_codec_data_extension (FOURCC_hvcC, codec_data);
|
|
|
|
if (ext_atom != NULL)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
|
|
|
|
2009-10-29 11:36:02 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-svq") == 0) {
|
|
|
|
gint version = 0;
|
|
|
|
const GstBuffer *seqh = NULL;
|
|
|
|
const GValue *seqh_value;
|
|
|
|
gdouble gamma = 0;
|
|
|
|
|
|
|
|
gst_structure_get_int (structure, "svqversion", &version);
|
|
|
|
if (version == 3) {
|
|
|
|
entry.fourcc = FOURCC_SVQ3;
|
|
|
|
entry.version = 3;
|
|
|
|
entry.depth = 32;
|
|
|
|
|
|
|
|
seqh_value = gst_structure_get_value (structure, "seqh");
|
|
|
|
if (seqh_value) {
|
|
|
|
seqh = gst_value_get_buffer (seqh_value);
|
|
|
|
ext_atom = build_SMI_atom (seqh);
|
|
|
|
if (ext_atom)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need to add the gamma anyway because quicktime might crash
|
|
|
|
* when it doesn't find it */
|
|
|
|
if (!gst_structure_get_double (structure, "applied-gamma", &gamma)) {
|
|
|
|
/* it seems that using 0 here makes it ignored */
|
|
|
|
gamma = 0.0;
|
|
|
|
}
|
|
|
|
ext_atom = build_gama_atom (gamma);
|
|
|
|
if (ext_atom)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (qtmux, "SVQ version %d not supported. Please file "
|
|
|
|
"a bug at http://bugzilla.gnome.org", version);
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-dv") == 0) {
|
|
|
|
gint version = 0;
|
|
|
|
gboolean pal = TRUE;
|
|
|
|
|
|
|
|
sync = FALSE;
|
|
|
|
if (framerate_num != 25 || framerate_den != 1)
|
|
|
|
pal = FALSE;
|
|
|
|
gst_structure_get_int (structure, "dvversion", &version);
|
|
|
|
/* fall back to typical one */
|
|
|
|
if (!version)
|
|
|
|
version = 25;
|
|
|
|
switch (version) {
|
|
|
|
case 25:
|
|
|
|
if (pal)
|
2015-11-19 18:36:39 +00:00
|
|
|
entry.fourcc = FOURCC_dvcp;
|
2008-11-08 02:00:58 +00:00
|
|
|
else
|
2015-11-19 18:36:39 +00:00
|
|
|
entry.fourcc = FOURCC_dvc_;
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
|
|
|
case 50:
|
|
|
|
if (pal)
|
2015-11-19 18:36:39 +00:00
|
|
|
entry.fourcc = FOURCC_dv5p;
|
2008-11-08 02:00:58 +00:00
|
|
|
else
|
2015-11-19 18:36:39 +00:00
|
|
|
entry.fourcc = FOURCC_dv5n;
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING_OBJECT (qtmux, "unrecognized dv version");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (strcmp (mimetype, "image/jpeg") == 0) {
|
|
|
|
entry.fourcc = FOURCC_jpeg;
|
|
|
|
sync = FALSE;
|
2017-06-15 22:31:24 +00:00
|
|
|
} else if (strcmp (mimetype, "image/png") == 0) {
|
|
|
|
entry.fourcc = FOURCC_png;
|
|
|
|
sync = FALSE;
|
2009-12-11 01:20:45 +00:00
|
|
|
} else if (strcmp (mimetype, "image/x-j2c") == 0 ||
|
|
|
|
strcmp (mimetype, "image/x-jpc") == 0) {
|
2011-08-22 10:24:15 +00:00
|
|
|
const gchar *colorspace;
|
2009-12-11 01:20:45 +00:00
|
|
|
const GValue *cmap_array;
|
|
|
|
const GValue *cdef_array;
|
|
|
|
gint ncomp = 0;
|
|
|
|
|
|
|
|
if (strcmp (mimetype, "image/x-jpc") == 0) {
|
|
|
|
qtpad->prepare_buf_func = gst_qt_mux_prepare_jpc_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_structure_get_int (structure, "num-components", &ncomp);
|
|
|
|
cmap_array = gst_structure_get_value (structure, "component-map");
|
|
|
|
cdef_array = gst_structure_get_value (structure, "channel-definitions");
|
2008-11-14 20:17:10 +00:00
|
|
|
|
2009-10-29 11:36:02 +00:00
|
|
|
ext_atom = NULL;
|
2008-11-14 20:17:10 +00:00
|
|
|
entry.fourcc = FOURCC_mjp2;
|
|
|
|
sync = FALSE;
|
2011-08-22 10:24:15 +00:00
|
|
|
|
|
|
|
colorspace = gst_structure_get_string (structure, "colorspace");
|
|
|
|
if (colorspace &&
|
2009-12-11 01:20:45 +00:00
|
|
|
(ext_atom =
|
2015-12-10 17:41:46 +00:00
|
|
|
build_jp2h_extension (width, height, colorspace, ncomp, cmap_array,
|
|
|
|
cdef_array)) != NULL) {
|
2009-12-11 01:20:45 +00:00
|
|
|
ext_atom_list = g_list_append (ext_atom_list, ext_atom);
|
|
|
|
|
|
|
|
ext_atom = build_jp2x_extension (codec_data);
|
|
|
|
if (ext_atom)
|
|
|
|
ext_atom_list = g_list_append (ext_atom_list, ext_atom);
|
|
|
|
} else {
|
2008-11-14 20:17:10 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "missing or invalid fourcc in jp2 caps");
|
|
|
|
goto refuse_caps;
|
|
|
|
}
|
2010-05-13 01:50:34 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-vp8") == 0) {
|
2017-11-13 01:43:11 +00:00
|
|
|
entry.fourcc = FOURCC_vp08;
|
2017-11-13 01:38:06 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-vp9") == 0) {
|
|
|
|
entry.fourcc = FOURCC_vp09;
|
2011-07-07 00:18:05 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-dirac") == 0) {
|
|
|
|
entry.fourcc = FOURCC_drac;
|
2008-11-08 02:00:58 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-qt-part") == 0) {
|
2017-03-10 10:24:14 +00:00
|
|
|
guint32 fourcc = 0;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-08-22 10:24:15 +00:00
|
|
|
gst_structure_get_uint (structure, "format", &fourcc);
|
2008-11-08 02:00:58 +00:00
|
|
|
entry.fourcc = fourcc;
|
2008-11-15 02:56:31 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-mp4-part") == 0) {
|
2017-03-10 10:24:14 +00:00
|
|
|
guint32 fourcc = 0;
|
2008-11-15 02:56:31 +00:00
|
|
|
|
2011-08-22 10:24:15 +00:00
|
|
|
gst_structure_get_uint (structure, "format", &fourcc);
|
2008-11-15 02:56:31 +00:00
|
|
|
entry.fourcc = fourcc;
|
2015-10-11 08:18:40 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-prores") == 0) {
|
|
|
|
const gchar *variant;
|
|
|
|
|
2016-06-17 13:08:08 +00:00
|
|
|
variant = gst_structure_get_string (structure, "variant");
|
2015-10-11 08:18:40 +00:00
|
|
|
if (!variant || !g_strcmp0 (variant, "standard"))
|
2015-11-19 18:36:39 +00:00
|
|
|
entry.fourcc = FOURCC_apcn;
|
2015-10-11 08:18:40 +00:00
|
|
|
else if (!g_strcmp0 (variant, "lt"))
|
2015-11-19 18:36:39 +00:00
|
|
|
entry.fourcc = FOURCC_apcs;
|
2015-10-11 08:18:40 +00:00
|
|
|
else if (!g_strcmp0 (variant, "hq"))
|
2015-11-19 18:36:39 +00:00
|
|
|
entry.fourcc = FOURCC_apch;
|
2015-10-11 08:18:40 +00:00
|
|
|
else if (!g_strcmp0 (variant, "proxy"))
|
2016-07-12 16:14:52 +00:00
|
|
|
entry.fourcc = FOURCC_apco;
|
2016-09-30 15:05:38 +00:00
|
|
|
else if (!g_strcmp0 (variant, "4444"))
|
|
|
|
entry.fourcc = FOURCC_ap4h;
|
|
|
|
else if (!g_strcmp0 (variant, "4444xq"))
|
|
|
|
entry.fourcc = FOURCC_ap4x;
|
2016-10-19 11:33:33 +00:00
|
|
|
|
2017-01-16 13:50:22 +00:00
|
|
|
sync = FALSE;
|
|
|
|
|
2016-10-19 11:33:33 +00:00
|
|
|
if (!qtmux->interleave_time_set)
|
|
|
|
qtmux->interleave_time = 500 * GST_MSECOND;
|
|
|
|
if (!qtmux->interleave_bytes_set)
|
|
|
|
qtmux->interleave_bytes = width > 720 ? 4 * 1024 * 1024 : 2 * 1024 * 1024;
|
2017-03-14 09:10:19 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-cineform") == 0) {
|
|
|
|
entry.fourcc = FOURCC_cfhd;
|
|
|
|
sync = FALSE;
|
2018-07-25 22:37:48 +00:00
|
|
|
} else if (strcmp (mimetype, "video/x-av1") == 0) {
|
|
|
|
gint presentation_delay;
|
|
|
|
guint8 presentation_delay_byte = 0;
|
|
|
|
GstBuffer *av1_codec_data;
|
|
|
|
|
|
|
|
if (gst_structure_get_int (structure, "presentation-delay",
|
|
|
|
&presentation_delay)) {
|
|
|
|
presentation_delay_byte = 1 << 5;
|
|
|
|
presentation_delay_byte |= MAX (0xF, presentation_delay & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
av1_codec_data = gst_buffer_new_allocate (NULL, 5, NULL);
|
|
|
|
/* Fill version and 3 bytes of flags to 0 */
|
|
|
|
gst_buffer_memset (av1_codec_data, 0, 0, 4);
|
|
|
|
gst_buffer_fill (av1_codec_data, 4, &presentation_delay_byte, 1);
|
|
|
|
if (codec_data)
|
|
|
|
av1_codec_data = gst_buffer_append (av1_codec_data,
|
|
|
|
gst_buffer_ref ((GstBuffer *) codec_data));
|
|
|
|
|
|
|
|
entry.fourcc = FOURCC_av01;
|
|
|
|
|
|
|
|
ext_atom = build_btrt_extension (0, qtpad->avg_bitrate, qtpad->max_bitrate);
|
|
|
|
if (ext_atom != NULL)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
|
|
|
ext_atom = build_codec_data_extension (FOURCC_av1C, av1_codec_data);
|
|
|
|
if (ext_atom != NULL)
|
|
|
|
ext_atom_list = g_list_prepend (ext_atom_list, ext_atom);
|
|
|
|
gst_buffer_unref (av1_codec_data);
|
2016-09-29 18:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!entry.fourcc)
|
|
|
|
goto refuse_caps;
|
|
|
|
|
|
|
|
if (qtmux_klass->format == GST_QT_MUX_FORMAT_QT ||
|
|
|
|
qtmux_klass->format == GST_QT_MUX_FORMAT_MP4) {
|
|
|
|
const gchar *s;
|
|
|
|
GstVideoColorimetry colorimetry;
|
2016-07-11 16:30:12 +00:00
|
|
|
|
2016-09-29 18:56:18 +00:00
|
|
|
s = gst_structure_get_string (structure, "colorimetry");
|
|
|
|
if (s && gst_video_colorimetry_from_string (&colorimetry, s)) {
|
|
|
|
ext_atom =
|
|
|
|
build_colr_extension (&colorimetry,
|
|
|
|
qtmux_klass->format == GST_QT_MUX_FORMAT_MP4);
|
2016-07-11 16:30:12 +00:00
|
|
|
if (ext_atom)
|
|
|
|
ext_atom_list = g_list_append (ext_atom_list, ext_atom);
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2016-09-29 15:16:18 +00:00
|
|
|
if (qtmux_klass->format == GST_QT_MUX_FORMAT_QT
|
|
|
|
|| strcmp (mimetype, "image/x-j2c") == 0
|
|
|
|
|| strcmp (mimetype, "image/x-jpc") == 0) {
|
|
|
|
const gchar *s;
|
|
|
|
GstVideoInterlaceMode interlace_mode;
|
|
|
|
GstVideoFieldOrder field_order;
|
|
|
|
gint fields = -1;
|
|
|
|
|
|
|
|
if (strcmp (mimetype, "image/x-j2c") == 0 ||
|
|
|
|
strcmp (mimetype, "image/x-jpc") == 0) {
|
|
|
|
|
|
|
|
fields = 1;
|
|
|
|
gst_structure_get_int (structure, "fields", &fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = gst_structure_get_string (structure, "interlace-mode");
|
|
|
|
if (s)
|
|
|
|
interlace_mode = gst_video_interlace_mode_from_string (s);
|
|
|
|
else
|
|
|
|
interlace_mode =
|
|
|
|
(fields <=
|
|
|
|
1) ? GST_VIDEO_INTERLACE_MODE_PROGRESSIVE :
|
|
|
|
GST_VIDEO_INTERLACE_MODE_MIXED;
|
|
|
|
|
|
|
|
field_order = GST_VIDEO_FIELD_ORDER_UNKNOWN;
|
|
|
|
if (interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED) {
|
|
|
|
s = gst_structure_get_string (structure, "field-order");
|
|
|
|
if (s)
|
|
|
|
field_order = gst_video_field_order_from_string (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
ext_atom = build_fiel_extension (interlace_mode, field_order);
|
|
|
|
if (ext_atom)
|
|
|
|
ext_atom_list = g_list_append (ext_atom_list, ext_atom);
|
|
|
|
}
|
|
|
|
|
2017-01-10 16:19:55 +00:00
|
|
|
|
2017-01-11 17:29:05 +00:00
|
|
|
if (qtmux_klass->format == GST_QT_MUX_FORMAT_QT &&
|
|
|
|
width > 640 && width <= 1052 && height >= 480 && height <= 576) {
|
2017-01-10 16:19:55 +00:00
|
|
|
/* The 'clap' extension is also defined for MP4 but inventing values in
|
2017-01-11 17:29:05 +00:00
|
|
|
* general seems a bit tricky for this one. We only write it for
|
|
|
|
* SD resolution in MOV, where it is a requirement.
|
2017-01-10 16:19:55 +00:00
|
|
|
* The same goes for the 'tapt' extension, just that it is not defined for
|
|
|
|
* MP4 and only for MOV
|
|
|
|
*/
|
2017-01-11 17:29:05 +00:00
|
|
|
gint dar_num, dar_den;
|
|
|
|
gint clef_width, clef_height, prof_width;
|
|
|
|
gint clap_width_n, clap_width_d, clap_height;
|
|
|
|
gint cdiv;
|
|
|
|
double approx_dar;
|
|
|
|
|
|
|
|
/* First, guess display aspect ratio based on pixel aspect ratio,
|
|
|
|
* width and height. We assume that display aspect ratio is either
|
|
|
|
* 4:3 or 16:9
|
|
|
|
*/
|
|
|
|
approx_dar = (gdouble) (width * par_num) / (height * par_den);
|
|
|
|
if (approx_dar > 11.0 / 9 && approx_dar < 14.0 / 9) {
|
|
|
|
dar_num = 4;
|
|
|
|
dar_den = 3;
|
|
|
|
} else if (approx_dar > 15.0 / 9 && approx_dar < 18.0 / 9) {
|
|
|
|
dar_num = 16;
|
|
|
|
dar_den = 9;
|
2017-01-10 16:19:55 +00:00
|
|
|
} else {
|
2017-01-11 17:29:05 +00:00
|
|
|
dar_num = width * par_num;
|
|
|
|
dar_den = height * par_den;
|
|
|
|
cdiv = gst_util_greatest_common_divisor (dar_num, dar_den);
|
|
|
|
dar_num /= cdiv;
|
|
|
|
dar_den /= cdiv;
|
2017-01-10 16:19:55 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 17:29:05 +00:00
|
|
|
/* Then, calculate clean-aperture values (clap and clef)
|
|
|
|
* using the guessed DAR.
|
|
|
|
*/
|
|
|
|
clef_height = clap_height = (height == 486 ? 480 : height);
|
|
|
|
clef_width = gst_util_uint64_scale (clef_height,
|
|
|
|
dar_num * G_GUINT64_CONSTANT (65536), dar_den);
|
|
|
|
prof_width = gst_util_uint64_scale (width,
|
|
|
|
par_num * G_GUINT64_CONSTANT (65536), par_den);
|
|
|
|
clap_width_n = clap_height * dar_num * par_den;
|
|
|
|
clap_width_d = dar_den * par_num;
|
|
|
|
cdiv = gst_util_greatest_common_divisor (clap_width_n, clap_width_d);
|
|
|
|
clap_width_n /= cdiv;
|
|
|
|
clap_width_d /= cdiv;
|
|
|
|
|
|
|
|
ext_atom = build_tapt_extension (clef_width, clef_height << 16, prof_width,
|
|
|
|
height << 16, width << 16, height << 16);
|
|
|
|
qtpad->trak->tapt = ext_atom;
|
|
|
|
|
|
|
|
ext_atom = build_clap_extension (clap_width_n, clap_width_d,
|
|
|
|
clap_height, 1, 0, 1, 0, 1);
|
|
|
|
if (ext_atom)
|
|
|
|
ext_atom_list = g_list_append (ext_atom_list, ext_atom);
|
2017-01-10 16:19:55 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* ok, set the pad info accordingly */
|
|
|
|
qtpad->fourcc = entry.fourcc;
|
|
|
|
qtpad->sync = sync;
|
2015-06-11 01:27:27 +00:00
|
|
|
qtpad->trak_ste =
|
|
|
|
(SampleTableEntry *) atom_trak_set_video_type (qtpad->trak,
|
|
|
|
qtmux->context, &entry, rate, ext_atom_list);
|
2016-07-11 16:30:12 +00:00
|
|
|
if (strcmp (mimetype, "video/x-prores") == 0) {
|
|
|
|
SampleTableEntryMP4V *mp4v = (SampleTableEntryMP4V *) qtpad->trak_ste;
|
2016-09-30 15:22:27 +00:00
|
|
|
const gchar *compressor = NULL;
|
2016-07-11 16:30:12 +00:00
|
|
|
mp4v->spatial_quality = 0x3FF;
|
|
|
|
mp4v->temporal_quality = 0;
|
|
|
|
mp4v->vendor = FOURCC_appl;
|
2016-09-30 15:22:27 +00:00
|
|
|
mp4v->horizontal_resolution = 72 << 16;
|
|
|
|
mp4v->vertical_resolution = 72 << 16;
|
|
|
|
mp4v->depth = (entry.fourcc == FOURCC_ap4h
|
|
|
|
|| entry.fourcc == FOURCC_ap4x) ? 32 : 24;
|
|
|
|
|
|
|
|
/* Set compressor name, required by some software */
|
|
|
|
switch (entry.fourcc) {
|
|
|
|
case FOURCC_apcn:
|
|
|
|
compressor = "Apple ProRes 422";
|
|
|
|
break;
|
|
|
|
case FOURCC_apcs:
|
|
|
|
compressor = "Apple ProRes 422 LT";
|
|
|
|
break;
|
|
|
|
case FOURCC_apch:
|
|
|
|
compressor = "Apple ProRes 422 HQ";
|
|
|
|
break;
|
|
|
|
case FOURCC_apco:
|
|
|
|
compressor = "Apple ProRes 422 Proxy";
|
|
|
|
break;
|
|
|
|
case FOURCC_ap4h:
|
|
|
|
compressor = "Apple ProRes 4444";
|
|
|
|
break;
|
|
|
|
case FOURCC_ap4x:
|
|
|
|
compressor = "Apple ProRes 4444 XQ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (compressor) {
|
|
|
|
strcpy ((gchar *) mp4v->compressor + 1, compressor);
|
|
|
|
mp4v->compressor[0] = strlen (compressor);
|
|
|
|
}
|
2016-07-11 16:30:12 +00:00
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
gst_object_unref (qtmux);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
refuse_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT,
|
|
|
|
GST_PAD_NAME (pad), caps);
|
|
|
|
gst_object_unref (qtmux);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-05 13:27:54 +00:00
|
|
|
static gboolean
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_subtitle_sink_set_caps (GstQTMuxPad * qtpad, GstCaps * caps)
|
2014-02-05 13:27:54 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstPad *pad = GST_PAD (qtpad);
|
2014-02-05 13:27:54 +00:00
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad));
|
2014-02-06 15:15:22 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
SubtitleSampleEntry entry = { 0, };
|
2014-02-05 13:27:54 +00:00
|
|
|
|
2018-02-06 13:36:50 +00:00
|
|
|
if (qtpad->fourcc)
|
|
|
|
return gst_qt_mux_can_renegotiate (qtmux, pad, caps);
|
2014-02-05 13:27:54 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT,
|
|
|
|
GST_DEBUG_PAD_NAME (pad), caps);
|
|
|
|
|
|
|
|
/* subtitles default */
|
2014-02-06 15:15:22 +00:00
|
|
|
subtitle_sample_entry_init (&entry);
|
2014-02-05 13:27:54 +00:00
|
|
|
qtpad->is_out_of_order = FALSE;
|
|
|
|
qtpad->sync = FALSE;
|
2014-02-07 04:49:26 +00:00
|
|
|
qtpad->sparse = TRUE;
|
2014-02-06 15:15:22 +00:00
|
|
|
qtpad->prepare_buf_func = NULL;
|
2014-02-05 13:27:54 +00:00
|
|
|
|
2014-02-06 15:15:22 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
if (gst_structure_has_name (structure, "text/x-raw")) {
|
|
|
|
const gchar *format = gst_structure_get_string (structure, "format");
|
|
|
|
if (format && strcmp (format, "utf8") == 0) {
|
|
|
|
entry.fourcc = FOURCC_tx3g;
|
|
|
|
qtpad->prepare_buf_func = gst_qt_mux_prepare_tx3g_buffer;
|
2014-02-07 04:49:26 +00:00
|
|
|
qtpad->create_empty_buffer = gst_qt_mux_create_empty_tx3g_buffer;
|
2014-02-06 15:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!entry.fourcc)
|
|
|
|
goto refuse_caps;
|
|
|
|
|
|
|
|
qtpad->fourcc = entry.fourcc;
|
2015-06-11 01:27:27 +00:00
|
|
|
qtpad->trak_ste =
|
|
|
|
(SampleTableEntry *) atom_trak_set_subtitle_type (qtpad->trak,
|
|
|
|
qtmux->context, &entry);
|
2014-02-05 13:27:54 +00:00
|
|
|
|
|
|
|
gst_object_unref (qtmux);
|
2014-02-06 15:15:22 +00:00
|
|
|
return TRUE;
|
2014-02-05 13:27:54 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2014-02-06 15:15:22 +00:00
|
|
|
refuse_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT,
|
|
|
|
GST_PAD_NAME (pad), caps);
|
|
|
|
gst_object_unref (qtmux);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-05 13:27:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 10:00:18 +00:00
|
|
|
static gboolean
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_caption_sink_set_caps (GstQTMuxPad * qtpad, GstCaps * caps)
|
2018-02-07 10:00:18 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstPad *pad = GST_PAD (qtpad);
|
2018-02-07 10:00:18 +00:00
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad));
|
|
|
|
GstStructure *structure;
|
|
|
|
guint32 fourcc_entry;
|
|
|
|
guint32 timescale;
|
|
|
|
|
|
|
|
if (qtpad->fourcc)
|
|
|
|
return gst_qt_mux_can_renegotiate (qtmux, pad, caps);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT,
|
|
|
|
GST_DEBUG_PAD_NAME (pad), caps);
|
|
|
|
|
|
|
|
/* captions default */
|
|
|
|
qtpad->is_out_of_order = FALSE;
|
|
|
|
qtpad->sync = FALSE;
|
|
|
|
qtpad->sparse = TRUE;
|
|
|
|
/* Closed caption data are within atoms */
|
|
|
|
qtpad->prepare_buf_func = gst_qt_mux_prepare_caption_buffer;
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2018-12-10 15:34:03 +00:00
|
|
|
/* We know we only handle 608,format=s334-1a and 708,format=cdp */
|
2018-02-07 10:00:18 +00:00
|
|
|
if (gst_structure_has_name (structure, "closedcaption/x-cea-608")) {
|
|
|
|
fourcc_entry = FOURCC_c608;
|
|
|
|
} else if (gst_structure_has_name (structure, "closedcaption/x-cea-708")) {
|
|
|
|
fourcc_entry = FOURCC_c708;
|
|
|
|
} else
|
|
|
|
goto refuse_caps;
|
|
|
|
|
2018-12-05 17:31:25 +00:00
|
|
|
/* We set the real timescale later to the one from the video track when
|
|
|
|
* writing the headers */
|
2018-02-07 10:00:18 +00:00
|
|
|
timescale = gst_qt_mux_pad_get_timescale (GST_QT_MUX_PAD_CAST (pad));
|
|
|
|
if (!timescale && qtmux->trak_timescale)
|
|
|
|
timescale = qtmux->trak_timescale;
|
|
|
|
else if (!timescale)
|
|
|
|
timescale = 30000;
|
|
|
|
|
|
|
|
qtpad->fourcc = fourcc_entry;
|
|
|
|
qtpad->trak_ste =
|
|
|
|
(SampleTableEntry *) atom_trak_set_caption_type (qtpad->trak,
|
|
|
|
qtmux->context, timescale, fourcc_entry);
|
|
|
|
|
2018-09-06 17:10:30 +00:00
|
|
|
/* Initialize caption track language code to 0 unless something else is
|
|
|
|
* specified. Without this, Final Cut considers it "non-standard"
|
|
|
|
*/
|
|
|
|
qtpad->trak->mdia.mdhd.language_code = 0;
|
|
|
|
|
2018-02-07 10:00:18 +00:00
|
|
|
gst_object_unref (qtmux);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
refuse_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT,
|
|
|
|
GST_PAD_NAME (pad), caps);
|
|
|
|
gst_object_unref (qtmux);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static gboolean
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_qt_mux_sink_event (GstAggregator * agg, GstAggregatorPad * agg_pad,
|
|
|
|
GstEvent * event)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstAggregatorClass *agg_class = GST_AGGREGATOR_CLASS (parent_class);
|
|
|
|
GstQTMuxPad *qtmux_pad;
|
2008-11-08 02:00:58 +00:00
|
|
|
GstQTMux *qtmux;
|
2010-07-05 08:39:50 +00:00
|
|
|
guint32 avg_bitrate = 0, max_bitrate = 0;
|
2019-12-03 14:30:06 +00:00
|
|
|
GstPad *pad = GST_PAD (agg_pad);
|
2012-04-16 14:37:49 +00:00
|
|
|
gboolean ret = TRUE;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
qtmux = GST_QT_MUX_CAST (agg);
|
|
|
|
qtmux_pad = GST_QT_MUX_PAD_CAST (agg_pad);
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2011-06-29 10:46:20 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
|
|
|
|
/* find stream data */
|
2019-12-03 14:30:06 +00:00
|
|
|
g_assert (qtmux_pad->set_caps);
|
2011-06-29 10:46:20 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
ret = qtmux_pad->set_caps (qtmux_pad, caps);
|
2012-01-26 09:40:06 +00:00
|
|
|
gst_event_unref (event);
|
2012-04-16 14:37:49 +00:00
|
|
|
event = NULL;
|
2011-06-29 10:46:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-16 16:26:52 +00:00
|
|
|
case GST_EVENT_TAG:{
|
|
|
|
GstTagList *list;
|
|
|
|
GstTagSetter *setter = GST_TAG_SETTER (qtmux);
|
2010-02-26 19:50:25 +00:00
|
|
|
GstTagMergeMode mode;
|
2013-03-22 01:24:01 +00:00
|
|
|
gchar *code;
|
2010-02-26 19:50:25 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
mode = gst_tag_setter_get_tag_merge_mode (setter);
|
2008-12-16 16:26:52 +00:00
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
gst_event_parse_tag (event, &list);
|
2011-12-12 14:51:06 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "received tag event on pad %s:%s : %"
|
|
|
|
GST_PTR_FORMAT, GST_DEBUG_PAD_NAME (pad), list);
|
2010-02-26 19:50:25 +00:00
|
|
|
|
2015-01-31 17:32:34 +00:00
|
|
|
if (gst_tag_list_get_scope (list) == GST_TAG_SCOPE_GLOBAL) {
|
|
|
|
gst_tag_setter_merge_tags (setter, list, mode);
|
2015-04-01 00:15:38 +00:00
|
|
|
qtmux->tags_changed = TRUE;
|
2015-01-31 17:32:34 +00:00
|
|
|
} else {
|
2019-12-03 14:30:06 +00:00
|
|
|
if (!qtmux_pad->tags)
|
|
|
|
qtmux_pad->tags = gst_tag_list_new_empty ();
|
|
|
|
gst_tag_list_insert (qtmux_pad->tags, list, mode);
|
|
|
|
qtmux_pad->tags_changed = TRUE;
|
2015-01-31 17:32:34 +00:00
|
|
|
}
|
2010-02-26 19:50:25 +00:00
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
2010-07-05 08:39:50 +00:00
|
|
|
|
|
|
|
if (gst_tag_list_get_uint (list, GST_TAG_BITRATE, &avg_bitrate) |
|
|
|
|
gst_tag_list_get_uint (list, GST_TAG_MAXIMUM_BITRATE, &max_bitrate)) {
|
|
|
|
if (avg_bitrate > 0 && avg_bitrate < G_MAXUINT32)
|
2019-12-03 14:30:06 +00:00
|
|
|
qtmux_pad->avg_bitrate = avg_bitrate;
|
2010-07-05 08:39:50 +00:00
|
|
|
if (max_bitrate > 0 && max_bitrate < G_MAXUINT32)
|
2019-12-03 14:30:06 +00:00
|
|
|
qtmux_pad->max_bitrate = max_bitrate;
|
2010-07-05 08:39:50 +00:00
|
|
|
}
|
2013-03-22 01:24:01 +00:00
|
|
|
|
|
|
|
if (gst_tag_list_get_string (list, GST_TAG_LANGUAGE_CODE, &code)) {
|
|
|
|
const char *iso_code = gst_tag_get_language_code_iso_639_2T (code);
|
|
|
|
if (iso_code) {
|
2019-12-03 14:30:06 +00:00
|
|
|
if (qtmux_pad->trak) {
|
2013-03-22 01:24:01 +00:00
|
|
|
/* https://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html */
|
2019-12-03 14:30:06 +00:00
|
|
|
qtmux_pad->trak->mdia.mdhd.language_code = language_code (iso_code);
|
2013-03-22 01:24:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (code);
|
|
|
|
}
|
2010-07-05 08:39:50 +00:00
|
|
|
|
2012-01-26 09:40:06 +00:00
|
|
|
gst_event_unref (event);
|
2012-04-16 14:37:49 +00:00
|
|
|
event = NULL;
|
2012-01-26 09:40:06 +00:00
|
|
|
ret = TRUE;
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
2008-12-16 16:26:52 +00:00
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-16 14:37:49 +00:00
|
|
|
if (event != NULL)
|
2019-12-03 14:30:06 +00:00
|
|
|
ret = agg_class->sink_event (agg, agg_pad, event);
|
2012-04-16 14:37:49 +00:00
|
|
|
|
2012-01-26 09:40:06 +00:00
|
|
|
return ret;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_release_pad (GstElement * element, GstPad * pad)
|
|
|
|
{
|
|
|
|
GstQTMux *mux = GST_QT_MUX_CAST (element);
|
|
|
|
|
2010-06-21 17:39:54 +00:00
|
|
|
GST_DEBUG_OBJECT (element, "Releasing %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
gst_element_remove_pad (element, pad);
|
2010-06-21 17:39:54 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
if (mux->current_pad && GST_PAD (mux->current_pad) == pad) {
|
2016-10-19 11:25:28 +00:00
|
|
|
mux->current_pad = NULL;
|
|
|
|
mux->current_chunk_size = 0;
|
|
|
|
mux->current_chunk_duration = 0;
|
|
|
|
}
|
|
|
|
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
2019-12-03 14:30:06 +00:00
|
|
|
if (GST_ELEMENT (mux)->sinkpads == NULL) {
|
2017-01-12 13:01:06 +00:00
|
|
|
/* No more outstanding request pads, reset our counters */
|
|
|
|
mux->video_pads = 0;
|
|
|
|
mux->audio_pads = 0;
|
|
|
|
mux->subtitle_pads = 0;
|
|
|
|
}
|
2019-12-12 19:20:35 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
static GstAggregatorPad *
|
|
|
|
gst_qt_mux_create_new_pad (GstAggregator * self,
|
|
|
|
GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
|
|
|
|
{
|
|
|
|
return g_object_new (GST_TYPE_QT_MUX_PAD, "name", req_name, "direction",
|
|
|
|
templ->direction, "template", templ, NULL);
|
|
|
|
}
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
static GstPad *
|
|
|
|
gst_qt_mux_request_new_pad (GstElement * element,
|
2011-06-29 10:46:20 +00:00
|
|
|
GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
|
|
|
GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
|
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (element);
|
2019-12-03 14:30:06 +00:00
|
|
|
GstQTMuxPad *qtpad;
|
2014-02-05 13:27:54 +00:00
|
|
|
GstQTPadSetCapsFunc setcaps_func;
|
2009-12-27 21:51:50 +00:00
|
|
|
gchar *name;
|
2011-07-04 09:07:13 +00:00
|
|
|
gint pad_id;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2009-12-27 21:32:58 +00:00
|
|
|
if (templ->direction != GST_PAD_SINK)
|
|
|
|
goto wrong_direction;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2010-01-13 18:30:45 +00:00
|
|
|
if (qtmux->state > GST_QT_MUX_STATE_STARTED)
|
2009-12-27 21:32:58 +00:00
|
|
|
goto too_late;
|
|
|
|
|
2011-11-04 10:58:22 +00:00
|
|
|
if (templ == gst_element_class_get_pad_template (klass, "audio_%u")) {
|
2014-02-05 13:27:54 +00:00
|
|
|
setcaps_func = gst_qt_mux_audio_sink_set_caps;
|
2011-11-04 10:58:22 +00:00
|
|
|
if (req_name != NULL && sscanf (req_name, "audio_%u", &pad_id) == 1) {
|
2011-07-04 09:07:13 +00:00
|
|
|
name = g_strdup (req_name);
|
|
|
|
} else {
|
2011-11-04 10:58:22 +00:00
|
|
|
name = g_strdup_printf ("audio_%u", qtmux->audio_pads++);
|
2011-07-04 09:07:13 +00:00
|
|
|
}
|
2011-11-04 10:58:22 +00:00
|
|
|
} else if (templ == gst_element_class_get_pad_template (klass, "video_%u")) {
|
2014-02-05 13:27:54 +00:00
|
|
|
setcaps_func = gst_qt_mux_video_sink_set_caps;
|
2011-11-04 10:58:22 +00:00
|
|
|
if (req_name != NULL && sscanf (req_name, "video_%u", &pad_id) == 1) {
|
2011-07-04 09:07:13 +00:00
|
|
|
name = g_strdup (req_name);
|
|
|
|
} else {
|
2011-11-04 10:58:22 +00:00
|
|
|
name = g_strdup_printf ("video_%u", qtmux->video_pads++);
|
2011-07-04 09:07:13 +00:00
|
|
|
}
|
2014-02-05 13:27:54 +00:00
|
|
|
} else if (templ == gst_element_class_get_pad_template (klass, "subtitle_%u")) {
|
|
|
|
setcaps_func = gst_qt_mux_subtitle_sink_set_caps;
|
|
|
|
if (req_name != NULL && sscanf (req_name, "subtitle_%u", &pad_id) == 1) {
|
|
|
|
name = g_strdup (req_name);
|
|
|
|
} else {
|
|
|
|
name = g_strdup_printf ("subtitle_%u", qtmux->subtitle_pads++);
|
|
|
|
}
|
2018-02-07 10:00:18 +00:00
|
|
|
} else if (templ == gst_element_class_get_pad_template (klass, "caption_%u")) {
|
|
|
|
setcaps_func = gst_qt_mux_caption_sink_set_caps;
|
|
|
|
if (req_name != NULL && sscanf (req_name, "caption_%u", &pad_id) == 1) {
|
|
|
|
name = g_strdup (req_name);
|
|
|
|
} else {
|
|
|
|
name = g_strdup_printf ("caption_%u", qtmux->caption_pads++);
|
|
|
|
}
|
2009-12-27 21:32:58 +00:00
|
|
|
} else
|
|
|
|
goto wrong_template;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2009-12-27 21:51:50 +00:00
|
|
|
GST_DEBUG_OBJECT (qtmux, "Requested pad: %s", name);
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
qtpad = (GstQTMuxPad *)
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->request_new_pad (element,
|
|
|
|
templ, name, caps);
|
|
|
|
|
2009-12-27 21:51:50 +00:00
|
|
|
g_free (name);
|
2009-09-28 14:11:35 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
/* set up pad */
|
|
|
|
gst_qt_mux_pad_reset (qtpad);
|
|
|
|
qtpad->trak = atom_trak_new (qtmux->context);
|
|
|
|
atom_moov_add_trak (qtmux->moov, qtpad->trak);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/* set up pad functions */
|
2019-12-03 14:30:06 +00:00
|
|
|
qtpad->set_caps = setcaps_func;
|
|
|
|
qtpad->dts = G_MININT64;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
return GST_PAD (qtpad);
|
2009-12-27 21:32:58 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
wrong_direction:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Request pad that is not a SINK pad.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
too_late:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (qtmux, "Not providing request pad after stream start.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wrong_template:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (qtmux, "This is not our template!");
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (object);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_MOVIE_TIMESCALE:
|
|
|
|
g_value_set_uint (value, qtmux->timescale);
|
|
|
|
break;
|
2010-07-30 10:48:29 +00:00
|
|
|
case PROP_TRAK_TIMESCALE:
|
|
|
|
g_value_set_uint (value, qtmux->trak_timescale);
|
|
|
|
break;
|
2008-11-08 02:00:58 +00:00
|
|
|
case PROP_DO_CTTS:
|
2008-11-15 02:56:31 +00:00
|
|
|
g_value_set_boolean (value, qtmux->guess_pts);
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
2013-03-22 20:24:33 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2011-01-03 16:24:23 +00:00
|
|
|
case PROP_DTS_METHOD:
|
|
|
|
g_value_set_enum (value, qtmux->dts_method);
|
|
|
|
break;
|
2013-03-22 20:24:33 +00:00
|
|
|
#endif
|
2008-11-08 02:00:58 +00:00
|
|
|
case PROP_FAST_START:
|
|
|
|
g_value_set_boolean (value, qtmux->fast_start);
|
|
|
|
break;
|
|
|
|
case PROP_FAST_START_TEMP_FILE:
|
|
|
|
g_value_set_string (value, qtmux->fast_start_file_path);
|
|
|
|
break;
|
2009-12-12 19:07:15 +00:00
|
|
|
case PROP_MOOV_RECOV_FILE:
|
|
|
|
g_value_set_string (value, qtmux->moov_recov_file_path);
|
|
|
|
break;
|
2010-11-15 14:17:59 +00:00
|
|
|
case PROP_FRAGMENT_DURATION:
|
|
|
|
g_value_set_uint (value, qtmux->fragment_duration);
|
|
|
|
break;
|
2010-08-06 11:26:27 +00:00
|
|
|
case PROP_STREAMABLE:
|
|
|
|
g_value_set_boolean (value, qtmux->streamable);
|
|
|
|
break;
|
2015-04-01 00:15:38 +00:00
|
|
|
case PROP_RESERVED_MAX_DURATION:
|
|
|
|
g_value_set_uint64 (value, qtmux->reserved_max_duration);
|
|
|
|
break;
|
|
|
|
case PROP_RESERVED_DURATION_REMAINING:
|
|
|
|
if (qtmux->reserved_duration_remaining == GST_CLOCK_TIME_NONE)
|
|
|
|
g_value_set_uint64 (value, qtmux->reserved_max_duration);
|
|
|
|
else {
|
|
|
|
GstClockTime remaining = qtmux->reserved_duration_remaining;
|
|
|
|
|
|
|
|
/* Report the remaining space as the calculated remaining, minus
|
|
|
|
* however much we've muxed since the last update */
|
|
|
|
if (remaining > qtmux->muxed_since_last_update)
|
|
|
|
remaining -= qtmux->muxed_since_last_update;
|
|
|
|
else
|
|
|
|
remaining = 0;
|
|
|
|
GST_LOG_OBJECT (qtmux, "reserved duration remaining - reporting %"
|
|
|
|
G_GUINT64_FORMAT "(%" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT,
|
|
|
|
remaining, qtmux->reserved_duration_remaining,
|
|
|
|
qtmux->muxed_since_last_update);
|
|
|
|
g_value_set_uint64 (value, remaining);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_RESERVED_MOOV_UPDATE_PERIOD:
|
|
|
|
g_value_set_uint64 (value, qtmux->reserved_moov_update_period);
|
|
|
|
break;
|
|
|
|
case PROP_RESERVED_BYTES_PER_SEC:
|
|
|
|
g_value_set_uint (value, qtmux->reserved_bytes_per_sec_per_trak);
|
|
|
|
break;
|
2017-03-09 08:15:34 +00:00
|
|
|
case PROP_RESERVED_PREFILL:
|
|
|
|
g_value_set_boolean (value, qtmux->reserved_prefill);
|
|
|
|
break;
|
2016-10-19 11:25:28 +00:00
|
|
|
case PROP_INTERLEAVE_BYTES:
|
|
|
|
g_value_set_uint64 (value, qtmux->interleave_bytes);
|
|
|
|
break;
|
|
|
|
case PROP_INTERLEAVE_TIME:
|
|
|
|
g_value_set_uint64 (value, qtmux->interleave_time);
|
|
|
|
break;
|
2017-03-29 11:01:25 +00:00
|
|
|
case PROP_MAX_RAW_AUDIO_DRIFT:
|
|
|
|
g_value_set_uint64 (value, qtmux->max_raw_audio_drift);
|
|
|
|
break;
|
2018-10-19 14:02:11 +00:00
|
|
|
case PROP_START_GAP_THRESHOLD:
|
|
|
|
g_value_set_uint64 (value, qtmux->start_gap_threshold);
|
|
|
|
break;
|
2008-11-08 02:00:58 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_generate_fast_start_file_path (GstQTMux * qtmux)
|
|
|
|
{
|
|
|
|
gchar *tmp;
|
|
|
|
|
2010-01-26 16:44:04 +00:00
|
|
|
g_free (qtmux->fast_start_file_path);
|
|
|
|
qtmux->fast_start_file_path = NULL;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
tmp = g_strdup_printf ("%s%d", "qtmux", g_random_int ());
|
|
|
|
qtmux->fast_start_file_path = g_build_filename (g_get_tmp_dir (), tmp, NULL);
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qt_mux_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (object);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (qtmux);
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_MOVIE_TIMESCALE:
|
|
|
|
qtmux->timescale = g_value_get_uint (value);
|
|
|
|
break;
|
2010-07-30 10:48:29 +00:00
|
|
|
case PROP_TRAK_TIMESCALE:
|
|
|
|
qtmux->trak_timescale = g_value_get_uint (value);
|
|
|
|
break;
|
2008-11-08 02:00:58 +00:00
|
|
|
case PROP_DO_CTTS:
|
2008-11-15 02:56:31 +00:00
|
|
|
qtmux->guess_pts = g_value_get_boolean (value);
|
2008-11-08 02:00:58 +00:00
|
|
|
break;
|
2013-03-22 20:24:33 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2011-01-03 16:24:23 +00:00
|
|
|
case PROP_DTS_METHOD:
|
|
|
|
qtmux->dts_method = g_value_get_enum (value);
|
|
|
|
break;
|
2013-03-22 20:24:33 +00:00
|
|
|
#endif
|
2008-11-08 02:00:58 +00:00
|
|
|
case PROP_FAST_START:
|
|
|
|
qtmux->fast_start = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case PROP_FAST_START_TEMP_FILE:
|
2010-01-26 16:44:04 +00:00
|
|
|
g_free (qtmux->fast_start_file_path);
|
2008-11-08 02:00:58 +00:00
|
|
|
qtmux->fast_start_file_path = g_value_dup_string (value);
|
|
|
|
/* NULL means to generate a random one */
|
|
|
|
if (!qtmux->fast_start_file_path) {
|
|
|
|
gst_qt_mux_generate_fast_start_file_path (qtmux);
|
|
|
|
}
|
|
|
|
break;
|
2009-12-12 19:07:15 +00:00
|
|
|
case PROP_MOOV_RECOV_FILE:
|
|
|
|
g_free (qtmux->moov_recov_file_path);
|
|
|
|
qtmux->moov_recov_file_path = g_value_dup_string (value);
|
|
|
|
break;
|
2010-11-15 14:17:59 +00:00
|
|
|
case PROP_FRAGMENT_DURATION:
|
|
|
|
qtmux->fragment_duration = g_value_get_uint (value);
|
|
|
|
break;
|
2013-09-17 10:01:30 +00:00
|
|
|
case PROP_STREAMABLE:{
|
|
|
|
GstQTMuxClass *qtmux_klass =
|
|
|
|
(GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
|
|
|
|
if (qtmux_klass->format == GST_QT_MUX_FORMAT_ISML) {
|
|
|
|
qtmux->streamable = g_value_get_boolean (value);
|
|
|
|
}
|
2010-08-06 11:26:27 +00:00
|
|
|
break;
|
2013-09-17 10:01:30 +00:00
|
|
|
}
|
2015-04-01 00:15:38 +00:00
|
|
|
case PROP_RESERVED_MAX_DURATION:
|
|
|
|
qtmux->reserved_max_duration = g_value_get_uint64 (value);
|
|
|
|
break;
|
|
|
|
case PROP_RESERVED_MOOV_UPDATE_PERIOD:
|
|
|
|
qtmux->reserved_moov_update_period = g_value_get_uint64 (value);
|
|
|
|
break;
|
|
|
|
case PROP_RESERVED_BYTES_PER_SEC:
|
|
|
|
qtmux->reserved_bytes_per_sec_per_trak = g_value_get_uint (value);
|
|
|
|
break;
|
2017-03-09 08:15:34 +00:00
|
|
|
case PROP_RESERVED_PREFILL:
|
|
|
|
qtmux->reserved_prefill = g_value_get_boolean (value);
|
|
|
|
break;
|
2016-10-19 11:25:28 +00:00
|
|
|
case PROP_INTERLEAVE_BYTES:
|
|
|
|
qtmux->interleave_bytes = g_value_get_uint64 (value);
|
|
|
|
qtmux->interleave_bytes_set = TRUE;
|
|
|
|
break;
|
|
|
|
case PROP_INTERLEAVE_TIME:
|
|
|
|
qtmux->interleave_time = g_value_get_uint64 (value);
|
|
|
|
qtmux->interleave_time_set = TRUE;
|
|
|
|
break;
|
2017-03-29 11:01:25 +00:00
|
|
|
case PROP_MAX_RAW_AUDIO_DRIFT:
|
|
|
|
qtmux->max_raw_audio_drift = g_value_get_uint64 (value);
|
|
|
|
break;
|
2018-10-19 14:02:11 +00:00
|
|
|
case PROP_START_GAP_THRESHOLD:
|
|
|
|
qtmux->start_gap_threshold = g_value_get_uint64 (value);
|
|
|
|
break;
|
2008-11-08 02:00:58 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (qtmux);
|
|
|
|
}
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
static gboolean
|
|
|
|
gst_qt_mux_start (GstAggregator * agg)
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (agg);
|
|
|
|
GstSegment segment;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
qtmux->state = GST_QT_MUX_STATE_STARTED;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
/* let downstream know we think in BYTES and expect to do seeking later on */
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
|
|
|
gst_aggregator_update_segment (agg, &segment);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
static gboolean
|
|
|
|
gst_qt_mux_stop (GstAggregator * agg)
|
|
|
|
{
|
|
|
|
GstQTMux *qtmux = GST_QT_MUX_CAST (agg);
|
|
|
|
|
|
|
|
gst_qt_mux_reset (qtmux, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
2008-11-08 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_qt_mux_register (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
GTypeInfo typeinfo = {
|
|
|
|
sizeof (GstQTMuxClass),
|
|
|
|
(GBaseInitFunc) gst_qt_mux_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_qt_mux_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstQTMux),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_qt_mux_init,
|
|
|
|
};
|
|
|
|
static const GInterfaceInfo tag_setter_info = {
|
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
2011-03-21 13:56:51 +00:00
|
|
|
static const GInterfaceInfo tag_xmp_writer_info = {
|
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
2015-06-26 18:13:17 +00:00
|
|
|
static const GInterfaceInfo preset_info = {
|
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
2008-11-08 02:00:58 +00:00
|
|
|
GType type;
|
|
|
|
GstQTMuxFormat format;
|
|
|
|
GstQTMuxClassParams *params;
|
|
|
|
guint i = 0;
|
|
|
|
|
2010-03-25 00:20:54 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_qt_mux_debug, "qtmux", 0, "QT Muxer");
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
GST_LOG ("Registering muxers");
|
|
|
|
|
|
|
|
while (TRUE) {
|
|
|
|
GstQTMuxFormatProp *prop;
|
2018-02-07 10:00:18 +00:00
|
|
|
GstCaps *subtitle_caps, *caption_caps;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
prop = &gst_qt_mux_format_list[i];
|
|
|
|
format = prop->format;
|
|
|
|
if (format == GST_QT_MUX_FORMAT_NONE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* create a cache for these properties */
|
|
|
|
params = g_new0 (GstQTMuxClassParams, 1);
|
|
|
|
params->prop = prop;
|
|
|
|
params->src_caps = gst_static_caps_get (&prop->src_caps);
|
|
|
|
params->video_sink_caps = gst_static_caps_get (&prop->video_sink_caps);
|
|
|
|
params->audio_sink_caps = gst_static_caps_get (&prop->audio_sink_caps);
|
2014-02-05 13:27:54 +00:00
|
|
|
subtitle_caps = gst_static_caps_get (&prop->subtitle_sink_caps);
|
|
|
|
if (!gst_caps_is_equal (subtitle_caps, GST_CAPS_NONE)) {
|
|
|
|
params->subtitle_sink_caps = subtitle_caps;
|
|
|
|
} else {
|
|
|
|
gst_caps_unref (subtitle_caps);
|
|
|
|
}
|
2018-02-07 10:00:18 +00:00
|
|
|
caption_caps = gst_static_caps_get (&prop->caption_sink_caps);
|
|
|
|
if (!gst_caps_is_equal (caption_caps, GST_CAPS_NONE)) {
|
|
|
|
params->caption_sink_caps = caption_caps;
|
|
|
|
} else {
|
|
|
|
gst_caps_unref (caption_caps);
|
|
|
|
}
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/* create the type now */
|
2019-12-03 14:30:06 +00:00
|
|
|
type =
|
|
|
|
g_type_register_static (GST_TYPE_AGGREGATOR, prop->type_name, &typeinfo,
|
2008-11-08 02:00:58 +00:00
|
|
|
0);
|
|
|
|
g_type_set_qdata (type, GST_QT_MUX_PARAMS_QDATA, (gpointer) params);
|
|
|
|
g_type_add_interface_static (type, GST_TYPE_TAG_SETTER, &tag_setter_info);
|
2011-03-21 13:56:51 +00:00
|
|
|
g_type_add_interface_static (type, GST_TYPE_TAG_XMP_WRITER,
|
|
|
|
&tag_xmp_writer_info);
|
2015-06-26 18:13:17 +00:00
|
|
|
g_type_add_interface_static (type, GST_TYPE_PRESET, &preset_info);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-04-21 21:51:52 +00:00
|
|
|
if (!gst_element_register (plugin, prop->name, prop->rank, type))
|
2008-11-08 02:00:58 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG ("Finished registering muxers");
|
|
|
|
|
2009-12-10 19:53:19 +00:00
|
|
|
/* FIXME: ideally classification tag should be added and
|
|
|
|
registered in gstreamer core gsttaglist
|
|
|
|
*/
|
|
|
|
|
|
|
|
GST_LOG ("Registering tags");
|
|
|
|
|
|
|
|
gst_tag_register (GST_TAG_3GP_CLASSIFICATION, GST_TAG_FLAG_META,
|
|
|
|
G_TYPE_STRING, GST_TAG_3GP_CLASSIFICATION, "content classification",
|
|
|
|
gst_tag_merge_use_first);
|
|
|
|
|
|
|
|
GST_LOG ("Finished registering tags");
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|