Skip to content

Commit

Permalink
Merge pull request #84 from 0dayZh/master
Browse files Browse the repository at this point in the history
Update to v1.6.1
  • Loading branch information
0dayZh committed Jan 22, 2016
2 parents 0ca9b44 + 9045b76 commit 1b5dc23
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 125 deletions.
5 changes: 5 additions & 0 deletions APIDiffs/api-diffs-1.6.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PLCameraStreamingKit 1.6.0 to 1.6.1 API Differences

## General Headers

None
17 changes: 17 additions & 0 deletions Example/PLCameraStreamingKit/Base.lproj/Main_iPhone.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="2" translatesAutoresizingMaskIntoConstraints="NO" id="PKp-Bc-QgB">
<rect key="frame" x="217" y="36" width="166" height="29"/>
<constraints>
<constraint firstAttribute="width" constant="166" id="BfM-XD-zBn"/>
</constraints>
<segments>
<segment title="15fps"/>
<segment title="24fps"/>
<segment title="30fps"/>
</segments>
<connections>
<action selector="segmentedControlValueDidChange:" destination="vXZ-lx-hvc" eventType="valueChanged" id="X2X-RZ-EsQ"/>
</connections>
</segmentedControl>
</subviews>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand All @@ -148,13 +162,16 @@
<constraint firstAttribute="centerX" secondItem="qYA-qU-D3h" secondAttribute="centerX" id="dVY-Mb-fna"/>
<constraint firstItem="23g-Fm-A4B" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="psL-mu-8kS"/>
<constraint firstItem="O35-P7-T0e" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="8" id="r6k-zK-YQt"/>
<constraint firstItem="PKp-Bc-QgB" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="sNC-4a-3gs"/>
<constraint firstItem="PKp-Bc-QgB" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="16" id="xaE-DG-8w5"/>
<constraint firstItem="imY-d4-8r9" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="-4" id="yNq-YN-Xwk"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="qYA-qU-D3h" secondAttribute="bottom" constant="20" id="yOr-9z-uvm"/>
</constraints>
</view>
<connections>
<outlet property="actionButton" destination="qYA-qU-D3h" id="Dlq-dH-brC"/>
<outlet property="muteButton" destination="O35-P7-T0e" id="NQa-GO-UDy"/>
<outlet property="segementedControl" destination="PKp-Bc-QgB" id="0fZ-Za-h0a"/>
<outlet property="textView" destination="24d-PX-2NR" id="TiM-CW-3VE"/>
<outlet property="toggleCameraButton" destination="23g-Fm-A4B" id="bFE-st-cCr"/>
<outlet property="torchButton" destination="rft-Nr-a9A" id="TMn-Zv-Dl6"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
@property (weak, nonatomic) IBOutlet UIButton *torchButton;
@property (weak, nonatomic) IBOutlet UIButton *muteButton;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UISegmentedControl *segementedControl;

- (IBAction)segmentedControlValueDidChange:(id)sender;

@end
15 changes: 12 additions & 3 deletions Example/PLCameraStreamingKit/PLCameraStreamingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"Reachable via CELL"
};

#define kReloadConfigurationEnable 0

// 假设在 videoFPS 低于预期 50% 的情况下就触发降低推流质量的操作,这里的 40% 是一个假定数值,你可以更改数值来尝试不同的策略
#define kMaxVideoFPSPercent 0.5

Expand Down Expand Up @@ -85,9 +87,9 @@ - (void)viewDidLoad {
// 预先设定几组编码质量,之后可以切换
CGSize videoSize = CGSizeMake(320, 480);
self.videoConfigurations = @[
[PLVideoStreamingConfiguration configurationWithVideoSize:videoSize videoQuality:kPLVideoStreamingQualityMedium1],
[PLVideoStreamingConfiguration configurationWithVideoSize:videoSize videoQuality:kPLVideoStreamingQualityMedium2],
[PLVideoStreamingConfiguration configurationWithVideoSize:videoSize videoQuality:kPLVideoStreamingQualityMedium3],
[[PLVideoStreamingConfiguration alloc] initWithVideoSize:videoSize videoFrameRate:15 videoMaxKeyframeInterval:45 videoBitrate:800 * 1000 videoProfileLevel:AVVideoProfileLevelH264Baseline31],
[[PLVideoStreamingConfiguration alloc] initWithVideoSize:videoSize videoFrameRate:24 videoMaxKeyframeInterval:72 videoBitrate:800 * 1000 videoProfileLevel:AVVideoProfileLevelH264Baseline31],
[[PLVideoStreamingConfiguration alloc] initWithVideoSize:videoSize videoFrameRate:30 videoMaxKeyframeInterval:90 videoBitrate:800 * 1000 videoProfileLevel:AVVideoProfileLevelH264Baseline31],
];
self.sessionQueue = dispatch_queue_create("pili.queue.streaming", DISPATCH_QUEUE_SERIAL);

Expand Down Expand Up @@ -227,6 +229,7 @@ - (void)cameraStreamingSession:(PLCameraStreamingSession *)session streamStatusD
NSLog(@"%@", status);
self.textView.text = LogString();

#if kReloadConfigurationEnable
NSDate *now = [NSDate date];
if (!self.keyTime) {
self.keyTime = now;
Expand All @@ -246,6 +249,7 @@ - (void)cameraStreamingSession:(PLCameraStreamingSession *)session streamStatusD
[self higherQuality];
}
}
#endif // #if kReloadConfigurationEnable
}

#pragma mark -
Expand Down Expand Up @@ -295,6 +299,11 @@ - (void)startSession {

#pragma mark - Action

- (IBAction)segmentedControlValueDidChange:(id)sender {
PLVideoStreamingConfiguration *config = self.videoConfigurations[self.segementedControl.selectedSegmentIndex];
[self.session reloadVideoConfiguration:config];
}

- (IBAction)actionButtonPressed:(id)sender {
if (PLStreamStateConnected == self.session.streamState) {
[self stopSession];
Expand Down
14 changes: 7 additions & 7 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
PODS:
- HappyDNS (0.2.3)
- PLCameraStreamingKit (1.6.0):
- PLStreamingKit (~> 1.1.2)
- PLStreamingKit (1.1.2):
- PLCameraStreamingKit (1.6.1):
- PLStreamingKit (~> 1.1.3)
- PLStreamingKit (1.1.3):
- HappyDNS
- PLStreamingKit/precompiled (= 1.1.2)
- PLStreamingKit/precompiled (1.1.2):
- PLStreamingKit/precompiled (= 1.1.3)
- PLStreamingKit/precompiled (1.1.3):
- HappyDNS

DEPENDENCIES:
Expand All @@ -17,7 +17,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
HappyDNS: 6d85942e64c28b4fa61f8c76580398f52d6d1d11
PLCameraStreamingKit: 3ca6897d972fa8913165f8be1d6246ae73a32c4a
PLStreamingKit: 0031931293c5acbe5874515f13f8451a33186755
PLCameraStreamingKit: df7c55ad9527dc83bff75ae077aa9a9afec996c6
PLStreamingKit: 4ce7abd3688c4e6767b4ac83a813bd785a2c1748

COCOAPODS: 0.39.0
6 changes: 3 additions & 3 deletions Example/Pods/Local Podspecs/PLCameraStreamingKit.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Example/Pods/PLStreamingKit/Pod/Library/lib/libPLStreamingKit.a
Binary file not shown.
2 changes: 2 additions & 0 deletions Example/Pods/PLStreamingKit/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions PLCameraStreamingKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "PLCameraStreamingKit"
s.version = "1.6.0"
s.version = "1.6.1"
s.summary = "Pili iOS camera streaming framework via RTMP."
s.homepage = "https://github.com/pili-engineering/PLCameraStreamingKit"
s.license = 'Apache License, Version 2.0'
Expand All @@ -22,7 +22,7 @@ Pod::Spec.new do |s|
s.public_header_files = 'Pod/Classes/*.h'
s.source_files = 'Pod/Classes/*.h', 'Pod/Classes/*.m'

s.dependency 'PLStreamingKit', '~> 1.1.2'
s.dependency 'PLStreamingKit', '~> 1.1.3'
s.frameworks = ['UIKit', 'AVFoundation', 'CoreGraphics', 'CFNetwork', 'AudioToolbox', 'CoreMedia', 'VideoToolbox']
s.libraries = 'z', 'c++'

Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/PLCameraSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ PLSourceAccessProtocol

@property (nonatomic, PL_WEAK) id<PLCameraSourceDelegate> delegate;

@property (nonatomic, PL_WEAK) PLVideoStreamingConfiguration *videoConfiguration;
@property (nonatomic, copy) PLVideoStreamingConfiguration *videoConfiguration;
@property (nonatomic, readwrite, assign) PLCaptureDevicePosition cameraPosition;
@property (nonatomic, readwrite, assign, getter=isTorchOn) BOOL torchOn;
@property (nonatomic, readonly, PL_WEAK) AVCaptureVideoPreviewLayer *previewLayer;
Expand All @@ -62,6 +62,6 @@ PLSourceAccessProtocol
- (void)startRunning;
- (void)stopRunning;

- (void)reloadVideoConfiguration;
- (void)reloadVideoConfiguration:(PLVideoStreamingConfiguration *)videoConfiguration;

@end
30 changes: 8 additions & 22 deletions Pod/Classes/PLCameraSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,8 @@ - (instancetype)initWithVideoConfiguration:(PLVideoStreamingConfiguration *)conf
if ([device hasMediaType:AVMediaTypeVideo]) {
if (device.position == position) {
self.captureDevice = device;
break;
}

NSError *error;
[device lockForConfiguration:&error];
if (PL_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
device.activeVideoMinFrameDuration = CMTimeMake(1, self.videoConfiguration.videoFrameRate);
device.activeVideoMaxFrameDuration = CMTimeMake(1, self.videoConfiguration.videoFrameRate);
}
[device unlockForConfiguration];
}
}

Expand Down Expand Up @@ -137,7 +130,7 @@ - (void)refreshFPS {
} else {
NSUInteger frameRate = self.videoConfiguration.videoFrameRate;
AVFrameRateRange *range = [captureDevice.activeFormat.videoSupportedFrameRateRanges firstObject];
if (frameRate < range.maxFrameRate && frameRate > range.minFrameRate) {
if (frameRate <= range.maxFrameRate && frameRate >= range.minFrameRate) {
if ([captureDevice respondsToSelector:@selector(activeVideoMaxFrameDuration)]) {
captureDevice.activeVideoMaxFrameDuration = CMTimeMake(1, (int32_t)frameRate);
captureDevice.activeVideoMinFrameDuration = CMTimeMake(1, (int32_t)frameRate);
Expand Down Expand Up @@ -264,20 +257,13 @@ - (void)stopRunning {
self.isRunning = NO;
}

- (void)reloadVideoConfiguration {
NSArray *devices = [AVCaptureDevice devices];
for (AVCaptureDevice *device in devices) {
if ([device hasMediaType:AVMediaTypeVideo]) {

NSError *error;
[device lockForConfiguration:&error];
if (PL_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
device.activeVideoMinFrameDuration = CMTimeMake(1, self.videoConfiguration.videoFrameRate);
device.activeVideoMaxFrameDuration = CMTimeMake(1, self.videoConfiguration.videoFrameRate);
}
[device unlockForConfiguration];
}
- (void)reloadVideoConfiguration:(PLVideoStreamingConfiguration *)videoConfiguration {
if ([videoConfiguration isEqual:self.videoConfiguration]) {
return;
}

self.videoConfiguration = videoConfiguration;
[self refreshFPS];
}

#pragma mark - Property
Expand Down
13 changes: 8 additions & 5 deletions Pod/Classes/PLCameraStreamingSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,19 @@ extern NSString *PLAudioComponentFailedToCreateNotification;

@property (nonatomic, PL_WEAK) id<PLStreamingSendingBufferDelegate> bufferDelegate;

/// 最低阈值, [0..1], 不可超出这个范围, 默认为 0.5
@property (nonatomic, assign) CGFloat lowThreshold;

/// 最高阈值, [0..1], 不可超出这个范围, 默认为 1
@property (nonatomic, assign) CGFloat highThreshold;
/// [0..1], 不可超出这个范围, 默认为 0.5
@property (nonatomic, assign) CGFloat threshold;

/// Buffer 最多可包含的包数,默认为 300
@property (nonatomic, assign) NSUInteger maxCount;
@property (nonatomic, assign, readonly) NSUInteger currentCount;


/// 已弃用,最低阈值, [0..1], 不可超出这个范围, 默认为 0.5
@property (nonatomic, assign) CGFloat lowThreshold DEPRECATED_ATTRIBUTE;
/// 已弃用,最高阈值, [0..1], 不可超出这个范围, 默认为 1
@property (nonatomic, assign) CGFloat highThreshold DEPRECATED_ATTRIBUTE;

@end

#pragma mark - Category (CameraSource)
Expand Down
27 changes: 10 additions & 17 deletions Pod/Classes/PLCameraStreamingSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ @interface PLCameraStreamingSession ()

// Category rewrite
@property (nonatomic, PL_WEAK) id<PLStreamingSendingBufferDelegate> bufferDelegate;
@property (nonatomic, assign) CGFloat threshold;
@property (nonatomic, assign) CGFloat lowThreshold;
@property (nonatomic, assign) CGFloat highThreshold;
@property (nonatomic, assign) NSTimeInterval maxDuration;
Expand Down Expand Up @@ -147,7 +148,9 @@ - (void)reloadVideoConfiguration:(PLVideoStreamingConfiguration *)videoConfigura
return;
}

self.streamingSession.videoConfiguration = videoConfiguration;
self.videoConfiguration = videoConfiguration;

[self.cameraSource reloadVideoConfiguration:videoConfiguration];
[self.streamingSession reloadVideoConfiguration:videoConfiguration];
}

Expand Down Expand Up @@ -338,24 +341,14 @@ - (void)previewViewTaped:(UITapGestureRecognizer *)tap {

#pragma mark - Property

- (CGFloat)lowThreshold {
return self.streamingSession.lowThreshold;
}

- (void)setLowThreshold:(CGFloat)lowThreshold {
[self willChangeValueForKey:@"lowThreshold"];
self.streamingSession.lowThreshold = lowThreshold;
[self didChangeValueForKey:@"lowThreshold"];
}

- (CGFloat)highThreshold {
return self.streamingSession.highThreshold;
- (CGFloat)threshold {
return self.streamingSession.threshold;
}

- (void)setHighThreshold:(CGFloat)highThreshold {
[self willChangeValueForKey:@"highThreshold"];
self.streamingSession.highThreshold = highThreshold;
[self didChangeValueForKey:@"highThreshold"];
- (void)setThreshold:(CGFloat)threshold {
[self willChangeValueForKey:@"threshold"];
self.streamingSession.threshold = threshold;
[self didChangeValueForKey:@"threshold"];
}

- (NSUInteger)maxCount {
Expand Down
Loading

0 comments on commit 1b5dc23

Please sign in to comment.