OpenShot Library | libopenshot  0.2.4
DecklinkOutput.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for DecklinkOutput class
4  * @author Jonathan Thomas <jonathan@openshot.org>, Blackmagic Design
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2009 Blackmagic Design
12  *
13  * Permission is hereby granted, free of charge, to any person or organization
14  * obtaining a copy of the software and accompanying documentation covered by
15  * this license (the "Software") to use, reproduce, display, distribute,
16  * execute, and transmit the Software, and to prepare derivative works of the
17  * Software, and to permit third-parties to whom the Software is furnished to
18  * do so, all subject to the following:
19  *
20  * The copyright notices in the Software and this entire statement, including
21  * the above license grant, this restriction and the following disclaimer,
22  * must be included in all copies of the Software, in whole or in part, and
23  * all derivative works of the Software, unless such copies or derivative
24  * works are solely in the form of machine-executable object code generated by
25  * a source language processor.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
30  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
31  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
32  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33  * DEALINGS IN THE SOFTWARE.
34  *
35  *
36  * Copyright (c) 2008-2019 OpenShot Studios, LLC
37  * <http://www.openshotstudios.com/>. This file is part of
38  * OpenShot Library (libopenshot), an open-source project dedicated to
39  * delivering high quality video editing and animation solutions to the
40  * world. For more information visit <http://www.openshot.org/>.
41  *
42  * OpenShot Library (libopenshot) is free software: you can redistribute it
43  * and/or modify it under the terms of the GNU Lesser General Public License
44  * as published by the Free Software Foundation, either version 3 of the
45  * License, or (at your option) any later version.
46  *
47  * OpenShot Library (libopenshot) is distributed in the hope that it will be
48  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
49  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50  * GNU Lesser General Public License for more details.
51  *
52  * You should have received a copy of the GNU Lesser General Public License
53  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
54  */
55 
56 #ifndef OPENSHOT_DECKLINK_OUTPUT_H
57 #define OPENSHOT_DECKLINK_OUTPUT_H
58 
59 #include <iostream>
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <pthread.h>
64 #include <unistd.h>
65 #include <fcntl.h>
66 
67 #include "DeckLinkAPI.h"
68 #include "CacheMemory.h"
69 #include "Frame.h"
70 #include "OpenMPUtilities.h"
71 
75 };
76 
77 /// Implementation of the Blackmagic Decklink API (used by the DecklinkWriter)
78 class DeckLinkOutputDelegate : public IDeckLinkVideoOutputCallback, public IDeckLinkAudioOutputCallback
79 {
80 protected:
81  unsigned long m_totalFramesScheduled;
85  unsigned long m_audioBufferOffset;
86  unsigned long m_audioChannelCount;
87  BMDAudioSampleRate m_audioSampleRate;
88  unsigned long m_audioSampleDepth;
89  unsigned long audioSamplesPerFrame;
90  unsigned long m_framesPerSecond;
91  int height;
92  int width;
93 
94  unsigned long frameCount;
95  //map<int, IDeckLinkMutableVideoFrame* > temp_cache;
96  std::map<int, uint8_t * > temp_cache;
97 
99 
100  // Queue of raw video frames
101  //deque<IDeckLinkMutableVideoFrame*> final_frames;
102  std::deque<uint8_t * > final_frames;
103  std::deque<std::shared_ptr<openshot::Frame> > raw_video_frames;
104 
105  // Convert between YUV and RGB
106  IDeckLinkOutput *deckLinkOutput;
107  IDeckLinkDisplayMode *displayMode;
108 
109  // Current frame being displayed
110  IDeckLinkMutableVideoFrame *m_currentFrame;
111 
112 public:
113  DeckLinkOutputDelegate(IDeckLinkDisplayMode *displayMode, IDeckLinkOutput* deckLinkOutput);
115 
116  // *** DeckLink API implementation of IDeckLinkVideoOutputCallback IDeckLinkAudioOutputCallback *** //
117  // IUnknown needs only a dummy implementation
118  virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID iid, LPVOID *ppv) {return E_NOINTERFACE;}
119  virtual ULONG STDMETHODCALLTYPE AddRef () {return 1;}
120  virtual ULONG STDMETHODCALLTYPE Release () {return 1;}
121 
122  virtual HRESULT STDMETHODCALLTYPE ScheduledFrameCompleted (IDeckLinkVideoFrame* completedFrame, BMDOutputFrameCompletionResult result);
123  virtual HRESULT STDMETHODCALLTYPE ScheduledPlaybackHasStopped ();
124 
125  virtual HRESULT STDMETHODCALLTYPE RenderAudioSamples (bool preroll);
126 
127  /// Schedule the next frame
128  void ScheduleNextFrame(bool prerolling);
129 
130  /// Custom method to write new frames
131  void WriteFrame(std::shared_ptr<openshot::Frame> frame);
132 
133 private:
134  ULONG m_refCount;
135  pthread_mutex_t m_mutex;
136 };
137 
138 
139 #endif
std::deque< uint8_t *> final_frames
virtual HRESULT STDMETHODCALLTYPE ScheduledFrameCompleted(IDeckLinkVideoFrame *completedFrame, BMDOutputFrameCompletionResult result)
unsigned long m_audioBufferOffset
Implementation of the Blackmagic Decklink API (used by the DecklinkWriter)
std::deque< std::shared_ptr< openshot::Frame > > raw_video_frames
DeckLinkOutputDelegate(IDeckLinkDisplayMode *displayMode, IDeckLinkOutput *deckLinkOutput)
Header file for OpenMPUtilities (set some common macros)
IDeckLinkDisplayMode * displayMode
BMDTimeValue frameRateScale
Header file for CacheMemory class.
Header file for Frame class.
unsigned long m_audioSampleDepth
IDeckLinkMutableVideoFrame * m_currentFrame
unsigned long frameCount
OutputSignal
virtual ULONG STDMETHODCALLTYPE AddRef()
std::map< int, uint8_t *> temp_cache
void WriteFrame(std::shared_ptr< openshot::Frame > frame)
Custom method to write new frames.
unsigned long m_totalFramesScheduled
virtual ULONG STDMETHODCALLTYPE Release()
OutputSignal m_outputSignal
unsigned long m_audioChannelCount
IDeckLinkOutput * deckLinkOutput
unsigned long audioSamplesPerFrame
BMDAudioSampleRate m_audioSampleRate
BMDTimeValue frameRateDuration
virtual HRESULT STDMETHODCALLTYPE RenderAudioSamples(bool preroll)
virtual HRESULT STDMETHODCALLTYPE ScheduledPlaybackHasStopped()
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
unsigned long m_audioBufferSampleLength
void ScheduleNextFrame(bool prerolling)
Schedule the next frame.
unsigned long m_framesPerSecond