Skip to content

Commit

Permalink
Merge pull request #135 from HeraShowFeng/v3.0.3_docs_release
Browse files Browse the repository at this point in the history
v3.0.3 release
  • Loading branch information
HeraShowFeng authored Mar 4, 2021
2 parents c96807a + d4ff5c0 commit b9cadc8
Show file tree
Hide file tree
Showing 64 changed files with 2,917 additions and 579 deletions.
26 changes: 26 additions & 0 deletions APIDiffs/api-diffs-3.0.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# PLMediaStreamingKit 3.0.2 to 3.0.3 API Differences

## General Headers


```
PLStreamingEnv.h
```
- *Added* `+(void)initEnvWithUserUID:(NSString *)UID;`

- *Deprecated* `+(void)initEnv`


```
PLMediaStreamingSession.h
```
- *Added* `- (AudioBuffer *)mediaStreamingSession:(PLMediaStreamingSession *)session microphoneSourceDidGetAudioBuffer:(AudioBuffer *)audioBuffer asbd:(const AudioStreamBasicDescription *)asbd;`

- *Added* `- (void)reloadAudioStreamingConfiguration:(PLAudioStreamingConfiguration *)audioStreamingConfiguration;`


```
PLStreamStatus.h
```
- *Added* `@property (nonatomic, assign, readonly) double videoBitrate;`
- *Added* `@property (nonatomic, assign, readonly) double audioBitrate;`
26 changes: 26 additions & 0 deletions Example/BroadcastUploadExtension/BroadcastManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// BroadcastManager.h
// PLReplaykitExtension
//
// Created by 冯文秀 on 2020/3/23.
// Copyright © 2020 冯文秀. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <PLMediaStreamingKit/PLMediaStreamingKit.h>

@interface BroadcastManager : NSObject

@property (nonatomic, strong) PLStreamingSession *session;

+ (instancetype)createBroadcastManagerWithVideoSize:(CGSize)videoSize streamingURL:(NSString *)streamingURL;
+ (instancetype)sharedBroadcastManager;
- (PLStreamState)streamState;

- (void)pushVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer;
- (void)pushAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer;
- (void)pushAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer withChannelID:(const NSString *)channelID;
- (void)restartStreaming;
- (void)stopStreaming;

@end
123 changes: 123 additions & 0 deletions Example/BroadcastUploadExtension/BroadcastManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//
// BroadcastManager.m
// PLReplaykitExtension
//
// Created by 冯文秀 on 2020/3/23.
// Copyright © 2020 冯文秀. All rights reserved.
//

#import "BroadcastManager.h"
#import <PLMediaStreamingKit/PLMediaStreamingKit.h>

@interface BroadcastManager ()
<
PLStreamingSessionDelegate
>

@end

@implementation BroadcastManager

static BroadcastManager *_instance;

+ (instancetype)sharedBroadcastManager {
return _instance;
}

+ (instancetype)createBroadcastManagerWithVideoSize:(CGSize)videoSize streamingURL:(NSString *)streamingURL {
_instance = [[BroadcastManager alloc] initWithVideoSize:videoSize streamingURL:streamingURL];
return _instance;
}

- (instancetype)initWithVideoSize:(CGSize)videoSize streamingURL:(NSString *)streamingURL
{
if (self = [super init]) {
[PLStreamingEnv initEnv];
[PLStreamingEnv enableFileLogging];
[PLStreamingEnv setLogLevel:PLStreamLogLevelDebug];

NSLog(@"%@", PLMediaStreamingSession.versionInfo);

// [PLStreamingEnv setLogLevel:PLStreamLogLevelDebug];
// [PLStreamingEnv enableFileLogging];

PLVideoStreamingConfiguration *videoConfiguration = [[PLVideoStreamingConfiguration alloc] initWithVideoSize:videoSize expectedSourceVideoFrameRate:24 videoMaxKeyframeInterval:72 averageVideoBitRate:1000*1024 videoProfileLevel:AVVideoProfileLevelH264HighAutoLevel videoEncoderType:PLH264EncoderType_AVFoundation];
PLAudioStreamingConfiguration *audioConfiguration = [PLAudioStreamingConfiguration defaultConfiguration];
audioConfiguration.encodedAudioSampleRate = PLStreamingAudioSampleRate_44100Hz;
audioConfiguration.inputAudioChannelDescriptions = @[kPLAudioChannelApp, kPLAudioChannelMic];
audioConfiguration.audioEncoderType = PLAACEncoderType_iOS_AAC;

self.session = [[PLStreamingSession alloc] initWithVideoStreamingConfiguration:videoConfiguration
audioStreamingConfiguration:audioConfiguration
stream:nil];
self.session.autoReconnectEnable = YES;
self.session.connectionInterruptionHandler = ^(NSError *error) {
return YES;
};
self.session.connectionChangeActionCallback = ^(PLNetworkStateTransition transition) {
return YES;
};
[self.session enableAdaptiveBitrateControlWithMinVideoBitRate:500 * 1024];
self.session.delegate = self;

__weak typeof(self) weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.session startWithPushURL:[NSURL URLWithString:streamingURL] feedback:^(PLStreamStartStateFeedback feedback) {
if (PLStreamStartStateSuccess == feedback) {
NSLog(@"[PLReplaykitExtension] streaming connected successfully");
} else {
NSLog(@"[PLReplaykitExtension] stream failed to connect");
}
}];
});
}
return self;
}

- (PLStreamState)streamState {
return self.session.streamState;
}

- (void)pushVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer {
[self.session pushVideoSampleBuffer:sampleBuffer];
}

- (void)pushAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer {
[self.session pushAudioSampleBuffer:sampleBuffer];
}

- (void)pushAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer withChannelID:(const NSString *)channelID {
[self.session pushAudioSampleBuffer:sampleBuffer withChannelID:channelID completion:nil];
}

- (void)restartStreaming {
[self.session restartWithFeedback:^(PLStreamStartStateFeedback feedback) {
if (PLStreamStartStateSuccess == feedback) {
NSLog(@"[PLReplaykitExtension] stream restarted successfully");
}
}];
}

- (void)stopStreaming {
[self.session destroy];
NSLog(@"[PLReplaykitExtension] stream stopped");
}


#pragma mark - PLStreamingSessionDelegate
- (void)streamingSession:(PLStreamingSession *)session didDisconnectWithError:(NSError *)error {
NSLog(@"[PLReplaykitExtension] streaming error : %@", error);
}

- (void)streamingSession:(PLStreamingSession *)session streamStateDidChange:(PLStreamState)state {
NSLog(@"[PLReplaykitExtension] stream state did change to: %ld", (long)state);
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.qbox"];
[userDefaults setObject:@(state) forKey:@"PLReplayStreamState"];
[userDefaults synchronize];
}

- (void)streamingSession:(PLStreamingSession *)session streamStatusDidUpdate:(PLStreamStatus *)status {
NSLog(@"[PLReplaykitExtension] stream status updated: %@", status);
}

@end
33 changes: 33 additions & 0 deletions Example/BroadcastUploadExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>BroadcastUploadExtension</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.broadcast-services-upload</string>
<key>NSExtensionPrincipalClass</key>
<string>SampleHandler</string>
<key>RPBroadcastProcessMode</key>
<string>RPBroadcastProcessModeSampleBuffer</string>
</dict>
</dict>
</plist>
13 changes: 13 additions & 0 deletions Example/BroadcastUploadExtension/SampleHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SampleHandler.h
// BroadcastUploadExtension
//
// Created by 冯文秀 on 2021/3/4.
// Copyright © 2021 0dayZh. All rights reserved.
//

#import <ReplayKit/ReplayKit.h>

@interface SampleHandler : RPBroadcastSampleHandler

@end
68 changes: 68 additions & 0 deletions Example/BroadcastUploadExtension/SampleHandler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// SampleHandler.m
// PLReplaykitExtension
//
// Created by 冯文秀 on 2020/3/23.
// Copyright © 2020 冯文秀. All rights reserved.
//


#import "SampleHandler.h"
#import "BroadcastManager.h"

@interface SampleHandler ()

@end

@implementation SampleHandler

- (void)broadcastStartedWithSetupInfo:(NSDictionary<NSString *,NSObject *> *)setupInfo {
// User has requested to start the broadcast. Setup info from the UI extension will be supplied.
#warning 填入您的推流地址
NSString *streamingURL = @"";

CGSize videoSize = CGSizeMake(540, 960);
[BroadcastManager createBroadcastManagerWithVideoSize:videoSize streamingURL:streamingURL];
}

- (void)broadcastPaused {
// User has requested to pause the broadcast. Samples will stop being delivered.
[[BroadcastManager sharedBroadcastManager] stopStreaming];
}

- (void)broadcastResumed {
// User has requested to resume the broadcast. Samples delivery will resume.
[[BroadcastManager sharedBroadcastManager] restartStreaming];
}

- (void)broadcastFinished {
// User has requested to finish the broadcast.
[[BroadcastManager sharedBroadcastManager] stopStreaming];
}

- (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer withType:(RPSampleBufferType)sampleBufferType {

if (sampleBuffer && [BroadcastManager sharedBroadcastManager].streamState == PLStreamStateConnected) {
@autoreleasepool {
switch (sampleBufferType) {
case RPSampleBufferTypeVideo:
// Handle video sample buffer
[[BroadcastManager sharedBroadcastManager] pushVideoSampleBuffer:sampleBuffer];
break;
case RPSampleBufferTypeAudioApp:
// Handle audio sample buffer for app audio
[[BroadcastManager sharedBroadcastManager] pushAudioSampleBuffer:sampleBuffer withChannelID:kPLAudioChannelApp];
break;
case RPSampleBufferTypeAudioMic:
// Handle audio sample buffer for mic audio
[[BroadcastManager sharedBroadcastManager] pushAudioSampleBuffer:sampleBuffer withChannelID:kPLAudioChannelMic];
break;

default:
break;
}
}
}
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// BroadcastSetupViewController.h
// BroadcastUploadExtensionSetupUI
//
// Created by 冯文秀 on 2021/3/4.
// Copyright © 2021 0dayZh. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <ReplayKit/ReplayKit.h>

@interface BroadcastSetupViewController : UIViewController

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// BroadcastSetupViewController.m
// BroadcastUploadExtensionSetupUI
//
// Created by 冯文秀 on 2021/3/4.
// Copyright © 2021 0dayZh. All rights reserved.
//

#import "BroadcastSetupViewController.h"

@implementation BroadcastSetupViewController

// Call this method when the user has finished interacting with the view controller and a broadcast stream can start
- (void)userDidFinishSetup {

// URL of the resource where broadcast can be viewed that will be returned to the application
NSURL *broadcastURL = [NSURL URLWithString:@"http://apple.com/broadcast/streamID"];

// Dictionary with setup information that will be provided to broadcast extension when broadcast is started
NSDictionary *setupInfo = @{ @"broadcastName" : @"example" };

// Tell ReplayKit that the extension is finished setting up and can begin broadcasting
[self.extensionContext completeRequestWithBroadcastURL:broadcastURL setupInfo:setupInfo];
}

- (void)userDidCancelSetup {
// Tell ReplayKit that the extension was cancelled by the user
[self.extensionContext cancelRequestWithError:[NSError errorWithDomain:@"YourAppDomain" code:-1 userInfo:nil]];
}

@end
39 changes: 39 additions & 0 deletions Example/BroadcastUploadExtensionSetupUI/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>BroadcastUploadExtensionSetupUI</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsReplayKitStreaming</key>
<true/>
</dict>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.broadcast-services-setupui</string>
<key>NSExtensionPrincipalClass</key>
<string>BroadcastSetupViewController</string>
</dict>
</dict>
</plist>
Loading

0 comments on commit b9cadc8

Please sign in to comment.