| 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 |
| 29 | an InvalidAccessError. |
| 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(); |
| 82 | const transceiver = pc.addTransceiver('audio'); |
| 83 | const capabilities = RTCRtpSender.getCapabilities('video'); |
| 84 | assert_throws(() => transceiver.setCodecPreferences(capabilities.codecs)); |
| 85 | |
| 86 | }, `setCodecPreferences() on audio transceiver with codecs returned from getCapabilities('video') should throw InvalidAccessError`); |
| 87 | |
| 88 | test(() => { |
| 89 | const pc = new RTCPeerConnection(); |
| 90 | const transceiver = pc.addTransceiver('audio'); |
| 91 | const codecs = [{ |
| 92 | mimeType: 'audio/piepiper', |
| 93 | clockRate: 2000, |
| 94 | channels: 2, |
| 95 | sdpFmtpLine: 'a=fmtp:98 0-15' |
| 96 | }]; |
| 97 | |
| 98 | assert_throws(() => transceiver.setCodecPreferences(codecs)); |
| 99 | |
| 100 | }, `setCodecPreferences() with user defined codec should throw InvalidAccessError`); |
| 101 | |
| 102 | test(() => { |
| 103 | const pc = new RTCPeerConnection(); |
| 104 | const transceiver = pc.addTransceiver('audio'); |
| 105 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 106 | const codecs = [ |
| 107 | ...capabilities.codecs, |
| 108 | { |
| 109 | mimeType: 'audio/piepiper', |
| 110 | clockRate: 2000, |
| 111 | channels: 2, |
| 112 | sdpFmtpLine: 'a=fmtp:98 0-15' |
| 113 | }]; |
| 114 | |
| 115 | assert_throws(() => transceiver.setCodecPreferences(codecs)); |
| 116 | |
| 117 | }, `setCodecPreferences() with user defined codec together with codecs returned from getCapabilities() should throw InvalidAccessError`); |
| 118 | |
| 119 | test(() => { |
| 120 | const pc = new RTCPeerConnection(); |
| 121 | const transceiver = pc.addTransceiver('audio'); |
| 122 | const capabilities = RTCRtpSender.getCapabilities('audio'); |
| 123 | |
| 124 | const { codecs } = capabilities; |
| 125 | assert_greater_than(codecs.length, 0, |
| 126 | 'Expect at least one codec available'); |
| 127 | |
| 128 | const [ codec ] = codecs; |
| 129 | const { channels=2 } = codec; |
| 130 | codec.channels = channels+1; |
| 131 | |
| 132 | assert_throws(() => transceiver.setCodecPreferences(codecs)); |
| 133 | |
| 134 | }, `setCodecPreferences() with modified codecs returned from getCapabilities() should throw InvalidAccessError`); |
| 135 | |
| 136 | </script> |