Adding injectable audio decoder and encoder factory support to the RTCPeerConnection obj-c layer.

Bug: webrtc:8093
Change-Id: I868ce5f75a72c6deb065dec60784289d045ae22a
Reviewed-on: https://chromium-review.googlesource.com/608981
Commit-Queue: Jeremy Newton-Smith <jeremyns@webrtc.org>
Reviewed-by: Zeke Chin <tkchin@webrtc.org>
Reviewed-by: Kári Tristan Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#19477}
This commit is contained in:
Jeremy Newton-Smith
2017-08-23 10:02:23 -07:00
committed by Commit Bot
parent 82fac89381
commit 96de428fd1
10 changed files with 248 additions and 60 deletions

View File

@ -0,0 +1,27 @@
/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import "WebRTC/RTCBuiltinAudioDecoderFactory.h"
#include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
#include "webrtc/rtc_base/scoped_ref_ptr.h"
@implementation RTCBuiltinAudioDecoderFactory {
rtc::scoped_refptr<webrtc::AudioDecoderFactory> _nativeAudioDecoderFactory;
}
- (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)nativeAudioDecoderFactory {
if (_nativeAudioDecoderFactory == nullptr) {
_nativeAudioDecoderFactory = webrtc::CreateBuiltinAudioDecoderFactory();
}
return _nativeAudioDecoderFactory;
}
@end

View File

@ -0,0 +1,27 @@
/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import "WebRTC/RTCBuiltinAudioEncoderFactory.h"
#include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h"
#include "webrtc/rtc_base/scoped_ref_ptr.h"
@implementation RTCBuiltinAudioEncoderFactory {
rtc::scoped_refptr<webrtc::AudioEncoderFactory> _nativeAudioEncoderFactory;
}
- (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)nativeAudioEncoderFactory {
if (_nativeAudioEncoderFactory == nullptr) {
_nativeAudioEncoderFactory = webrtc::CreateBuiltinAudioEncoderFactory();
}
return _nativeAudioEncoderFactory;
}
@end

View File

@ -19,9 +19,13 @@
#import "RTCPeerConnection+Private.h"
#import "RTCVideoSource+Private.h"
#import "RTCVideoTrack+Private.h"
#import "WebRTC/RTCAudioDecoderFactory.h"
#import "WebRTC/RTCAudioEncoderFactory.h"
#import "WebRTC/RTCLogging.h"
#import "WebRTC/RTCVideoCodecFactory.h"
#ifndef HAVE_NO_MEDIA
#import "WebRTC/RTCBuiltinAudioDecoderFactory.h"
#import "WebRTC/RTCBuiltinAudioEncoderFactory.h"
#import "WebRTC/RTCVideoCodecH264.h"
#endif
@ -47,15 +51,22 @@
- (instancetype)init {
#ifdef HAVE_NO_MEDIA
return [self initWithEncoderFactory:nil decoderFactory:nil];
return [self initWithAudioEncoderFactory:nil
audioDecoderFactory:nil
videoEncoderFactory:nil
videoDecoderFactory:nil];
#else
return [self initWithEncoderFactory:[[RTCVideoEncoderFactoryH264 alloc] init]
decoderFactory:[[RTCVideoDecoderFactoryH264 alloc] init]];
return [self initWithAudioEncoderFactory:[[RTCBuiltinAudioEncoderFactory alloc] init]
audioDecoderFactory:[[RTCBuiltinAudioDecoderFactory alloc] init]
videoEncoderFactory:[[RTCVideoEncoderFactoryH264 alloc] init]
videoDecoderFactory:[[RTCVideoDecoderFactoryH264 alloc] init]];
#endif
}
- (instancetype)initWithEncoderFactory:(nullable id<RTCVideoEncoderFactory>)encoderFactory
decoderFactory:(nullable id<RTCVideoDecoderFactory>)decoderFactory {
- (instancetype)initWithAudioEncoderFactory:(id<RTCAudioEncoderFactory>)audioEncoderFactory
audioDecoderFactory:(id<RTCAudioDecoderFactory>)audioDecoderFactory
videoEncoderFactory:(id<RTCVideoEncoderFactory>)videoEncoderFactory
videoDecoderFactory:(id<RTCVideoDecoderFactory>)videoDecoderFactory {
if (self = [super init]) {
_networkThread = rtc::Thread::CreateWithSocketServer();
BOOL result = _networkThread->Start();
@ -83,13 +94,21 @@
std::unique_ptr<webrtc::CallFactoryInterface>(),
std::unique_ptr<webrtc::RtcEventLogFactoryInterface>());
#else
cricket::WebRtcVideoEncoderFactory *platform_encoder_factory = nullptr;
cricket::WebRtcVideoDecoderFactory *platform_decoder_factory = nullptr;
if (encoderFactory) {
platform_encoder_factory = new webrtc::ObjCVideoEncoderFactory(encoderFactory);
rtc::scoped_refptr<webrtc::AudioEncoderFactory> platform_audio_encoder_factory = nullptr;
rtc::scoped_refptr<webrtc::AudioDecoderFactory> platform_audio_decoder_factory = nullptr;
if (audioEncoderFactory) {
platform_audio_encoder_factory = [audioEncoderFactory nativeAudioEncoderFactory];
}
if (decoderFactory) {
platform_decoder_factory = new webrtc::ObjCVideoDecoderFactory(decoderFactory);
if (audioDecoderFactory) {
platform_audio_decoder_factory = [audioDecoderFactory nativeAudioDecoderFactory];
}
cricket::WebRtcVideoEncoderFactory *platform_video_encoder_factory = nullptr;
cricket::WebRtcVideoDecoderFactory *platform_video_decoder_factory = nullptr;
if (videoEncoderFactory) {
platform_video_encoder_factory = new webrtc::ObjCVideoEncoderFactory(videoEncoderFactory);
}
if (videoDecoderFactory) {
platform_video_decoder_factory = new webrtc::ObjCVideoDecoderFactory(videoDecoderFactory);
}
// Ownership of encoder/decoder factories is passed on to the
@ -97,9 +116,11 @@
_nativeFactory = webrtc::CreatePeerConnectionFactory(_networkThread.get(),
_workerThread.get(),
_signalingThread.get(),
nullptr,
platform_encoder_factory,
platform_decoder_factory);
nullptr, // audio device module
platform_audio_encoder_factory,
platform_audio_decoder_factory,
platform_video_encoder_factory,
platform_video_decoder_factory);
#endif
NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
}
@ -121,15 +142,12 @@
return [self audioTrackWithSource:audioSource trackId:trackId];
}
- (RTCAudioTrack *)audioTrackWithSource:(RTCAudioSource *)source
trackId:(NSString *)trackId {
return [[RTCAudioTrack alloc] initWithFactory:self
source:source
trackId:trackId];
- (RTCAudioTrack *)audioTrackWithSource:(RTCAudioSource *)source trackId:(NSString *)trackId {
return [[RTCAudioTrack alloc] initWithFactory:self source:source trackId:trackId];
}
- (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints:
(nullable RTCMediaConstraints *)constraints {
(nullable RTCMediaConstraints *)constraints {
#ifdef HAVE_NO_MEDIA
return nil;
#else
@ -146,32 +164,25 @@
objcVideoTrackSource)];
}
- (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source
trackId:(NSString *)trackId {
return [[RTCVideoTrack alloc] initWithFactory:self
source:source
trackId:trackId];
- (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source trackId:(NSString *)trackId {
return [[RTCVideoTrack alloc] initWithFactory:self source:source trackId:trackId];
}
- (RTCMediaStream *)mediaStreamWithStreamId:(NSString *)streamId {
return [[RTCMediaStream alloc] initWithFactory:self
streamId:streamId];
return [[RTCMediaStream alloc] initWithFactory:self streamId:streamId];
}
- (RTCPeerConnection *)peerConnectionWithConfiguration:
(RTCConfiguration *)configuration
constraints:
(RTCMediaConstraints *)constraints
- (RTCPeerConnection *)peerConnectionWithConfiguration:(RTCConfiguration *)configuration
constraints:(RTCMediaConstraints *)constraints
delegate:
(nullable id<RTCPeerConnectionDelegate>)delegate {
(nullable id<RTCPeerConnectionDelegate>)delegate {
return [[RTCPeerConnection alloc] initWithFactory:self
configuration:configuration
constraints:constraints
delegate:delegate];
}
- (BOOL)startAecDumpWithFilePath:(NSString *)filePath
maxSizeInBytes:(int64_t)maxSizeInBytes {
- (BOOL)startAecDumpWithFilePath:(NSString *)filePath maxSizeInBytes:(int64_t)maxSizeInBytes {
RTC_DCHECK(filePath.length);
RTC_DCHECK_GT(maxSizeInBytes, 0);