OpenShot Library | libopenshot  0.2.6
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 "Frame.h"
50 #include "DecklinkInput.h"
51 
52 namespace openshot
53 {
54 
55  /**
56  * @brief This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices.
57  *
58  * This requires special hardware manufactured by <a href="http://www.blackmagicdesign.com/products">Blackmagic Designs</a>.
59  * Once the device is acquired and connected, this reader returns openshot::Frame objects containing the image and audio data.
60  */
61  class DecklinkReader : public ReaderBase
62  {
63  private:
64  bool is_open;
65 
66  IDeckLink *deckLink;
67  IDeckLinkInput *deckLinkInput;
68  IDeckLinkDisplayModeIterator *displayModeIterator;
69  IDeckLinkOutput *m_deckLinkOutput;
70  IDeckLinkVideoConversion *m_deckLinkConverter;
71  pthread_mutex_t sleepMutex;
72  pthread_cond_t sleepCond;
73  IDeckLinkIterator *deckLinkIterator;
74  DeckLinkInputDelegate *delegate;
75  IDeckLinkDisplayMode *displayMode;
76  BMDVideoInputFlags inputFlags;
77  BMDDisplayMode selectedDisplayMode;
78  BMDPixelFormat pixelFormat;
79  int displayModeCount;
80  int exitStatus;
81  int ch;
82  bool foundDisplayMode;
83  HRESULT result;
84  int g_videoModeIndex;
85  int g_audioChannels;
86  int g_audioSampleDepth;
87  int g_maxFrames;
88  int device;
89  BMDTimeValue frameRateDuration, frameRateScale;
90  const char *displayModeName;
91 
92  public:
93 
94  /// Constructor for DecklinkReader. This automatically opens the device and loads
95  /// the first second of video, or it throws one of the following exceptions.
96  DecklinkReader(int device, int video_mode, int pixel_format, int channels, int sample_depth);
97  ~DecklinkReader(); /// Destructor
98 
99  /// Close the device and video stream
100  void Close();
101 
102  /// Get the cache object used by this reader (always returns NULL for this reader)
103  CacheMemory* GetCache() { return NULL; };
104 
105  /// Get an openshot::Frame object for a specific frame number of this reader. Frame number
106  /// is ignored, since it always gets the latest LIVE frame.
107  ///
108  /// @returns The requested frame (containing the image)
109  /// @param requested_frame The frame number that is requested.
110  std::shared_ptr<Frame> GetFrame(int64_t requested_frame);
111  unsigned long GetCurrentFrameNumber();
112 
113  /// Determine if reader is open or closed
114  bool IsOpen() { return is_open; };
115 
116  /// Return the type name of the class
117  std::string Name() { return "DecklinkReader"; };
118 
119  // Get and Set JSON methods
120  std::string Json() const override; ///< Generate JSON string of this object
121  void SetJson(const std::string value); ///< Load JSON string into this object
122  Json::Value JsonValue() const; ///< Generate Json::Value for this object
123  void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
124 
125  /// Open device and video stream - which is called by the constructor automatically
126  void Open();
127  };
128 
129 }
130 
131 #endif
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Header file for ReaderBase class.
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
Header file for DecklinkInput class.
void Open()
Open device and video stream - which is called by the constructor automatically.
unsigned long GetCurrentFrameNumber()
CacheMemory * GetCache()
Get the cache object used by this reader (always returns NULL for this reader)
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:97
std::string Json() const override
Generate JSON string of this object.
Header file for CacheMemory class.
bool IsOpen()
Determine if reader is open or closed.
Header file for Frame class.
Implementation of the Blackmagic Decklink API (used by the DecklinkReader)
Definition: DecklinkInput.h:73
void SetJson(const std::string value)
Load JSON string into this object.
DecklinkReader(int device, int video_mode, int pixel_format, int channels, int sample_depth)
Json::Value JsonValue() const
Generate Json::Value for this object.
std::string Name()
Return the type name of the class.
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:46
void Close()
Destructor.
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:50
This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices...