| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
| 12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
| 13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
| 14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
| 15 * | 15 * |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #import "ARDSDPUtils.h" | 28 #import "ARDSDPUtils.h" |
| 29 | 29 |
| 30 #import "ARDLogging.h" | 30 #import "RTCLogging.h" |
| 31 #import "RTCSessionDescription.h" | 31 #import "RTCSessionDescription.h" |
| 32 | 32 |
| 33 @implementation ARDSDPUtils | 33 @implementation ARDSDPUtils |
| 34 | 34 |
| 35 + (RTCSessionDescription *) | 35 + (RTCSessionDescription *) |
| 36 descriptionForDescription:(RTCSessionDescription *)description | 36 descriptionForDescription:(RTCSessionDescription *)description |
| 37 preferredVideoCodec:(NSString *)codec { | 37 preferredVideoCodec:(NSString *)codec { |
| 38 NSString *sdpString = description.description; | 38 NSString *sdpString = description.description; |
| 39 NSString *lineSeparator = @"\n"; | 39 NSString *lineSeparator = @"\n"; |
| 40 NSString *mLineSeparator = @" "; | 40 NSString *mLineSeparator = @" "; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 64 [regex firstMatchInString:line | 64 [regex firstMatchInString:line |
| 65 options:0 | 65 options:0 |
| 66 range:NSMakeRange(0, line.length)]; | 66 range:NSMakeRange(0, line.length)]; |
| 67 if (codecMatches) { | 67 if (codecMatches) { |
| 68 codecRtpMap = | 68 codecRtpMap = |
| 69 [line substringWithRange:[codecMatches rangeAtIndex:1]]; | 69 [line substringWithRange:[codecMatches rangeAtIndex:1]]; |
| 70 continue; | 70 continue; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 if (mLineIndex == -1) { | 73 if (mLineIndex == -1) { |
| 74 ARDLog(@"No m=video line, so can't prefer %@", codec); | 74 RTCLog(@"No m=video line, so can't prefer %@", codec); |
| 75 return description; | 75 return description; |
| 76 } | 76 } |
| 77 if (!codecRtpMap) { | 77 if (!codecRtpMap) { |
| 78 ARDLog(@"No rtpmap for %@", codec); | 78 RTCLog(@"No rtpmap for %@", codec); |
| 79 return description; | 79 return description; |
| 80 } | 80 } |
| 81 NSArray *origMLineParts = | 81 NSArray *origMLineParts = |
| 82 [lines[mLineIndex] componentsSeparatedByString:mLineSeparator]; | 82 [lines[mLineIndex] componentsSeparatedByString:mLineSeparator]; |
| 83 if (origMLineParts.count > 3) { | 83 if (origMLineParts.count > 3) { |
| 84 NSMutableArray *newMLineParts = | 84 NSMutableArray *newMLineParts = |
| 85 [NSMutableArray arrayWithCapacity:origMLineParts.count]; | 85 [NSMutableArray arrayWithCapacity:origMLineParts.count]; |
| 86 NSInteger origPartIndex = 0; | 86 NSInteger origPartIndex = 0; |
| 87 // Format is: m=<media> <port> <proto> <fmt> ... | 87 // Format is: m=<media> <port> <proto> <fmt> ... |
| 88 [newMLineParts addObject:origMLineParts[origPartIndex++]]; | 88 [newMLineParts addObject:origMLineParts[origPartIndex++]]; |
| 89 [newMLineParts addObject:origMLineParts[origPartIndex++]]; | 89 [newMLineParts addObject:origMLineParts[origPartIndex++]]; |
| 90 [newMLineParts addObject:origMLineParts[origPartIndex++]]; | 90 [newMLineParts addObject:origMLineParts[origPartIndex++]]; |
| 91 [newMLineParts addObject:codecRtpMap]; | 91 [newMLineParts addObject:codecRtpMap]; |
| 92 for (; origPartIndex < origMLineParts.count; ++origPartIndex) { | 92 for (; origPartIndex < origMLineParts.count; ++origPartIndex) { |
| 93 if (![codecRtpMap isEqualToString:origMLineParts[origPartIndex]]) { | 93 if (![codecRtpMap isEqualToString:origMLineParts[origPartIndex]]) { |
| 94 [newMLineParts addObject:origMLineParts[origPartIndex]]; | 94 [newMLineParts addObject:origMLineParts[origPartIndex]]; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 NSString *newMLine = | 97 NSString *newMLine = |
| 98 [newMLineParts componentsJoinedByString:mLineSeparator]; | 98 [newMLineParts componentsJoinedByString:mLineSeparator]; |
| 99 [lines replaceObjectAtIndex:mLineIndex | 99 [lines replaceObjectAtIndex:mLineIndex |
| 100 withObject:newMLine]; | 100 withObject:newMLine]; |
| 101 } else { | 101 } else { |
| 102 ARDLog(@"Wrong SDP media description format: %@", lines[mLineIndex]); | 102 RTCLogWarning(@"Wrong SDP media description format: %@", lines[mLineIndex]); |
| 103 } | 103 } |
| 104 NSString *mangledSdpString = [lines componentsJoinedByString:lineSeparator]; | 104 NSString *mangledSdpString = [lines componentsJoinedByString:lineSeparator]; |
| 105 return [[RTCSessionDescription alloc] initWithType:description.type | 105 return [[RTCSessionDescription alloc] initWithType:description.type |
| 106 sdp:mangledSdpString]; | 106 sdp:mangledSdpString]; |
| 107 } | 107 } |
| 108 | 108 |
| 109 @end | 109 @end |
| OLD | NEW |