Make FFmpegStream::_id private.
authorCarl Hetherington <cth@carlh.net>
Fri, 21 Feb 2014 10:43:54 +0000 (10:43 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 21 Feb 2014 10:43:54 +0000 (10:43 +0000)
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
src/wx/audio_panel.cc
src/wx/subtitle_panel.cc
test/stream_test.cc

index 2c888baaf087fa49a5c1239900db35617d2f5593..bb2b629c8cfdcee73c5337cf1f03f0b9e9c7454f 100644 (file)
@@ -207,12 +207,12 @@ FFmpegContent::technical_summary () const
 {
        string as = "none";
        if (_audio_stream) {
-               as = String::compose ("id %1", _audio_stream->id);
+               as = String::compose ("id %1", _audio_stream->id ());
        }
 
        string ss = "none";
        if (_subtitle_stream) {
-               ss = String::compose ("id %1", _subtitle_stream->id);
+               ss = String::compose ("id %1", _subtitle_stream->id ());
        }
 
        pair<string, string> filt = Filter::ffmpeg_strings (_filters);
@@ -326,34 +326,22 @@ FFmpegContent::output_audio_frame_rate () const
 }
 
 bool
-operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b)
+operator== (FFmpegStream const & a, FFmpegStream const & b)
 {
-       return a.id == b.id;
+       return a._id == b._id;
 }
 
 bool
-operator!= (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b)
+operator!= (FFmpegStream const & a, FFmpegStream const & b)
 {
-       return a.id != b.id;
-}
-
-bool
-operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b)
-{
-       return a.id == b.id;
-}
-
-bool
-operator!= (FFmpegAudioStream const & a, FFmpegAudioStream const & b)
-{
-       return a.id != b.id;
+       return a._id != b._id;
 }
 
 FFmpegStream::FFmpegStream (shared_ptr<const cxml::Node> node, int version)
-       : _legacy_id (false)
+       : name (node->string_child ("Name"))
+       , _id (node->number_child<int> ("Id"))
+       , _legacy_id (false)
 {
-       name = node->string_child ("Name");
-       id = node->number_child<int> ("Id");
        if (version == 4 || node->optional_bool_child ("LegacyId")) {
                _legacy_id = true;
        }
@@ -363,7 +351,7 @@ void
 FFmpegStream::as_xml (xmlpp::Node* root) const
 {
        root->add_child("Name")->add_child_text (name);
-       root->add_child("Id")->add_child_text (lexical_cast<string> (id));
+       root->add_child("Id")->add_child_text (lexical_cast<string> (_id));
        if (_legacy_id) {
                /* Write this so that version > 4 files are read in correctly
                   if the Id came originally from a version <= 4 file.
@@ -397,12 +385,12 @@ bool
 FFmpegStream::uses_index (AVFormatContext const * fc, int index) const
 {
        if (_legacy_id) {
-               return id == index;
+               return _id == index;
        }
        
        size_t i = 0;
        while (i < fc->nb_streams) {
-               if (fc->streams[i]->id == id) {
+               if (fc->streams[i]->id == _id) {
                        return int (i) == index;
                }
                ++i;
@@ -415,16 +403,16 @@ AVStream *
 FFmpegStream::stream (AVFormatContext const * fc) const
 {
        if (_legacy_id) {
-               if (id >= int (fc->nb_streams)) {
+               if (_id >= int (fc->nb_streams)) {
                        return 0;
                }
                
-               return fc->streams[id];
+               return fc->streams[_id];
        }
        
        size_t i = 0;
        while (i < fc->nb_streams) {
-               if (fc->streams[i]->id == id) {
+               if (fc->streams[i]->id == _id) {
                        return fc->streams[i];
                }
                ++i;
@@ -500,7 +488,7 @@ FFmpegContent::identifier () const
        boost::mutex::scoped_lock lm (_mutex);
 
        if (_subtitle_stream) {
-               s << "_" << _subtitle_stream->id;
+               s << "_" << _subtitle_stream->id ();
        }
 
        for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
index d1aa3a0b56ec88f04e1078b5998f99f2f639d912..2339705d0d17377768b9bd1dbae0f7d2cbda3f2c 100644 (file)
@@ -37,7 +37,7 @@ class FFmpegStream
 public:
        FFmpegStream (std::string n, int i)
                : name (n)
-               , id (i)
+               , _id (i)
                , _legacy_id (false)
        {}
                                
@@ -52,10 +52,16 @@ public:
        bool uses_index (AVFormatContext const * c, int index) const;
        AVStream* stream (AVFormatContext const * c) const;
 
+       int id () const {
+               return _id;
+       }
        std::string name;
-       int id;
+
+       friend bool operator== (FFmpegStream const & a, FFmpegStream const & b);
+       friend bool operator!= (FFmpegStream const & a, FFmpegStream const & b);
        
 private:
+       int _id;
        /** If this is true, id is in fact the index */
        bool _legacy_id;
 };
@@ -93,9 +99,6 @@ private:
        {}
 };
 
-extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
-extern bool operator!= (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
-
 class FFmpegSubtitleStream : public FFmpegStream
 {
 public:
@@ -108,9 +111,6 @@ public:
        void as_xml (xmlpp::Node *) const;
 };
 
-extern bool operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
-extern bool operator!= (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
-
 class FFmpegContentProperty : public VideoContentProperty
 {
 public:
index ba458f1ff813f58dc596a850884b7b7c666df874..683751264c874f162878f038afa0aaa2cbb95695 100644 (file)
@@ -134,11 +134,11 @@ AudioPanel::film_content_changed (int property)
                if (fcs) {
                        vector<shared_ptr<FFmpegAudioStream> > a = fcs->audio_streams ();
                        for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
-                               _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
+                               _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id ()))));
                        }
                        
                        if (fcs->audio_stream()) {
-                               checked_set (_stream, lexical_cast<string> (fcs->audio_stream()->id));
+                               checked_set (_stream, lexical_cast<string> (fcs->audio_stream()->id ()));
                                setup_stream_description ();
                        }
                }
@@ -206,7 +206,7 @@ AudioPanel::stream_changed ()
        vector<shared_ptr<FFmpegAudioStream> > a = fcs->audio_streams ();
        vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin ();
        string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
-       while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
+       while (i != a.end() && lexical_cast<string> ((*i)->id ()) != s) {
                ++i;
        }
 
index 02c8776d6f8c5ea3a57e50e4885cf34bd6196d72..24e3688f894b1f0c9df36631a3683133b0ca0995 100644 (file)
@@ -120,11 +120,11 @@ SubtitlePanel::film_content_changed (int property)
                if (fcs) {
                        vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
                        for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
-                               _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
+                               _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id ()))));
                        }
                        
                        if (fcs->subtitle_stream()) {
-                               checked_set (_stream, lexical_cast<string> (fcs->subtitle_stream()->id));
+                               checked_set (_stream, lexical_cast<string> (fcs->subtitle_stream()->id ()));
                        } else {
                                _stream->SetSelection (wxNOT_FOUND);
                        }
@@ -179,7 +179,7 @@ SubtitlePanel::stream_changed ()
        vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
        vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
        string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
-       while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
+       while (i != a.end() && lexical_cast<string> ((*i)->id ()) != s) {
                ++i;
        }
 
index 6abcf6e22aedf95a0dec879a05746accf4a5d443..3e18d0d14a0ea70201ac9823540e873bed4f8aad 100644 (file)
@@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE (stream_test)
                
        FFmpegAudioStream a (shared_ptr<cxml::Node> (new cxml::Node (root)), 5);
 
-       BOOST_CHECK_EQUAL (a.id, 4);
+       BOOST_CHECK_EQUAL (a.id(), 4);
        BOOST_CHECK_EQUAL (a.frame_rate, 44100);
        BOOST_CHECK_EQUAL (a.channels, 2);
        BOOST_CHECK_EQUAL (a.name, "hello there world");