splitmuxsink: Allow time and bytes to reach their respective thresholds
[platform/upstream/gst-plugins-good.git] / gst / multifile / gstsplitmuxsink.h
1 /* GStreamer split muxer bin
2  * Copyright (C) 2014 Jan Schmidt <jan@centricular.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __GST_SPLITMUXSINK_H__
21 #define __GST_SPLITMUXSINK_H__
22
23 #include <gst/gst.h>
24 #include <gst/pbutils/pbutils.h>
25
26 G_BEGIN_DECLS
27
28 #define GST_TYPE_SPLITMUX_SINK               (gst_splitmux_sink_get_type())
29 #define GST_SPLITMUX_SINK(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPLITMUX_SINK,GstSplitMuxSink))
30 #define GST_SPLITMUX_SINK_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPLITMUX_SINK,GstSplitMuxSinkClass))
31 #define GST_IS_SPLITMUX_SINK(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPLITMUX_SINK))
32 #define GST_IS_SPLITMUX_SINK_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPLITMUX_SINK))
33
34 typedef struct _GstSplitMuxSink GstSplitMuxSink;
35 typedef struct _GstSplitMuxSinkClass GstSplitMuxSinkClass;
36
37 GType gst_splitmux_sink_get_type(void);
38 gboolean register_splitmuxsink (GstPlugin * plugin);
39
40 typedef enum _SplitMuxState {
41   SPLITMUX_STATE_STOPPED,
42   SPLITMUX_STATE_COLLECTING_GOP_START,
43   SPLITMUX_STATE_WAITING_GOP_COMPLETE,
44   SPLITMUX_STATE_ENDING_FILE,
45   SPLITMUX_STATE_START_NEXT_FRAGMENT,
46 } SplitMuxState;
47
48 typedef struct _MqStreamBuf
49 {
50   gboolean keyframe;
51   GstClockTimeDiff run_ts;
52   gsize buf_size;
53 } MqStreamBuf;
54
55 typedef struct _MqStreamCtx
56 {
57   gint refcount;
58
59   GstSplitMuxSink *splitmux;
60
61   guint sink_pad_block_id;
62   guint src_pad_block_id;
63
64   gboolean is_reference;
65
66   gboolean flushing;
67   gboolean in_eos;
68   gboolean out_eos;
69
70   GstSegment in_segment;
71   GstSegment out_segment;
72
73   GstClockTimeDiff in_running_time;
74   GstClockTimeDiff out_running_time;
75
76   gsize in_bytes;
77
78   GQueue queued_bufs;
79
80   GstPad *sinkpad;
81   GstPad *srcpad;
82
83   gboolean out_blocked;
84 } MqStreamCtx;
85
86 struct _GstSplitMuxSink {
87   GstBin parent;
88
89   GMutex lock;
90   GCond data_cond;
91
92   SplitMuxState state;
93   gdouble mux_overhead;
94
95   GstClockTime threshold_time;
96   guint64 threshold_bytes;
97   guint max_files;
98
99   guint mq_max_buffers;
100
101   GstElement *mq;
102   GstElement *muxer;
103   GstElement *sink;
104
105   GstElement *provided_muxer;
106
107   GstElement *provided_sink;
108   GstElement *active_sink;
109
110   gchar *location;
111   guint fragment_id;
112
113   GList *contexts;
114
115   MqStreamCtx *reference_ctx;
116   guint queued_gops;
117   GstClockTimeDiff max_in_running_time;
118   GstClockTimeDiff max_out_running_time;
119
120   GstClockTimeDiff muxed_out_time;
121   gsize muxed_out_bytes;
122   gboolean have_muxed_something;
123
124   GstClockTimeDiff mux_start_time;
125   gsize mux_start_bytes;
126
127   gboolean opening_first_fragment;
128   gboolean switching_fragment;
129 };
130
131 struct _GstSplitMuxSinkClass {
132   GstBinClass parent_class;
133 };
134
135 G_END_DECLS
136
137 #endif /* __GST_SPLITMUXSINK_H__ */