1 /*
2  * GStreamer
3  * Copyright (C) 2016 Vivia Nikolaidou <vivia@toolsonair.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef __GST_AVWAIT_H__
22 #define __GST_AVWAIT_H__
23 
24 #include <gst/gst.h>
25 #include <gst/audio/audio.h>
26 #include <gst/video/video.h>
27 
28 G_BEGIN_DECLS
29 #define GST_TYPE_AVWAIT                    (gst_avwait_get_type())
30 #define GST_AVWAIT(obj)                    (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AVWAIT,GstAvWait))
31 #define GST_IS_AVWAIT(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AVWAIT))
32 #define GST_AVWAIT_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_AVWAIT,GstAvWaitClass))
33 #define GST_IS_AVWAIT_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_AVWAIT))
34 #define GST_AVWAIT_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_AVWAIT,GstAvWaitClass))
35 #define GST_TYPE_AVWAIT_MODE (gst_avwait_mode_get_type ())
36 typedef struct _GstAvWait GstAvWait;
37 typedef struct _GstAvWaitClass GstAvWaitClass;
38 
39 typedef enum
40 {
41   MODE_TIMECODE,
42   MODE_RUNNING_TIME,
43   MODE_VIDEO_FIRST
44 } GstAvWaitMode;
45 
46 struct _GstAvWait
47 {
48   GstElement parent;
49 
50   GstVideoTimeCode *tc;
51   GstClockTime target_running_time;
52   GstAvWaitMode mode;
53 
54   GstVideoTimeCode *end_tc;
55   GstClockTime running_time_to_end_at;
56 
57   GstPad *asrcpad, *asinkpad, *vsrcpad, *vsinkpad;
58 
59   GstAudioInfo ainfo;
60   GstVideoInfo vinfo;
61 
62   GstSegment asegment, vsegment;
63 
64   GstClockTime running_time_to_wait_for;
65   GstClockTime last_seen_video_running_time;
66   GstClockTime first_audio_running_time;
67   GstVideoTimeCode *last_seen_tc;
68 
69   /* If running_time_to_wait_for has been reached but we are
70    * not recording, audio shouldn't start running. It should
71    * instead start synchronised with the video when we start
72    * recording. Similarly when stopping recording manually vs
73    * when the target timecode has been reached. So we use
74    * different variables for the audio */
75   GstClockTime audio_running_time_to_wait_for;
76   GstClockTime audio_running_time_to_end_at;
77 
78   gboolean video_eos_flag;
79   gboolean audio_eos_flag;
80   gboolean video_flush_flag;
81   gboolean audio_flush_flag;
82   gboolean shutdown_flag;
83 
84   gboolean dropping;
85   gboolean recording;
86   gboolean was_recording;
87   gint must_send_end_message;
88 
89   GCond cond;
90   GMutex mutex;
91   GCond audio_cond;
92 };
93 
94 struct _GstAvWaitClass
95 {
96   GstElementClass parent_class;
97 };
98 
99 GType gst_avwait_get_type (void);
100 
101 G_END_DECLS
102 #endif /* __GST_AVWAIT_H__ */
103