Skip to content

Commit 9e9ebf7

Browse files
authored
Merge pull request #96 from depthlove/master
v2.3.2 release
2 parents c642719 + 9eac2f0 commit 9e9ebf7

File tree

71 files changed

+1573
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1573
-410
lines changed

APIDiffs/api-diffs-2.3.2.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# PLMediaStreamingKit 2.3.1 to 2.3.2 API Differences
2+
3+
## General Headers

Example/PLMediaStreamingKitDemo.xcodeproj/project.pbxproj

+114-20
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2011 Michael Dippery <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
#import <Foundation/Foundation.h>
24+
25+
@interface NSString (Randomized)
26+
+ (NSString *)defaultAlphabet;
27+
+ (id)randomizedString;
28+
+ (id)randomizedStringWithAlphabet:(NSString *)alphabet;
29+
+ (id)randomizedStringWithAlphabet:(NSString *)alphabet length:(NSUInteger)len;
30+
- (id)initWithDefaultAlphabet;
31+
- (id)initWithAlphabet:(NSString *)alphabet;
32+
- (id)initWithAlphabet:(NSString *)alphabet length:(NSUInteger)len;
33+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2011 Michael Dippery <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
#import "NSString+Random.h"
24+
#include <stdlib.h>
25+
26+
#define DEFAULT_LENGTH 8
27+
28+
@implementation NSString (Randomized)
29+
30+
+ (NSString *)defaultAlphabet
31+
{
32+
return @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789";
33+
}
34+
35+
+ (id)randomizedString
36+
{
37+
return [self randomizedStringWithAlphabet:[self defaultAlphabet]];
38+
}
39+
40+
+ (id)randomizedStringWithAlphabet:(NSString *)alphabet
41+
{
42+
return [self randomizedStringWithAlphabet:alphabet length:DEFAULT_LENGTH];
43+
}
44+
45+
+ (id)randomizedStringWithAlphabet:(NSString *)alphabet length:(NSUInteger)len
46+
{
47+
return [[self alloc] initWithAlphabet:alphabet length:len];
48+
}
49+
50+
- (id)initWithDefaultAlphabet
51+
{
52+
return [self initWithAlphabet:[NSString defaultAlphabet]];
53+
}
54+
55+
- (id)initWithAlphabet:(NSString *)alphabet
56+
{
57+
return [self initWithAlphabet:alphabet length:DEFAULT_LENGTH];
58+
}
59+
60+
- (id)initWithAlphabet:(NSString *)alphabet length:(NSUInteger)len
61+
{
62+
NSMutableString *s = [NSMutableString stringWithCapacity:len];
63+
for (NSUInteger i = 0U; i < len; i++) {
64+
u_int32_t r = arc4random() % [alphabet length];
65+
unichar c = [alphabet characterAtIndex:r];
66+
[s appendFormat:@"%C", c];
67+
}
68+
return [NSString stringWithString:s];
69+
}
70+
71+
@end

Example/PLMediaStreamingKitDemo/PLMainViewController.m

+97-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
#import "PLStreamingSessionConstructor.h"
1212
#import "PLPermissionRequestor.h"
1313
#import "PLPanelDelegateGenerator.h"
14+
15+
#import "NSString+Random.h"
16+
1417
#import <PLMediaStreamingKit/PLMediaStreamingKit.h>
18+
1519
#import <Masonry/Masonry.h>
1620
#import <BlocksKit/BlocksKit.h>
1721
#import <BlocksKit/BlocksKit+UIKit.h>
@@ -24,8 +28,12 @@
2428
#define kWeiboAppSecret @"Your weibo app secret"
2529
#define kWeiXinAppID @"Your weixin app ID"
2630

27-
@interface PLMainViewController () <PLMediaStreamingSessionDelegate, PLPanelDelegateGeneratorDelegate, PLStreamingSessionConstructorDelegate>
28-
31+
@interface PLMainViewController ()
32+
<
33+
PLMediaStreamingSessionDelegate,
34+
PLPanelDelegateGeneratorDelegate,
35+
UIAlertViewDelegate
36+
>
2937
@end
3038

3139
@implementation PLMainViewController
@@ -34,13 +42,21 @@ @implementation PLMainViewController
3442
PLModelPanelGenerator *_modelPanelGenerator;
3543
PLPanelDelegateGenerator *_panelDelegateGenerator;
3644
PLStreamingSessionConstructor *_sessionConstructor;
45+
PLAudioCaptureConfiguration *_audioCaptureConfiguration;
3746
UIButton *_startButton;
47+
UIButton *_liveButton;
3848
UISlider *_zoomSlider;
49+
NSURL *_streamCloudURL;
3950
NSURL *_streamURL;
4051
UIView *_inputURLView;
4152
UITextView *_inputURLTextView;
4253
}
4354

55+
- (void)dealloc
56+
{
57+
58+
}
59+
4460
- (void)viewDidLoad
4561
{
4662
[super viewDidLoad];
@@ -49,6 +65,31 @@ - (void)viewDidLoad
4965

5066
[WXApi registerApp:kWeiXinAppID withDescription:@"PLMediaStreamingKitDemo"];
5167

68+
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"需要开启回声消除么?" delegate:self cancelButtonTitle:@"不要" otherButtonTitles:@"开开开", nil];
69+
[alertView show];
70+
}
71+
72+
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
73+
UITextField *textFiled = [alertView textFieldAtIndex:0];
74+
if (textFiled) {
75+
if (buttonIndex == 0) {
76+
return;
77+
}
78+
79+
NSString *deviceID = textFiled.text;
80+
[PLStreamingEnv setDeviceID:deviceID];
81+
return;
82+
}
83+
84+
if (!_audioCaptureConfiguration) {
85+
_audioCaptureConfiguration = [PLAudioCaptureConfiguration defaultConfiguration];
86+
}
87+
_audioCaptureConfiguration.acousticEchoCancellationEnable = (buttonIndex == 1);
88+
89+
// 获取推流地址,该地址要拿去鉴权获取 token,最终使用的推流 URL 为 _streamURL
90+
[self _getStreamCloudURL];
91+
[self _generateStreamURLFromServerWithURL:_streamCloudURL];
92+
5293
[self _prepareForCameraSetting];
5394
[self _prepareButtons];
5495

@@ -66,12 +107,19 @@ - (void)viewDidDisappear:(BOOL)animated
66107
[_streamingSession destroy];
67108
}
68109

110+
- (void)_getStreamCloudURL {
111+
#warning 在这里填写获取推流地址的业务服务器 url
112+
NSString *streamServer = @"your app server url";
113+
NSString *streamID = [NSString randomizedString];
114+
115+
NSString *streamURLString = [streamServer stringByAppendingPathComponent:streamID];
116+
117+
_streamCloudURL = [NSURL URLWithString:streamURLString];
118+
}
119+
69120
- (void)_prepareForCameraSetting
70121
{
71-
#warning 在这里填写获取推流地址的业务服务器 url
72-
NSURL *streamCloudURL = [NSURL URLWithString:@"your app server url"];
73-
_sessionConstructor = [[PLStreamingSessionConstructor alloc] initWithStreamCloudURL:streamCloudURL];
74-
_sessionConstructor.delegate = self;
122+
_sessionConstructor = [[PLStreamingSessionConstructor alloc] initWithAudioCaptureConfiguration:_audioCaptureConfiguration];
75123
_streamingSession = [_sessionConstructor streamingSession];
76124

77125
_streamingSession.delegate = self;
@@ -89,6 +137,41 @@ - (void)_prepareForCameraSetting
89137
[permission checkAndRequestPermission];
90138
}
91139

140+
- (void)_generateStreamURLFromServerWithURL:(NSURL *)url
141+
{
142+
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
143+
request.HTTPMethod = @"GET";
144+
request.timeoutInterval = 10;
145+
146+
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
147+
if (error != nil || response == nil || data == nil) {
148+
NSLog(@"get play json faild, %@, %@, %@", error, response, data);
149+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
150+
[self _generateStreamURLFromServerWithURL:url];
151+
});
152+
return;
153+
}
154+
155+
NSURL *streamURL = [NSURL URLWithString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]];
156+
157+
dispatch_async(dispatch_get_main_queue(), ^{
158+
NSString *streamURLString = streamURL.absoluteString;
159+
160+
// 将推流地址复制到剪切板
161+
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
162+
pasteboard.string = streamURLString;
163+
164+
// 弹出提示框,显示推流地址,当点击 ok 确认键后,推流被复制到了剪切板,方便将推流地址粘贴用于其它地方
165+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"streamURL" message:streamURLString delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
166+
[alert show];
167+
});
168+
169+
// 更新推流的 URL
170+
_streamURL = streamURL;
171+
}];
172+
[task resume];
173+
}
174+
92175
- (void)_prepareButtons
93176
{
94177
_startButton = ({
@@ -250,7 +333,10 @@ - (void)_pressedStartButton:(UIButton *)button
250333
if (PLStreamStartStateSuccess == feedback) {
251334
[button setTitle:@"stop" forState:UIControlStateNormal];
252335
} else {
253-
[[[UIAlertView alloc] initWithTitle:@"错误" message:@"推流失败了" delegate:nil cancelButtonTitle:@"知道啦" otherButtonTitles:nil] show];
336+
[[[UIAlertView alloc] initWithTitle:@"错误" message:@"推流失败了,将重新请求有效的URL" delegate:nil cancelButtonTitle:@"知道啦" otherButtonTitles:nil] show];
337+
338+
// 重新获取有效的URL,即更换 token,播放端的地址不会变
339+
[self _generateStreamURLFromServerWithURL:_streamCloudURL];
254340
}
255341
});
256342
}];
@@ -281,9 +367,8 @@ - (void)_pressedQRButton:(UIButton *)button
281367
if (!_streamURL) {
282368
[[[UIAlertView alloc] initWithTitle:@"错误" message:@"还没有获取到 streamJson 没有可供播放的二维码哦" delegate:nil cancelButtonTitle:@"知道啦" otherButtonTitles:nil] show];
283369
} else {
284-
#warning 在这里填写相关的 host,hub 即可使用播放器直接扫码播放
285-
NSString *host = @"your play host";
286-
NSString *hub = @"your hub";
370+
NSString *host = @"rtmp://pili-live-rtmp.pili2test.qbox.net";
371+
NSString *hub = @"pili2test";
287372
NSString *streamID = [[[[_streamURL.absoluteString componentsSeparatedByString:@"/"] objectAtIndex:4] componentsSeparatedByString:@"?"] objectAtIndex:0];
288373
NSString *url = [NSString stringWithFormat:@"%@/%@/%@",host, hub, streamID];
289374
UIImage *image = [self createQRForString:url];
@@ -398,11 +483,9 @@ - (void)panelDelegateGenerator:(PLPanelDelegateGenerator *)panelDelegateGenerato
398483
- (void)panelDelegateGenerator:(PLPanelDelegateGenerator *)panelDelegateGenerator streamStateDidChange:(PLStreamState)state {
399484
if (PLStreamStateDisconnected == state) {
400485
[_startButton setTitle:@"start" forState:UIControlStateNormal];
486+
} else if (PLStreamStateConnected == state) {
487+
[_startButton setTitle:@"stop" forState:UIControlStateNormal];
401488
}
402489
}
403490

404-
- (void)PLStreamingSessionConstructor:(PLStreamingSessionConstructor *)constructor didGetStreamURL:(NSURL *)streamURL {
405-
_streamURL = streamURL;
406-
}
407-
408491
@end

0 commit comments

Comments
 (0)