Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1065)

Unified Diff: webrtc/pc/mediasession.cc

Issue 1966333002: Refactoring some tests in peerconnectioninterface_unittest.cc. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« webrtc/api/peerconnectioninterface_unittest.cc ('K') | « webrtc/pc/mediasession.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/pc/mediasession.cc
diff --git a/webrtc/pc/mediasession.cc b/webrtc/pc/mediasession.cc
index 52abfe855f6aef47fa83d7e1ce51321f090a2417..0fa20d8bd5d292990bf68fbc3899741b56491cd0 100644
--- a/webrtc/pc/mediasession.cc
+++ b/webrtc/pc/mediasession.cc
@@ -1919,10 +1919,9 @@ bool IsDataContent(const ContentInfo* content) {
const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
MediaType media_type) {
- for (ContentInfos::const_iterator content = contents.begin();
- content != contents.end(); content++) {
- if (IsMediaContentOfType(&*content, media_type)) {
- return &*content;
+ for (const ContentInfo& content : contents) {
tommi 2016/05/12 11:41:44 nit: I wonder if a template like this could cover
Taylor Brandstetter 2016/05/12 15:16:44 The problem is that if Infos is const, Info still
+ if (IsMediaContentOfType(&content, media_type)) {
+ return &content;
}
}
return nullptr;
@@ -1986,4 +1985,77 @@ const DataContentDescription* GetFirstDataContentDescription(
GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA));
}
+//
+// Non-const versions of the above functions.
+//
+
+ContentInfo* GetFirstMediaContent(ContentInfos& contents,
+ MediaType media_type) {
+ for (ContentInfo& content : contents) {
+ if (IsMediaContentOfType(&content, media_type)) {
+ return &content;
+ }
+ }
+ return nullptr;
+}
+
+ContentInfo* GetFirstAudioContent(ContentInfos& contents) {
+ return GetFirstMediaContent(contents, MEDIA_TYPE_AUDIO);
+}
+
+ContentInfo* GetFirstVideoContent(ContentInfos& contents) {
+ return GetFirstMediaContent(contents, MEDIA_TYPE_VIDEO);
+}
+
+ContentInfo* GetFirstDataContent(ContentInfos& contents) {
+ return GetFirstMediaContent(contents, MEDIA_TYPE_DATA);
+}
+
+static ContentInfo* GetFirstMediaContent(SessionDescription* sdesc,
+ MediaType media_type) {
+ if (sdesc == nullptr) {
+ return nullptr;
+ }
+
+ return GetFirstMediaContent(sdesc->contents(), media_type);
+}
+
+ContentInfo* GetFirstAudioContent(SessionDescription* sdesc) {
+ return GetFirstMediaContent(sdesc, MEDIA_TYPE_AUDIO);
+}
+
+ContentInfo* GetFirstVideoContent(SessionDescription* sdesc) {
+ return GetFirstMediaContent(sdesc, MEDIA_TYPE_VIDEO);
+}
+
+ContentInfo* GetFirstDataContent(SessionDescription* sdesc) {
+ return GetFirstMediaContent(sdesc, MEDIA_TYPE_DATA);
+}
+
+MediaContentDescription* GetFirstMediaContentDescription(
+ SessionDescription* sdesc,
+ MediaType media_type) {
+ ContentInfo* content = GetFirstMediaContent(sdesc, media_type);
+ ContentDescription* description = content ? content->description : NULL;
+ return static_cast<MediaContentDescription*>(description);
+}
+
+AudioContentDescription* GetFirstAudioContentDescription(
+ SessionDescription* sdesc) {
+ return static_cast<AudioContentDescription*>(
+ GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_AUDIO));
+}
+
+VideoContentDescription* GetFirstVideoContentDescription(
+ SessionDescription* sdesc) {
+ return static_cast<VideoContentDescription*>(
+ GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO));
+}
+
+DataContentDescription* GetFirstDataContentDescription(
+ SessionDescription* sdesc) {
+ return static_cast<DataContentDescription*>(
+ GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA));
+}
+
} // namespace cricket
« webrtc/api/peerconnectioninterface_unittest.cc ('K') | « webrtc/pc/mediasession.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698