X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=4ffe3bd12bb8ed4f76092286f8aad08ce4fe0691;hb=3c86d70cf46ca11212ae2e2f4d711db0f478c2f5;hp=574d1d8894a94b9a6735e81b2246b9632dc8f2b8;hpb=67a68bd971ebe1b35daa3f75873b4ccb53c00ba0;p=dcpomatic.git diff --git a/src/lib/util.cc b/src/lib/util.cc index 574d1d889..4ffe3bd12 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -36,6 +36,7 @@ #include "digester.h" #include "audio_processor.h" #include "compose.hpp" +#include "audio_buffers.h" #include #include #include @@ -44,6 +45,7 @@ #include extern "C" { #include +#include #include } #include @@ -88,6 +90,7 @@ using std::pair; using std::cout; using std::bad_alloc; using std::set_terminate; +using std::make_pair; using boost::shared_ptr; using boost::thread; using boost::optional; @@ -322,6 +325,7 @@ dcpomatic_setup () SetUnhandledExceptionFilter(exception_handler); #endif + av_register_all (); avfilter_register_all (); #ifdef DCPOMATIC_OSX @@ -706,3 +710,51 @@ careful_string_filter (string s) return out; } + +/** @param mapped List of mapped audio channels from a Film. + * @param channels Total number of channels in the Film. + * @return First: number of non-LFE channels, second: number of LFE channels. + */ +pair +audio_channel_types (list mapped, int channels) +{ + int non_lfe = 0; + int lfe = 0; + + BOOST_FOREACH (int i, mapped) { + if (i >= channels) { + /* This channel is mapped but is not included in the DCP */ + continue; + } + + if (static_cast (i) == dcp::LFE) { + ++lfe; + } else { + ++non_lfe; + } + } + + return make_pair (non_lfe, lfe); +} + +shared_ptr +remap (shared_ptr input, int output_channels, AudioMapping map) +{ + shared_ptr mapped (new AudioBuffers (output_channels, input->frames())); + mapped->make_silent (); + + for (int i = 0; i < map.input_channels(); ++i) { + for (int j = 0; j < mapped->channels(); ++j) { + if (map.get (i, static_cast (j)) > 0) { + mapped->accumulate_channel ( + input.get(), + i, + static_cast (j), + map.get (i, static_cast (j)) + ); + } + } + } + + return mapped; +}