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

Side by Side Diff: chrome/test/data/webrtc/munge_sdp.js

Issue 2951713002: RTCPeerConnection.addTrack and removeTrack added (behind flag) (Closed)
Patch Set: Addressed deadbeef's comments Created 3 years, 5 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 unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * Copyright 2016 The Chromium Authors. All rights reserved. 2 * Copyright 2016 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /** 7 /**
8 * See |setSdpDefaultCodec|. 8 * See |setSdpDefaultCodec|.
9 */ 9 */
10 function setSdpDefaultAudioCodec(sdp, codec) { 10 function setSdpDefaultAudioCodec(sdp, codec) {
(...skipping 11 matching lines...) Expand all
22 * Returns a modified version of |sdp| where the opus DTX flag has been 22 * Returns a modified version of |sdp| where the opus DTX flag has been
23 * enabled. 23 * enabled.
24 */ 24 */
25 function setOpusDtxEnabled(sdp) { 25 function setOpusDtxEnabled(sdp) {
26 var sdpLines = splitSdpLines(sdp); 26 var sdpLines = splitSdpLines(sdp);
27 27
28 // Get default audio codec 28 // Get default audio codec
29 var defaultCodec = getSdpDefaultAudioCodec(sdp); 29 var defaultCodec = getSdpDefaultAudioCodec(sdp);
30 if (defaultCodec !== 'opus') { 30 if (defaultCodec !== 'opus') {
31 failure('setOpusDtxEnabled', 31 failure('setOpusDtxEnabled',
32 'Default audio codec is not set to \'opus\'.'); 32 'Default audio codec is not set to \'opus\'.');
33 } 33 }
34 34
35 // Find codec ID for Opus, e.g. 111 if 'a=rtpmap:111 opus/48000/2'. 35 // Find codec ID for Opus, e.g. 111 if 'a=rtpmap:111 opus/48000/2'.
36 var codecId = findRtpmapId(sdpLines, 'opus'); 36 var codecId = findRtpmapId(sdpLines, 'opus');
37 if (codecId === null) { 37 if (codecId === null) {
38 failure('setOpusDtxEnabled', 'Unknown ID for |codec| = \'opus\'.'); 38 failure('setOpusDtxEnabled', 'Unknown ID for |codec| = \'opus\'.');
39 } 39 }
40 40
41 // Find 'a=fmtp:111' line, where 111 is the codecId 41 // Find 'a=fmtp:111' line, where 111 is the codecId
42 var fmtLineNo = findFmtpLine(sdpLines, codecId); 42 var fmtLineNo = findFmtpLine(sdpLines, codecId);
(...skipping 14 matching lines...) Expand all
57 * the default codec, i.e. the codec whose ID is first in the list of codecs on 57 * the default codec, i.e. the codec whose ID is first in the list of codecs on
58 * the 'm=|type|' line, where |type| is 'audio' or 'video'. 58 * the 'm=|type|' line, where |type| is 'audio' or 'video'.
59 * @private 59 * @private
60 */ 60 */
61 function setSdpDefaultCodec(sdp, type, codec) { 61 function setSdpDefaultCodec(sdp, type, codec) {
62 var sdpLines = splitSdpLines(sdp); 62 var sdpLines = splitSdpLines(sdp);
63 63
64 // Find codec ID, e.g. 100 for 'VP8' if 'a=rtpmap:100 VP8/9000'. 64 // Find codec ID, e.g. 100 for 'VP8' if 'a=rtpmap:100 VP8/9000'.
65 var codecId = findRtpmapId(sdpLines, codec); 65 var codecId = findRtpmapId(sdpLines, codec);
66 if (codecId === null) { 66 if (codecId === null) {
67 failure('sdpPreferCodec', 'Unknown ID for |codec| = \'' + codec + '\'.'); 67 failure('setSdpDefaultCodec',
68 'Unknown ID for |codec| = \'' + codec + '\'.');
68 } 69 }
69 70
70 // Find 'm=|type|' line, e.g. 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116'. 71 // Find 'm=|type|' line, e.g. 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116'.
71 var mLineNo = findLine(sdpLines, 'm=' + type); 72 var mLineNo = findLine(sdpLines, 'm=' + type);
72 if (mLineNo === null) { 73 if (mLineNo === null) {
73 failure('setSdpDefaultCodec', 74 failure('setSdpDefaultCodec',
74 '\'m=' + type + '\' line missing from |sdp|.'); 75 '\'m=' + type + '\' line missing from |sdp|.');
75 } 76 }
76 77
77 // Modify video line to use the desired codec as the default. 78 // Modify video line to use the desired codec as the default.
78 sdpLines[mLineNo] = setMLineDefaultCodec(sdpLines[mLineNo], codecId); 79 sdpLines[mLineNo] = setMLineDefaultCodec(sdpLines[mLineNo], codecId);
79 return mergeSdpLines(sdpLines); 80 return mergeSdpLines(sdpLines);
80 } 81 }
81 82
82 /** 83 /**
83 * See |getSdpDefaultCodec|. 84 * See |getSdpDefaultCodec|.
84 */ 85 */
(...skipping 14 matching lines...) Expand all
99 * is 'audio' or 'video'. 100 * is 'audio' or 'video'.
100 * @private 101 * @private
101 */ 102 */
102 function getSdpDefaultCodec(sdp, type) { 103 function getSdpDefaultCodec(sdp, type) {
103 var sdpLines = splitSdpLines(sdp); 104 var sdpLines = splitSdpLines(sdp);
104 105
105 // Find 'm=|type|' line, e.g. 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116'. 106 // Find 'm=|type|' line, e.g. 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116'.
106 var mLineNo = findLine(sdpLines, 'm=' + type); 107 var mLineNo = findLine(sdpLines, 'm=' + type);
107 if (mLineNo === null) { 108 if (mLineNo === null) {
108 failure('getSdpDefaultCodec', 109 failure('getSdpDefaultCodec',
109 '\'m=' + type + '\' line missing from |sdp|.'); 110 '\'m=' + type + '\' line missing from |sdp|.');
110 } 111 }
111 112
112 // The default codec's ID. 113 // The default codec's ID.
113 var defaultCodecId = getMLineDefaultCodec(sdpLines[mLineNo]); 114 var defaultCodecId = getMLineDefaultCodec(sdpLines[mLineNo]);
114 if (defaultCodecId === null) { 115 if (defaultCodecId === null) {
115 failure('getSdpDefaultCodec', 116 failure('getSdpDefaultCodec',
116 '\'m=' + type + '\' line contains no codecs.'); 117 '\'m=' + type + '\' line contains no codecs.');
117 } 118 }
118 119
119 // Find codec name, e.g. 'VP8' for 100 if 'a=rtpmap:100 VP8/9000'. 120 // Find codec name, e.g. 'VP8' for 100 if 'a=rtpmap:100 VP8/9000'.
120 var defaultCodec = findRtpmapCodec(sdpLines, defaultCodecId); 121 var defaultCodec = findRtpmapCodec(sdpLines, defaultCodecId);
121 if (defaultCodec === null) { 122 if (defaultCodec === null) {
122 failure('getSdpDefaultCodec', 123 failure('getSdpDefaultCodec',
123 'Unknown codec name for default codec ' + defaultCodecId + '.'); 124 'Unknown codec name for default codec ' + defaultCodecId + '.');
124 } 125 }
125 return defaultCodec; 126 return defaultCodec;
126 } 127 }
127 128
128 /** 129 /**
129 * Searches through all |sdpLines| for the 'a=rtpmap:' line for the codec of 130 * Searches through all |sdpLines| for the 'a=rtpmap:' line for the codec of
130 * the specified name, returning its ID as an int if found, or null otherwise. 131 * the specified name, returning its ID as an int if found, or null otherwise.
131 * |codec| is the case-sensitive name of the codec. 132 * |codec| is the case-sensitive name of the codec.
132 * For example, if |sdpLines| contains 'a=rtpmap:100 VP8/9000' and |codec| is 133 * For example, if |sdpLines| contains 'a=rtpmap:100 VP8/9000' and |codec| is
133 * 'VP8', this function returns 100. 134 * 'VP8', this function returns 100.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 function splitSdpLines(sdp) { 238 function splitSdpLines(sdp) {
238 return sdp.split('\r\n'); 239 return sdp.split('\r\n');
239 } 240 }
240 241
241 /** @private */ 242 /** @private */
242 function mergeSdpLines(sdpLines) { 243 function mergeSdpLines(sdpLines) {
243 return sdpLines.join('\r\n'); 244 return sdpLines.join('\r\n');
244 } 245 }
245 246
246 /** @private */ 247 /** @private */
247 function findLine(lines, startsWith) { 248 function findLine(lines, lineStartsWith, startingLine = 0) {
248 for (var i = 0; i < lines.length; i++) { 249 for (var i = startingLine; i < lines.length; i++) {
249 if (lines[i].startsWith(startsWith)) 250 if (lines[i].startsWith(lineStartsWith))
250 return i; 251 return i;
251 } 252 }
252 return null; 253 return null;
253 } 254 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc/webrtc_rtp_browsertest.cc ('k') | chrome/test/data/webrtc/peerconnection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698