Try to make audio discard work properly.
authorCarl Hetherington <cth@carlh.net>
Mon, 22 Oct 2012 12:40:55 +0000 (13:40 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 22 Oct 2012 12:40:55 +0000 (13:40 +0100)
src/lib/decoder.cc
src/lib/film.cc
src/lib/film_state.cc
src/lib/film_state.h

index a90c14b2bdc995af6664e51965a68bd7995978f8..c9235f8e1d595ae0d60b537a88f696222c3b2980 100644 (file)
@@ -90,10 +90,12 @@ Decoder::~Decoder ()
 void
 Decoder::process_begin ()
 {
-       _delay_in_bytes = _fs->audio_delay() * _fs->audio_sample_rate() * _fs->audio_channels() * bytes_per_audio_sample() / 1000;
+       _delay_in_bytes = _fs->total_audio_delay() * _fs->audio_sample_rate() * _fs->audio_channels() * bytes_per_audio_sample() / 1000;
        delete _delay_line;
        _delay_line = new DelayLine (_delay_in_bytes);
 
+       _log->log (String::compose ("Decoding audio with total delay of %1", _fs->total_audio_delay()));
+
        _audio_frames_processed = 0;
 }
 
index aa0bfa21192cfb6d1c87c2bf858198c1b283072c..3a8b29f8603a8ddf30938a0bc06f6f005b2c37cd 100644 (file)
@@ -256,6 +256,7 @@ void
 Film::examine_content_post_gui ()
 {
        set_length (_examine_content_job->last_video_frame ());
+       set_audio_to_discard (_examine_content_job->audio_to_discard ());
        _examine_content_job.reset ();
 
        string const tdir = dir ("thumbs");
index c8d519d71216336cff196b7e8d8e1a9f17c119fe..deaacca84fd377767e4185ccd79eeac2c03a5949 100644 (file)
@@ -809,6 +809,13 @@ FilmState::set_frames_per_second (float f)
        _frames_per_second = f;
        signal_changed (FRAMES_PER_SECOND);
 }
+
+void
+FilmState::set_audio_to_discard (int a)
+{
+       _audio_to_discard = a;
+       signal_changed (AUDIO_TO_DISCARD);
+}
        
 void
 FilmState::signal_changed (Property p)
@@ -833,3 +840,8 @@ FilmState::audio_channels () const
        return _audio_streams[_audio_stream].channels ();
 }
 
+int
+FilmState::total_audio_delay () const
+{
+       return _audio_delay - _audio_to_discard;
+}
index 294b9aa10ebcb301f220a6850acabd64016b799e..d1d7489f6ba0c5c73cc48f2d43f964fa9d672cc9 100644 (file)
@@ -73,6 +73,7 @@ public:
                , _audio_sample_rate (0)
                , _has_subtitles (false)
                , _frames_per_second (0)
+               , _audio_to_discard (0)
                , _dirty (false)
        {}
 
@@ -113,6 +114,7 @@ public:
                , _audio_streams     (o._audio_streams)
                , _subtitle_streams  (o._subtitle_streams)
                , _frames_per_second (o._frames_per_second)
+               , _audio_to_discard  (o._audio_to_discard)
                , _dirty             (o._dirty)
        {}
 
@@ -148,6 +150,7 @@ public:
        }
 
        int audio_channels () const;
+       int total_audio_delay () const;
 
        enum Property {
                NONE,
@@ -179,6 +182,7 @@ public:
                AUDIO_STREAMS,
                SUBTITLE_STREAMS,
                FRAMES_PER_SECOND,
+               AUDIO_TO_DISCARD
        };
 
 
@@ -338,6 +342,10 @@ public:
                return _frames_per_second;
        }
 
+       int audio_to_discard () const {
+               return _audio_to_discard;
+       }
+
        
        /* SET */
 
@@ -382,6 +390,7 @@ public:
        void set_audio_streams (std::vector<AudioStream>);
        void set_subtitle_streams (std::vector<SubtitleStream>);
        void set_frames_per_second (float);
+       void set_audio_to_discard (int);
 
        /** Emitted when some property has changed */
        mutable sigc::signal1<void, Property> Changed;
@@ -471,6 +480,10 @@ private:
        std::vector<SubtitleStream> _subtitle_streams;
        /** Frames per second of the source */
        float _frames_per_second;
+       /** Number of milliseconds of audio to discard at the start of this film
+           in order to sync audio with video.  Can be negative.
+       */
+       int _audio_to_discard;
 
        mutable bool _dirty;