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 "oal_consumer.h"
\r
25 #include "../../video_format.h"
\r
27 #include "../../mixer/frame/read_frame.h"
\r
29 #include <SFML/Audio.hpp>
\r
31 #include <boost/circular_buffer.hpp>
\r
33 namespace caspar { namespace core {
\r
35 struct oal_consumer::implementation : public sf::SoundStream, boost::noncopyable
\r
37 tbb::concurrent_bounded_queue<std::vector<short>> input_;
\r
38 boost::circular_buffer<std::vector<short>> container_;
\r
39 tbb::atomic<bool> is_running_;
\r
45 sf::SoundStream::Initialize(2, 48000);
\r
47 CASPAR_LOG(info) << "Sucessfully started oal_consumer";
\r
52 is_running_ = false;
\r
53 input_.try_push(std::vector<short>());
\r
54 input_.try_push(std::vector<short>());
\r
55 CASPAR_LOG(info) << "Sucessfully ended oal_consumer";
\r
58 virtual void send(const safe_ptr<const read_frame>& frame)
\r
60 if(frame->audio_data().empty())
\r
63 input_.push(std::vector<short>(frame->audio_data().begin(), frame->audio_data().end()));
\r
66 virtual size_t buffer_depth() const{return 3;}
\r
68 virtual bool OnGetData(sf::SoundStream::Chunk& data)
\r
70 std::vector<short> audio_data;
\r
71 input_.pop(audio_data);
\r
73 container_.push_back(std::move(audio_data));
\r
74 data.Samples = container_.back().data();
\r
75 data.NbSamples = container_.back().size();
\r
81 oal_consumer::oal_consumer(oal_consumer&& other) : impl_(std::move(other.impl_)){}
\r
82 oal_consumer::oal_consumer(const video_format_desc&) : impl_(new implementation()){}
\r
83 void oal_consumer::send(const safe_ptr<const read_frame>& frame){impl_->send(frame);}
\r
84 size_t oal_consumer::buffer_depth() const{return impl_->buffer_depth();}
\r
86 safe_ptr<frame_consumer> create_oal_consumer(const std::vector<std::wstring>& params)
\r
88 if(params.size() < 2 || params[0] != L"OAL")
\r
89 return frame_consumer::empty();
\r
91 auto format_desc = video_format_desc::get(params[1]);
\r
92 if(format_desc.format == video_format::invalid)
\r
93 return frame_consumer::empty();
\r
95 return make_safe<oal_consumer>(format_desc);
\r