1 /* 2 * GStreamer 3 * Copyright (C) 2016 Vivia Nikolaidou <vivia@toolsonair.com> 4 * 5 * gsttimecodestamper.h 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public 18 * License along with this library; if not, write to the 19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #ifndef __GST_TIME_CODE_STAMPER_H__ 24 #define __GST_TIME_CODE_STAMPER_H__ 25 26 #include <gst/gst.h> 27 #include <gst/video/video.h> 28 #include <gst/audio/audio.h> 29 30 #if HAVE_LTC 31 #include <ltc.h> 32 #endif 33 34 #define GST_TYPE_TIME_CODE_STAMPER (gst_timecodestamper_get_type()) 35 #define GST_TIME_CODE_STAMPER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TIME_CODE_STAMPER,GstTimeCodeStamper)) 36 #define GST_TIME_CODE_STAMPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_TIME_CODE_STAMPER,GstTimeCodeStamperClass)) 37 #define GST_TIME_CODE_STAMPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_TIME_CODE_STAMPER,GstTimeCodeStamperClass)) 38 #define GST_IS_TIME_CODE_STAMPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TIME_CODE_STAMPER)) 39 #define GST_IS_TIME_CODE_STAMPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_TIME_CODE_STAMPER)) 40 41 #define GST_TYPE_TIME_CODE_STAMPER_SOURCE (gst_timecodestamper_source_get_type()) 42 #define GST_TYPE_TIME_CODE_STAMPER_SET (gst_timecodestamper_set_get_type()) 43 44 typedef struct _GstTimeCodeStamper GstTimeCodeStamper; 45 typedef struct _GstTimeCodeStamperClass GstTimeCodeStamperClass; 46 47 typedef enum GstTimeCodeStamperSource 48 { 49 GST_TIME_CODE_STAMPER_SOURCE_INTERNAL, 50 GST_TIME_CODE_STAMPER_SOURCE_ZERO, 51 GST_TIME_CODE_STAMPER_SOURCE_LAST_KNOWN, 52 GST_TIME_CODE_STAMPER_SOURCE_LAST_KNOWN_OR_ZERO, 53 GST_TIME_CODE_STAMPER_SOURCE_LTC, 54 GST_TIME_CODE_STAMPER_SOURCE_RTC, 55 } GstTimeCodeStamperSource; 56 57 typedef enum GstTimeCodeStamperSet { 58 GST_TIME_CODE_STAMPER_SET_NEVER, 59 GST_TIME_CODE_STAMPER_SET_KEEP, 60 GST_TIME_CODE_STAMPER_SET_ALWAYS, 61 } GstTimeCodeStamperSet; 62 63 /** 64 * GstTimeCodeStamper: 65 * 66 * Opaque data structure. 67 */ 68 struct _GstTimeCodeStamper 69 { 70 GstBaseTransform videofilter; 71 72 /* protected by object lock */ 73 GstPad *ltcpad; 74 75 /* < private > */ 76 77 /* Properties, protected by object lock */ 78 GstTimeCodeStamperSource tc_source; 79 GstTimeCodeStamperSet tc_set; 80 gboolean tc_auto_resync; 81 GstClockTime tc_timeout; 82 gboolean drop_frame; 83 gboolean post_messages; 84 GstVideoTimeCode *set_internal_tc; 85 GDateTime *ltc_daily_jam; 86 gboolean ltc_auto_resync; 87 GstClockTime ltc_timeout; 88 GstClockTime ltc_extra_latency; 89 GstClockTime rtc_max_drift; 90 gboolean rtc_auto_resync; 91 gint timecode_offset; 92 93 /* Timecode tracking, protected by object lock */ 94 GstVideoTimeCode *internal_tc; 95 GstVideoTimeCode *last_tc; 96 GstClockTime last_tc_running_time; 97 GstVideoTimeCode *rtc_tc; 98 99 /* Internal state, protected by object lock, changed only from video streaming thread */ 100 gint fps_n; 101 gint fps_d; 102 GstVideoInterlaceMode interlace_mode; 103 104 /* Seek handling, protected by the object lock */ 105 guint32 prev_seek_seqnum; 106 gboolean reset_internal_tc_from_seek; 107 gint64 seeked_frames; 108 109 /* LTC specific fields */ 110 #if HAVE_LTC 111 GMutex mutex; 112 GCond ltc_cond_video; 113 GCond ltc_cond_audio; 114 115 /* Only accessed from audio streaming thread */ 116 GstAudioInfo ainfo; 117 GstAudioStreamAlign *stream_align; 118 GstSegment ltc_segment; 119 /* Running time of the first audio buffer passed to the LTC decoder */ 120 GstClockTime ltc_first_running_time; 121 /* Running time of the last sample we passed to the LTC decoder so far */ 122 GstClockTime ltc_current_running_time; 123 124 /* Protected by object lock */ 125 /* Queue of LTC timecodes we took out of the LTC decoder already 126 * together with their corresponding running times */ 127 GQueue ltc_current_tcs; 128 129 /* LTC timecode we last synced to and potentially incremented manually since 130 * then */ 131 GstVideoTimeCode *ltc_internal_tc; 132 GstClockTime ltc_internal_running_time; 133 134 /* Running time of last video frame we received */ 135 GstClockTime video_current_running_time; 136 137 /* Protected by mutex above */ 138 LTCDecoder *ltc_dec; 139 ltc_off_t ltc_total; 140 141 /* Protected by mutex above */ 142 gboolean video_flushing; 143 gboolean video_eos; 144 145 /* Protected by mutex above */ 146 gboolean ltc_flushing; 147 gboolean ltc_eos; 148 149 /* Latency information for LTC audio and video stream */ 150 GstClockTime audio_latency, video_latency; 151 gboolean audio_live, video_live; 152 /* Latency we report to downstream */ 153 GstClockTime latency; 154 GstClockID video_clock_id; 155 156 GstPadActivateModeFunction video_activatemode_default; 157 #endif 158 }; 159 160 struct _GstTimeCodeStamperClass 161 { 162 GstBaseTransformClass parent_class; 163 }; 164 165 GType gst_timecodestamper_get_type (void); 166 GST_ELEMENT_REGISTER_DECLARE (timecodestamper); 167 168 GType gst_timecodestamper_source_get_type (void); 169 GType gst_timecodestamper_set_get_type (void); 170 171 G_END_DECLS 172 #endif /* __GST_TIME_CODE_STAMPER_H__ */ 173