From 661de111c0dbc968ecb004eca5b26f8400b136f1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 27 May 2015 16:38:28 +0100 Subject: [PATCH] FFmpegContent does not need audio_length(). --- src/lib/audio_content.cc | 14 ++--- src/lib/audio_content.h | 3 - src/lib/ffmpeg_content.cc | 14 ----- src/lib/ffmpeg_content.h | 1 - src/lib/single_stream_audio_content.cc | 1 - src/lib/single_stream_audio_content.h | 2 +- src/wx/content_properties_dialog.cc | 7 ++- test/audio_decoder_test.cc | 78 +++++++++++++------------- 8 files changed, 53 insertions(+), 67 deletions(-) diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index def123fb1..e4b5a804e 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -40,12 +40,11 @@ using boost::shared_ptr; using boost::dynamic_pointer_cast; int const AudioContentProperty::AUDIO_CHANNELS = 200; -int const AudioContentProperty::AUDIO_LENGTH = 201; -int const AudioContentProperty::AUDIO_FRAME_RATE = 202; -int const AudioContentProperty::AUDIO_GAIN = 203; -int const AudioContentProperty::AUDIO_DELAY = 204; -int const AudioContentProperty::AUDIO_MAPPING = 205; -int const AudioContentProperty::AUDIO_PROCESSOR = 206; +int const AudioContentProperty::AUDIO_FRAME_RATE = 201; +int const AudioContentProperty::AUDIO_GAIN = 202; +int const AudioContentProperty::AUDIO_DELAY = 203; +int const AudioContentProperty::AUDIO_MAPPING = 204; +int const AudioContentProperty::AUDIO_PROCESSOR = 205; AudioContent::AudioContent (shared_ptr f) : Content (f) @@ -188,9 +187,8 @@ string AudioContent::technical_summary () const { return String::compose ( - "audio: channels %1, length %2 frames, content rate %3, resampled rate %4", + "audio: channels %1, content rate %2, resampled rate %3", audio_channels(), - audio_length(), audio_frame_rate(), resampled_audio_frame_rate() ); diff --git a/src/lib/audio_content.h b/src/lib/audio_content.h index ee5a7db7a..85728922a 100644 --- a/src/lib/audio_content.h +++ b/src/lib/audio_content.h @@ -40,7 +40,6 @@ class AudioContentProperty { public: static int const AUDIO_CHANNELS; - static int const AUDIO_LENGTH; static int const AUDIO_FRAME_RATE; static int const AUDIO_GAIN; static int const AUDIO_DELAY; @@ -65,8 +64,6 @@ public: /** @return number of audio channels in the content */ virtual int audio_channels () const = 0; - /** @return the length of the audio in the content */ - virtual Frame audio_length () const = 0; /** @return the frame rate of the content */ virtual int audio_frame_rate () const = 0; virtual AudioMapping audio_mapping () const = 0; diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 9acc883fd..1ca194f09 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -249,20 +249,6 @@ FFmpegContent::set_audio_stream (shared_ptr s) signal_changed (FFmpegContentProperty::AUDIO_STREAM); } -Frame -FFmpegContent::audio_length () const -{ - if (!audio_stream ()) { - return 0; - } - - /* We're talking about the content's audio length here, at the content's frame - rate. We assume it's the same as the video's length, and we can just convert - using the content's rates. - */ - return (video_length () / video_frame_rate ()) * audio_frame_rate (); -} - int FFmpegContent::audio_channels () const { diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index cff5eaed8..6d27c66ca 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -69,7 +69,6 @@ public: /* AudioContent */ int audio_channels () const; - Frame audio_length () const; int audio_frame_rate () const; AudioMapping audio_mapping () const; void set_audio_mapping (AudioMapping); diff --git a/src/lib/single_stream_audio_content.cc b/src/lib/single_stream_audio_content.cc index b470d1a99..76f6e00d9 100644 --- a/src/lib/single_stream_audio_content.cc +++ b/src/lib/single_stream_audio_content.cc @@ -89,7 +89,6 @@ SingleStreamAudioContent::take_from_audio_examiner (shared_ptr ex } signal_changed (AudioContentProperty::AUDIO_CHANNELS); - signal_changed (AudioContentProperty::AUDIO_LENGTH); signal_changed (AudioContentProperty::AUDIO_FRAME_RATE); int const p = processed_audio_channels (); diff --git a/src/lib/single_stream_audio_content.h b/src/lib/single_stream_audio_content.h index d1d512d67..944d887b0 100644 --- a/src/lib/single_stream_audio_content.h +++ b/src/lib/single_stream_audio_content.h @@ -44,7 +44,7 @@ public: boost::mutex::scoped_lock lm (_mutex); return _audio_channels; } - + Frame audio_length () const { boost::mutex::scoped_lock lm (_mutex); return _audio_length; diff --git a/src/wx/content_properties_dialog.cc b/src/wx/content_properties_dialog.cc index 45593fd5b..c212eb50a 100644 --- a/src/wx/content_properties_dialog.cc +++ b/src/wx/content_properties_dialog.cc @@ -23,6 +23,7 @@ #include "lib/content.h" #include "lib/video_content.h" #include "lib/audio_content.h" +#include "lib/single_stream_audio_content.h" #include using std::string; @@ -58,9 +59,13 @@ ContentPropertiesDialog::ContentPropertiesDialog (wxWindow* parent, shared_ptr (audio->audio_channels ())) ); + } + + shared_ptr single = dynamic_pointer_cast (content); + if (single) { add_property ( _("Audio length"), - std_to_wx (raw_convert (audio->audio_length())) + " " + _("audio frames") + std_to_wx (raw_convert (single->audio_length())) + " " + _("audio frames") ); } diff --git a/test/audio_decoder_test.cc b/test/audio_decoder_test.cc index 8e570f674..3753ca379 100644 --- a/test/audio_decoder_test.cc +++ b/test/audio_decoder_test.cc @@ -32,44 +32,6 @@ using std::cout; using std::min; using boost::shared_ptr; -class TestAudioDecoder : public AudioDecoder -{ -public: - TestAudioDecoder (shared_ptr content) - : AudioDecoder (content) - , _position (0) - {} - - bool pass (PassReason) - { - Frame const N = min ( - Frame (2000), - _audio_content->audio_length() - _position - ); - - shared_ptr buffers (new AudioBuffers (_audio_content->audio_channels(), N)); - for (int i = 0; i < _audio_content->audio_channels(); ++i) { - for (int j = 0; j < N; ++j) { - buffers->data(i)[j] = j + _position; - } - } - - audio (buffers, ContentTime::from_frames (_position, _audio_content->resampled_audio_frame_rate ())); - _position += N; - - return N < 2000; - } - - void seek (ContentTime t, bool accurate) - { - AudioDecoder::seek (t, accurate); - _position = t.frames (_audio_content->resampled_audio_frame_rate ()); - } - -private: - Frame _position; -}; - class TestAudioContent : public AudioContent { public: @@ -109,6 +71,46 @@ public: void set_audio_mapping (AudioMapping) {} }; +class TestAudioDecoder : public AudioDecoder +{ +public: + TestAudioDecoder (shared_ptr content) + : AudioDecoder (content) + , _test_audio_content (content) + , _position (0) + {} + + bool pass (PassReason) + { + Frame const N = min ( + Frame (2000), + _test_audio_content->audio_length() - _position + ); + + shared_ptr buffers (new AudioBuffers (_audio_content->audio_channels(), N)); + for (int i = 0; i < _audio_content->audio_channels(); ++i) { + for (int j = 0; j < N; ++j) { + buffers->data(i)[j] = j + _position; + } + } + + audio (buffers, ContentTime::from_frames (_position, _audio_content->resampled_audio_frame_rate ())); + _position += N; + + return N < 2000; + } + + void seek (ContentTime t, bool accurate) + { + AudioDecoder::seek (t, accurate); + _position = t.frames (_audio_content->resampled_audio_frame_rate ()); + } + +private: + boost::shared_ptr _test_audio_content; + Frame _position; +}; + shared_ptr content; shared_ptr decoder; -- 2.30.2