From: Carl Hetherington Date: Sun, 25 Dec 2022 21:34:21 +0000 (+0100) Subject: Show audio bit depth in content properties (#559). X-Git-Tag: v2.16.38~4 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=f3617efde1751ac9e55f692369dc4ba3c6350ca8 Show audio bit depth in content properties (#559). --- diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 192a50068..6a93ff119 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -314,6 +314,9 @@ AudioContent::add_properties (shared_ptr film, list& p if (stream) { p.push_back (UserProperty(UserProperty::AUDIO, _("Channels"), stream->channels())); p.push_back (UserProperty(UserProperty::AUDIO, _("Content sample rate"), stream->frame_rate(), _("Hz"))); + if (auto bits = stream->bit_depth()) { + p.push_back(UserProperty(UserProperty::AUDIO, _("Content bit depth"), *bits, _("bits"))); + } } FrameRateChange const frc (_parent->active_video_frame_rate(film), film->video_frame_rate()); diff --git a/src/lib/audio_stream.cc b/src/lib/audio_stream.cc index bd53c9b26..f771d44a2 100644 --- a/src/lib/audio_stream.cc +++ b/src/lib/audio_stream.cc @@ -24,19 +24,24 @@ #include "constants.h" -AudioStream::AudioStream (int frame_rate, Frame length, int channels) +using boost::optional; + + +AudioStream::AudioStream(int frame_rate, Frame length, int channels, optional bit_depth) : _frame_rate (frame_rate) , _length (length) , _mapping (AudioMapping (channels, MAX_DCP_AUDIO_CHANNELS)) + , _bit_depth(bit_depth) { } -AudioStream::AudioStream (int frame_rate, Frame length, AudioMapping mapping) +AudioStream::AudioStream(int frame_rate, Frame length, AudioMapping mapping, optional bit_depth) : _frame_rate (frame_rate) , _length (length) , _mapping (mapping) + , _bit_depth(bit_depth) { } @@ -56,3 +61,11 @@ AudioStream::channels () const boost::mutex::scoped_lock lm (_mutex); return _mapping.input_channels (); } + +optional +AudioStream::bit_depth() const +{ + boost::mutex::scoped_lock lm(_mutex); + return _bit_depth; +} + diff --git a/src/lib/audio_stream.h b/src/lib/audio_stream.h index 470d9c854..cf874242f 100644 --- a/src/lib/audio_stream.h +++ b/src/lib/audio_stream.h @@ -33,8 +33,8 @@ struct audio_sampling_rate_test; class AudioStream { public: - AudioStream (int frame_rate, Frame length, int channels); - AudioStream (int frame_rate, Frame length, AudioMapping mapping); + AudioStream(int frame_rate, Frame length, int channels, boost::optional bit_depth); + AudioStream(int frame_rate, Frame length, AudioMapping mapping, boost::optional bit_depth); virtual ~AudioStream () {} void set_mapping (AudioMapping mapping); @@ -55,6 +55,7 @@ public: } int channels () const; + boost::optional bit_depth() const; protected: mutable boost::mutex _mutex; @@ -66,6 +67,7 @@ private: int _frame_rate; Frame _length; AudioMapping _mapping; + boost::optional _bit_depth; }; diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc index 5f1e6c9b7..b23a088b4 100644 --- a/src/lib/content_factory.cc +++ b/src/lib/content_factory.cc @@ -81,7 +81,8 @@ content_factory (cxml::ConstNodePtr node, int version, list& notes) "Stream", 0, node->number_child ("AudioFrameRate"), node->number_child ("AudioLength"), - AudioMapping (node->node_child ("AudioMapping"), version) + AudioMapping(node->node_child("AudioMapping"), version), + 16 ) ); diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 3cc724b8e..cdf104f03 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -105,7 +105,8 @@ DCPContent::DCPContent (cxml::ConstNodePtr node, int version) node->optional_number_child("AudioLength").get_value_or ( video->length() * node->number_child("AudioFrameRate") / video_frame_rate().get() ), - AudioMapping (node->node_child ("AudioMapping"), version) + AudioMapping(node->node_child("AudioMapping"), version), + 24 ) ); } @@ -238,7 +239,7 @@ DCPContent::examine (shared_ptr film, shared_ptr job) boost::mutex::scoped_lock lm (_mutex); audio = make_shared(this); } - auto as = make_shared(examiner->audio_frame_rate(), examiner->audio_length(), examiner->audio_channels()); + auto as = make_shared(examiner->audio_frame_rate(), examiner->audio_length(), examiner->audio_channels(), 24); audio->set_stream (as); auto m = as->mapping (); m.make_default (film ? film->audio_processor() : 0); diff --git a/src/lib/ffmpeg_audio_stream.cc b/src/lib/ffmpeg_audio_stream.cc index 05e1a3fc8..9400eb60d 100644 --- a/src/lib/ffmpeg_audio_stream.cc +++ b/src/lib/ffmpeg_audio_stream.cc @@ -39,7 +39,8 @@ FFmpegAudioStream::FFmpegAudioStream (cxml::ConstNodePtr node, int version) , AudioStream ( node->number_child("FrameRate"), node->optional_number_child("Length").get_value_or(0), - AudioMapping (node->node_child("Mapping"), version) + AudioMapping(node->node_child("Mapping"), version), + node->optional_number_child("BitDepth") ) { optional const f = node->optional_number_child("FirstAudio"); @@ -63,4 +64,7 @@ FFmpegAudioStream::as_xml (xmlpp::Node* root) const if (codec_name) { root->add_child("CodecName")->add_child_text(codec_name.get()); } + if (bit_depth()) { + root->add_child("BitDepth")->add_child_text(raw_convert(bit_depth().get())); + } } diff --git a/src/lib/ffmpeg_audio_stream.h b/src/lib/ffmpeg_audio_stream.h index a5ed90c97..aae982f9e 100644 --- a/src/lib/ffmpeg_audio_stream.h +++ b/src/lib/ffmpeg_audio_stream.h @@ -30,20 +30,20 @@ struct ffmpeg_pts_offset_test; class FFmpegAudioStream : public FFmpegStream, public AudioStream { public: - FFmpegAudioStream (std::string name, int id, int frame_rate, Frame length, int channels) + FFmpegAudioStream(std::string name, int id, int frame_rate, Frame length, int channels, int bit_depth) : FFmpegStream (name, id) - , AudioStream (frame_rate, length, channels) + , AudioStream(frame_rate, length, channels, bit_depth) {} - FFmpegAudioStream (std::string name, std::string codec_name_, int id, int frame_rate, Frame length, int channels) + FFmpegAudioStream(std::string name, std::string codec_name_, int id, int frame_rate, Frame length, int channels, int bit_depth) : FFmpegStream (name, id) - , AudioStream (frame_rate, length, channels) + , AudioStream(frame_rate, length, channels, bit_depth) , codec_name (codec_name_) {} - FFmpegAudioStream (std::string name, int id, int frame_rate, Frame length, AudioMapping mapping) + FFmpegAudioStream(std::string name, int id, int frame_rate, Frame length, AudioMapping mapping, int bit_depth) : FFmpegStream (name, id) - , AudioStream (frame_rate, length, mapping) + , AudioStream(frame_rate, length, mapping, bit_depth) {} FFmpegAudioStream (cxml::ConstNodePtr, int); @@ -61,7 +61,7 @@ private: /* Constructor for tests */ FFmpegAudioStream () : FFmpegStream ("", 0) - , AudioStream (0, 0, 0) + , AudioStream(0, 0, 0, 0) {} }; diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc index fdcacb465..46f4f236e 100644 --- a/src/lib/ffmpeg_examiner.cc +++ b/src/lib/ffmpeg_examiner.cc @@ -91,7 +91,8 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptrid, s->codecpar->sample_rate, llrint ((double(_format_context->duration) / AV_TIME_BASE) * s->codecpar->sample_rate), - s->codecpar->channels + s->codecpar->channels, + s->codecpar->bits_per_raw_sample ? s->codecpar->bits_per_raw_sample : s->codecpar->bits_per_coded_sample ) ); diff --git a/test/frame_rate_test.cc b/test/frame_rate_test.cc index 90216af5c..610ac0380 100644 --- a/test/frame_rate_test.cc +++ b/test/frame_rate_test.cc @@ -263,7 +263,7 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test) afr.push_back (30); Config::instance()->set_allowed_dcp_frame_rates (afr); - shared_ptr stream (new FFmpegAudioStream ("foo", 0, 0, 0, 0)); + auto stream = std::make_shared("foo", 0, 0, 0, 0, 0); content->audio.reset (new AudioContent (content.get())); content->audio->add_stream (stream); content->_video_frame_rate = 24;