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
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
#ifndef __GST_QT_MUX_H__
|
|
|
|
#define __GST_QT_MUX_H__
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2019-12-03 14:30:06 +00:00
|
|
|
#include <gst/base/gstaggregator.h>
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
#include "fourcc.h"
|
|
|
|
#include "atoms.h"
|
2009-12-12 19:07:15 +00:00
|
|
|
#include "atomsrecovery.h"
|
2008-11-08 02:00:58 +00:00
|
|
|
#include "gstqtmuxmap.h"
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
#define GST_TYPE_QT_MUX (gst_qt_mux_get_type())
|
|
|
|
#define GST_QT_MUX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_QT_MUX, GstQTMux))
|
|
|
|
#define GST_QT_MUX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_QT_MUX, GstQTMux))
|
|
|
|
#define GST_IS_QT_MUX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_QT_MUX))
|
|
|
|
#define GST_IS_QT_MUX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_QT_MUX))
|
|
|
|
#define GST_QT_MUX_CAST(obj) ((GstQTMux*)(obj))
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _GstQTMux GstQTMux;
|
|
|
|
typedef struct _GstQTMuxClass GstQTMuxClass;
|
2019-12-03 14:30:06 +00:00
|
|
|
typedef struct _GstQTMuxPad GstQTMuxPad;
|
|
|
|
typedef struct _GstQTMuxPadClass GstQTMuxPadClass;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2009-12-11 01:20:45 +00:00
|
|
|
/*
|
|
|
|
* GstQTPadPrepareBufferFunc
|
|
|
|
*
|
|
|
|
* Receives a buffer (takes ref) and returns a new buffer that should
|
|
|
|
* replace the passed one.
|
|
|
|
*
|
|
|
|
* Useful for when the pad/datatype needs some manipulation before
|
|
|
|
* being muxed. (Originally added for image/x-jpc support, for which buffers
|
|
|
|
* need to be wrapped into a isom box)
|
|
|
|
*/
|
2019-12-03 14:30:06 +00:00
|
|
|
typedef GstBuffer * (*GstQTPadPrepareBufferFunc) (GstQTMuxPad * pad,
|
2009-12-11 01:20:45 +00:00
|
|
|
GstBuffer * buf, GstQTMux * qtmux);
|
2019-12-03 14:30:06 +00:00
|
|
|
typedef gboolean (*GstQTPadSetCapsFunc) (GstQTMuxPad * pad, GstCaps * caps);
|
|
|
|
typedef GstBuffer * (*GstQTPadCreateEmptyBufferFunc) (GstQTMuxPad * pad, gint64 duration);
|
|
|
|
|
|
|
|
GType gst_qt_mux_pad_get_type (void);
|
|
|
|
|
|
|
|
#define GST_TYPE_QT_MUX_PAD \
|
|
|
|
(gst_qt_mux_pad_get_type())
|
|
|
|
#define GST_QT_MUX_PAD(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_QT_MUX_PAD, GstQTMuxPad))
|
|
|
|
#define GST_QT_MUX_PAD_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_QT_MUX_PAD, GstQTMuxPadClass))
|
|
|
|
#define GST_IS_QT_MUX_PAD(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_QT_MUX_PAD))
|
|
|
|
#define GST_IS_QT_MUX_PAD_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_QT_MUX_PAD))
|
|
|
|
#define GST_QT_MUX_PAD_CAST(obj) \
|
|
|
|
((GstQTMuxPad *)(obj))
|
|
|
|
|
|
|
|
struct _GstQTMuxPad
|
2008-11-08 02:00:58 +00:00
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstAggregatorPad parent;
|
|
|
|
|
|
|
|
guint32 trak_timescale;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/* fourcc id of stream */
|
|
|
|
guint32 fourcc;
|
|
|
|
/* whether using format that have out of order buffers */
|
|
|
|
gboolean is_out_of_order;
|
|
|
|
/* if not 0, track with constant sized samples, e.g. raw audio */
|
|
|
|
guint sample_size;
|
|
|
|
/* make sync table entry */
|
|
|
|
gboolean sync;
|
2014-02-07 04:49:26 +00:00
|
|
|
/* if it is a sparse stream
|
|
|
|
* (meaning we can't use PTS differences to compute duration) */
|
|
|
|
gboolean sparse;
|
2010-07-05 08:39:50 +00:00
|
|
|
/* bitrates */
|
|
|
|
guint32 avg_bitrate, max_bitrate;
|
2017-03-09 08:15:34 +00:00
|
|
|
/* expected sample duration */
|
|
|
|
guint expected_sample_duration_n;
|
|
|
|
guint expected_sample_duration_d;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2011-09-28 14:41:49 +00:00
|
|
|
/* for avg bitrate calculation */
|
|
|
|
guint64 total_bytes;
|
|
|
|
guint64 total_duration;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
GstBuffer *last_buf;
|
|
|
|
/* dts of last_buf */
|
|
|
|
GstClockTime last_dts;
|
2017-03-29 11:01:25 +00:00
|
|
|
guint64 sample_offset;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-04 00:34:42 +00:00
|
|
|
/* This is compensate for CTTS */
|
|
|
|
GstClockTime dts_adjustment;
|
|
|
|
|
2009-11-06 13:34:39 +00:00
|
|
|
/* store the first timestamp for comparing with other streams and
|
|
|
|
* know if there are late streams */
|
2017-06-19 19:13:42 +00:00
|
|
|
/* subjected to dts adjustment */
|
2009-11-06 13:34:39 +00:00
|
|
|
GstClockTime first_ts;
|
2015-06-23 21:54:31 +00:00
|
|
|
GstClockTime first_dts;
|
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
gint64 dts; /* the signed version of the DTS converted to running time. */
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* all the atom and chunk book-keeping is delegated here
|
|
|
|
* unowned/uncounted reference, parent MOOV owns */
|
|
|
|
AtomTRAK *trak;
|
2016-06-24 13:32:37 +00:00
|
|
|
AtomTRAK *tc_trak;
|
2015-06-11 01:27:27 +00:00
|
|
|
SampleTableEntry *trak_ste;
|
2010-11-15 14:17:59 +00:00
|
|
|
/* fragmented support */
|
|
|
|
/* meta data book-keeping delegated here */
|
|
|
|
AtomTRAF *traf;
|
|
|
|
/* fragment buffers */
|
|
|
|
ATOM_ARRAY (GstBuffer *) fragment_buffers;
|
|
|
|
/* running fragment duration */
|
|
|
|
gint64 fragment_duration;
|
2010-11-18 15:48:06 +00:00
|
|
|
/* optional fragment index book-keeping */
|
|
|
|
AtomTFRA *tfra;
|
2009-12-11 01:20:45 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Set when tags are received, cleared when written to moov */
|
|
|
|
gboolean tags_changed;
|
|
|
|
|
2015-01-31 17:32:34 +00:00
|
|
|
GstTagList *tags;
|
|
|
|
|
2009-12-11 01:20:45 +00:00
|
|
|
/* if nothing is set, it won't be called */
|
|
|
|
GstQTPadPrepareBufferFunc prepare_buf_func;
|
2014-02-05 13:27:54 +00:00
|
|
|
GstQTPadSetCapsFunc set_caps;
|
2014-02-07 04:49:26 +00:00
|
|
|
GstQTPadCreateEmptyBufferFunc create_empty_buffer;
|
2017-03-22 16:52:51 +00:00
|
|
|
|
|
|
|
/* SMPTE timecode */
|
|
|
|
GstVideoTimeCode *first_tc;
|
|
|
|
GstClockTime first_pts;
|
|
|
|
guint64 tc_pos;
|
2017-03-09 08:15:34 +00:00
|
|
|
|
|
|
|
/* for keeping track in pre-fill mode */
|
|
|
|
GArray *samples;
|
2018-09-05 18:10:51 +00:00
|
|
|
guint first_cc_sample_size;
|
2017-03-09 08:15:34 +00:00
|
|
|
/* current sample */
|
|
|
|
GstAdapter *raw_audio_adapter;
|
|
|
|
guint64 raw_audio_adapter_offset;
|
|
|
|
GstClockTime raw_audio_adapter_pts;
|
2019-07-30 10:07:18 +00:00
|
|
|
GstFlowReturn flow_status;
|
2009-12-11 01:20:45 +00:00
|
|
|
};
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2019-12-03 14:30:06 +00:00
|
|
|
struct _GstQTMuxPadClass
|
|
|
|
{
|
|
|
|
GstAggregatorPadClass parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define QTMUX_NO_OF_TS 10
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
typedef enum _GstQTMuxState
|
|
|
|
{
|
|
|
|
GST_QT_MUX_STATE_NONE,
|
|
|
|
GST_QT_MUX_STATE_STARTED,
|
|
|
|
GST_QT_MUX_STATE_DATA,
|
|
|
|
GST_QT_MUX_STATE_EOS
|
|
|
|
} GstQTMuxState;
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
typedef enum _GstQtMuxMode {
|
|
|
|
GST_QT_MUX_MODE_MOOV_AT_END,
|
|
|
|
GST_QT_MUX_MODE_FRAGMENTED,
|
|
|
|
GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE,
|
2015-04-01 00:15:38 +00:00
|
|
|
GST_QT_MUX_MODE_FAST_START,
|
2017-03-09 08:15:34 +00:00
|
|
|
GST_QT_MUX_MODE_ROBUST_RECORDING,
|
|
|
|
GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL,
|
2015-04-01 00:15:38 +00:00
|
|
|
} GstQtMuxMode;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
struct _GstQTMux
|
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstAggregator parent;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
/* state */
|
|
|
|
GstQTMuxState state;
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Mux mode, inferred from property
|
|
|
|
* set in gst_qt_mux_start_file() */
|
|
|
|
GstQtMuxMode mux_mode;
|
|
|
|
|
|
|
|
/* size of header (prefix, atoms (ftyp, possibly moov, mdat header)) */
|
2008-11-08 02:00:58 +00:00
|
|
|
guint64 header_size;
|
2015-04-01 00:15:38 +00:00
|
|
|
/* accumulated size of raw media data (not including mdat header) */
|
2008-11-08 02:00:58 +00:00
|
|
|
guint64 mdat_size;
|
2015-04-01 00:15:38 +00:00
|
|
|
/* position of the moov (for fragmented mode) or reserved moov atom
|
|
|
|
* area (for robust-muxing mode) */
|
|
|
|
guint64 moov_pos;
|
|
|
|
/* position of mdat atom header (for later updating of size) in
|
|
|
|
* moov-at-end, fragmented and robust-muxing modes */
|
2008-11-08 02:00:58 +00:00
|
|
|
guint64 mdat_pos;
|
|
|
|
|
2009-10-16 13:47:32 +00:00
|
|
|
/* keep track of the largest chunk to fine-tune brands */
|
|
|
|
GstClockTime longest_chunk;
|
|
|
|
|
2017-06-19 19:13:42 +00:00
|
|
|
/* Earliest timestamp across all pads/traks
|
|
|
|
* (unadjusted incoming PTS) */
|
2015-04-01 00:15:38 +00:00
|
|
|
GstClockTime first_ts;
|
|
|
|
/* Last DTS across all pads (= duration) */
|
|
|
|
GstClockTime last_dts;
|
|
|
|
|
2016-10-19 11:25:28 +00:00
|
|
|
/* Last pad we used for writing the current chunk */
|
2019-12-03 14:30:06 +00:00
|
|
|
GstQTMuxPad *current_pad;
|
2016-10-19 11:25:28 +00:00
|
|
|
guint64 current_chunk_size;
|
|
|
|
GstClockTime current_chunk_duration;
|
|
|
|
guint64 current_chunk_offset;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* atom helper objects */
|
|
|
|
AtomsContext *context;
|
|
|
|
AtomFTYP *ftyp;
|
|
|
|
AtomMOOV *moov;
|
2010-09-15 20:54:49 +00:00
|
|
|
GSList *extra_atoms; /* list of extra top-level atoms (e.g. UUID for xmp)
|
|
|
|
* Stored as AtomInfo structs */
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Set when tags are received, cleared when written to moov */
|
|
|
|
gboolean tags_changed;
|
|
|
|
|
2010-11-18 15:48:06 +00:00
|
|
|
/* fragmented file index */
|
|
|
|
AtomMFRA *mfra;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* fast start */
|
|
|
|
FILE *fast_start_file;
|
|
|
|
|
2009-12-12 19:07:15 +00:00
|
|
|
/* moov recovery */
|
|
|
|
FILE *moov_recov_file;
|
|
|
|
|
2010-11-15 14:17:59 +00:00
|
|
|
/* fragment sequence */
|
|
|
|
guint32 fragment_sequence;
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
/* properties */
|
|
|
|
guint32 timescale;
|
2010-07-30 10:48:29 +00:00
|
|
|
guint32 trak_timescale;
|
2008-11-08 02:00:58 +00:00
|
|
|
AtomsTreeFlavor flavor;
|
|
|
|
gboolean fast_start;
|
2008-11-15 02:56:31 +00:00
|
|
|
gboolean guess_pts;
|
2013-03-22 20:24:33 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2011-01-03 16:24:23 +00:00
|
|
|
gint dts_method;
|
2013-03-22 20:24:33 +00:00
|
|
|
#endif
|
2008-11-08 02:00:58 +00:00
|
|
|
gchar *fast_start_file_path;
|
2009-12-12 19:07:15 +00:00
|
|
|
gchar *moov_recov_file_path;
|
2010-11-15 14:17:59 +00:00
|
|
|
guint32 fragment_duration;
|
2015-04-01 12:46:13 +00:00
|
|
|
/* Whether or not to work in 'streamable' mode and not
|
|
|
|
* seek to rewrite headers - only valid for fragmented
|
|
|
|
* mode. */
|
2010-08-06 11:26:27 +00:00
|
|
|
gboolean streamable;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Requested target maximum duration */
|
|
|
|
GstClockTime reserved_max_duration;
|
|
|
|
/* Estimate of remaining reserved header space (in ns of recording) */
|
|
|
|
GstClockTime reserved_duration_remaining;
|
|
|
|
/* Multiplier for conversion from reserved_max_duration to bytes */
|
|
|
|
guint reserved_bytes_per_sec_per_trak;
|
|
|
|
|
2016-10-19 11:25:28 +00:00
|
|
|
guint64 interleave_bytes;
|
|
|
|
GstClockTime interleave_time;
|
|
|
|
gboolean interleave_bytes_set, interleave_time_set;
|
2020-04-06 13:25:59 +00:00
|
|
|
gboolean force_chunks;
|
2016-10-19 11:25:28 +00:00
|
|
|
|
2017-03-29 11:01:25 +00:00
|
|
|
GstClockTime max_raw_audio_drift;
|
|
|
|
|
2015-04-01 00:15:38 +00:00
|
|
|
/* Reserved minimum MOOV size in bytes
|
|
|
|
* This is converted from reserved_max_duration
|
|
|
|
* using the bytes/trak/sec estimate */
|
|
|
|
guint32 reserved_moov_size;
|
|
|
|
/* Basic size of the moov (static headers + tags) */
|
|
|
|
guint32 base_moov_size;
|
|
|
|
/* Size of the most recently generated moov header */
|
|
|
|
guint32 last_moov_size;
|
|
|
|
/* True if the first moov in the ping-pong buffers
|
|
|
|
* is the active one. See gst_qt_mux_robust_recording_rewrite_moov() */
|
|
|
|
gboolean reserved_moov_first_active;
|
|
|
|
|
|
|
|
/* Tracking of periodic MOOV updates */
|
|
|
|
GstClockTime last_moov_update;
|
|
|
|
GstClockTime reserved_moov_update_period;
|
|
|
|
GstClockTime muxed_since_last_update;
|
|
|
|
|
2017-03-09 08:15:34 +00:00
|
|
|
gboolean reserved_prefill;
|
|
|
|
|
2018-10-19 14:02:11 +00:00
|
|
|
GstClockTime start_gap_threshold;
|
|
|
|
|
2018-10-22 12:41:56 +00:00
|
|
|
gboolean force_create_timecode_trak;
|
|
|
|
|
2009-12-28 09:34:35 +00:00
|
|
|
/* for request pad naming */
|
2018-02-07 10:00:18 +00:00
|
|
|
guint video_pads, audio_pads, subtitle_pads, caption_pads;
|
2008-11-08 02:00:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstQTMuxClass
|
|
|
|
{
|
2019-12-03 14:30:06 +00:00
|
|
|
GstAggregatorClass parent_class;
|
2008-11-08 02:00:58 +00:00
|
|
|
|
|
|
|
GstQTMuxFormat format;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* type register helper struct */
|
|
|
|
typedef struct _GstQTMuxClassParams
|
|
|
|
{
|
|
|
|
GstQTMuxFormatProp *prop;
|
|
|
|
GstCaps *src_caps;
|
|
|
|
GstCaps *video_sink_caps;
|
|
|
|
GstCaps *audio_sink_caps;
|
2014-02-05 13:27:54 +00:00
|
|
|
GstCaps *subtitle_sink_caps;
|
2018-02-07 10:00:18 +00:00
|
|
|
GstCaps *caption_sink_caps;
|
2008-11-08 02:00:58 +00:00
|
|
|
} GstQTMuxClassParams;
|
|
|
|
|
|
|
|
#define GST_QT_MUX_PARAMS_QDATA g_quark_from_static_string("qt-mux-params")
|
|
|
|
|
|
|
|
GType gst_qt_mux_get_type (void);
|
2009-12-12 19:07:15 +00:00
|
|
|
gboolean gst_qt_mux_register (GstPlugin * plugin);
|
2008-11-08 02:00:58 +00:00
|
|
|
|
2009-12-10 19:53:19 +00:00
|
|
|
/* FIXME: ideally classification tag should be added and
|
|
|
|
* registered in gstreamer core gsttaglist
|
|
|
|
*
|
|
|
|
* this tag is a string in the format: entityfourcc://table_num/content
|
|
|
|
* FIXME Shouldn't we add a field for 'language'?
|
|
|
|
*/
|
|
|
|
#define GST_TAG_3GP_CLASSIFICATION "classification"
|
|
|
|
|
2008-11-08 02:00:58 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_QT_MUX_H__ */
|