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