Added the API to create an RTCRtpSender to the Objective C wrapper.
Objective C applications can now create new RTCRtpSenders and change their tracks, which gives them more fine grained control than MediaStreams. BUG= Review-Url: https://codereview.webrtc.org/1888633002 Cr-Commit-Position: refs/heads/master@{#12570}
This commit is contained in:
@ -12,6 +12,11 @@
|
||||
|
||||
#import "NSString+StdString.h"
|
||||
|
||||
NSString * const kRTCMediaStreamTrackKindAudio =
|
||||
@(webrtc::MediaStreamTrackInterface::kAudioKind);
|
||||
NSString * const kRTCMediaStreamTrackKindVideo =
|
||||
@(webrtc::MediaStreamTrackInterface::kVideoKind);
|
||||
|
||||
@implementation RTCMediaStreamTrack {
|
||||
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> _nativeTrack;
|
||||
RTCMediaStreamTrackType _type;
|
||||
|
||||
@ -311,6 +311,17 @@ void PeerConnectionDelegateAdapter::OnIceCandidate(
|
||||
_peerConnection->SetRemoteDescription(observer, sdp.nativeDescription);
|
||||
}
|
||||
|
||||
- (RTCRtpSender *)senderWithKind:(NSString *)kind
|
||||
streamId:(NSString *)streamId {
|
||||
std::string nativeKind = [NSString stdStringForString:kind];
|
||||
std::string nativeStreamId = [NSString stdStringForString:streamId];
|
||||
rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeSender(
|
||||
_peerConnection->CreateSender(nativeKind, nativeStreamId));
|
||||
return nativeSender ?
|
||||
[[RTCRtpSender alloc] initWithNativeRtpSender:nativeSender]
|
||||
: nil;
|
||||
}
|
||||
|
||||
- (NSArray<RTCRtpSender *> *)senders {
|
||||
std::vector<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenders(
|
||||
_peerConnection->GetSenders());
|
||||
|
||||
@ -10,8 +10,10 @@
|
||||
|
||||
#import "RTCRtpSender+Private.h"
|
||||
|
||||
#import "NSString+StdString.h"
|
||||
#import "RTCMediaStreamTrack+Private.h"
|
||||
#import "RTCRtpParameters+Private.h"
|
||||
#import "WebRTC/RTCLogging.h"
|
||||
|
||||
#include "webrtc/api/mediastreaminterface.h"
|
||||
|
||||
@ -21,19 +23,28 @@
|
||||
|
||||
- (instancetype)initWithNativeRtpSender:
|
||||
(rtc::scoped_refptr<webrtc::RtpSenderInterface>)nativeRtpSender {
|
||||
NSParameterAssert(nativeRtpSender);
|
||||
if (self = [super init]) {
|
||||
_nativeRtpSender = nativeRtpSender;
|
||||
RTCLogInfo(@"RTCRtpSender(%p): created sender: %@", self, self.description);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)senderId {
|
||||
return [NSString stringForStdString:_nativeRtpSender->id()];
|
||||
}
|
||||
|
||||
- (RTCRtpParameters *)parameters {
|
||||
return [[RTCRtpParameters alloc]
|
||||
initWithNativeParameters:_nativeRtpSender->GetParameters()];
|
||||
}
|
||||
|
||||
- (BOOL)setParameters:(RTCRtpParameters *)parameters {
|
||||
return _nativeRtpSender->SetParameters(parameters.nativeParameters);
|
||||
- (void)setParameters:(RTCRtpParameters *)parameters {
|
||||
if (!_nativeRtpSender->SetParameters(parameters.nativeParameters)) {
|
||||
RTCLogError(@"RTCRtpSender(%p): Failed to set parameters: %@", self,
|
||||
parameters);
|
||||
}
|
||||
}
|
||||
|
||||
- (RTCMediaStreamTrack *)track {
|
||||
@ -45,4 +56,15 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setTrack:(RTCMediaStreamTrack *)track {
|
||||
if (!_nativeRtpSender->SetTrack(track.nativeTrack)) {
|
||||
RTCLogError(@"RTCRtpSender(%p): Failed to set track %@", self, track);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
return [NSString stringWithFormat:@"RTCRtpSender {\n senderId: %@\n}",
|
||||
self.senderId];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user