/*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
*\r
-* This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\r
*\r
-* CasparCG is free software: you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation, either version 3 of the License, or\r
-* (at your option) any later version.\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
*\r
-* CasparCG is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-\r
-* You should have received a copy of the GNU General Public License\r
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
*\r
+* Author: Robert Nagy, ronag89@gmail.com\r
*/\r
+\r
#include "../../stdafx.h"\r
\r
#include "audio_decoder.h"\r
std::queue<safe_ptr<AVPacket>> packets_;\r
\r
const int64_t nb_frames_;\r
+ tbb::atomic<size_t> file_frame_number_;\r
public:\r
explicit implementation(const safe_ptr<AVFormatContext>& context, const core::video_format_desc& format_desc) \r
: format_desc_(format_desc) \r
format_desc.audio_sample_rate, codec_context_->sample_rate,\r
AV_SAMPLE_FMT_S32, codec_context_->sample_fmt)\r
, buffer1_(AVCODEC_MAX_AUDIO_FRAME_SIZE*2)\r
- , nb_frames_(context->streams[index_]->nb_frames)\r
+ , nb_frames_(0)//context->streams[index_]->nb_frames)\r
{ \r
+ file_frame_number_ = 0;\r
CASPAR_LOG(debug) << "[audio_decoder] " << context->streams[index_]->codec->codec->long_name; \r
}\r
\r
if(!packet)\r
return;\r
\r
- if(packet->stream_index == index_ || packet == flush_packet())\r
+ if(packet->stream_index == index_ || packet->data == nullptr)\r
packets_.push(make_safe_ptr(packet));\r
} \r
\r
\r
auto packet = packets_.front();\r
\r
- if(packet == flush_packet())\r
+ if(packet->data == nullptr)\r
{\r
packets_.pop();\r
+ file_frame_number_ = static_cast<size_t>(packet->pos);\r
avcodec_flush_buffers(codec_context_.get());\r
return flush_audio();\r
}\r
const auto n_samples = buffer1_.size() / av_get_bytes_per_sample(AV_SAMPLE_FMT_S32);\r
const auto samples = reinterpret_cast<int32_t*>(buffer1_.data());\r
\r
+ ++file_frame_number_;\r
+\r
return std::make_shared<core::audio_buffer>(samples, samples + n_samples);\r
}\r
\r
{\r
return packets_.size() > 10;\r
}\r
+\r
+ uint32_t nb_frames() const\r
+ {\r
+ return 0;//std::max<int64_t>(nb_frames_, file_frame_number_);\r
+ }\r
};\r
\r
audio_decoder::audio_decoder(const safe_ptr<AVFormatContext>& context, const core::video_format_desc& format_desc) : impl_(new implementation(context, format_desc)){}\r
void audio_decoder::push(const std::shared_ptr<AVPacket>& packet){impl_->push(packet);}\r
bool audio_decoder::ready() const{return impl_->ready();}\r
std::shared_ptr<core::audio_buffer> audio_decoder::poll(){return impl_->poll();}\r
-int64_t audio_decoder::nb_frames() const{return impl_->nb_frames_;}\r
+uint32_t audio_decoder::nb_frames() const{return impl_->nb_frames();}\r
+uint32_t audio_decoder::file_frame_number() const{return impl_->file_frame_number_;}\r
\r
}}
\ No newline at end of file