| 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> |
| 6 | <script> |
| 7 | 'use strict'; |
| 8 | |
| 9 | // Test is based on the following editor draft: |
| 10 | // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html |
| 11 | |
| 12 | /* |
| 13 | 5.4. RTCRtpTransceiver Interface |
| 14 | interface RTCRtpTransceiver { |
| 15 | ... |
| 16 | void setCodecPreferences(sequence<RTCRtpCodecCapability> codecs); |
| 17 | }; |
| 18 | |
| 19 | setCodecPreferences |
| 20 | - Setting codecs to an empty sequence resets codec preferences to any |
| 21 | default value. |
| 22 | |
| 23 | - The codecs sequence passed into setCodecPreferences can only contain |
| 24 | codecs that are returned by RTCRtpSender.getCapabilities(kind) or |
| 25 | RTCRtpReceiver.getCapabilities(kind), where kind is the kind of the |
| 26 | RTCRtpTransceiver on which the method is called. Additionally, the |
| 27 | RTCRtpCodecParameters dictionary members cannot be modified. If |
| 28 | codecs does not fulfill these requirements, the user agent MUST throw |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 29 | an InvalidModificationError. |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | test(() => { |
| 33 | const pc = new RTCPeerConnection(); |
| 34 | const transceiver = pc.addTransceiver('audio'); |
| 35 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 36 | transceiver.setCodecPreferences(capabilities.codecs); |
| 37 | |
| 38 | }, `setCodecPreferences() on audio transceiver with codecs returned from RTCRtpSender.getCapabilities('audio') should succeed`); |
| 39 | |
| 40 | test(() => { |
| 41 | const pc = new RTCPeerConnection(); |
| 42 | const transceiver = pc.addTransceiver('video'); |
| 43 | const capabilities = RTCRtpReceiver.getCapabilities('video'); |
| 44 | transceiver.setCodecPreferences(capabilities.codecs); |
| 45 | |
| 46 | }, `setCodecPreferences() on video transceiver with codecs returned from RTCRtpReceiver.getCapabilities('video') should succeed`); |
| 47 | |
| 48 | test(() => { |
| 49 | const pc = new RTCPeerConnection(); |
| 50 | const transceiver = pc.addTransceiver('audio'); |
| 51 | const capabilities1 = RTCRtpSender.getCapabilities('audio'); |
| 52 | const capabilities2 = RTCRtpReceiver.getCapabilities('audio'); |
| 53 | transceiver.setCodecPreferences([...capabilities1.codecs, ... capabilities2.codecs]); |
| 54 | |
| 55 | }, `setCodecPreferences() with both sender receiver codecs combined should succeed`); |
| 56 | |
| 57 | test(() => { |
| 58 | const pc = new RTCPeerConnection(); |
| 59 | const transceiver = pc.addTransceiver('audio'); |
| 60 | transceiver.setCodecPreferences([]); |
| 61 | |
| 62 | }, `setCodecPreferences([]) should succeed`); |
| 63 | |
| 64 | test(() => { |
| 65 | const pc = new RTCPeerConnection(); |
| 66 | const transceiver = pc.addTransceiver('audio'); |
| 67 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 68 | const { codecs } = capabilities; |
| 69 | |
| 70 | if(codecs.length >= 2) { |
| 71 | const tmp = codecs[0]; |
| 72 | codecs[0] = codecs[1]; |
| 73 | codecs[1] = tmp; |
| 74 | } |
| 75 | |
| 76 | transceiver.setCodecPreferences(codecs); |
| 77 | |
| 78 | }, `setCodecPreferences() with reordered codecs should succeed`); |
| 79 | |
| 80 | test(() => { |
| 81 | const pc = new RTCPeerConnection(); |
| Harald Alvestrand | 3130f02 | 2020-02-06 10:50:27 | [diff] [blame^] | 82 | const transceiver = pc.addTransceiver('video'); |
| 83 | const capabilities = RTCRtpSender.getCapabilities('video'); |
| 84 | const { codecs } = capabilities; |
| 85 | // This test verifies that the mandatory VP8 codec is present |
| 86 | // and can be set. |
| 87 | let tried = false; |
| 88 | codecs.forEach(codec => { |
| 89 | if (codec.mimeType.toLowerCase() === 'video/vp8') { |
| 90 | transceiver.setCodecPreferences([codecs[0]]); |
| 91 | tried = true; |
| 92 | } |
| 93 | }); |
| 94 | assert_true(tried, 'VP8 video codec was found and tried'); |
| 95 | }, `setCodecPreferences() with only one video codec should succeed`); |
| 96 | |
| 97 | test(() => { |
| 98 | const pc = new RTCPeerConnection(); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 99 | const transceiver = pc.addTransceiver('audio'); |
| 100 | const capabilities = RTCRtpSender.getCapabilities('video'); |
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 101 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(capabilities.codecs)); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 102 | |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 103 | }, `setCodecPreferences() on audio transceiver with codecs returned from getCapabilities('video') should throw InvalidModificationError`); |
| 104 | |
| 105 | test(() => { |
| 106 | const pc = new RTCPeerConnection(); |
| 107 | const transceiver = pc.addTransceiver('audio'); |
| 108 | const codecs = [{ |
| 109 | mimeType: 'data', |
| 110 | clockRate: 2000, |
| 111 | channels: 2, |
| 112 | sdpFmtpLine: '0-15' |
| 113 | }]; |
| 114 | |
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 115 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 116 | |
| 117 | }, `setCodecPreferences() with user defined codec with invalid mimeType should throw InvalidModificationError`); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 118 | |
| 119 | test(() => { |
| 120 | const pc = new RTCPeerConnection(); |
| 121 | const transceiver = pc.addTransceiver('audio'); |
| 122 | const codecs = [{ |
| 123 | mimeType: 'audio/piepiper', |
| 124 | clockRate: 2000, |
| 125 | channels: 2, |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 126 | sdpFmtpLine: '0-15' |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 127 | }]; |
| 128 | |
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 129 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 130 | |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 131 | }, `setCodecPreferences() with user defined codec should throw InvalidModificationError`); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 132 | |
| 133 | test(() => { |
| 134 | const pc = new RTCPeerConnection(); |
| 135 | const transceiver = pc.addTransceiver('audio'); |
| 136 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 137 | const codecs = [ |
| 138 | ...capabilities.codecs, |
| 139 | { |
| 140 | mimeType: 'audio/piepiper', |
| 141 | clockRate: 2000, |
| 142 | channels: 2, |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 143 | sdpFmtpLine: '0-15' |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 144 | }]; |
| 145 | |
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 146 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 147 | |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 148 | }, `setCodecPreferences() with user defined codec together with codecs returned from getCapabilities() should throw InvalidModificationError`); |
| 149 | |
| 150 | test(() => { |
| 151 | const pc = new RTCPeerConnection(); |
| 152 | const transceiver = pc.addTransceiver('audio'); |
| 153 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 154 | const codecs = [capabilities.codecs[0]]; |
| 155 | codecs[0].clockRate = codecs[0].clockRate / 2; |
| 156 | |
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 157 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 158 | |
| 159 | }, `setCodecPreferences() with modified codec clock rate should throw InvalidModificationError`); |
| 160 | |
| 161 | test(() => { |
| 162 | const pc = new RTCPeerConnection(); |
| 163 | const transceiver = pc.addTransceiver('audio'); |
| 164 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 165 | const codecs = [capabilities.codecs[0]]; |
| 166 | codecs[0].channels = codecs[0].channels + 11; |
| 167 | |
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 168 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 169 | |
| 170 | }, `setCodecPreferences() with modified codec channel count should throw InvalidModificationError`); |
| 171 | |
| 172 | test(() => { |
| 173 | const pc = new RTCPeerConnection(); |
| 174 | const transceiver = pc.addTransceiver('audio'); |
| 175 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 176 | const codecs = [capabilities.codecs[0]]; |
| 177 | codecs[0].sdpFmtpLine = "modifiedparameter=1"; |
| 178 | |
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 179 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 180 | |
| 181 | }, `setCodecPreferences() with modified codec parameters should throw InvalidModificationError`); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 182 | |
| 183 | test(() => { |
| 184 | const pc = new RTCPeerConnection(); |
| 185 | const transceiver = pc.addTransceiver('audio'); |
| 186 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 187 | |
| 188 | const { codecs } = capabilities; |
| 189 | assert_greater_than(codecs.length, 0, |
| 190 | 'Expect at least one codec available'); |
| 191 | |
| 192 | const [ codec ] = codecs; |
| 193 | const { channels=2 } = codec; |
| 194 | codec.channels = channels+1; |
| 195 | |
| Stephen McGruer | d510304 | 2020-01-23 21:45:45 | [diff] [blame] | 196 | assert_throws_dom('InvalidModificationError', () => transceiver.setCodecPreferences(codecs)); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 197 | |
| Florent Castelli | dd2829c | 2019-05-08 15:36:36 | [diff] [blame] | 198 | }, `setCodecPreferences() with modified codecs returned from getCapabilities() should throw InvalidModificationError`); |
| Soares Chen | d8b19bc | 2017-07-19 07:44:51 | [diff] [blame] | 199 | |
| 200 | </script> |