decklink{audio,video}src: Take the capture times from the pipeline clock

Not from the decklink clock. Both will return exactly the same time once the
decklink clock got slaved to the pipeline clock and received the first
observation, but until then it will return bogus values. But as both return
exactly the same values, we can as well use the pipeline clock directly.
This commit is contained in:
Sebastian Dröge 2015-02-08 21:53:58 +01:00
parent 6725ff5598
commit 22b0a4dad5
4 changed files with 61 additions and 43 deletions

View file

@ -474,24 +474,37 @@ public:
VideoInputFrameArrived (IDeckLinkVideoInputFrame * video_frame,
IDeckLinkAudioInputPacket * audio_packet)
{
GstClockTime clock_time = gst_clock_get_time (m_input->clock);
GstElement *videosrc = NULL, *audiosrc = NULL;
void (*got_video_frame) (GstElement * videosrc,
IDeckLinkVideoInputFrame * frame, GstDecklinkModeEnum mode) = NULL;
void (*got_audio_packet) (GstElement * videosrc,
IDeckLinkAudioInputPacket * packet) = NULL;
GstDecklinkModeEnum mode;
g_mutex_lock (&m_input->lock);
if (m_input->got_video_frame) {
GstClockTime capture_time = clock_time -
gst_element_get_base_time (m_input->videosrc);
m_input->got_video_frame (m_input->videosrc, video_frame,
gst_decklink_get_mode_enum_from_bmd (m_input->mode->mode),
capture_time);
if (m_input->videosrc) {
videosrc = GST_ELEMENT_CAST (gst_object_ref (m_input->videosrc));
got_video_frame = m_input->got_video_frame;
}
mode = gst_decklink_get_mode_enum_from_bmd (m_input->mode->mode);
if (m_input->got_audio_packet) {
GstClockTime capture_time = clock_time -
gst_element_get_base_time (m_input->audiosrc);
m_input->got_audio_packet (m_input->audiosrc, audio_packet, capture_time);
if (m_input->audiosrc) {
audiosrc = GST_ELEMENT_CAST (gst_object_ref (m_input->audiosrc));
got_audio_packet = m_input->got_audio_packet;
}
g_mutex_unlock (&m_input->lock);
if (got_video_frame && videosrc) {
got_video_frame (videosrc, video_frame, mode);
}
if (got_audio_packet && audiosrc) {
m_input->got_audio_packet (audiosrc, audio_packet);
}
gst_object_replace ((GstObject **) & videosrc, NULL);
gst_object_replace ((GstObject **) & audiosrc, NULL);
return S_OK;
}
};

View file

@ -169,12 +169,12 @@ struct _GstDecklinkInput {
GMutex lock;
/* Set by the video source */
void (*got_video_frame) (GstElement *videosrc, IDeckLinkVideoInputFrame * frame, GstDecklinkModeEnum mode, GstClockTime capture_time);
void (*got_video_frame) (GstElement *videosrc, IDeckLinkVideoInputFrame * frame, GstDecklinkModeEnum mode);
/* Configured mode or NULL */
const GstDecklinkMode *mode;
/* Set by the audio source */
void (*got_audio_packet) (GstElement *videosrc, IDeckLinkAudioInputPacket * packet, GstClockTime capture_time);
void (*got_audio_packet) (GstElement *videosrc, IDeckLinkAudioInputPacket * packet);
GstElement *audiosrc;
gboolean audio_enabled;

View file

@ -411,9 +411,25 @@ gst_decklink_audio_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
static void
gst_decklink_audio_src_got_packet (GstElement * element,
IDeckLinkAudioInputPacket * packet, GstClockTime capture_time)
IDeckLinkAudioInputPacket * packet)
{
GstDecklinkAudioSrc *self = GST_DECKLINK_AUDIO_SRC_CAST (element);
GstClock *clock;
GstClockTime capture_time;
clock = gst_element_get_clock (element);
if (clock) {
GstClockTime clock_time, base_time;
clock_time = gst_clock_get_time (clock);
g_return_if_fail (clock_time != GST_CLOCK_TIME_NONE);
base_time = gst_element_get_base_time (element);
g_return_if_fail (base_time != GST_CLOCK_TIME_NONE);
capture_time = clock_time - base_time;
gst_object_unref (clock);
} else {
capture_time = GST_CLOCK_TIME_NONE;
}
GST_LOG_OBJECT (self, "Got audio packet at %" GST_TIME_FORMAT,
GST_TIME_ARGS (capture_time));
@ -748,18 +764,6 @@ gst_decklink_audio_src_change_state (GstElement * element,
self->next_offset = -1;
break;
}
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:{
GstClock *clock;
clock = gst_element_get_clock (GST_ELEMENT_CAST (self));
if (clock && clock != self->input->clock) {
gst_clock_set_master (self->input->clock, clock);
}
if (clock)
gst_object_unref (clock);
break;
}
default:
break;
}
@ -773,7 +777,6 @@ gst_decklink_audio_src_change_state (GstElement * element,
gst_element_post_message (element,
gst_message_new_clock_lost (GST_OBJECT_CAST (element),
self->input->clock));
gst_clock_set_master (self->input->clock, NULL);
g_queue_foreach (&self->current_packets, (GFunc) capture_packet_free,
NULL);

View file

@ -364,10 +364,25 @@ gst_decklink_video_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
static void
gst_decklink_video_src_got_frame (GstElement * element,
IDeckLinkVideoInputFrame * frame, GstDecklinkModeEnum mode,
GstClockTime capture_time)
IDeckLinkVideoInputFrame * frame, GstDecklinkModeEnum mode)
{
GstDecklinkVideoSrc *self = GST_DECKLINK_VIDEO_SRC_CAST (element);
GstClock *clock;
GstClockTime capture_time;
clock = gst_element_get_clock (element);
if (clock) {
GstClockTime clock_time, base_time;
clock_time = gst_clock_get_time (clock);
g_return_if_fail (clock_time != GST_CLOCK_TIME_NONE);
base_time = gst_element_get_base_time (element);
g_return_if_fail (base_time != GST_CLOCK_TIME_NONE);
capture_time = clock_time - base_time;
gst_object_unref (clock);
} else {
capture_time = GST_CLOCK_TIME_NONE;
}
GST_LOG_OBJECT (self, "Got video frame at %" GST_TIME_FORMAT,
GST_TIME_ARGS (capture_time));
@ -637,18 +652,6 @@ gst_decklink_video_src_change_state (GstElement * element,
self->input->clock, TRUE));
self->flushing = FALSE;
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:{
GstClock *clock;
clock = gst_element_get_clock (GST_ELEMENT_CAST (self));
if (clock && clock != self->input->clock) {
gst_clock_set_master (self->input->clock, clock);
}
if (clock)
gst_object_unref (clock);
break;
}
default:
break;
}
@ -662,7 +665,6 @@ gst_decklink_video_src_change_state (GstElement * element,
gst_element_post_message (element,
gst_message_new_clock_lost (GST_OBJECT_CAST (element),
self->input->clock));
gst_clock_set_master (self->input->clock, NULL);
g_mutex_lock (&self->input->lock);
self->input->clock_start_time = GST_CLOCK_TIME_NONE;
self->input->clock_last_time = 0;