| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 1 | <!doctype html> | 
|  | 2 | <meta charset=utf-8> | 
|  | 3 | <title>RTCRtpTransceiver.prototype.setCodecPreferences</title> | 
|  | 4 | <script src="/resources/testharness.js"></script> | 
|  | 5 | <script src="/resources/testharnessreport.js"></script> | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 6 | <script src="./third_party/sdp/sdp.js"></script> | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 7 | <script> | 
|  | 8 | 'use strict'; | 
|  | 9 |  | 
|  | 10 | // Test is based on the following editor draft: | 
|  | 11 | // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html | 
|  | 12 |  | 
|  | 13 | /* | 
|  | 14 | 5.4. RTCRtpTransceiver Interface | 
|  | 15 | interface RTCRtpTransceiver { | 
|  | 16 | ... | 
|  | 17 | void setCodecPreferences(sequence<RTCRtpCodecCapability> codecs); | 
|  | 18 | }; | 
|  | 19 |  | 
|  | 20 | setCodecPreferences | 
|  | 21 | - Setting codecs to an empty sequence resets codec preferences to any | 
|  | 22 | default value. | 
|  | 23 |  | 
|  | 24 | - The codecs sequence passed into setCodecPreferences can only contain | 
|  | 25 | codecs that are returned by RTCRtpSender.getCapabilities(kind) or | 
|  | 26 | RTCRtpReceiver.getCapabilities(kind), where kind is the kind of the | 
|  | 27 | RTCRtpTransceiver on which the method is called. Additionally, the | 
|  | 28 | RTCRtpCodecParameters dictionary members cannot be modified. If | 
|  | 29 | codecs does not fulfill these requirements, the user agent MUST throw | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 30 | an InvalidModificationError. | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 31 | */ | 
| Philipp Hancke | 57cb5de | 2020-09-17 11:56:35 | [diff] [blame] | 32 | /* | 
|  | 33 | * Chromium note: this requires build bots with H264 support. See | 
|  | 34 | * https://bugs.chromium.org/p/chromium/issues/detail?id=840659 | 
|  | 35 | * for details on how to enable support. | 
|  | 36 | */ | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 37 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 38 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 39 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 40 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 41 | const transceiver = pc.addTransceiver('audio'); | 
|  | 42 | const capabilities = RTCRtpSender.getCapabilities('audio'); | 
|  | 43 | transceiver.setCodecPreferences(capabilities.codecs); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 44 | }, `setCodecPreferences() on audio transceiver with codecs returned from RTCRtpSender.getCapabilities('audio') should succeed`); | 
|  | 45 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 46 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 47 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 48 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 49 | const transceiver = pc.addTransceiver('video'); | 
|  | 50 | const capabilities = RTCRtpReceiver.getCapabilities('video'); | 
|  | 51 | transceiver.setCodecPreferences(capabilities.codecs); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 52 | }, `setCodecPreferences() on video transceiver with codecs returned from RTCRtpReceiver.getCapabilities('video') should succeed`); | 
|  | 53 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 54 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 55 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 56 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 57 | const transceiver = pc.addTransceiver('audio'); | 
|  | 58 | const capabilities1 = RTCRtpSender.getCapabilities('audio'); | 
|  | 59 | const capabilities2 = RTCRtpReceiver.getCapabilities('audio'); | 
|  | 60 | transceiver.setCodecPreferences([...capabilities1.codecs, ... capabilities2.codecs]); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 61 | }, `setCodecPreferences() with both sender receiver codecs combined should succeed`); | 
|  | 62 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 63 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 64 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 65 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 66 | const transceiver = pc.addTransceiver('audio'); | 
|  | 67 | transceiver.setCodecPreferences([]); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 68 | }, `setCodecPreferences([]) should succeed`); | 
|  | 69 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 70 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 71 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 72 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 73 | const transceiver = pc.addTransceiver('audio'); | 
|  | 74 | const capabilities = RTCRtpSender.getCapabilities('audio'); | 
|  | 75 | const { codecs } = capabilities; | 
|  | 76 |  | 
|  | 77 | if(codecs.length >= 2) { | 
|  | 78 | const tmp = codecs[0]; | 
|  | 79 | codecs[0] = codecs[1]; | 
|  | 80 | codecs[1] = tmp; | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | transceiver.setCodecPreferences(codecs); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 84 | }, `setCodecPreferences() with reordered codecs should succeed`); | 
|  | 85 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 86 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 87 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 88 | t.add_cleanup(() => pc.close()); | 
| Harald Alvestrand | 3130f02 | 2020-02-06 10:50:27 | [diff] [blame] | 89 | const transceiver = pc.addTransceiver('video'); | 
|  | 90 | const capabilities = RTCRtpSender.getCapabilities('video'); | 
|  | 91 | const { codecs } = capabilities; | 
|  | 92 | // This test verifies that the mandatory VP8 codec is present | 
|  | 93 | // and can be set. | 
|  | 94 | let tried = false; | 
|  | 95 | codecs.forEach(codec => { | 
|  | 96 | if (codec.mimeType.toLowerCase() === 'video/vp8') { | 
|  | 97 | transceiver.setCodecPreferences([codecs[0]]); | 
|  | 98 | tried = true; | 
|  | 99 | } | 
|  | 100 | }); | 
|  | 101 | assert_true(tried, 'VP8 video codec was found and tried'); | 
| youennf | b8ff087 | 2020-09-03 08:35:01 | [diff] [blame] | 102 | }, `setCodecPreferences() with only VP8 should succeed`); | 
|  | 103 |  | 
|  | 104 | test(() => { | 
|  | 105 | const pc = new RTCPeerConnection(); | 
|  | 106 | const transceiver = pc.addTransceiver('video'); | 
|  | 107 | const capabilities = RTCRtpSender.getCapabilities('video'); | 
|  | 108 | const { codecs } = capabilities; | 
|  | 109 | // This test verifies that the mandatory H264 codec is present | 
|  | 110 | // and can be set. | 
|  | 111 | let tried = false; | 
|  | 112 | codecs.forEach(codec => { | 
|  | 113 | if (codec.mimeType.toLowerCase() === 'video/h264') { | 
|  | 114 | transceiver.setCodecPreferences([codecs[0]]); | 
|  | 115 | tried = true; | 
|  | 116 | } | 
|  | 117 | }); | 
| Philipp Hancke | 8561786 | 2020-09-07 13:15:29 | [diff] [blame] | 118 | assert_true(tried, 'H264 video codec was found and tried'); | 
| youennf | b8ff087 | 2020-09-03 08:35:01 | [diff] [blame] | 119 | }, `setCodecPreferences() with only H264 should succeed`); | 
|  | 120 |  | 
|  | 121 | async function getRTPMapLinesWithCodecAsFirst(firstCodec) | 
|  | 122 | { | 
|  | 123 | const capabilities = RTCRtpSender.getCapabilities('video').codecs; | 
|  | 124 | capabilities.forEach((codec, idx) => { | 
|  | 125 | if (codec.mimeType === firstCodec) { | 
|  | 126 | capabilities.splice(idx, 1); | 
|  | 127 | capabilities.unshift(codec); | 
|  | 128 | } | 
|  | 129 | }); | 
|  | 130 |  | 
|  | 131 | const pc = new RTCPeerConnection(); | 
|  | 132 | const transceiver = pc.addTransceiver('video'); | 
|  | 133 | transceiver.setCodecPreferences(capabilities); | 
|  | 134 | const offer = await pc.createOffer(); | 
|  | 135 |  | 
|  | 136 | return offer.sdp.split('\r\n').filter(line => line.indexOf("a=rtpmap") === 0); | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | promise_test(async () => { | 
|  | 140 | const lines = await getRTPMapLinesWithCodecAsFirst('video/H264'); | 
|  | 141 |  | 
|  | 142 | assert_greater_than(lines.length, 1); | 
|  | 143 | assert_true(lines[0].indexOf("H264") !== -1, "H264 should be the first codec"); | 
|  | 144 | }, `setCodecPreferences() should allow setting H264 as first codec`); | 
|  | 145 |  | 
|  | 146 | promise_test(async () => { | 
|  | 147 | const lines = await getRTPMapLinesWithCodecAsFirst('video/VP8'); | 
|  | 148 |  | 
|  | 149 | assert_greater_than(lines.length, 1); | 
|  | 150 | assert_true(lines[0].indexOf("VP8") !== -1, "VP8 should be the first codec"); | 
|  | 151 | }, `setCodecPreferences() should allow setting VP8 as first codec`); | 
| Harald Alvestrand | 3130f02 | 2020-02-06 10:50:27 | [diff] [blame] | 152 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 153 | test((t) => { | 
| Harald Alvestrand | 3130f02 | 2020-02-06 10:50:27 | [diff] [blame] | 154 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 155 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 156 | const transceiver = pc.addTransceiver('audio'); | 
|  | 157 | const capabilities = RTCRtpSender.getCapabilities('video'); | 
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 158 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(capabilities.codecs)); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 159 | }, `setCodecPreferences() on audio transceiver with codecs returned from getCapabilities('video') should throw InvalidModificationError`); | 
|  | 160 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 161 | test((t) => { | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 162 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 163 | t.add_cleanup(() => pc.close()); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 164 | const transceiver = pc.addTransceiver('audio'); | 
|  | 165 | const codecs = [{ | 
|  | 166 | mimeType: 'data', | 
|  | 167 | clockRate: 2000, | 
|  | 168 | channels: 2, | 
|  | 169 | sdpFmtpLine: '0-15' | 
|  | 170 | }]; | 
|  | 171 |  | 
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 172 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 173 | }, `setCodecPreferences() with user defined codec with invalid mimeType should throw InvalidModificationError`); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 174 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 175 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 176 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 177 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 178 | const transceiver = pc.addTransceiver('audio'); | 
|  | 179 | const codecs = [{ | 
|  | 180 | mimeType: 'audio/piepiper', | 
|  | 181 | clockRate: 2000, | 
|  | 182 | channels: 2, | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 183 | sdpFmtpLine: '0-15' | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 184 | }]; | 
|  | 185 |  | 
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 186 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 187 | }, `setCodecPreferences() with user defined codec should throw InvalidModificationError`); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 188 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 189 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 190 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 191 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 192 | const transceiver = pc.addTransceiver('audio'); | 
|  | 193 | const capabilities = RTCRtpSender.getCapabilities('audio'); | 
|  | 194 | const codecs = [ | 
|  | 195 | ...capabilities.codecs, | 
|  | 196 | { | 
|  | 197 | mimeType: 'audio/piepiper', | 
|  | 198 | clockRate: 2000, | 
|  | 199 | channels: 2, | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 200 | sdpFmtpLine: '0-15' | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 201 | }]; | 
|  | 202 |  | 
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 203 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 204 | }, `setCodecPreferences() with user defined codec together with codecs returned from getCapabilities() should throw InvalidModificationError`); | 
|  | 205 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 206 | test((t) => { | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 207 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 208 | t.add_cleanup(() => pc.close()); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 209 | const transceiver = pc.addTransceiver('audio'); | 
|  | 210 | const capabilities = RTCRtpSender.getCapabilities('audio'); | 
|  | 211 | const codecs = [capabilities.codecs[0]]; | 
|  | 212 | codecs[0].clockRate = codecs[0].clockRate / 2; | 
|  | 213 |  | 
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 214 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 215 | }, `setCodecPreferences() with modified codec clock rate should throw InvalidModificationError`); | 
|  | 216 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 217 | test((t) => { | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 218 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 219 | t.add_cleanup(() => pc.close()); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 220 | const transceiver = pc.addTransceiver('audio'); | 
|  | 221 | const capabilities = RTCRtpSender.getCapabilities('audio'); | 
|  | 222 | const codecs = [capabilities.codecs[0]]; | 
|  | 223 | codecs[0].channels = codecs[0].channels + 11; | 
|  | 224 |  | 
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 225 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 226 | }, `setCodecPreferences() with modified codec channel count should throw InvalidModificationError`); | 
|  | 227 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 228 | test((t) => { | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 229 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 230 | t.add_cleanup(() => pc.close()); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 231 | const transceiver = pc.addTransceiver('audio'); | 
|  | 232 | const capabilities = RTCRtpSender.getCapabilities('audio'); | 
|  | 233 | const codecs = [capabilities.codecs[0]]; | 
|  | 234 | codecs[0].sdpFmtpLine = "modifiedparameter=1"; | 
|  | 235 |  | 
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 236 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 237 | }, `setCodecPreferences() with modified codec parameters should throw InvalidModificationError`); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 238 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 239 | test((t) => { | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 240 | const pc = new RTCPeerConnection(); | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 241 | t.add_cleanup(() => pc.close()); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 242 | const transceiver = pc.addTransceiver('audio'); | 
|  | 243 | const capabilities = RTCRtpSender.getCapabilities('audio'); | 
|  | 244 |  | 
|  | 245 | const { codecs } = capabilities; | 
|  | 246 | assert_greater_than(codecs.length, 0, | 
|  | 247 | 'Expect at least one codec available'); | 
|  | 248 |  | 
|  | 249 | const [ codec ] = codecs; | 
|  | 250 | const { channels=2 } = codec; | 
|  | 251 | codec.channels = channels+1; | 
|  | 252 |  | 
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 253 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); | 
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 254 | }, `setCodecPreferences() with modified codecs returned from getCapabilities() should throw InvalidModificationError`); | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 255 |  | 
| Philipp Hancke | ef0384e | 2020-09-07 09:12:42 | [diff] [blame] | 256 | promise_test(async (t) => { | 
|  | 257 | const pc = new RTCPeerConnection(); | 
|  | 258 | t.add_cleanup(() => pc.close()); | 
|  | 259 | const transceiver = pc.addTransceiver('audio'); | 
|  | 260 | const {codecs} = RTCRtpSender.getCapabilities('audio'); | 
|  | 261 | // Reorder codecs, put PCMU/PCMA first. | 
|  | 262 | let firstCodec; | 
|  | 263 | let i; | 
|  | 264 | for (i = 0; i < codecs.length; i++) { | 
|  | 265 | const codec = codecs[i]; | 
|  | 266 | if (codec.mimeType === 'audio/PCMU' || codec.mimeType === 'audio/PCMA') { | 
|  | 267 | codecs.splice(i, 1); | 
|  | 268 | codecs.unshift(codec); | 
|  | 269 | firstCodec = codec.mimeType.substr(6); | 
|  | 270 | break; | 
|  | 271 | } | 
|  | 272 | } | 
|  | 273 | assert_not_equals(firstCodec, undefined, 'PCMU or PCMA codec not found'); | 
|  | 274 | transceiver.setCodecPreferences(codecs); | 
|  | 275 |  | 
|  | 276 | const offer = await pc.createOffer(); | 
|  | 277 | const mediaSection = SDPUtils.getMediaSections(offer.sdp)[0]; | 
|  | 278 | const rtpParameters = SDPUtils.parseRtpParameters(mediaSection); | 
|  | 279 | assert_equals(rtpParameters.codecs[0].name, firstCodec); | 
|  | 280 | }, `setCodecPreferences() modifies the order of audio codecs in createOffer`); | 
|  | 281 |  | 
|  | 282 | promise_test(async (t) => { | 
|  | 283 | const pc = new RTCPeerConnection(); | 
|  | 284 | t.add_cleanup(() => pc.close()); | 
|  | 285 | const transceiver = pc.addTransceiver('video'); | 
|  | 286 | const {codecs} = RTCRtpSender.getCapabilities('video'); | 
|  | 287 | // Reorder codecs, swap H264 and VP8. | 
|  | 288 | let vp8 = -1; | 
|  | 289 | let h264 = -1; | 
|  | 290 | let firstCodec; | 
|  | 291 | let i; | 
|  | 292 | for (i = 0; i < codecs.length; i++) { | 
|  | 293 | const codec = codecs[i]; | 
|  | 294 | if (codec.mimeType === 'video/VP8') { | 
|  | 295 | vp8 = i; | 
|  | 296 | if (h264 !== -1) { | 
|  | 297 | codecs[vp8] = codecs[h264]; | 
|  | 298 | codecs[h264] = codec; | 
|  | 299 | firstCodec = 'VP8'; | 
|  | 300 | break; | 
|  | 301 | } | 
|  | 302 | } | 
|  | 303 | if (codec.mimeType === 'video/H264') { | 
|  | 304 | h264 = i; | 
|  | 305 | if (vp8 !== -1) { | 
|  | 306 | codecs[h264] = codecs[vp8]; | 
|  | 307 | codecs[vp8] = codec; | 
|  | 308 | firstCodec = 'H264'; | 
|  | 309 | break; | 
|  | 310 | } | 
|  | 311 | } | 
|  | 312 | } | 
|  | 313 | assert_not_equals(firstCodec, undefined, 'VP8 and H264 codecs not found'); | 
|  | 314 | transceiver.setCodecPreferences(codecs); | 
|  | 315 |  | 
|  | 316 | const offer = await pc.createOffer(); | 
|  | 317 | const mediaSection = SDPUtils.getMediaSections(offer.sdp)[0]; | 
|  | 318 | const rtpParameters = SDPUtils.parseRtpParameters(mediaSection); | 
|  | 319 | assert_equals(rtpParameters.codecs[0].name, firstCodec); | 
|  | 320 | }, `setCodecPreferences() modifies the order of video codecs in createOffer`); | 
|  | 321 |  | 
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 322 | </script> |