Fix for RtcEventLog ObjC interface

This moves the RtcEventLog start/stop functions to PeerConnection on the objC interface.

BUG=
R=tkchin@webrtc.org

Review URL: https://codereview.webrtc.org/2106103003 .

Cr-Commit-Position: refs/heads/master@{#13337}
This commit is contained in:
Ivo Creusen 2016-06-30 09:31:52 +02:00
parent a3333bfafb
commit c43bf56ef1
5 changed files with 44 additions and 46 deletions

View File

@ -308,11 +308,13 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB.
_isInitiator = NO; _isInitiator = NO;
_hasReceivedSdp = NO; _hasReceivedSdp = NO;
_messageQueue = [NSMutableArray array]; _messageQueue = [NSMutableArray array];
#if defined(WEBRTC_IOS)
[_peerConnection stopRtcEventLog];
#endif
_peerConnection = nil; _peerConnection = nil;
self.state = kARDAppClientStateDisconnected; self.state = kARDAppClientStateDisconnected;
#if defined(WEBRTC_IOS) #if defined(WEBRTC_IOS)
RTCStopInternalCapture(); RTCStopInternalCapture();
[_factory stopRtcEventLog];
#endif #endif
} }
@ -526,17 +528,6 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB.
} }
self.state = kARDAppClientStateConnected; self.state = kARDAppClientStateConnected;
#if defined(WEBRTC_IOS)
// Start event log.
if (kARDAppClientEnableRtcEventLog) {
NSString *filePath = [self documentsFilePathForFileName:@"webrtc-rtceventlog"];
if (![_factory startRtcEventLogWithFilePath:filePath
maxSizeInBytes:kARDAppClientRtcEventLogMaxSizeInBytes]) {
RTCLogError(@"Failed to start event logging.");
}
}
#endif
// Create peer connection. // Create peer connection.
RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints];
RTCConfiguration *config = [[RTCConfiguration alloc] init]; RTCConfiguration *config = [[RTCConfiguration alloc] init];
@ -562,6 +553,16 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB.
// Check if we've received an offer. // Check if we've received an offer.
[self drainMessageQueueIfReady]; [self drainMessageQueueIfReady];
} }
#if defined(WEBRTC_IOS)
// Start event log.
if (kARDAppClientEnableRtcEventLog) {
NSString *filePath = [self documentsFilePathForFileName:@"webrtc-rtceventlog"];
if (![_peerConnection startRtcEventLogWithFilePath:filePath
maxSizeInBytes:kARDAppClientRtcEventLogMaxSizeInBytes]) {
RTCLogError(@"Failed to start event logging.");
}
}
#endif
} }
// Processes the messages that we've received from the room server and the // Processes the messages that we've received from the room server and the

View File

@ -207,6 +207,7 @@ void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved(
NSMutableArray *_localStreams; NSMutableArray *_localStreams;
std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer;
rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection;
BOOL _hasStartedRtcEventLog;
} }
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
@ -356,6 +357,31 @@ void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved(
_peerConnection->SetRemoteDescription(observer, sdp.nativeDescription); _peerConnection->SetRemoteDescription(observer, sdp.nativeDescription);
} }
- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
maxSizeInBytes:(int64_t)maxSizeInBytes {
RTC_DCHECK(filePath.length);
RTC_DCHECK_GT(maxSizeInBytes, 0);
RTC_DCHECK(!_hasStartedRtcEventLog);
if (_hasStartedRtcEventLog) {
RTCLogError(@"Event logging already started.");
return NO;
}
int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR);
if (fd < 0) {
RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno);
return NO;
}
_hasStartedRtcEventLog =
_peerConnection->StartRtcEventLog(fd, maxSizeInBytes);
return _hasStartedRtcEventLog;
}
- (void)stopRtcEventLog {
_peerConnection->StopRtcEventLog();
_hasStartedRtcEventLog = NO;
}
- (RTCRtpSender *)senderWithKind:(NSString *)kind - (RTCRtpSender *)senderWithKind:(NSString *)kind
streamId:(NSString *)streamId { streamId:(NSString *)streamId {
std::string nativeKind = [NSString stdStringForString:kind]; std::string nativeKind = [NSString stdStringForString:kind];

View File

@ -10,8 +10,6 @@
#import "RTCPeerConnectionFactory+Private.h" #import "RTCPeerConnectionFactory+Private.h"
#include <memory>
#import "NSString+StdString.h" #import "NSString+StdString.h"
#import "RTCAVFoundationVideoSource+Private.h" #import "RTCAVFoundationVideoSource+Private.h"
#import "RTCAudioTrack+Private.h" #import "RTCAudioTrack+Private.h"
@ -19,15 +17,11 @@
#import "RTCPeerConnection+Private.h" #import "RTCPeerConnection+Private.h"
#import "RTCVideoSource+Private.h" #import "RTCVideoSource+Private.h"
#import "RTCVideoTrack+Private.h" #import "RTCVideoTrack+Private.h"
#import "WebRTC/RTCLogging.h"
#include "webrtc/base/checks.h"
@implementation RTCPeerConnectionFactory { @implementation RTCPeerConnectionFactory {
std::unique_ptr<rtc::Thread> _networkThread; std::unique_ptr<rtc::Thread> _networkThread;
std::unique_ptr<rtc::Thread> _workerThread; std::unique_ptr<rtc::Thread> _workerThread;
std::unique_ptr<rtc::Thread> _signalingThread; std::unique_ptr<rtc::Thread> _signalingThread;
BOOL _hasStartedRtcEventLog;
} }
@synthesize nativeFactory = _nativeFactory; @synthesize nativeFactory = _nativeFactory;
@ -54,29 +48,6 @@
return self; return self;
} }
- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
maxSizeInBytes:(int64_t)maxSizeInBytes {
RTC_DCHECK(filePath.length);
RTC_DCHECK_GT(maxSizeInBytes, 0);
RTC_DCHECK(!_hasStartedRtcEventLog);
if (_hasStartedRtcEventLog) {
RTCLogError(@"Event logging already started.");
return NO;
}
int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd < 0) {
RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno);
return NO;
}
_hasStartedRtcEventLog = _nativeFactory->StartRtcEventLog(fd, maxSizeInBytes);
return _hasStartedRtcEventLog;
}
- (void)stopRtcEventLog {
_nativeFactory->StopRtcEventLog();
_hasStartedRtcEventLog = NO;
}
- (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints:
(nullable RTCMediaConstraints *)constraints { (nullable RTCMediaConstraints *)constraints {
return [[RTCAVFoundationVideoSource alloc] initWithFactory:self return [[RTCAVFoundationVideoSource alloc] initWithFactory:self

View File

@ -183,6 +183,11 @@ RTC_EXPORT
completionHandler: completionHandler:
(nullable void (^)(NSError * _Nullable error))completionHandler; (nullable void (^)(NSError * _Nullable error))completionHandler;
/** Start or stop recording an Rtc EventLog. */
- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
maxSizeInBytes:(int64_t)maxSizeInBytes;
- (void)stopRtcEventLog;
@end @end
@interface RTCPeerConnection (Media) @interface RTCPeerConnection (Media)

View File

@ -53,11 +53,6 @@ RTC_EXPORT
delegate: delegate:
(nullable id<RTCPeerConnectionDelegate>)delegate; (nullable id<RTCPeerConnectionDelegate>)delegate;
/** Temporary interface. Use at your own risk. See peerconnectioninterface.h for details. */
- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath
maxSizeInBytes:(int64_t)maxSizeInBytes;
- (void)stopRtcEventLog;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END