[vlc-commits] demux: adaptive: constify getRepresentations()
Francois Cartegnie
git at videolan.org
Tue Mar 2 23:44:55 UTC 2021
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Mar 2 14:32:47 2021 +0100| [a5863ff7a95a44545bf0b4c7fdfce6e6e71c5ca7] | committer: Francois Cartegnie
demux: adaptive: constify getRepresentations()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a5863ff7a95a44545bf0b4c7fdfce6e6e71c5ca7
---
.../adaptive/logic/Representationselectors.cpp | 23 ++++++++++------------
.../adaptive/logic/Representationselectors.hpp | 2 +-
.../demux/adaptive/playlist/BaseAdaptationSet.cpp | 2 +-
.../demux/adaptive/playlist/BaseAdaptationSet.h | 2 +-
modules/demux/adaptive/test/playlist/M3U8.cpp | 7 +++----
modules/demux/hls/playlist/M3U8.cpp | 4 ++--
6 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/modules/demux/adaptive/logic/Representationselectors.cpp b/modules/demux/adaptive/logic/Representationselectors.cpp
index 746e56672e..72fc1a1203 100644
--- a/modules/demux/adaptive/logic/Representationselectors.cpp
+++ b/modules/demux/adaptive/logic/Representationselectors.cpp
@@ -42,16 +42,15 @@ RepresentationSelector::~RepresentationSelector()
BaseRepresentation * RepresentationSelector::lowest(BaseAdaptationSet *adaptSet) const
{
- std::vector<BaseRepresentation *> reps = adaptSet->getRepresentations();
+ const std::vector<BaseRepresentation *> &reps = adaptSet->getRepresentations();
return (reps.empty()) ? nullptr : *(reps.begin());
}
BaseRepresentation * RepresentationSelector::highest(BaseAdaptationSet *adaptSet) const
{
- std::vector<BaseRepresentation *> reps = adaptSet->getRepresentations();
+ const std::vector<BaseRepresentation *> &reps = adaptSet->getRepresentations();
- std::vector<BaseRepresentation *>::const_reverse_iterator it;
- for(it=reps.rbegin(); it!=reps.rend(); ++it)
+ for(auto it=reps.crbegin(); it!=reps.crend(); ++it)
{
if( (*it)->getWidth() <= maxwidth && (*it)->getHeight() <= maxheight )
return *it;
@@ -61,9 +60,8 @@ BaseRepresentation * RepresentationSelector::highest(BaseAdaptationSet *adaptSet
BaseRepresentation * RepresentationSelector::higher(BaseAdaptationSet *adaptSet, BaseRepresentation *rep) const
{
- std::vector<BaseRepresentation *> reps = adaptSet->getRepresentations();
- std::vector<BaseRepresentation *>::iterator it = std::upper_bound(reps.begin(), reps.end(), rep,
- BaseRepresentation::bwCompare);
+ const std::vector<BaseRepresentation *> &reps = adaptSet->getRepresentations();
+ auto it = std::upper_bound(reps.cbegin(), reps.cend(), rep, BaseRepresentation::bwCompare);
BaseRepresentation *upperRep = (it == reps.end()) ? rep : *it;
if( upperRep->getWidth() > maxwidth || upperRep->getHeight() > maxheight )
upperRep = rep;
@@ -72,10 +70,9 @@ BaseRepresentation * RepresentationSelector::higher(BaseAdaptationSet *adaptSet,
BaseRepresentation * RepresentationSelector::lower(BaseAdaptationSet *adaptSet, BaseRepresentation *rep) const
{
- std::vector<BaseRepresentation *> reps = adaptSet->getRepresentations();
- std::vector<BaseRepresentation *>::iterator it = std::lower_bound(reps.begin(), reps.end(), rep,
- BaseRepresentation::bwCompare);
- return (it > reps.begin()) ? *(--it) : rep;
+ const std::vector<BaseRepresentation *> &reps = adaptSet->getRepresentations();
+ auto it = std::lower_bound(reps.cbegin(), reps.cend(), rep, BaseRepresentation::bwCompare);
+ return (it > reps.cbegin()) ? *(--it) : rep;
}
BaseRepresentation * RepresentationSelector::select(BaseAdaptationSet *adaptSet) const
@@ -87,11 +84,11 @@ BaseRepresentation * RepresentationSelector::select(BaseAdaptationSet *adaptSet,
if (adaptSet == nullptr)
return nullptr;
- std::vector<BaseRepresentation *> reps = adaptSet->getRepresentations();
+ const std::vector<BaseRepresentation *> &reps = adaptSet->getRepresentations();
return select(reps, 0, bitrate);
}
-BaseRepresentation * RepresentationSelector::select(std::vector<BaseRepresentation *>& reps,
+BaseRepresentation * RepresentationSelector::select(const std::vector<BaseRepresentation *>& reps,
uint64_t minbitrate, uint64_t maxbitrate) const
{
BaseRepresentation *candidate = nullptr, *lowest = nullptr;
diff --git a/modules/demux/adaptive/logic/Representationselectors.hpp b/modules/demux/adaptive/logic/Representationselectors.hpp
index fd69b7e709..800ac15657 100644
--- a/modules/demux/adaptive/logic/Representationselectors.hpp
+++ b/modules/demux/adaptive/logic/Representationselectors.hpp
@@ -50,7 +50,7 @@ namespace adaptive
protected:
int maxwidth;
int maxheight;
- BaseRepresentation * select(std::vector<BaseRepresentation *>&reps,
+ BaseRepresentation * select(const std::vector<BaseRepresentation *>&reps,
uint64_t minbitrate, uint64_t maxbitrate) const;
};
diff --git a/modules/demux/adaptive/playlist/BaseAdaptationSet.cpp b/modules/demux/adaptive/playlist/BaseAdaptationSet.cpp
index 43287b987e..8f3cac8a2c 100644
--- a/modules/demux/adaptive/playlist/BaseAdaptationSet.cpp
+++ b/modules/demux/adaptive/playlist/BaseAdaptationSet.cpp
@@ -61,7 +61,7 @@ StreamFormat BaseAdaptationSet::getStreamFormat() const
return StreamFormat();
}
-std::vector<BaseRepresentation*>& BaseAdaptationSet::getRepresentations()
+const std::vector<BaseRepresentation*>& BaseAdaptationSet::getRepresentations() const
{
return representations;
}
diff --git a/modules/demux/adaptive/playlist/BaseAdaptationSet.h b/modules/demux/adaptive/playlist/BaseAdaptationSet.h
index f1d19b72bc..574352cf3e 100644
--- a/modules/demux/adaptive/playlist/BaseAdaptationSet.h
+++ b/modules/demux/adaptive/playlist/BaseAdaptationSet.h
@@ -50,7 +50,7 @@ namespace adaptive
virtual ~BaseAdaptationSet();
virtual StreamFormat getStreamFormat() const; /*reimpl*/
- std::vector<BaseRepresentation *>& getRepresentations ();
+ const std::vector<BaseRepresentation *>& getRepresentations() const;
BaseRepresentation * getRepresentationByID(const ID &);
void setSegmentAligned(bool);
bool isSegmentAligned() const;
diff --git a/modules/demux/adaptive/test/playlist/M3U8.cpp b/modules/demux/adaptive/test/playlist/M3U8.cpp
index 62e3f463a9..fc96faa4a4 100644
--- a/modules/demux/adaptive/test/playlist/M3U8.cpp
+++ b/modules/demux/adaptive/test/playlist/M3U8.cpp
@@ -79,13 +79,12 @@ int M3U8MasterPlaylist_test()
Expect(m3u->getFirstPeriod()->getAdaptationSets().size() == 1);
Expect(m3u->getFirstPeriod()->getAdaptationSets().front()->getRepresentations().size() == 4);
BaseAdaptationSet *set = m3u->getFirstPeriod()->getAdaptationSets().front();
- std::vector<BaseRepresentation *> &reps = set->getRepresentations();
- std::vector<BaseRepresentation *>::iterator it;
- it = std::find_if(reps.begin(), reps.end(),
+ const std::vector<BaseRepresentation *> &reps = set->getRepresentations();
+ auto it = std::find_if(reps.cbegin(), reps.cend(),
[](BaseRepresentation *r) { return r->getBandwidth() == 1280000; });
Expect(it != reps.end());
Expect(static_cast<HLSRepresentation *>(*it)->getPlaylistUrl().toString() == "http://example.com/low.m3u8");
- it = std::find_if(reps.begin(), reps.end(),
+ it = std::find_if(reps.cbegin(), reps.cend(),
[](BaseRepresentation *r) { return r->getBandwidth() == 65000; });
Expect(it != reps.end());
Expect(static_cast<HLSRepresentation *>(*it)->getPlaylistUrl().toString() == "http://example.com/audio-only.m3u8");
diff --git a/modules/demux/hls/playlist/M3U8.cpp b/modules/demux/hls/playlist/M3U8.cpp
index 35531205a7..d38d139843 100644
--- a/modules/demux/hls/playlist/M3U8.cpp
+++ b/modules/demux/hls/playlist/M3U8.cpp
@@ -49,8 +49,8 @@ bool M3U8::isLive() const
for(ita = period->getAdaptationSets().begin(); ita != period->getAdaptationSets().end(); ++ita)
{
BaseAdaptationSet *adaptSet = *ita;
- std::vector<BaseRepresentation *>::iterator itr;
- for(itr = adaptSet->getRepresentations().begin(); itr != adaptSet->getRepresentations().end(); ++itr)
+ const std::vector<BaseRepresentation *> &reps = adaptSet->getRepresentations();
+ for(auto itr = reps.cbegin(); itr != reps.cend(); ++itr)
{
const HLSRepresentation *rep = dynamic_cast<const HLSRepresentation *>(*itr);
if(rep->initialized())
More information about the vlc-commits
mailing list