Cleanup FakeRtcEventLog from thread awareness

To avoid it relying on AsyncInvoker.

Bug: webrtc:12339
Change-Id: I086305a74cc05fc8ed88a651e71a8f707c2c1d5c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/202252
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33044}
This commit is contained in:
Danil Chapovalov
2021-01-18 13:29:00 +01:00
committed by Commit Bot
parent 812c73cdc2
commit 4f281f142a
6 changed files with 37 additions and 46 deletions

View File

@ -284,11 +284,9 @@ rtc_library("fake_rtc_event_log") {
]
deps = [
":ice_log",
"../api/rtc_event_log",
"../rtc_base",
"../rtc_base:checks",
"../rtc_base:threading",
"../rtc_base/synchronization:mutex",
]
}

View File

@ -10,31 +10,29 @@
#include "logging/rtc_event_log/fake_rtc_event_log.h"
#include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include <map>
#include <memory>
#include "api/rtc_event_log/rtc_event_log.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
FakeRtcEventLog::FakeRtcEventLog(rtc::Thread* thread) : thread_(thread) {
RTC_DCHECK(thread_);
}
FakeRtcEventLog::~FakeRtcEventLog() = default;
bool FakeRtcEventLog::StartLogging(std::unique_ptr<RtcEventLogOutput> output,
int64_t output_period_ms) {
return true;
}
void FakeRtcEventLog::StopLogging() {
invoker_.Flush(thread_);
}
void FakeRtcEventLog::StopLogging() {}
void FakeRtcEventLog::Log(std::unique_ptr<RtcEvent> event) {
RtcEvent::Type rtc_event_type = event->GetType();
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, thread_, [this, rtc_event_type] {
++count_[rtc_event_type];
});
MutexLock lock(&mu_);
++count_[event->GetType()];
}
int FakeRtcEventLog::GetEventCount(RtcEvent::Type event_type) {
MutexLock lock(&mu_);
return count_[event_type];
}
} // namespace webrtc

View File

@ -16,25 +16,25 @@
#include "api/rtc_event_log/rtc_event.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "rtc_base/async_invoker.h"
#include "rtc_base/thread.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
namespace webrtc {
class FakeRtcEventLog : public RtcEventLog {
public:
explicit FakeRtcEventLog(rtc::Thread* thread);
~FakeRtcEventLog() override;
FakeRtcEventLog() = default;
~FakeRtcEventLog() override = default;
bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
int64_t output_period_ms) override;
void StopLogging() override;
void Log(std::unique_ptr<RtcEvent> event) override;
int GetEventCount(RtcEvent::Type event_type) { return count_[event_type]; }
int GetEventCount(RtcEvent::Type event_type);
private:
std::map<RtcEvent::Type, int> count_;
rtc::Thread* thread_;
rtc::AsyncInvoker invoker_;
Mutex mu_;
std::map<RtcEvent::Type, int> count_ RTC_GUARDED_BY(mu_);
};
} // namespace webrtc

View File

@ -10,14 +10,16 @@
#include "logging/rtc_event_log/fake_rtc_event_log_factory.h"
#include <memory>
#include "api/rtc_event_log/rtc_event_log.h"
#include "logging/rtc_event_log/fake_rtc_event_log.h"
namespace webrtc {
std::unique_ptr<RtcEventLog> FakeRtcEventLogFactory::CreateRtcEventLog(
RtcEventLog::EncodingType encoding_type) {
std::unique_ptr<RtcEventLog> fake_event_log(new FakeRtcEventLog(thread()));
RtcEventLog::EncodingType /*encoding_type*/) {
auto fake_event_log = std::make_unique<FakeRtcEventLog>();
last_log_created_ = fake_event_log.get();
return fake_event_log;
}

View File

@ -15,24 +15,21 @@
#include "api/rtc_event_log/rtc_event_log_factory_interface.h"
#include "logging/rtc_event_log/fake_rtc_event_log.h"
#include "rtc_base/thread.h"
namespace webrtc {
class FakeRtcEventLogFactory : public RtcEventLogFactoryInterface {
public:
explicit FakeRtcEventLogFactory(rtc::Thread* thread) : thread_(thread) {}
~FakeRtcEventLogFactory() override {}
FakeRtcEventLogFactory() = default;
~FakeRtcEventLogFactory() override = default;
std::unique_ptr<RtcEventLog> CreateRtcEventLog(
RtcEventLog::EncodingType encoding_type) override;
webrtc::RtcEventLog* last_log_created() { return last_log_created_; }
rtc::Thread* thread() { return thread_; }
webrtc::FakeRtcEventLog* last_log_created() { return last_log_created_; }
private:
webrtc::RtcEventLog* last_log_created_;
rtc::Thread* thread_;
webrtc::FakeRtcEventLog* last_log_created_;
};
} // namespace webrtc

View File

@ -1356,11 +1356,9 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test {
const PeerConnectionFactory::Options* options,
const RTCConfiguration* config,
webrtc::PeerConnectionDependencies dependencies) {
std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory(
new webrtc::FakeRtcEventLogFactory(rtc::Thread::Current()));
return CreatePeerConnectionWrapper(debug_name, options, config,
std::move(dependencies),
std::move(event_log_factory),
return CreatePeerConnectionWrapper(
debug_name, options, config, std::move(dependencies),
std::make_unique<webrtc::FakeRtcEventLogFactory>(),
/*reset_encoder_factory=*/false,
/*reset_decoder_factory=*/false);
}
@ -5238,11 +5236,9 @@ TEST_P(PeerConnectionIntegrationTest,
ASSERT_NE(nullptr, caller()->event_log_factory());
ASSERT_NE(nullptr, callee()->event_log_factory());
webrtc::FakeRtcEventLog* caller_event_log =
static_cast<webrtc::FakeRtcEventLog*>(
caller()->event_log_factory()->last_log_created());
caller()->event_log_factory()->last_log_created();
webrtc::FakeRtcEventLog* callee_event_log =
static_cast<webrtc::FakeRtcEventLog*>(
callee()->event_log_factory()->last_log_created());
callee()->event_log_factory()->last_log_created();
ASSERT_NE(nullptr, caller_event_log);
ASSERT_NE(nullptr, callee_event_log);
int caller_ice_config_count = caller_event_log->GetEventCount(