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

Side by Side Diff: talk/examples/objc/AppRTCDemo/ARDSDPUtils.m

Issue 1187573004: iOS HW H264 support. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Fix partial availability errors Created 5 years, 6 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
« no previous file with comments | « talk/examples/objc/AppRTCDemo/ARDSDPUtils.h ('k') | talk/libjingle.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2015 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
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
14 * derived from this software without specific prior written permission.
15 *
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
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
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,
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
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #import "ARDSDPUtils.h"
29
30 #import "RTCSessionDescription.h"
31
32 @implementation ARDSDPUtils
33
phoglund 2015/06/22 08:17:38 This looks like something that would greatly benef
34 + (RTCSessionDescription *)
35 descriptionForDescription:(RTCSessionDescription *)description
36 preferredVideoCodec:(NSString *)codec {
37 NSString *sdpString = description.description;
38 NSString *lineSeparator = @"\n";
39 NSString *mLineSeparator = @" ";
40 // Copied from PeerConnectionClient.java.
41 // TODO(tkchin): Move this to a shared C++ file.
42 NSMutableArray *lines =
43 [NSMutableArray arrayWithArray:
44 [sdpString componentsSeparatedByString:lineSeparator]];
45 int mLineIndex = -1;
46 NSString *codecRtpMap = nil;
47 // a=rtpmap:<payload type> <encoding name>/<clock rate>
48 // [/<encoding parameters>]
49 NSString *pattern =
50 [NSString stringWithFormat:@"^a=rtpmap:(\\d+) %@(/\\d+)+[\r]?$", codec];
51 NSRegularExpression *regex =
52 [NSRegularExpression regularExpressionWithPattern:pattern
53 options:0
54 error:nil];
55 for (NSInteger i = 0; (i < lines.count) && (mLineIndex == -1 || !codecRtpMap);
56 ++i) {
57 NSString *line = lines[i];
58 if ([line hasPrefix:@"m=video"]) {
59 mLineIndex = i;
60 continue;
61 }
62 NSTextCheckingResult *codecMatches =
63 [regex firstMatchInString:line
64 options:0
65 range:NSMakeRange(0, line.length)];
66 if (codecMatches) {
67 codecRtpMap =
68 [line substringWithRange:[codecMatches rangeAtIndex:1]];
69 continue;
70 }
71 }
72 if (mLineIndex == -1) {
73 NSLog(@"No m=video line, so can't prefer %@", codec);
74 return description;
75 }
76 if (!codecRtpMap) {
77 NSLog(@"No rtpmap for %@", codec);
78 return description;
79 }
80 NSArray *origMLineParts =
81 [lines[mLineIndex] componentsSeparatedByString:mLineSeparator];
82 if (origMLineParts.count > 3) {
83 NSMutableArray *newMLineParts =
84 [NSMutableArray arrayWithCapacity:origMLineParts.count];
85 NSInteger origPartIndex = 0;
86 // Format is: m=<media> <port> <proto> <fmt> ...
87 [newMLineParts addObject:origMLineParts[origPartIndex++]];
88 [newMLineParts addObject:origMLineParts[origPartIndex++]];
89 [newMLineParts addObject:origMLineParts[origPartIndex++]];
90 [newMLineParts addObject:codecRtpMap];
91 for (; origPartIndex < origMLineParts.count; ++origPartIndex) {
92 if (![codecRtpMap isEqualToString:origMLineParts[origPartIndex]]) {
93 [newMLineParts addObject:origMLineParts[origPartIndex]];
94 }
95 }
96 NSString *newMLine =
97 [newMLineParts componentsJoinedByString:mLineSeparator];
98 [lines replaceObjectAtIndex:mLineIndex
99 withObject:newMLine];
100 } else {
101 NSLog(@"Wrong SDP media description format: %@", lines[mLineIndex]);
102 }
103 NSString *mangledSdpString = [lines componentsJoinedByString:lineSeparator];
104 return [[RTCSessionDescription alloc] initWithType:description.type
105 sdp:mangledSdpString];
106 }
107
108 @end
OLDNEW
« no previous file with comments | « talk/examples/objc/AppRTCDemo/ARDSDPUtils.h ('k') | talk/libjingle.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698