2013-02-01 13:13:48 -06:00
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @file
|
2013-09-11 17:32:40 -05:00
|
|
|
* @brief Header file for DecklinkReader class
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
2013-09-11 17:32:40 -05:00
|
|
|
*
|
2019-06-11 06:48:32 -04:00
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
2014-03-29 18:49:22 -05:00
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-11 17:32:40 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-11 17:32:40 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-11 17:32:40 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2013-02-01 13:13:48 -06:00
|
|
|
*/
|
|
|
|
|
|
2013-09-11 17:32:40 -05:00
|
|
|
#ifndef OPENSHOT_DECKLINK_READER_H
|
|
|
|
|
#define OPENSHOT_DECKLINK_READER_H
|
|
|
|
|
|
2013-09-08 16:40:57 -05:00
|
|
|
#include "ReaderBase.h"
|
2013-02-01 13:13:48 -06:00
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <ctime>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <omp.h>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2017-08-20 17:37:39 -05:00
|
|
|
#include <memory>
|
2013-02-01 13:13:48 -06:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2016-08-31 23:57:06 -05:00
|
|
|
#include "CacheMemory.h"
|
2013-02-01 13:13:48 -06:00
|
|
|
#include "Exceptions.h"
|
|
|
|
|
#include "Frame.h"
|
2013-02-10 02:19:40 -06:00
|
|
|
#include "DecklinkInput.h"
|
2013-02-01 13:13:48 -06:00
|
|
|
|
|
|
|
|
namespace openshot
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-10 22:11:47 -05:00
|
|
|
* @brief This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices.
|
|
|
|
|
*
|
|
|
|
|
* This requires special hardware manufactured by <a href="http://www.blackmagicdesign.com/products">Blackmagic Designs</a>.
|
2018-01-06 02:22:05 -06:00
|
|
|
* Once the device is acquired and connected, this reader returns openshot::Frame objects containing the image and audio data.
|
2013-02-01 13:13:48 -06:00
|
|
|
*/
|
2013-09-08 16:40:57 -05:00
|
|
|
class DecklinkReader : public ReaderBase
|
2013-02-01 13:13:48 -06:00
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
bool is_open;
|
|
|
|
|
|
2013-02-09 01:54:40 -06:00
|
|
|
IDeckLink *deckLink;
|
|
|
|
|
IDeckLinkInput *deckLinkInput;
|
|
|
|
|
IDeckLinkDisplayModeIterator *displayModeIterator;
|
|
|
|
|
IDeckLinkOutput *m_deckLinkOutput;
|
|
|
|
|
IDeckLinkVideoConversion *m_deckLinkConverter;
|
|
|
|
|
pthread_mutex_t sleepMutex;
|
|
|
|
|
pthread_cond_t sleepCond;
|
|
|
|
|
IDeckLinkIterator *deckLinkIterator;
|
2013-02-10 02:19:40 -06:00
|
|
|
DeckLinkInputDelegate *delegate;
|
2013-02-09 01:54:40 -06:00
|
|
|
IDeckLinkDisplayMode *displayMode;
|
|
|
|
|
BMDVideoInputFlags inputFlags;
|
|
|
|
|
BMDDisplayMode selectedDisplayMode;
|
|
|
|
|
BMDPixelFormat pixelFormat;
|
|
|
|
|
int displayModeCount;
|
|
|
|
|
int exitStatus;
|
|
|
|
|
int ch;
|
|
|
|
|
bool foundDisplayMode;
|
|
|
|
|
HRESULT result;
|
|
|
|
|
int g_videoModeIndex;
|
|
|
|
|
int g_audioChannels;
|
|
|
|
|
int g_audioSampleDepth;
|
|
|
|
|
int g_maxFrames;
|
2013-02-10 02:19:40 -06:00
|
|
|
int device;
|
2013-02-10 21:16:46 -06:00
|
|
|
BMDTimeValue frameRateDuration, frameRateScale;
|
|
|
|
|
const char *displayModeName;
|
2013-02-09 01:54:40 -06:00
|
|
|
|
2013-02-01 13:13:48 -06:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// Constructor for DecklinkReader. This automatically opens the device and loads
|
|
|
|
|
/// the first second of video, or it throws one of the following exceptions.
|
2017-10-26 18:44:35 -05:00
|
|
|
DecklinkReader(int device, int video_mode, int pixel_format, int channels, int sample_depth);
|
2013-02-10 21:16:46 -06:00
|
|
|
~DecklinkReader(); /// Destructor
|
2013-02-01 13:13:48 -06:00
|
|
|
|
|
|
|
|
/// Close the device and video stream
|
|
|
|
|
void Close();
|
|
|
|
|
|
2015-06-01 00:20:14 -07:00
|
|
|
/// Get the cache object used by this reader (always returns NULL for this reader)
|
2016-08-31 23:57:06 -05:00
|
|
|
CacheMemory* GetCache() { return NULL; };
|
2015-06-01 00:20:14 -07:00
|
|
|
|
2013-02-01 13:13:48 -06:00
|
|
|
/// Get an openshot::Frame object for a specific frame number of this reader. Frame number
|
|
|
|
|
/// is ignored, since it always gets the latest LIVE frame.
|
|
|
|
|
///
|
|
|
|
|
/// @returns The requested frame (containing the image)
|
2013-09-12 17:52:10 -05:00
|
|
|
/// @param requested_frame The frame number that is requested.
|
2017-10-26 18:44:35 -05:00
|
|
|
std::shared_ptr<Frame> GetFrame(int64_t requested_frame);
|
2013-02-12 02:42:18 -06:00
|
|
|
unsigned long GetCurrentFrameNumber();
|
2013-02-01 13:13:48 -06:00
|
|
|
|
2013-12-18 21:55:43 -06:00
|
|
|
/// Determine if reader is open or closed
|
|
|
|
|
bool IsOpen() { return is_open; };
|
|
|
|
|
|
2016-01-05 01:59:50 -06:00
|
|
|
/// Return the type name of the class
|
2019-08-04 23:14:38 -04:00
|
|
|
std::string Name() { return "DecklinkReader"; };
|
2016-01-05 01:59:50 -06:00
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
/// Get and Set JSON methods
|
2019-08-04 23:14:38 -04:00
|
|
|
std::string Json(); ///< Generate JSON string of this object
|
|
|
|
|
void SetJson(std::string value); ///< Load JSON string into this object
|
2013-12-07 21:09:55 -06:00
|
|
|
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
|
2017-10-26 18:44:35 -05:00
|
|
|
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
|
2013-12-07 21:09:55 -06:00
|
|
|
|
2013-02-01 13:13:48 -06:00
|
|
|
/// Open device and video stream - which is called by the constructor automatically
|
2017-10-26 18:44:35 -05:00
|
|
|
void Open();
|
2013-02-01 13:13:48 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|