]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/audio/audio_decoder.cpp
Refactored to use non-static data member initializers where it makes sense. Mixes...
[casparcg] / modules / ffmpeg / producer / audio / audio_decoder.cpp
index e6d5431a1f3334daf7868d40783baedfc3e91853..3442aa7c7e2cc0382ca899953b25fcd90e91953e 100644 (file)
@@ -59,13 +59,25 @@ uint64_t get_channel_layout(AVCodecContext* dec)
 
 struct audio_decoder::impl : boost::noncopyable
 {      
-       monitor::basic_subject                                                                          event_subject_;
+       core::monitor::subject                                                                          monitor_subject_;
        input*                                                                                                          input_;
        int                                                                                                                     index_;
-       const spl::shared_ptr<AVCodecContext>                                           codec_context_;         
        const core::video_format_desc                                                           format_desc_;
-
-       std::shared_ptr<SwrContext>                                                                     swr_;
+       const spl::shared_ptr<AVCodecContext>                                           codec_context_ = open_codec(input_->context(), AVMEDIA_TYPE_AUDIO, index_);
+
+       std::shared_ptr<SwrContext>                                                                     swr_                            {
+                                                                                                                                                                               swr_alloc_set_opts(
+                                                                                                                                                                                               nullptr,
+                                                                                                                                                                                               av_get_default_channel_layout(format_desc_.audio_channels),
+                                                                                                                                                                                               AV_SAMPLE_FMT_S32,
+                                                                                                                                                                                               format_desc_.audio_sample_rate,
+                                                                                                                                                                                               get_channel_layout(codec_context_.get()),
+                                                                                                                                                                                               codec_context_->sample_fmt,
+                                                                                                                                                                                               codec_context_->sample_rate,
+                                                                                                                                                                                               0,
+                                                                                                                                                                                               nullptr),
+                                                                                                                                                                               [](SwrContext* p){swr_free(&p); }
+                                                                                                                                                                       };
 
        std::vector<uint8_t, tbb::cache_aligned_allocator<int8_t>>      buffer_;
 
@@ -76,11 +88,7 @@ public:
                : input_(&in)
                , format_desc_(format_desc)     
                , codec_context_(open_codec(input_->context(), AVMEDIA_TYPE_AUDIO, index_))
-               , swr_(swr_alloc_set_opts(nullptr,
-                                                                               av_get_default_channel_layout(format_desc_.audio_channels), AV_SAMPLE_FMT_S32, format_desc_.audio_sample_rate,
-                                                                               get_channel_layout(codec_context_.get()), codec_context_->sample_fmt, codec_context_->sample_rate,
-                                                                               0, nullptr), [](SwrContext* p){swr_free(&p);})
-               , buffer_(AVCODEC_MAX_AUDIO_FRAME_SIZE*4)
+               , buffer_(480000 * 4)
        {               
                if(!swr_)
                        CASPAR_THROW_EXCEPTION(bad_alloc());
@@ -149,10 +157,10 @@ public:
                frame->nb_samples       = channel_samples;
                frame->format           = AV_SAMPLE_FMT_S32;
                                                        
-               event_subject_  << monitor::event("file/audio/sample-rate")     % codec_context_->sample_rate
-                                               << monitor::event("file/audio/channels")        % codec_context_->channels
-                                               << monitor::event("file/audio/format")          % u8(av_get_sample_fmt_name(codec_context_->sample_fmt))
-                                               << monitor::event("file/audio/codec")           % u8(codec_context_->codec->long_name);                 
+               monitor_subject_  << core::monitor::message("/file/audio/sample-rate")  % codec_context_->sample_rate
+                                               << core::monitor::message("/file/audio/channels")       % codec_context_->channels
+                                               << core::monitor::message("/file/audio/format")         % u8(av_get_sample_fmt_name(codec_context_->sample_fmt))
+                                               << core::monitor::message("/file/audio/codec")          % u8(codec_context_->codec->long_name);                 
 
                return frame;
        }
@@ -174,7 +182,5 @@ audio_decoder& audio_decoder::operator=(audio_decoder&& other){impl_ = std::move
 std::shared_ptr<AVFrame> audio_decoder::operator()(){return impl_->poll();}
 uint32_t audio_decoder::nb_frames() const{return impl_->nb_frames();}
 std::wstring audio_decoder::print() const{return impl_->print();}
-void audio_decoder::subscribe(const monitor::observable::observer_ptr& o){impl_->event_subject_.subscribe(o);}
-void audio_decoder::unsubscribe(const monitor::observable::observer_ptr& o){impl_->event_subject_.unsubscribe(o);}
-
+core::monitor::subject& audio_decoder::monitor_output() { return impl_->monitor_subject_;}
 }}
\ No newline at end of file