提交 5e43be0d 编写于 作者: 杨时权

【需求】支持可动态更新码率。

上级 a6abc3a9
......@@ -39,9 +39,9 @@ typedef NS_ENUM(NSUInteger, LWVideoEncodeStatus) {
- (LWVideoEncodeStatus)reconfig:(LWVideoEncoderConfig*)config;
- (LWVideoEncodeStatus)setOptionWithInt32:(NSString*)key value:(int32_t)value;
- (LWVideoEncodeStatus)setOptionWithInt32:(const NSString*)key value:(int32_t)value;
- (LWVideoEncodeStatus)getOptionWithInt32:(NSString*)key value:(int32_t*)value;
- (LWVideoEncodeStatus)getOptionWithInt32:(const NSString*)key value:(int32_t*)value;
@end
......
#import <Foundation/Foundation.h>
#import "LWVideoEncoder.h"
#import "LWVideoOptions.h"
@interface LWVideoEncoder ()
{
......@@ -59,6 +60,23 @@ void compressSessionOutputCallback(void *opaque,
return kLWVideoEncodeStatus_Success;
}
- (LWVideoEncodeStatus)setOptionWithInt32:(const NSString*)key value:(int32_t)value {
LWVideoEncodeStatus status = kLWVideoEncodeStatus_Success;
// 动态更新码率
if ([key isEqual:kLWVideoOptions_Bitrate]) {
_config.bitrate = value;
[self setBitrate:value];
NSLog(@"%s:%d dynamic bitrate %d", __func__, __LINE__, value);
} else {
status = kLWVideoEncodeStatus_Err_NO_Support;
}
return status;
}
- (LWVideoEncodeStatus)getOptionWithInt32:(const NSString*)key value:(int32_t*)value {
return kLWVideoEncodeStatus_Err_NO_Support;
}
- (void)dealloc {
[self destroySession];
}
......
......@@ -4,11 +4,17 @@
#import "LWCheckBoxView.h"
#import "LWVideoCaptureSession.h"
#import "LWVideoEncoder.h"
#import "LWVideoOptions.h"
@interface CaptureViewController () <LWVideoCaptureSessionDelegate, LWCheckBoxViewDelegate, LWVideoEncoderDelegate>
@interface CaptureViewController () <LWVideoCaptureSessionDelegate, LWCheckBoxViewDelegate, LWVideoEncoderDelegate, UITextFieldDelegate>
@property (strong, nonatomic) UIView* displayView;
@property (strong, nonatomic) LWCheckBoxView* checkBoxView;
@property (strong, nonatomic) UILabel* captureTypeLabel;
@property (strong, nonatomic) UILabel* encodeBitRateLabel;
@property (strong, nonatomic) UITextField* encodeBitRateField;
@property (strong, nonatomic) UIButton* encodeBitRateSettedBtn;
@property (strong, nonatomic) UIButton* startBtn;
@property (strong, nonatomic) UIButton* stopBtn;
......@@ -24,10 +30,11 @@
@implementation CaptureViewController
- (void) viewDidLoad {
CGRect bounds = [UIScreen mainScreen].bounds;
int displayViewX = 0;
int displayViewY = 20;
int displayViewW = [UIScreen mainScreen].bounds.size.width;
int displayViewH = displayViewW / 16 * 9;
int displayViewH = displayViewW / 16 * 12;
self.hatsuneMiKuColor = [UIColor colorWithRed:(0x39 * 1.0 / 0xff) green:(0xc5 * 1.0 / 0xff) blue:(0xbb * 1.0 / 0xff) alpha:1.0];
self.displayView = [[UIView alloc] initWithFrame:CGRectMake(displayViewX, displayViewY, displayViewW, displayViewH)];
self.displayView.backgroundColor = [UIColor blackColor];
......@@ -52,7 +59,32 @@
self.captureTypeLabel.textColor = [UIColor blackColor];
[self.view addSubview:self.captureTypeLabel];
self.startBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, checkBoxViewY + checkBoxViewH + 10, [UIScreen mainScreen].bounds.size.width / 2, 30)];
int bitrateLabelX = 0;
int bitrateLabelY = checkBoxViewY + checkBoxViewH + 10;
int bitrateLabelW = 60;
int bitrateLabelH = 30;
int bitrateBtnW = 90;
self.encodeBitRateLabel = [[UILabel alloc] initWithFrame:CGRectMake(bitrateLabelX, bitrateLabelY, bitrateLabelW, bitrateLabelH)];
self.encodeBitRateLabel.text = @"码率:";
self.encodeBitRateLabel.backgroundColor = [UIColor whiteColor];
self.encodeBitRateLabel.textColor = [UIColor blackColor];
[self.view addSubview:self.encodeBitRateLabel];
self.encodeBitRateField = [[UITextField alloc] initWithFrame:CGRectMake(bitrateLabelX + bitrateLabelW, bitrateLabelY, bounds.size.width - bitrateBtnW - bitrateLabelX - bitrateLabelW, 30)];
self.encodeBitRateField.backgroundColor = [UIColor whiteColor];
self.encodeBitRateField.textColor = [UIColor blackColor];
self.encodeBitRateField.text = @"2000";
self.encodeBitRateField.delegate = self;
[self.view addSubview:self.encodeBitRateField];
self.encodeBitRateSettedBtn = [[UIButton alloc] initWithFrame:CGRectMake(bounds.size.width - bitrateBtnW, bitrateLabelY, bitrateBtnW, 30)];
[self.encodeBitRateSettedBtn setTitle:@"设置" forState:UIControlStateNormal];
[self.encodeBitRateSettedBtn setBackgroundColor:[UIColor whiteColor]];
[self.encodeBitRateSettedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.encodeBitRateSettedBtn addTarget:self action:@selector(setBitrateSender:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.encodeBitRateSettedBtn];
self.startBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, bitrateLabelY + bitrateLabelH + 10, [UIScreen mainScreen].bounds.size.width / 2, 30)];
// self.startBtn.enabled = YES;
[self.startBtn setTitle:@"start" forState:UIControlStateNormal];
[self.startBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
......@@ -64,7 +96,7 @@
[self.startBtn.layer setBorderColor:[UIColor blackColor].CGColor];
[self.view addSubview:self.startBtn];
self.stopBtn = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2, checkBoxViewY + checkBoxViewH + 10, [UIScreen mainScreen].bounds.size.width / 2, 30)];
self.stopBtn = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2, bitrateLabelY + bitrateLabelH + 10, [UIScreen mainScreen].bounds.size.width / 2, 30)];
// self.startBtn.enabled = YES;
[self.stopBtn setTitle:@"stop" forState:UIControlStateNormal];
[self.stopBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
......@@ -114,6 +146,16 @@
self.encoder = nil;
}
- (IBAction)setBitrateSender:(id)sender {
NSString* bitStr = self.encodeBitRateField.text;
int bitrate = [bitStr intValue];
if (self.encoder) {
[self.encoder setOptionWithInt32:kLWVideoOptions_Bitrate value:bitrate];
} else {
self.encoderConfig.bitrate = bitrate;
}
}
#pragma mark LWVideoCaptureSessionDelegate
- (void)onVideoWithSampleBuffer:(CMSampleBufferRef)sampleBuffer {
if (self.encoder) {
......@@ -137,4 +179,9 @@
sampleBuffer:(CMSampleBufferRef)sampleBuffer {
}
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
return [self.encodeBitRateField resignFirstResponder];
}
@end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册