2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
21 #include "..\..\stdafx.h"
\r
23 #include "AudioConsumer.h"
\r
24 #include "..\..\frame\FramePlaybackControl.h"
\r
25 #include "..\..\frame\SystemFrameManager.h"
\r
26 #include "..\..\frame\Frame.h"
\r
27 #include "..\..\frame\FramePlaybackStrategy.h"
\r
28 #include "..\..\utils\image\Image.hpp"
\r
34 struct AudioConsumer::Implementation
\r
36 struct AudioPlaybackStrategy : public IFramePlaybackStrategy
\r
38 explicit AudioPlaybackStrategy(Implementation* pConsumerImpl) : pConsumerImpl_(pConsumerImpl)
\r
40 lastTime_ = timeGetTime();
\r
43 FrameManagerPtr GetFrameManager()
\r
45 return pConsumerImpl_->pFrameManager_;
\r
47 FramePtr GetReservedFrame()
\r
49 return pConsumerImpl_->pFrameManager_->CreateFrame();
\r
52 void DisplayFrame(Frame* pFrame)
\r
54 DWORD timediff = timeGetTime() - lastTime_;
\r
56 Sleep(40 - timediff);
\r
60 lastTime_ = timeGetTime();
\r
62 if(pFrame == NULL || pFrame->ID() == lastFrameID_)
\r
65 lastFrameID_ = pFrame->ID();
\r
68 Implementation* pConsumerImpl_;
\r
70 utils::ID lastFrameID_;
\r
73 explicit Implementation(const FrameFormatDescription& fmtDesc) : fmtDesc_(fmtDesc)
\r
85 pFrameManager_.reset(new SystemFrameManager(fmtDesc_));
\r
86 pPlaybackControl_.reset(new FramePlaybackControl(FramePlaybackStrategyPtr(new AudioPlaybackStrategy(this))));
\r
88 pPlaybackControl_->Start();
\r
92 bool ReleaseDevice()
\r
94 pPlaybackControl_->Stop();
\r
98 FramePlaybackControlPtr pPlaybackControl_;
\r
99 SystemFrameManagerPtr pFrameManager_;
\r
101 FrameFormatDescription fmtDesc_;
\r
104 AudioConsumer::AudioConsumer(const FrameFormatDescription& fmtDesc) : pImpl_(new Implementation(fmtDesc))
\r
107 AudioConsumer::~AudioConsumer()
\r
110 IPlaybackControl* AudioConsumer::GetPlaybackControl() const
\r
112 return pImpl_->pPlaybackControl_.get();
\r
115 bool AudioConsumer::SetupDevice(unsigned int deviceIndex)
\r
117 return pImpl_->SetupDevice();
\r
120 bool AudioConsumer::ReleaseDevice()
\r
122 return pImpl_->ReleaseDevice();
\r
125 void AudioConsumer::EnableVideoOutput(){}
\r
126 void AudioConsumer::DisableVideoOutput(){}
\r
128 const FrameFormatDescription& AudioConsumer::GetFrameFormatDescription() const {
\r
129 return pImpl_->fmtDesc_;
\r
131 const TCHAR* AudioConsumer::GetFormatDescription() const {
\r
132 return pImpl_->fmtDesc_.name;
\r
136 } //namespace audio
\r