Added functions on libjingle API to start and stop the recording of an RtcEventLog.

BUG=webrtc:4741

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

Cr-Commit-Position: refs/heads/master@{#10297}
This commit is contained in:
ivoc
2015-10-16 02:22:18 -07:00
committed by Commit bot
parent f85efaeb73
commit 112a3d81db
12 changed files with 134 additions and 16 deletions

View File

@ -218,6 +218,16 @@ bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file) {
return channel_manager_->StartAecDump(file);
}
bool PeerConnectionFactory::StartRtcEventLog(rtc::PlatformFile file) {
RTC_DCHECK(signaling_thread_->IsCurrent());
return channel_manager_->StartRtcEventLog(file);
}
void PeerConnectionFactory::StopRtcEventLog() {
RTC_DCHECK(signaling_thread_->IsCurrent());
channel_manager_->StopRtcEventLog();
}
rtc::scoped_refptr<PeerConnectionInterface>
PeerConnectionFactory::CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,

View File

@ -80,6 +80,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
AudioSourceInterface* audio_source) override;
bool StartAecDump(rtc::PlatformFile file) override;
bool StartRtcEventLog(rtc::PlatformFile file) override;
void StopRtcEventLog() override;
virtual webrtc::MediaControllerInterface* CreateMediaController() const;
virtual rtc::Thread* signaling_thread();

View File

@ -62,6 +62,8 @@ BEGIN_PROXY_MAP(PeerConnectionFactory)
PROXY_METHOD2(rtc::scoped_refptr<AudioTrackInterface>,
CreateAudioTrack, const std::string&, AudioSourceInterface*)
PROXY_METHOD1(bool, StartAecDump, rtc::PlatformFile)
PROXY_METHOD1(bool, StartRtcEventLog, rtc::PlatformFile)
PROXY_METHOD0(void, StopRtcEventLog)
private:
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_ot(

View File

@ -619,6 +619,22 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
// http://crbug.com/264611.
virtual bool StartAecDump(rtc::PlatformFile file) = 0;
// Starts RtcEventLog using existing file. Takes ownership of |file| and
// passes it on to VoiceEngine, which will take the ownership. If the
// operation fails the file will be closed. The logging will stop
// automatically after 10 minutes have passed, or when the StopRtcEventLog
// function is called.
// This function as well as the StopRtcEventLog don't really belong on this
// interface, this is a temporary solution until we move the logging object
// from inside voice engine to webrtc::Call, which will happen when the VoE
// restructuring effort is further along.
// TODO(ivoc): Move this into being:
// PeerConnection => MediaController => webrtc::Call.
virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
// Stops logging the RtcEventLog.
virtual void StopRtcEventLog() = 0;
protected:
// Dtor and ctor protected as objects shouldn't be created or deleted via
// this interface.

View File

@ -785,6 +785,10 @@ class FakeVoiceEngine : public FakeBaseEngine {
bool StartAecDump(rtc::PlatformFile file) { return false; }
bool StartRtcEventLog(rtc::PlatformFile file) { return false; }
void StopRtcEventLog() {}
private:
std::vector<FakeVoiceMediaChannel*> channels_;
std::vector<AudioCodec> codecs_;

View File

@ -121,6 +121,12 @@ class MediaEngineInterface {
// Starts AEC dump using existing file.
virtual bool StartAecDump(rtc::PlatformFile file) = 0;
// Starts RtcEventLog using existing file.
virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
// Stops recording an RtcEventLog.
virtual void StopRtcEventLog() = 0;
};
@ -219,6 +225,12 @@ class CompositeMediaEngine : public MediaEngineInterface {
return voice_.StartAecDump(file);
}
virtual bool StartRtcEventLog(rtc::PlatformFile file) {
return voice_.StartRtcEventLog(file);
}
virtual void StopRtcEventLog() { voice_.StopRtcEventLog(); }
protected:
VOICE voice_;
VIDEO video_;
@ -251,6 +263,8 @@ class NullVoiceEngine {
}
void SetLogging(int min_sev, const char* filter) {}
bool StartAecDump(rtc::PlatformFile file) { return false; }
bool StartRtcEventLog(rtc::PlatformFile file) { return false; }
void StopRtcEventLog() {}
private:
std::vector<AudioCodec> codecs_;

View File

@ -50,6 +50,7 @@
#include "webrtc/base/logging.h"
#include "webrtc/base/stringencode.h"
#include "webrtc/base/stringutils.h"
#include "webrtc/call/rtc_event_log.h"
#include "webrtc/common.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/system_wrappers/interface/field_trial.h"
@ -1306,6 +1307,14 @@ void WebRtcVoiceEngine::StopAecDump() {
}
}
bool WebRtcVoiceEngine::StartRtcEventLog(rtc::PlatformFile file) {
return voe_wrapper_->codec()->GetEventLog()->StartLogging(file);
}
void WebRtcVoiceEngine::StopRtcEventLog() {
voe_wrapper_->codec()->GetEventLog()->StopLogging();
}
int WebRtcVoiceEngine::CreateVoiceChannel(VoEWrapper* voice_engine_wrapper) {
return voice_engine_wrapper->base()->CreateChannel(voe_config_);
}

View File

@ -108,6 +108,13 @@ class WebRtcVoiceEngine
// Starts AEC dump using existing file.
bool StartAecDump(rtc::PlatformFile file);
// Starts recording an RtcEventLog using an existing file until 10 minutes
// pass or the StopRtcEventLog function is called.
bool StartRtcEventLog(rtc::PlatformFile file);
// Stops recording the RtcEventLog.
void StopRtcEventLog();
// Create a VoiceEngine Channel.
int CreateMediaVoiceChannel();

View File

@ -630,4 +630,14 @@ bool ChannelManager::StartAecDump(rtc::PlatformFile file) {
Bind(&MediaEngineInterface::StartAecDump, media_engine_.get(), file));
}
bool ChannelManager::StartRtcEventLog(rtc::PlatformFile file) {
return worker_thread_->Invoke<bool>(
Bind(&MediaEngineInterface::StartRtcEventLog, media_engine_.get(), file));
}
void ChannelManager::StopRtcEventLog() {
worker_thread_->Invoke<void>(
Bind(&MediaEngineInterface::StopRtcEventLog, media_engine_.get()));
}
} // namespace cricket

View File

@ -170,6 +170,12 @@ class ChannelManager : public rtc::MessageHandler,
// Starts AEC dump using existing file.
bool StartAecDump(rtc::PlatformFile file);
// Starts RtcEventLog using existing file.
bool StartRtcEventLog(rtc::PlatformFile file);
// Stops logging RtcEventLog.
void StopRtcEventLog();
sigslot::signal2<VideoCapturer*, CaptureState> SignalVideoCaptureStateChange;
protected:

View File

@ -37,6 +37,7 @@ namespace webrtc {
class RtcEventLogImpl final : public RtcEventLog {
public:
void StartLogging(const std::string& file_name, int duration_ms) override {}
bool StartLogging(rtc::PlatformFile log_file) override { return false; }
void StopLogging(void) override {}
void LogVideoReceiveStreamConfig(
const VideoReceiveStream::Config& config) override {}
@ -57,9 +58,8 @@ class RtcEventLogImpl final : public RtcEventLog {
class RtcEventLogImpl final : public RtcEventLog {
public:
RtcEventLogImpl();
void StartLogging(const std::string& file_name, int duration_ms) override;
bool StartLogging(rtc::PlatformFile log_file) override;
void StopLogging() override;
void LogVideoReceiveStreamConfig(
const VideoReceiveStream::Config& config) override;
@ -75,6 +75,9 @@ class RtcEventLogImpl final : public RtcEventLog {
void LogAudioPlayout(uint32_t ssrc) override;
private:
// Starts logging. This function assumes the file_ has been opened succesfully
// and that the start_time_us_ and _duration_us_ have been set.
void StartLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
// Stops logging and clears the stored data and buffers.
void StopLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
// Adds a new event to the logfile if logging is active, or adds it to the
@ -93,13 +96,16 @@ class RtcEventLogImpl final : public RtcEventLog {
const int recent_log_duration_us = 10000000;
rtc::CriticalSection crit_;
rtc::scoped_ptr<FileWrapper> file_ GUARDED_BY(crit_);
rtc::scoped_ptr<FileWrapper> file_ GUARDED_BY(crit_) =
rtc::scoped_ptr<FileWrapper>(FileWrapper::Create());
rtc::PlatformFile platform_file_ GUARDED_BY(crit_) =
rtc::kInvalidPlatformFileValue;
rtclog::EventStream stream_ GUARDED_BY(crit_);
std::deque<rtclog::Event> recent_log_events_ GUARDED_BY(crit_);
bool currently_logging_ GUARDED_BY(crit_);
int64_t start_time_us_ GUARDED_BY(crit_);
int64_t duration_us_ GUARDED_BY(crit_);
const Clock* const clock_;
bool currently_logging_ GUARDED_BY(crit_) = false;
int64_t start_time_us_ GUARDED_BY(crit_) = 0;
int64_t duration_us_ GUARDED_BY(crit_) = 0;
const Clock* const clock_ = Clock::GetRealTimeClock();
};
namespace {
@ -143,14 +149,6 @@ rtclog::MediaType ConvertMediaType(MediaType media_type) {
} // namespace
// RtcEventLogImpl member functions.
RtcEventLogImpl::RtcEventLogImpl()
: file_(FileWrapper::Create()),
stream_(),
currently_logging_(false),
start_time_us_(0),
duration_us_(0),
clock_(Clock::GetRealTimeClock()) {
}
void RtcEventLogImpl::StartLogging(const std::string& file_name,
int duration_ms) {
@ -161,9 +159,39 @@ void RtcEventLogImpl::StartLogging(const std::string& file_name,
if (file_->OpenFile(file_name.c_str(), false) != 0) {
return;
}
currently_logging_ = true;
start_time_us_ = clock_->TimeInMicroseconds();
duration_us_ = static_cast<int64_t>(duration_ms) * 1000;
StartLoggingLocked();
}
bool RtcEventLogImpl::StartLogging(rtc::PlatformFile log_file) {
rtc::CritScope lock(&crit_);
if (currently_logging_) {
StopLoggingLocked();
}
RTC_DCHECK(platform_file_ == rtc::kInvalidPlatformFileValue);
FILE* file_stream = rtc::FdopenPlatformFileForWriting(log_file);
if (!file_stream) {
rtc::ClosePlatformFile(log_file);
return false;
}
if (file_->OpenFromFileHandle(file_stream, true, false) != 0) {
rtc::ClosePlatformFile(log_file);
return false;
}
platform_file_ = log_file;
// Set the start time and duration to keep logging for 10 minutes.
start_time_us_ = clock_->TimeInMicroseconds();
duration_us_ = 10 * 60 * 1000000;
StartLoggingLocked();
return true;
}
void RtcEventLogImpl::StartLoggingLocked() {
currently_logging_ = true;
// Write all the recent events to the log file, ignoring any old events.
for (auto& event : recent_log_events_) {
if (event.timestamp_us() >= start_time_us_ - recent_log_duration_us) {
@ -339,6 +367,10 @@ void RtcEventLogImpl::StopLoggingLocked() {
RTC_DCHECK(file_->Open());
StoreToFile(&event);
file_->CloseFile();
if (platform_file_ != rtc::kInvalidPlatformFileValue) {
rtc::ClosePlatformFile(platform_file_);
platform_file_ = rtc::kInvalidPlatformFileValue;
}
}
RTC_DCHECK(!file_->Open());
stream_.Clear();

View File

@ -13,6 +13,7 @@
#include <string>
#include "webrtc/base/platform_file.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/video_receive_stream.h"
#include "webrtc/video_send_stream.h"
@ -41,6 +42,11 @@ class RtcEventLog {
// If the file cannot be opened, the RtcEventLog will not start logging.
virtual void StartLogging(const std::string& file_name, int duration_ms) = 0;
// Starts logging until either the 10 minute timer runs out or the StopLogging
// function is called. The RtcEventLog takes ownership of the supplied
// rtc::PlatformFile.
virtual bool StartLogging(rtc::PlatformFile log_file) = 0;
virtual void StopLogging() = 0;
// Logs configuration information for webrtc::VideoReceiveStream