From df8f80913c8083c2d5d3408da6f8dd67193d890b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 21 Feb 2014 10:43:54 +0000 Subject: [PATCH] Make FFmpegStream::_id private. --- src/lib/ffmpeg_content.cc | 44 ++++++++++++++------------------------- src/lib/ffmpeg_content.h | 16 +++++++------- src/wx/audio_panel.cc | 6 +++--- src/wx/subtitle_panel.cc | 6 +++--- test/stream_test.cc | 2 +- 5 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 2c888baaf..bb2b629c8 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -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 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 node, int version) - : _legacy_id (false) + : name (node->string_child ("Name")) + , _id (node->number_child ("Id")) + , _legacy_id (false) { - name = node->string_child ("Name"); - id = node->number_child ("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 (id)); + root->add_child("Id")->add_child_text (lexical_cast (_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::const_iterator i = _filters.begin(); i != _filters.end(); ++i) { diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index d1aa3a0b5..2339705d0 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -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: diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc index ba458f1ff..683751264 100644 --- a/src/wx/audio_panel.cc +++ b/src/wx/audio_panel.cc @@ -134,11 +134,11 @@ AudioPanel::film_content_changed (int property) if (fcs) { vector > a = fcs->audio_streams (); for (vector >::iterator i = a.begin(); i != a.end(); ++i) { - _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast ((*i)->id)))); + _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast ((*i)->id ())))); } if (fcs->audio_stream()) { - checked_set (_stream, lexical_cast (fcs->audio_stream()->id)); + checked_set (_stream, lexical_cast (fcs->audio_stream()->id ())); setup_stream_description (); } } @@ -206,7 +206,7 @@ AudioPanel::stream_changed () vector > a = fcs->audio_streams (); vector >::iterator i = a.begin (); string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ())); - while (i != a.end() && lexical_cast ((*i)->id) != s) { + while (i != a.end() && lexical_cast ((*i)->id ()) != s) { ++i; } diff --git a/src/wx/subtitle_panel.cc b/src/wx/subtitle_panel.cc index 02c8776d6..24e3688f8 100644 --- a/src/wx/subtitle_panel.cc +++ b/src/wx/subtitle_panel.cc @@ -120,11 +120,11 @@ SubtitlePanel::film_content_changed (int property) if (fcs) { vector > s = fcs->subtitle_streams (); for (vector >::iterator i = s.begin(); i != s.end(); ++i) { - _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast ((*i)->id)))); + _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast ((*i)->id ())))); } if (fcs->subtitle_stream()) { - checked_set (_stream, lexical_cast (fcs->subtitle_stream()->id)); + checked_set (_stream, lexical_cast (fcs->subtitle_stream()->id ())); } else { _stream->SetSelection (wxNOT_FOUND); } @@ -179,7 +179,7 @@ SubtitlePanel::stream_changed () vector > a = fcs->subtitle_streams (); vector >::iterator i = a.begin (); string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ())); - while (i != a.end() && lexical_cast ((*i)->id) != s) { + while (i != a.end() && lexical_cast ((*i)->id ()) != s) { ++i; } diff --git a/test/stream_test.cc b/test/stream_test.cc index 6abcf6e22..3e18d0d14 100644 --- a/test/stream_test.cc +++ b/test/stream_test.cc @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE (stream_test) FFmpegAudioStream a (shared_ptr (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"); -- 2.30.2