OpenShot Library | libopenshot  0.2.7
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 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_DECKLINK_READER_H
14 #define OPENSHOT_DECKLINK_READER_H
15 
16 #include "ReaderBase.h"
17 
18 #include <cmath>
19 #include <ctime>
20 #include <fcntl.h>
21 #include <iostream>
22 #include <omp.h>
23 #include <pthread.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <memory>
28 #include <unistd.h>
29 
30 #include "CacheMemory.h"
31 #include "Frame.h"
32 #include "DecklinkInput.h"
33 
34 namespace openshot
35 {
36 
37  /**
38  * @brief This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices.
39  *
40  * This requires special hardware manufactured by <a href="http://www.blackmagicdesign.com/products">Blackmagic Designs</a>.
41  * Once the device is acquired and connected, this reader returns openshot::Frame objects containing the image and audio data.
42  */
43  class DecklinkReader : public ReaderBase
44  {
45  private:
46  bool is_open;
47 
48  IDeckLink *deckLink;
49  IDeckLinkInput *deckLinkInput;
50  IDeckLinkDisplayModeIterator *displayModeIterator;
51  IDeckLinkOutput *m_deckLinkOutput;
52  IDeckLinkVideoConversion *m_deckLinkConverter;
53  pthread_mutex_t sleepMutex;
54  pthread_cond_t sleepCond;
55  IDeckLinkIterator *deckLinkIterator;
56  DeckLinkInputDelegate *delegate;
57  IDeckLinkDisplayMode *displayMode;
58  BMDVideoInputFlags inputFlags;
59  BMDDisplayMode selectedDisplayMode;
60  BMDPixelFormat pixelFormat;
61  int displayModeCount;
62  int exitStatus;
63  int ch;
64  bool foundDisplayMode;
65  HRESULT result;
66  int g_videoModeIndex;
67  int g_audioChannels;
68  int g_audioSampleDepth;
69  int g_maxFrames;
70  int device;
71  BMDTimeValue frameRateDuration, frameRateScale;
72  const char *displayModeName;
73 
74  public:
75 
76  /// Constructor for DecklinkReader. This automatically opens the device and loads
77  /// the first second of video, or it throws one of the following exceptions.
78  DecklinkReader(int device, int video_mode, int pixel_format, int channels, int sample_depth);
79  ~DecklinkReader(); /// Destructor
80 
81  /// Close the device and video stream
82  void Close();
83 
84  /// Get the cache object used by this reader (always returns NULL for this reader)
85  CacheMemory* GetCache() { return NULL; };
86 
87  /// Get an openshot::Frame object for a specific frame number of this reader. Frame number
88  /// is ignored, since it always gets the latest LIVE frame.
89  ///
90  /// @returns The requested frame (containing the image)
91  /// @param requested_frame The frame number that is requested.
92  std::shared_ptr<Frame> GetFrame(int64_t requested_frame);
93  unsigned long GetCurrentFrameNumber();
94 
95  /// Determine if reader is open or closed
96  bool IsOpen() { return is_open; };
97 
98  /// Return the type name of the class
99  std::string Name() { return "DecklinkReader"; };
100 
101  // Get and Set JSON methods
102  std::string Json() const override; ///< Generate JSON string of this object
103  void SetJson(const std::string value); ///< Load JSON string into this object
104  Json::Value JsonValue() const; ///< Generate Json::Value for this object
105  void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
106 
107  /// Open device and video stream - which is called by the constructor automatically
108  void Open();
109  };
110 
111 }
112 
113 #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:77
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:32
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:28
void Close()
Destructor.
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:32
This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices...