OpenShot Library | libopenshot  0.2.2
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  * @section LICENSE
7  *
8  * Copyright (c) 2008-2014 OpenShot Studios, LLC
9  * <http://www.openshotstudios.com/>. This file is part of
10  * OpenShot Library (libopenshot), an open-source project dedicated to
11  * delivering high quality video editing and animation solutions to the
12  * world. For more information visit <http://www.openshot.org/>.
13  *
14  * OpenShot Library (libopenshot) is free software: you can redistribute it
15  * and/or modify it under the terms of the GNU Lesser General Public License
16  * as published by the Free Software Foundation, either version 3 of the
17  * License, or (at your option) any later version.
18  *
19  * OpenShot Library (libopenshot) is distributed in the hope that it will be
20  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef OPENSHOT_DECKLINK_READER_H
29 #define OPENSHOT_DECKLINK_READER_H
30 
31 #include "ReaderBase.h"
32 
33 #include <cmath>
34 #include <ctime>
35 #include <fcntl.h>
36 #include <iostream>
37 #include <omp.h>
38 #include <pthread.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <memory>
43 #include <unistd.h>
44 
45 #include "CacheMemory.h"
46 #include "Exceptions.h"
47 #include "Frame.h"
48 #include "DecklinkInput.h"
49 
50 using namespace std;
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  string Name() { return "DecklinkReader"; };
118 
119  /// Get and Set JSON methods
120  string Json(); ///< Generate JSON string of this object
121  void SetJson(string value); ///< Load JSON string into this object
122  Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
123  void SetJsonValue(Json::Value root); ///< Load Json::JsonValue 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
openshot::DecklinkReader::IsOpen
bool IsOpen()
Determine if reader is open or closed.
Definition: DecklinkReader.h:114
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:45
openshot::CacheMemory
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:48
DeckLinkInputDelegate
Implementation of the Blackmagic Decklink API (used by the DecklinkReader)
Definition: DecklinkInput.h:70
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:103
openshot::DecklinkReader
This class uses the Blackmagic Decklink libraries, to open video streams on Blackmagic devices.
Definition: DecklinkReader.h:61
ReaderBase.h
Header file for ReaderBase class.
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:96
Exceptions.h
Header file for all Exception classes.
openshot::DecklinkReader::Name
string Name()
Return the type name of the class.
Definition: DecklinkReader.h:117