2014-07-31 14:07:53 +00:00
|
|
|
/* GStreamer split muxer bin
|
2019-05-25 12:08:05 +00:00
|
|
|
* Copyright (C) 2014-2019 Jan Schmidt <jan@centricular.com>
|
2014-07-31 14:07:53 +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
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GST_SPLITMUXSINK_H__
|
|
|
|
#define __GST_SPLITMUXSINK_H__
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/pbutils/pbutils.h>
|
2018-09-26 14:43:05 +00:00
|
|
|
#include <gst/base/base.h>
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
#define GST_TYPE_SPLITMUX_SINK (gst_splitmux_sink_get_type())
|
|
|
|
#define GST_SPLITMUX_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPLITMUX_SINK,GstSplitMuxSink))
|
|
|
|
#define GST_SPLITMUX_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPLITMUX_SINK,GstSplitMuxSinkClass))
|
|
|
|
#define GST_IS_SPLITMUX_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPLITMUX_SINK))
|
|
|
|
#define GST_IS_SPLITMUX_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPLITMUX_SINK))
|
|
|
|
typedef struct _GstSplitMuxSink GstSplitMuxSink;
|
|
|
|
typedef struct _GstSplitMuxSinkClass GstSplitMuxSinkClass;
|
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
GType gst_splitmux_sink_get_type (void);
|
2014-07-31 14:07:53 +00:00
|
|
|
gboolean register_splitmuxsink (GstPlugin * plugin);
|
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
typedef enum _SplitMuxInputState
|
|
|
|
{
|
|
|
|
SPLITMUX_INPUT_STATE_STOPPED,
|
|
|
|
SPLITMUX_INPUT_STATE_COLLECTING_GOP_START, /* Waiting for the next ref ctx keyframe */
|
|
|
|
SPLITMUX_INPUT_STATE_WAITING_GOP_COLLECT, /* Waiting for all streams to collect GOP */
|
|
|
|
SPLITMUX_INPUT_STATE_FINISHING_UP /* Got EOS from reference ctx, send everything */
|
|
|
|
} SplitMuxInputState;
|
|
|
|
|
|
|
|
typedef enum _SplitMuxOutputState
|
|
|
|
{
|
|
|
|
SPLITMUX_OUTPUT_STATE_STOPPED,
|
|
|
|
SPLITMUX_OUTPUT_STATE_AWAITING_COMMAND, /* Waiting first command packet from input */
|
|
|
|
SPLITMUX_OUTPUT_STATE_OUTPUT_GOP, /* Outputting a collected GOP */
|
|
|
|
SPLITMUX_OUTPUT_STATE_ENDING_FILE, /* Finishing the current fragment */
|
|
|
|
SPLITMUX_OUTPUT_STATE_START_NEXT_FILE /* Restarting after ENDING_FILE */
|
|
|
|
} SplitMuxOutputState;
|
|
|
|
|
|
|
|
typedef struct _SplitMuxOutputCommand
|
|
|
|
{
|
|
|
|
gboolean start_new_fragment; /* Whether to start a new fragment before advancing output ts */
|
|
|
|
GstClockTimeDiff max_output_ts; /* Set the limit to stop GOP output */
|
|
|
|
} SplitMuxOutputCommand;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
typedef struct _MqStreamBuf
|
|
|
|
{
|
|
|
|
gboolean keyframe;
|
2016-07-17 12:41:02 +00:00
|
|
|
GstClockTimeDiff run_ts;
|
2016-08-20 08:59:30 +00:00
|
|
|
guint64 buf_size;
|
2016-08-09 09:55:59 +00:00
|
|
|
GstClockTime duration;
|
2014-07-31 14:07:53 +00:00
|
|
|
} MqStreamBuf;
|
|
|
|
|
|
|
|
typedef struct _MqStreamCtx
|
|
|
|
{
|
|
|
|
GstSplitMuxSink *splitmux;
|
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
guint q_overrun_id;
|
2014-07-31 14:07:53 +00:00
|
|
|
guint sink_pad_block_id;
|
|
|
|
guint src_pad_block_id;
|
2017-06-13 14:42:55 +00:00
|
|
|
gulong fragment_block_id;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2015-04-29 17:23:28 +00:00
|
|
|
gboolean is_reference;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
gboolean flushing;
|
|
|
|
gboolean in_eos;
|
|
|
|
gboolean out_eos;
|
2017-06-13 14:42:55 +00:00
|
|
|
gboolean out_eos_async_done;
|
2016-11-18 11:42:18 +00:00
|
|
|
gboolean need_unblock;
|
2017-02-15 19:48:58 +00:00
|
|
|
gboolean caps_change;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
GstSegment in_segment;
|
|
|
|
GstSegment out_segment;
|
|
|
|
|
2016-07-17 12:41:02 +00:00
|
|
|
GstClockTimeDiff in_running_time;
|
|
|
|
GstClockTimeDiff out_running_time;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2016-12-22 15:40:40 +00:00
|
|
|
GstBuffer *prev_in_keyframe; /* store keyframe for each GOP */
|
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
GstElement *q;
|
2014-07-31 14:07:53 +00:00
|
|
|
GQueue queued_bufs;
|
|
|
|
|
|
|
|
GstPad *sinkpad;
|
|
|
|
GstPad *srcpad;
|
|
|
|
|
2016-12-22 15:40:40 +00:00
|
|
|
GstBuffer *cur_out_buffer;
|
2016-11-17 12:40:27 +00:00
|
|
|
GstEvent *pending_gap;
|
2014-07-31 14:07:53 +00:00
|
|
|
} MqStreamCtx;
|
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
struct _GstSplitMuxSink
|
|
|
|
{
|
2014-07-31 14:07:53 +00:00
|
|
|
GstBin parent;
|
|
|
|
|
|
|
|
GMutex lock;
|
2016-11-18 11:42:18 +00:00
|
|
|
GCond input_cond;
|
|
|
|
GCond output_cond;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
gdouble mux_overhead;
|
|
|
|
|
|
|
|
GstClockTime threshold_time;
|
|
|
|
guint64 threshold_bytes;
|
2016-04-13 17:45:07 +00:00
|
|
|
guint max_files;
|
2016-08-09 09:55:59 +00:00
|
|
|
gboolean send_keyframe_requests;
|
2016-12-22 15:40:40 +00:00
|
|
|
gchar *threshold_timecode_str;
|
|
|
|
GstClockTime next_max_tc_time;
|
2017-05-12 14:53:57 +00:00
|
|
|
GstClockTime alignment_threshold;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2018-03-29 16:19:21 +00:00
|
|
|
gboolean reset_muxer;
|
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
GstElement *muxer;
|
|
|
|
GstElement *sink;
|
|
|
|
|
|
|
|
GstElement *provided_muxer;
|
|
|
|
|
|
|
|
GstElement *provided_sink;
|
|
|
|
GstElement *active_sink;
|
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
gboolean ready_for_output;
|
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
gchar *location;
|
|
|
|
guint fragment_id;
|
2019-12-05 14:58:40 +00:00
|
|
|
guint start_index;
|
2014-07-31 14:07:53 +00:00
|
|
|
GList *contexts;
|
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
SplitMuxInputState input_state;
|
2016-07-17 12:41:02 +00:00
|
|
|
GstClockTimeDiff max_in_running_time;
|
2016-11-18 11:42:18 +00:00
|
|
|
/* Number of bytes sent to the
|
|
|
|
* current fragment */
|
|
|
|
guint64 fragment_total_bytes;
|
|
|
|
/* Number of bytes we've collected into
|
|
|
|
* the GOP that's being collected */
|
|
|
|
guint64 gop_total_bytes;
|
|
|
|
/* Start time of the current fragment */
|
|
|
|
GstClockTimeDiff fragment_start_time;
|
|
|
|
/* Start time of the current GOP */
|
|
|
|
GstClockTimeDiff gop_start_time;
|
|
|
|
|
|
|
|
GQueue out_cmd_q; /* Queue of commands for output thread */
|
|
|
|
|
|
|
|
SplitMuxOutputState output_state;
|
2016-07-17 12:41:02 +00:00
|
|
|
GstClockTimeDiff max_out_running_time;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2016-08-20 08:59:30 +00:00
|
|
|
guint64 muxed_out_bytes;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
MqStreamCtx *reference_ctx;
|
|
|
|
/* Count of queued keyframes in the reference ctx */
|
|
|
|
guint queued_keyframes;
|
2015-04-17 12:25:43 +00:00
|
|
|
|
2016-08-07 16:53:48 +00:00
|
|
|
gboolean switching_fragment;
|
2016-10-26 03:32:48 +00:00
|
|
|
|
|
|
|
gboolean have_video;
|
2016-11-17 12:40:27 +00:00
|
|
|
|
|
|
|
gboolean need_async_start;
|
|
|
|
gboolean async_pending;
|
2015-04-07 13:53:19 +00:00
|
|
|
|
|
|
|
gboolean use_robust_muxing;
|
|
|
|
gboolean muxer_has_reserved_props;
|
2017-09-21 15:23:54 +00:00
|
|
|
|
2018-08-16 19:42:37 +00:00
|
|
|
gboolean split_requested;
|
|
|
|
gboolean do_split_next_gop;
|
2018-09-26 14:43:05 +00:00
|
|
|
GstQueueArray *times_to_split;
|
2017-06-13 14:42:55 +00:00
|
|
|
|
|
|
|
/* Async finalize options */
|
|
|
|
gboolean async_finalize;
|
|
|
|
gchar *muxer_factory;
|
|
|
|
GstStructure *muxer_properties;
|
|
|
|
gchar *sink_factory;
|
|
|
|
GstStructure *sink_properties;
|
2019-07-31 06:17:36 +00:00
|
|
|
|
|
|
|
GstStructure *muxerpad_map;
|
2014-07-31 14:07:53 +00:00
|
|
|
};
|
|
|
|
|
2016-11-18 11:42:18 +00:00
|
|
|
struct _GstSplitMuxSinkClass
|
|
|
|
{
|
2014-07-31 14:07:53 +00:00
|
|
|
GstBinClass parent_class;
|
2017-09-21 15:23:54 +00:00
|
|
|
|
|
|
|
/* actions */
|
|
|
|
void (*split_now) (GstSplitMuxSink * splitmux);
|
2018-08-16 19:42:37 +00:00
|
|
|
void (*split_after) (GstSplitMuxSink * splitmux);
|
2018-09-26 14:43:05 +00:00
|
|
|
void (*split_at_running_time) (GstSplitMuxSink * splitmux, GstClockTime split_time);
|
2014-07-31 14:07:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
#endif /* __GST_SPLITMUXSINK_H__ */
|