Try to clean up stream handling wrt audio channel counts.
authorCarl Hetherington <cth@carlh.net>
Sat, 20 Oct 2012 18:30:04 +0000 (19:30 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 20 Oct 2012 18:30:04 +0000 (19:30 +0100)
18 files changed:
src/lib/ab_transcoder.cc
src/lib/decoder.h
src/lib/encoder.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/lib/film_state.cc
src/lib/film_state.h
src/lib/imagemagick_encoder.h
src/lib/j2k_still_encoder.h
src/lib/j2k_wav_encoder.cc
src/lib/j2k_wav_encoder.h
src/lib/stream.cc
src/lib/stream.h
src/lib/transcoder.cc
src/wx/film_editor.cc
src/wx/film_editor.h
test/metadata.ref
test/test.cc

index 54153ec765f0304b1ac081c5010111627fce997d..08938a2827e822dceecb7fdbad4420207d6a4f6c 100644 (file)
@@ -104,7 +104,7 @@ ABTranscoder::process_video (shared_ptr<Image> yuv, int frame, shared_ptr<Subtit
 void
 ABTranscoder::go ()
 {
-       _encoder->process_begin (_da->audio_channel_layout(), _da->audio_sample_format());
+       _encoder->process_begin (_da->audio_channel_layout());
        _da->process_begin ();
        _db->process_begin ();
        
index 85b256f5bbe592629b8dad0c2b9c12396816aa73..2285cf4f9694ecd4edc4c6e9ec6b2a8b209898d2 100644 (file)
@@ -81,17 +81,14 @@ public:
                return _video_frame;
        }
 
-       virtual std::vector<Stream> audio_streams () const {
-               return std::vector<Stream> ();
+       virtual std::vector<AudioStream> audio_streams () const {
+               return std::vector<AudioStream> ();
        }
        
-       virtual std::vector<Stream> subtitle_streams () const {
-               return std::vector<Stream> ();
+       virtual std::vector<SubtitleStream> subtitle_streams () const {
+               return std::vector<SubtitleStream> ();
        }
 
-       virtual void set_audio_stream (Stream s) {}
-       virtual void set_subtitle_stream (Stream s) {}
-       
        /** Emitted when a video frame is ready.
         *  First parameter is the frame.
         *  Second parameter is its index within the content.
index 3317d30d18497290ffa3f01b893c576890cdc45c..561e419017b1e75488edf9cf0f55bdb85114bc7a 100644 (file)
@@ -55,7 +55,7 @@ public:
        Encoder (boost::shared_ptr<const FilmState> s, boost::shared_ptr<const Options> o, Log* l);
 
        /** Called to indicate that a processing run is about to begin */
-       virtual void process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format) = 0;
+       virtual void process_begin (int64_t audio_channel_layout) = 0;
 
        /** Called with a frame of video.
         *  @param i Video frame image.
index 4b0594adddfb0d7893f1ec7b87cb0d19da886c7d..d93b023c385fe27b65cc29ab58e6df91729e736e 100644 (file)
@@ -109,43 +109,30 @@ FFmpegDecoder::setup_general ()
        /* Find video, audio and subtitle streams and choose the first of each */
 
        for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
-               if (_format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+               AVStream* s = _format_context->streams[i];
+               if (s->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
                        _video_stream = i;
-               } else if (_format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+               } else if (s->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
                        if (_audio_stream == -1) {
                                _audio_stream = i;
                        }
-                       _audio_streams.push_back (Stream (stream_name (_format_context->streams[i]), i));
-               } else if (_format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+                       _audio_streams.push_back (AudioStream (stream_name (s), i, s->codec->channels));
+               } else if (s->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
                        if (_subtitle_stream == -1) {
                                _subtitle_stream = i;
                        }
-                       _subtitle_streams.push_back (Stream (stream_name (_format_context->streams[i]), i));
+                       _subtitle_streams.push_back (SubtitleStream (stream_name (s), i));
                }
        }
 
        /* Now override audio and subtitle streams with those from the Film, if it has any */
 
-       if (_fs->audio_stream() != -1) {
-               vector<Stream>::iterator i = _audio_streams.begin ();
-               while (i != _audio_streams.end() && i->id != _fs->audio_stream()) {
-                       ++i;
-               }
-
-               if (i != _audio_streams.end()) {
-                       _audio_stream = _fs->audio_stream ();
-               }
+       if (_fs->audio_stream_index() != -1) {
+               _audio_stream = _fs->audio_stream_decoder_id ();
        }
 
-       if (_fs->subtitle_stream() != -1) {
-               vector<Stream>::iterator i = _subtitle_streams.begin ();
-               while (i != _subtitle_streams.end() && i->id != _fs->subtitle_stream()) {
-                       ++i;
-               }
-
-               if (i != _subtitle_streams.end()) {
-                       _subtitle_stream = _fs->subtitle_stream ();
-               }
+       if (_fs->subtitle_stream_index() != -1) {
+               _subtitle_stream = _fs->subtitle_stream_decoder_id ();
        }
 
        if (_video_stream < 0) {
@@ -394,32 +381,18 @@ FFmpegDecoder::has_subtitles () const
        return (_subtitle_stream != -1);
 }
 
-vector<Stream>
+vector<AudioStream>
 FFmpegDecoder::audio_streams () const
 {
        return _audio_streams;
 }
 
-vector<Stream>
+vector<SubtitleStream>
 FFmpegDecoder::subtitle_streams () const
 {
        return _subtitle_streams;
 }
 
-void
-FFmpegDecoder::set_audio_stream (int s)
-{
-       _audio_stream = s;
-       setup_audio ();
-}
-
-void
-FFmpegDecoder::set_subtitle_stream (int s)
-{
-       _subtitle_stream = s;
-       setup_subtitle ();
-}
-
 string
 FFmpegDecoder::stream_name (AVStream* s) const
 {
index 0d256b37e4b0152237c605744589f0f302ae95e2..339afbaef368a1b85def1b1039301ea94dd039e1 100644 (file)
@@ -67,11 +67,8 @@ public:
        bool has_subtitles () const;
        int bytes_per_audio_sample () const;
 
-       std::vector<Stream> audio_streams () const;
-       std::vector<Stream> subtitle_streams () const;
-
-       void set_audio_stream (int id);
-       void set_subtitle_stream (int id);
+       std::vector<AudioStream> audio_streams () const;
+       std::vector<SubtitleStream> subtitle_streams () const;
 
 private:
 
@@ -97,8 +94,8 @@ private:
        int _subtitle_stream; ///< may be < 0 if there is no subtitle
        AVFrame* _frame;
 
-       std::vector<Stream> _audio_streams;
-       std::vector<Stream> _subtitle_streams;
+       std::vector<AudioStream> _audio_streams;
+       std::vector<SubtitleStream> _subtitle_streams;
        
        AVCodecContext* _video_codec_context;
        AVCodec* _video_codec;
index 46359677c1e0e3091fcaab4d3c9cf1f677407e13..8dd8309a8f0358a2d35c556623f6e569fe487d55 100644 (file)
@@ -113,16 +113,15 @@ FilmState::write_metadata () const
        f << "width " << _size.width << "\n";
        f << "height " << _size.height << "\n";
        f << "length " << _length << "\n";
-       f << "audio_channels " << _audio_channels << "\n";
        f << "audio_sample_rate " << _audio_sample_rate << "\n";
        f << "content_digest " << _content_digest << "\n";
        f << "has_subtitles " << _has_subtitles << "\n";
 
-       for (vector<Stream>::const_iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) {
+       for (vector<AudioStream>::const_iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) {
                f << "audio_stream " << i->to_string () << "\n";
        }
 
-       for (vector<Stream>::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
+       for (vector<SubtitleStream>::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
                f << "subtitle_stream " << i->to_string () << "\n";
        }
 
@@ -219,8 +218,6 @@ FilmState::read_metadata ()
                        _size.height = atoi (v.c_str ());
                } else if (k == "length") {
                        _length = atof (v.c_str ());
-               } else if (k == "audio_channels") {
-                       _audio_channels = atoi (v.c_str ());
                } else if (k == "audio_sample_rate") {
                        _audio_sample_rate = atoi (v.c_str ());
                } else if (k == "content_digest") {
@@ -228,9 +225,9 @@ FilmState::read_metadata ()
                } else if (k == "has_subtitles") {
                        _has_subtitles = (v == "1");
                } else if (k == "audio_stream") {
-                       _audio_streams.push_back (Stream (v));
+                       _audio_streams.push_back (AudioStream (v));
                } else if (k == "subtitle_stream") {
-                       _subtitle_streams.push_back (Stream (v));
+                       _subtitle_streams.push_back (SubtitleStream (v));
                } else if (k == "frames_per_second") {
                        _frames_per_second = atof (v.c_str ());
                }
@@ -424,7 +421,7 @@ FilmState::dci_name () const
                d << "_";
        }
 
-       switch (_audio_channels) {
+       switch (_audio_streams[_audio_stream].channels()) {
        case 1:
                d << "10_";
                break;
@@ -531,13 +528,12 @@ FilmState::set_content (string c)
        set_size (d->native_size ());
        set_length (d->length_in_frames ());
        set_frames_per_second (d->frames_per_second ());
-       set_audio_channels (d->audio_channels ());
        set_audio_sample_rate (d->audio_sample_rate ());
        set_has_subtitles (d->has_subtitles ());
        set_audio_streams (d->audio_streams ());
        set_subtitle_streams (d->subtitle_streams ());
-       set_audio_stream (audio_streams().empty() ? -1 : audio_streams().front().id);
-       set_subtitle_stream (subtitle_streams().empty() ? -1 : subtitle_streams().front().id);
+       set_audio_stream (audio_streams().empty() ? -1 : 0);
+       set_subtitle_stream (subtitle_streams().empty() ? -1 : 0);
        set_content_digest (md5_digest (content_path ()));
        
        _content = c;
@@ -770,13 +766,6 @@ FilmState::set_length (int l)
        signal_changed (LENGTH);
 }
 
-void
-FilmState::set_audio_channels (int c)
-{
-       _audio_channels = c;
-       signal_changed (AUDIO_CHANNELS);
-}
-
 void
 FilmState::set_audio_sample_rate (int r)
 {
@@ -799,14 +788,14 @@ FilmState::set_has_subtitles (bool s)
 }
 
 void
-FilmState::set_audio_streams (vector<Stream> s)
+FilmState::set_audio_streams (vector<AudioStream> s)
 {
        _audio_streams = s;
        _dirty = true;
 }
 
 void
-FilmState::set_subtitle_streams (vector<Stream> s)
+FilmState::set_subtitle_streams (vector<SubtitleStream> s)
 {
        _subtitle_streams = s;
        _dirty = true;
@@ -831,3 +820,16 @@ FilmState::state_copy () const
 {
        return shared_ptr<FilmState> (new FilmState (*this));
 }
+
+int
+FilmState::audio_channels () const
+{
+       if (_audio_stream == -1) {
+               return 0;
+       }
+
+       return _audio_streams[_audio_stream].channels ();
+}
+
+
+       
index 40908693f26c40dd7edfbd049adb4462549de67d..46374a17d7b468e7a250ba81d262fd67f1899745 100644 (file)
@@ -70,7 +70,6 @@ public:
                , _subtitle_offset (0)
                , _subtitle_scale (1)
                , _length (0)
-               , _audio_channels (0)
                , _audio_sample_rate (0)
                , _has_subtitles (false)
                , _frames_per_second (0)
@@ -106,6 +105,8 @@ public:
                return _dirty;
        }
 
+       int audio_channels () const;
+
        enum Property {
                NONE,
                NAME,
@@ -131,7 +132,6 @@ public:
                THUMBS,
                SIZE,
                LENGTH,
-               AUDIO_CHANNELS,
                AUDIO_SAMPLE_RATE,
                HAS_SUBTITLES,
                AUDIO_STREAMS,
@@ -190,10 +190,15 @@ public:
                return _dcp_ab;
        }
 
-       int audio_stream () const {
+       int audio_stream_index () const {
                return _audio_stream;
        }
 
+       int audio_stream_decoder_id () const {
+               assert (_audio_stream < int (_audio_streams.size()));
+               return _audio_streams[_audio_stream].id ();
+       }
+       
        float audio_gain () const {
                return _audio_gain;
        }
@@ -206,10 +211,15 @@ public:
                return _still_duration;
        }
 
-       int subtitle_stream () const {
+       int subtitle_stream_index () const {
                return _subtitle_stream;
        }
 
+       int subtitle_stream_decoder_id () const {
+               assert (_subtitle_stream < int (_subtitle_streams.size()));
+               return _subtitle_streams[_subtitle_stream].id ();
+       }
+
        bool with_subtitles () const {
                return _with_subtitles;
        }
@@ -262,10 +272,6 @@ public:
                return _length;
        }
 
-       int audio_channels () const {
-               return _audio_channels;
-       }
-       
        int audio_sample_rate () const {
                return _audio_sample_rate;
        }
@@ -278,11 +284,11 @@ public:
                return _has_subtitles;
        }
 
-       std::vector<Stream> audio_streams () const {
+       std::vector<AudioStream> audio_streams () const {
                return _audio_streams;
        }
 
-       std::vector<Stream> subtitle_streams () const {
+       std::vector<SubtitleStream> subtitle_streams () const {
                return _subtitle_streams;
        }
        
@@ -331,8 +337,8 @@ public:
        void set_audio_sample_rate (int);
        void set_content_digest (std::string);
        void set_has_subtitles (bool);
-       void set_audio_streams (std::vector<Stream>);
-       void set_subtitle_streams (std::vector<Stream>);
+       void set_audio_streams (std::vector<AudioStream>);
+       void set_subtitle_streams (std::vector<SubtitleStream>);
        void set_frames_per_second (float);
 
        /** Emitted when some property has changed */
@@ -375,7 +381,7 @@ private:
            has the specified filters and post-processing.
        */
        bool _dcp_ab;
-       /** The decoder's stream ID to use for audio, or -1 if there is none */
+       /** An index into our _audio_streams vector for the stream to use for audio, or -1 if there is none */
        int _audio_stream;
        /** Gain to apply to audio in dB */
        float _audio_gain;
@@ -383,7 +389,7 @@ private:
        int _audio_delay;
        /** Duration to make still-sourced films (in seconds) */
        int _still_duration;
-       /** The decoder's stream ID to use for subtitles, or -1 if there are none */
+       /** An index into our _subtitle_streams vector for the stream to use for subtitles, or -1 if there is none */
        int _subtitle_stream;
        /** True if subtitles should be shown for this film */
        bool _with_subtitles;
@@ -411,8 +417,6 @@ private:
        Size _size;
        /** Length of the source in frames */
        int _length;
-       /** Number of audio channels */
-       int _audio_channels;
        /** Sample rate of the source audio, in Hz */
        int _audio_sample_rate;
        /** MD5 digest of our content file */
@@ -420,9 +424,9 @@ private:
        /** true if the source has subtitles */
        bool _has_subtitles;
        /** the audio streams that the source has */
-       std::vector<Stream> _audio_streams;
+       std::vector<AudioStream> _audio_streams;
        /** the subtitle streams that the source has */
-       std::vector<Stream> _subtitle_streams;
+       std::vector<SubtitleStream> _subtitle_streams;
        /** Frames per second of the source */
        float _frames_per_second;
 
index 06f1723b196351fbb84e448e3fba2b06c27f3a69..29767ed033a3261336a531397f3c815bb4421d1a 100644 (file)
@@ -36,7 +36,7 @@ class ImageMagickEncoder : public Encoder
 public:
        ImageMagickEncoder (boost::shared_ptr<const FilmState> s, boost::shared_ptr<const Options> o, Log* l);
 
-       void process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format) {}
+       void process_begin (int64_t audio_channel_layout) {}
        void process_video (boost::shared_ptr<Image>, int, boost::shared_ptr<Subtitle>);
        void process_audio (boost::shared_ptr<const AudioBuffers>) {}
        void process_end () {}
index 7e7719321759efdb573f04fa97987b8b38c9ed6d..928afe372fe8a7bf3443facd37f18db815487d8e 100644 (file)
@@ -36,7 +36,7 @@ class J2KStillEncoder : public Encoder
 public:
        J2KStillEncoder (boost::shared_ptr<const FilmState>, boost::shared_ptr<const Options>, Log *);
 
-       void process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format) {}
+       void process_begin (int64_t audio_channel_layout) {}
        void process_video (boost::shared_ptr<Image>, int, boost::shared_ptr<Subtitle>);
        void process_audio (boost::shared_ptr<const AudioBuffers>) {}
        void process_end () {}
index a83c283d7fc08a062d1af4f07f21c9c24b97ad6f..8747bb7ad8fcad2a0d7e2d40130bd34259473e11 100644 (file)
@@ -216,7 +216,7 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server)
 }
 
 void
-J2KWAVEncoder::process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format)
+J2KWAVEncoder::process_begin (int64_t audio_channel_layout)
 {
        if (_fs->audio_sample_rate() != _fs->target_sample_rate()) {
 #ifdef HAVE_SWRESAMPLE
index 2c18a5730700acb69fad2bbf2aab4750ea791899..6733221deca3b47a9f785ccc312ba3f5cab6f194 100644 (file)
@@ -50,7 +50,7 @@ public:
        J2KWAVEncoder (boost::shared_ptr<const FilmState>, boost::shared_ptr<const Options>, Log *);
        ~J2KWAVEncoder ();
 
-       void process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format);
+       void process_begin (int64_t audio_channel_layout);
        void process_video (boost::shared_ptr<Image>, int, boost::shared_ptr<Subtitle>);
        void process_audio (boost::shared_ptr<const AudioBuffers>);
        void process_end ();
index e40738990fab050e4de0963628b30ebc6e7afc8a..d1c2b5a9e589790c4a5c5b8193a16cd5f98aa40b 100644 (file)
 
 using namespace std;
 
-Stream::Stream (string t)
+AudioStream::AudioStream (string t)
 {
        stringstream n (t);
-       n >> id;
-       
+       n >> _id >> _channels;
+
+       for (int i = 0; i < 2; ++i) {
+               size_t const s = t.find (' ');
+               if (s != string::npos) {
+                       t = t.substr (s + 1);
+               }
+       }
+
+       _name = t;
+}
+
+string
+AudioStream::to_string () const
+{
+       return String::compose ("%1 %2 %3", _id, _channels, _name);
+}
+
+SubtitleStream::SubtitleStream (string t)
+{
+       stringstream n (t);
+       n >> _id;
+
        size_t const s = t.find (' ');
        if (s != string::npos) {
-               name = t.substr (s + 1);
+               _name = t.substr (s + 1);
        }
 }
 
 string
-Stream::to_string () const
+SubtitleStream::to_string () const
 {
-       return String::compose ("%1 %2", id, name);
+       return String::compose ("%1 %2", _id, _name);
 }
index 764c03d79f5a809ba3935141e09505cfae3ac76c..2db63c6208e12c75d92360b1b1676a9637a282b6 100644 (file)
 #ifndef DVDOMATIC_STREAM_H
 #define DVDOMATIC_STREAM_H
 
-struct Stream
+class Stream
 {
 public:
-       Stream (std::string t);
+       Stream ()
+               : _id (-1)
+       {}
        
        Stream (std::string n, int i)
-               : name (n)
-               , id (i)
+               : _name (n)
+               , _id (i)
        {}
 
-       std::string to_string () const;
+       virtual std::string to_string () const = 0;
        
-       std::string name;
-       int id;
+       std::string name () const {
+               return _name;
+       }
+
+       int id () const {
+               return _id;
+       }
+
+protected:
+       std::string _name;
+       int _id;
+};
+
+struct AudioStream : public Stream
+{
+public:
+       AudioStream (std::string t);
+       
+       AudioStream (std::string n, int i, int c)
+               : Stream (n, i)
+               , _channels (c)
+       {}
+
+       std::string to_string () const;
+
+       int channels () const {
+               return _channels;
+       }
+
+private:
+       int _channels;
+};
+
+class SubtitleStream : public Stream
+{
+public:
+       SubtitleStream (std::string t);
+
+       SubtitleStream (std::string n, int i)
+               : Stream (n, i)
+       {}
+
+       std::string to_string () const;
 };
 
 #endif
index b74d09174ee1a53f6d77dab2e7864691559ef605..a809e55d2cf0bcb1c482a94a9fd94a3758580967 100644 (file)
@@ -57,7 +57,7 @@ Transcoder::Transcoder (shared_ptr<const FilmState> s, shared_ptr<const Options>
 void
 Transcoder::go ()
 {
-       _encoder->process_begin (_decoder->audio_channel_layout(), _decoder->audio_sample_format());
+       _encoder->process_begin (_decoder->audio_channel_layout());
        try {
                _decoder->go ();
        } catch (...) {
index 7ed3a14c7770180ae7536d68e5ea1a4b66303506..36f3bc8983e34f0b7c02298a296b551af60cc7d1 100644 (file)
@@ -467,8 +467,6 @@ FilmEditor::film_changed (FilmState::Property p)
                _frames_per_second->SetLabel (std_to_wx (s.str ()));
                break;
        }
-       case FilmState::AUDIO_CHANNELS:
-               _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
        case FilmState::AUDIO_SAMPLE_RATE:
                if (_film->audio_channels() == 0 && _film->audio_sample_rate() == 0) {
                        _audio->SetLabel (wxT (""));
@@ -546,10 +544,11 @@ FilmEditor::film_changed (FilmState::Property p)
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
        case FilmState::AUDIO_STREAM:
-               set_selected_stream (_film->audio_streams(), _film->audio_stream(), _audio_stream);
+               _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
+               _audio_stream->SetSelection (_film->audio_stream_index ());
                break;
        case FilmState::SUBTITLE_STREAM:
-               set_selected_stream (_film->subtitle_streams(), _film->subtitle_stream(), _subtitle_stream);
+               _subtitle_stream->SetSelection (_film->subtitle_stream_index ());
                break;
        }
 }
@@ -621,7 +620,6 @@ FilmEditor::set_film (Film* f)
        film_changed (FilmState::SIZE);
        film_changed (FilmState::LENGTH);
        film_changed (FilmState::FRAMES_PER_SECOND);
-       film_changed (FilmState::AUDIO_CHANNELS);
        film_changed (FilmState::AUDIO_SAMPLE_RATE);
        film_changed (FilmState::SCALER);
        film_changed (FilmState::AUDIO_GAIN);
@@ -885,33 +883,18 @@ void
 FilmEditor::setup_streams ()
 {
        _audio_stream->Clear ();
-       vector<Stream> s = _film->audio_streams ();
-       for (vector<Stream>::iterator i = s.begin(); i != s.end(); ++i) {
-               _audio_stream->Append (std_to_wx (i->name));
+       vector<AudioStream> a = _film->audio_streams ();
+       for (vector<AudioStream>::iterator i = a.begin(); i != a.end(); ++i) {
+               _audio_stream->Append (std_to_wx (i->name()));
        }
-       set_selected_stream (_film->audio_streams(), _film->audio_stream(), _audio_stream);
+       _audio_stream->SetSelection (_film->audio_stream_index ());
 
        _subtitle_stream->Clear ();
-       s = _film->subtitle_streams ();
-       for (vector<Stream>::iterator i = s.begin(); i != s.end(); ++i) {
-               _subtitle_stream->Append (std_to_wx (i->name));
-       }
-       set_selected_stream (_film->subtitle_streams(), _film->subtitle_stream(), _subtitle_stream);
-}
-
-void
-FilmEditor::set_selected_stream (vector<Stream> const & streams, int id, wxComboBox* combo) const
-{
-       if (id == -1) {
-               return;
-       }
-       
-       size_t n = 0;
-       while (n < streams.size() && streams[n].id != id) {
-               ++n;
+       vector<SubtitleStream> s = _film->subtitle_streams ();
+       for (vector<SubtitleStream>::iterator i = s.begin(); i != s.end(); ++i) {
+               _subtitle_stream->Append (std_to_wx (i->name()));
        }
-       assert (n < streams.size());
-       combo->SetSelection (n);
+       _subtitle_stream->SetSelection (_film->subtitle_stream_index ());
 }
 
 void
@@ -922,12 +905,7 @@ FilmEditor::audio_stream_changed (wxCommandEvent &)
        }
 
        _ignore_changes = Film::AUDIO_STREAM;
-       int const n = _audio_stream->GetSelection ();
-       if (n >= 0) {
-               vector<Stream> s = _film->audio_streams ();
-               assert (n < int (s.size ()));
-               _film->set_audio_stream (s[n].id);
-       }
+       _film->set_audio_stream (_audio_stream->GetSelection ());
        _ignore_changes = Film::NONE;
 }
 
@@ -939,11 +917,6 @@ FilmEditor::subtitle_stream_changed (wxCommandEvent &)
        }
 
        _ignore_changes = Film::SUBTITLE_STREAM;
-       int const n = _subtitle_stream->GetSelection ();
-       if (n >= 0) {
-               vector<Stream> s = _film->subtitle_streams ();
-               assert (n < int (s.size ()));
-               _film->set_subtitle_stream (s[n].id);
-       }
+       _film->set_subtitle_stream (_subtitle_stream->GetSelection ());
        _ignore_changes = Film::NONE;
 }
index b50bfd1f9816e4dc87ac5751f17cefc5f1e9c737..2439b01dd652b0379015aef2ab5812df21c62f32 100644 (file)
@@ -79,7 +79,6 @@ private:
        void setup_formats ();
        void setup_subtitle_button ();
        void setup_streams ();
-       void set_selected_stream (std::vector<Stream> const & streams, int id, wxComboBox* combo) const;
        
        wxControl* video_control (wxControl *);
        wxControl* still_control (wxControl *);
index 67053bd58340618c220f7bbda63fbd592470874e..652867ce0417578b2b82de87430146b2a5859297 100644 (file)
@@ -31,9 +31,7 @@ package_type
 width 0
 height 0
 length 0
-audio_channels 0
 audio_sample_rate 0
-audio_sample_format Unknown
 content_digest 
 has_subtitles 0
 frames_per_second 0
index 7ca6d0cd357d65e585eefa84986d8792790d5843..468e6c1fddcfd37da4920f7bf3085ee88e65c47c 100644 (file)
@@ -501,3 +501,16 @@ BOOST_AUTO_TEST_CASE (job_manager_test)
        BOOST_CHECK_EQUAL (a->finished_in_error(), true);
        BOOST_CHECK_EQUAL (b->running(), false);
 }
+
+BOOST_AUTO_TEST_CASE (stream_test)
+{
+       AudioStream a ("4 9 hello there world");
+       BOOST_CHECK_EQUAL (a.id(), 4);
+       BOOST_CHECK_EQUAL (a.channels(), 9);
+       BOOST_CHECK_EQUAL (a.name(), "hello there world");
+       BOOST_CHECK_EQUAL (a.to_string(), "4 9 hello there world");
+
+       SubtitleStream s ("5 a b c");
+       BOOST_CHECK_EQUAL (s.id(), 5);
+       BOOST_CHECK_EQUAL (s.name(), "a b c");
+}