OpenShot Library | libopenshot  0.2.5
DecklinkReader.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for DecklinkReader class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #ifndef OPENSHOT_DECKLINK_READER_H
32 #define OPENSHOT_DECKLINK_READER_H
33 
34 #include "ReaderBase.h"
35 
36 #include <cmath>
37 #include <ctime>
38 #include <fcntl.h>
39 #include <iostream>
40 #include <omp.h>
41 #include <pthread.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <memory>
46 #include <unistd.h>
47 
48 #include "CacheMemory.h"
49 #include "Exceptions.h"
50 #include "Frame.h"
51 #include "DecklinkInput.h"
52 
53 namespace openshot
54 {
55 
56  /**
57  * @brief This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices.
58  *
59  * This requires special hardware manufactured by <a href="http://www.blackmagicdesign.com/products">Blackmagic Designs</a>.
60  * Once the device is acquired and connected, this reader returns openshot::Frame objects containing the image and audio data.
61  */
62  class DecklinkReader : public ReaderBase
63  {
64  private:
65  bool is_open;
66 
67  IDeckLink *deckLink;
68  IDeckLinkInput *deckLinkInput;
69  IDeckLinkDisplayModeIterator *displayModeIterator;
70  IDeckLinkOutput *m_deckLinkOutput;
71  IDeckLinkVideoConversion *m_deckLinkConverter;
72  pthread_mutex_t sleepMutex;
73  pthread_cond_t sleepCond;
74  IDeckLinkIterator *deckLinkIterator;
75  DeckLinkInputDelegate *delegate;
76  IDeckLinkDisplayMode *displayMode;
77  BMDVideoInputFlags inputFlags;
78  BMDDisplayMode selectedDisplayMode;
79  BMDPixelFormat pixelFormat;
80  int displayModeCount;
81  int exitStatus;
82  int ch;
83  bool foundDisplayMode;
84  HRESULT result;
85  int g_videoModeIndex;
86  int g_audioChannels;
87  int g_audioSampleDepth;
88  int g_maxFrames;
89  int device;
90  BMDTimeValue frameRateDuration, frameRateScale;
91  const char *displayModeName;
92 
93  public:
94 
95  /// Constructor for DecklinkReader. This automatically opens the device and loads
96  /// the first second of video, or it throws one of the following exceptions.
97  DecklinkReader(int device, int video_mode, int pixel_format, int channels, int sample_depth);
98  ~DecklinkReader(); /// Destructor
99 
100  /// Close the device and video stream
101  void Close();
102 
103  /// Get the cache object used by this reader (always returns NULL for this reader)
104  CacheMemory* GetCache() { return NULL; };
105 
106  /// Get an openshot::Frame object for a specific frame number of this reader. Frame number
107  /// is ignored, since it always gets the latest LIVE frame.
108  ///
109  /// @returns The requested frame (containing the image)
110  /// @param requested_frame The frame number that is requested.
111  std::shared_ptr<Frame> GetFrame(int64_t requested_frame);
112  unsigned long GetCurrentFrameNumber();
113 
114  /// Determine if reader is open or closed
115  bool IsOpen() { return is_open; };
116 
117  /// Return the type name of the class
118  std::string Name() { return "DecklinkReader"; };
119 
120  /// Get and Set JSON methods
121  std::string Json() const override; ///< Generate JSON string of this object
122  void SetJson(const std::string value); ///< Load JSON string into this object
123  Json::Value JsonValue() const; ///< Generate Json::Value for this object
124  void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
125 
126  /// Open device and video stream - which is called by the constructor automatically
127  void Open();
128  };
129 
130 }
131 
132 #endif
openshot::DecklinkReader::IsOpen
bool IsOpen()
Determine if reader is open or closed.
Definition: DecklinkReader.h:115
openshot::DecklinkReader::Open
void Open()
Open device and video stream - which is called by the constructor automatically.
Definition: DecklinkReader.cpp:172
openshot::DecklinkReader::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: DecklinkReader.cpp:267
openshot::DecklinkReader::DecklinkReader
DecklinkReader(int device, int video_mode, int pixel_format, int channels, int sample_depth)
Definition: DecklinkReader.cpp:35
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:39
openshot::DecklinkReader::Close
void Close()
Destructor.
Definition: DecklinkReader.cpp:215
openshot::CacheMemory
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:51
DeckLinkInputDelegate
Implementation of the Blackmagic Decklink API (used by the DecklinkReader)
Definition: DecklinkInput.h:74
CacheMemory.h
Header file for CacheMemory class.
Frame.h
Header file for Frame class.
DecklinkInput.h
Header file for DecklinkInput class.
openshot::DecklinkReader::GetCache
CacheMemory * GetCache()
Get the cache object used by this reader (always returns NULL for this reader)
Definition: DecklinkReader.h:104
openshot::DecklinkReader
This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices.
Definition: DecklinkReader.h:63
ReaderBase.h
Header file for ReaderBase class.
openshot::DecklinkReader::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: DecklinkReader.cpp:284
openshot::DecklinkReader::GetFrame
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
Definition: DecklinkReader.cpp:237
openshot::DecklinkReader::GetCurrentFrameNumber
unsigned long GetCurrentFrameNumber()
Definition: DecklinkReader.cpp:231
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:98
openshot::DecklinkReader::~DecklinkReader
~DecklinkReader()
Definition: DecklinkReader.cpp:147
openshot::DecklinkReader::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: DecklinkReader.cpp:256
openshot::DecklinkReader::Json
std::string Json() const override
Get and Set JSON methods.
Definition: DecklinkReader.cpp:249
openshot::DecklinkReader::Name
std::string Name()
Return the type name of the class.
Definition: DecklinkReader.h:118
Exceptions.h
Header file for all Exception classes.