FFmpegContent does not need audio_length().
authorCarl Hetherington <cth@carlh.net>
Wed, 27 May 2015 15:38:28 +0000 (16:38 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 27 May 2015 15:38:28 +0000 (16:38 +0100)
src/lib/audio_content.cc
src/lib/audio_content.h
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
src/lib/single_stream_audio_content.cc
src/lib/single_stream_audio_content.h
src/wx/content_properties_dialog.cc
test/audio_decoder_test.cc

index def123fb11489870cb5090a698350a0c2bf3c241..e4b5a804e98a448d94975a538ea6c176f30a3c1b 100644 (file)
@@ -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<const Film> 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()
                );
index ee5a7db7ad10766dd8062fa64636688e87e921ad..85728922ac98661c90af0496c56915259008c421 100644 (file)
@@ -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;
index 9acc883fd0c306ebb01db70206b3693940e54f6a..1ca194f092f33f28c96a2ba04401c91da5691dd9 100644 (file)
@@ -249,20 +249,6 @@ FFmpegContent::set_audio_stream (shared_ptr<FFmpegAudioStream> 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
 {
index cff5eaed83ebe022707b0c8861b9203ae027d4cc..6d27c66ca6b42cf5773518a3068a0113f6955de4 100644 (file)
@@ -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);
index b470d1a995427d492e5062e33a191e78cb8694b1..76f6e00d96f1b964ecdd7439bfe9b10eda41d81d 100644 (file)
@@ -89,7 +89,6 @@ SingleStreamAudioContent::take_from_audio_examiner (shared_ptr<AudioExaminer> ex
        }
 
        signal_changed (AudioContentProperty::AUDIO_CHANNELS);
-       signal_changed (AudioContentProperty::AUDIO_LENGTH);
        signal_changed (AudioContentProperty::AUDIO_FRAME_RATE);
 
        int const p = processed_audio_channels ();
index d1d512d6765b33665ca2fe22db0f0fd1e1f40663..944d887b0ba4ae9ec293efe9e6b1385697e9372c 100644 (file)
@@ -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;
index 45593fd5b84921982d4658e948d7c5d19a50762a..c212eb50a7665e4ed9d37ef16f4e02b9d067ea13 100644 (file)
@@ -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 <boost/algorithm/string.hpp>
 
 using std::string;
@@ -58,9 +59,13 @@ ContentPropertiesDialog::ContentPropertiesDialog (wxWindow* parent, shared_ptr<C
                        _("Audio channels"),
                        std_to_wx (raw_convert<string> (audio->audio_channels ()))
                        );
+       }
+
+       shared_ptr<SingleStreamAudioContent> single = dynamic_pointer_cast<SingleStreamAudioContent> (content);
+       if (single) {
                add_property (
                        _("Audio length"),
-                       std_to_wx (raw_convert<string> (audio->audio_length())) + " " + _("audio frames")
+                       std_to_wx (raw_convert<string> (single->audio_length())) + " " + _("audio frames")
                        );
        }
        
index 8e570f674052419f65790ea37fa6422492b9f3dc..3753ca37992319027b5083f56725e36e35de3820 100644 (file)
@@ -32,44 +32,6 @@ using std::cout;
 using std::min;
 using boost::shared_ptr;
 
-class TestAudioDecoder : public AudioDecoder
-{
-public:
-       TestAudioDecoder (shared_ptr<AudioContent> content)
-               : AudioDecoder (content)
-               , _position (0)
-       {}
-
-       bool pass (PassReason)
-       {
-               Frame const N = min (
-                       Frame (2000),
-                       _audio_content->audio_length() - _position
-                       );
-
-               shared_ptr<AudioBuffers> 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<TestAudioContent> 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<AudioBuffers> 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<TestAudioContent> _test_audio_content;
+       Frame _position;
+};
+
 shared_ptr<TestAudioContent> content;
 shared_ptr<TestAudioDecoder> decoder;