2011-02-27 08:48:19 +00:00
|
|
|
/* -LICENSE-START-
|
|
|
|
** Copyright (c) 2009 Blackmagic Design
|
|
|
|
**
|
|
|
|
** Permission is hereby granted, free of charge, to any person or organization
|
|
|
|
** obtaining a copy of the software and accompanying documentation covered by
|
|
|
|
** this license (the "Software") to use, reproduce, display, distribute,
|
|
|
|
** execute, and transmit the Software, and to prepare derivative works of the
|
|
|
|
** Software, and to permit third-parties to whom the Software is furnished to
|
|
|
|
** do so, all subject to the following:
|
|
|
|
**
|
|
|
|
** The copyright notices in the Software and this entire statement, including
|
|
|
|
** the above license grant, this restriction and the following disclaimer,
|
|
|
|
** must be included in all copies of the Software, in whole or in part, and
|
|
|
|
** all derivative works of the Software, unless such copies or derivative
|
|
|
|
** works are solely in the form of machine-executable object code generated by
|
|
|
|
** a source language processor.
|
|
|
|
**
|
|
|
|
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
|
|
|
** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
|
|
|
** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
|
|
|
** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
** DEALINGS IN THE SOFTWARE.
|
|
|
|
** -LICENSE-END-
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2012-01-27 14:49:58 +00:00
|
|
|
#include <gst/glib-compat-private.h>
|
|
|
|
|
2011-02-27 08:48:19 +00:00
|
|
|
#include "gstdecklinksrc.h"
|
|
|
|
|
|
|
|
#include "capture.h"
|
|
|
|
|
2011-07-07 18:20:37 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_decklink_src_debug_category
|
2011-02-27 08:48:19 +00:00
|
|
|
|
|
|
|
IDeckLink *deckLink;
|
|
|
|
IDeckLinkInput *deckLinkInput;
|
|
|
|
IDeckLinkDisplayModeIterator *displayModeIterator;
|
|
|
|
|
2012-03-17 18:39:54 +00:00
|
|
|
static BMDTimecodeFormat g_timecodeFormat = (BMDTimecodeFormat) 0;
|
2011-02-27 08:48:19 +00:00
|
|
|
|
|
|
|
DeckLinkCaptureDelegate::DeckLinkCaptureDelegate ():m_refCount (0)
|
|
|
|
{
|
2012-03-17 18:39:54 +00:00
|
|
|
m_mutex = g_mutex_new ();
|
2011-02-27 08:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DeckLinkCaptureDelegate::~DeckLinkCaptureDelegate ()
|
|
|
|
{
|
2011-07-07 18:13:00 +00:00
|
|
|
g_mutex_free (m_mutex);
|
2011-02-27 08:48:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 18:39:54 +00:00
|
|
|
ULONG DeckLinkCaptureDelegate::AddRef (void)
|
2011-02-27 08:48:19 +00:00
|
|
|
{
|
2011-07-07 18:13:00 +00:00
|
|
|
g_mutex_lock (m_mutex);
|
2011-02-27 08:48:19 +00:00
|
|
|
m_refCount++;
|
2011-07-07 18:13:00 +00:00
|
|
|
g_mutex_unlock (m_mutex);
|
2011-02-27 08:48:19 +00:00
|
|
|
|
|
|
|
return (ULONG) m_refCount;
|
|
|
|
}
|
|
|
|
|
2012-03-17 18:39:54 +00:00
|
|
|
ULONG DeckLinkCaptureDelegate::Release (void)
|
2011-02-27 08:48:19 +00:00
|
|
|
{
|
2011-07-07 18:13:00 +00:00
|
|
|
g_mutex_lock (m_mutex);
|
2011-02-27 08:48:19 +00:00
|
|
|
m_refCount--;
|
2011-07-07 18:13:00 +00:00
|
|
|
g_mutex_unlock (m_mutex);
|
2011-02-27 08:48:19 +00:00
|
|
|
|
|
|
|
if (m_refCount == 0) {
|
2012-03-17 18:39:54 +00:00
|
|
|
delete
|
|
|
|
this;
|
2011-02-27 08:48:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ULONG) m_refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
2011-06-06 04:17:04 +00:00
|
|
|
DeckLinkCaptureDelegate::VideoInputFrameArrived (IDeckLinkVideoInputFrame *
|
2011-02-27 08:48:19 +00:00
|
|
|
videoFrame, IDeckLinkAudioInputPacket * audioFrame)
|
|
|
|
{
|
2011-06-06 04:24:58 +00:00
|
|
|
GstDecklinkSrc *decklinksrc;
|
|
|
|
|
|
|
|
g_return_val_if_fail (priv != NULL, S_OK);
|
|
|
|
g_return_val_if_fail (GST_IS_DECKLINK_SRC (priv), S_OK);
|
|
|
|
|
|
|
|
decklinksrc = GST_DECKLINK_SRC (priv);
|
2011-02-27 08:48:19 +00:00
|
|
|
|
|
|
|
// Handle Video Frame
|
|
|
|
if (videoFrame) {
|
|
|
|
if (videoFrame->GetFlags () & bmdFrameHasNoInputSource) {
|
2011-06-06 04:17:04 +00:00
|
|
|
GST_DEBUG ("Frame received - No input signal detected");
|
2011-02-27 08:48:19 +00:00
|
|
|
} else {
|
|
|
|
const char *timecodeString = NULL;
|
|
|
|
if (g_timecodeFormat != 0) {
|
|
|
|
IDeckLinkTimecode *timecode;
|
|
|
|
if (videoFrame->GetTimecode (g_timecodeFormat, &timecode) == S_OK) {
|
2011-08-22 01:44:43 +00:00
|
|
|
timecode->GetString (&timecodeString);
|
2011-07-07 20:44:31 +00:00
|
|
|
CONVERT_COM_STRING (timecodeString);
|
2011-02-27 08:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-06 04:17:04 +00:00
|
|
|
GST_DEBUG ("Frame received [%s] - %s - Size: %li bytes",
|
2011-02-27 08:48:19 +00:00
|
|
|
timecodeString != NULL ? timecodeString : "No timecode",
|
2011-06-06 04:17:04 +00:00
|
|
|
"Valid Frame", videoFrame->GetRowBytes () * videoFrame->GetHeight ());
|
2011-02-27 08:48:19 +00:00
|
|
|
|
|
|
|
if (timecodeString)
|
2011-07-07 20:44:31 +00:00
|
|
|
FREE_COM_STRING (timecodeString);
|
2011-02-27 08:48:19 +00:00
|
|
|
|
|
|
|
g_mutex_lock (decklinksrc->mutex);
|
|
|
|
if (decklinksrc->video_frame != NULL) {
|
|
|
|
decklinksrc->dropped_frames++;
|
|
|
|
} else {
|
2011-06-06 04:17:04 +00:00
|
|
|
videoFrame->AddRef ();
|
2011-02-27 08:48:19 +00:00
|
|
|
decklinksrc->video_frame = videoFrame;
|
|
|
|
if (audioFrame) {
|
2011-06-06 04:17:04 +00:00
|
|
|
audioFrame->AddRef ();
|
2011-02-27 08:48:19 +00:00
|
|
|
decklinksrc->audio_frame = audioFrame;
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 18:34:01 +00:00
|
|
|
|
|
|
|
/* increment regardless whether frame was dropped or not */
|
|
|
|
decklinksrc->frame_num++;
|
|
|
|
|
2011-02-27 08:48:19 +00:00
|
|
|
g_cond_signal (decklinksrc->cond);
|
|
|
|
g_mutex_unlock (decklinksrc->mutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
2011-06-06 04:17:04 +00:00
|
|
|
DeckLinkCaptureDelegate::VideoInputFormatChanged
|
|
|
|
(BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode * mode,
|
|
|
|
BMDDetectedVideoInputFormatFlags) {
|
|
|
|
GST_ERROR ("moo");
|
2011-02-27 08:48:19 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|