Remove MessageHandler usage in pc test helpers

Bug: webrtc:11988
Change-Id: If4175c51b990d1d8ff6eb9a9ba63fa92139b95b6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272404
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37848}
This commit is contained in:
Danil Chapovalov 2022-08-19 18:22:15 +02:00 committed by WebRTC LUCI CQ
parent b1372f973a
commit 372ecc30fa
4 changed files with 36 additions and 78 deletions

View File

@ -2675,6 +2675,7 @@ if (rtc_include_tests && !build_with_chromium) {
"../api/audio_codecs:audio_codecs_api",
"../api/task_queue",
"../api/task_queue:default_task_queue_factory",
"../api/units:time_delta",
"../api/video:builtin_video_bitrate_allocator_factory",
"../api/video:video_frame",
"../api/video:video_rtp_headers",
@ -2694,7 +2695,6 @@ if (rtc_include_tests && !build_with_chromium) {
"../rtc_base",
"../rtc_base:checks",
"../rtc_base:gunit_helpers",
"../rtc_base:location",
"../rtc_base:logging",
"../rtc_base:macromagic",
"../rtc_base:rtc_task_queue",

View File

@ -13,11 +13,13 @@
#include <string.h>
#include "api/make_ref_counted.h"
#include "api/units/time_delta.h"
#include "rtc_base/checks.h"
#include "rtc_base/location.h"
#include "rtc_base/thread.h"
#include "rtc_base/time_utils.h"
using ::webrtc::TimeDelta;
// Audio sample value that is high enough that it doesn't occur naturally when
// frames are being faked. E.g. NetEq will not generate this large sample value
// unless it has received an audio frame containing a sample of this value.
@ -33,11 +35,6 @@ static const int kTotalDelayMs = 0;
static const int kClockDriftMs = 0;
static const uint32_t kMaxVolume = 14392;
enum {
MSG_START_PROCESS,
MSG_RUN_PROCESS,
};
FakeAudioCaptureModule::FakeAudioCaptureModule()
: audio_callback_(nullptr),
recording_(false),
@ -386,21 +383,6 @@ int32_t FakeAudioCaptureModule::PlayoutDelay(uint16_t* delay_ms) const {
return 0;
}
void FakeAudioCaptureModule::OnMessage(rtc::Message* msg) {
switch (msg->message_id) {
case MSG_START_PROCESS:
StartProcessP();
break;
case MSG_RUN_PROCESS:
ProcessFrameP();
break;
default:
// All existing messages should be caught. Getting here should never
// happen.
RTC_DCHECK_NOTREACHED();
}
}
bool FakeAudioCaptureModule::Initialize() {
// Set the send buffer samples high enough that it would not occur on the
// remote side unless a packet containing a sample of that magnitude has been
@ -444,7 +426,7 @@ void FakeAudioCaptureModule::UpdateProcessing(bool start) {
process_thread_ = rtc::Thread::Create();
process_thread_->Start();
}
process_thread_->Post(RTC_FROM_HERE, this, MSG_START_PROCESS);
process_thread_->PostTask([this] { StartProcessP(); });
} else {
if (process_thread_) {
process_thread_->Stop();
@ -490,7 +472,8 @@ void FakeAudioCaptureModule::ProcessFrameP() {
const int64_t current_time = rtc::TimeMillis();
const int64_t wait_time =
(next_frame_time_ > current_time) ? next_frame_time_ - current_time : 0;
process_thread_->PostDelayed(RTC_FROM_HERE, wait_time, this, MSG_RUN_PROCESS);
process_thread_->PostDelayedTask([this] { ProcessFrameP(); },
TimeDelta::Millis(wait_time));
}
void FakeAudioCaptureModule::ReceiveFrameP() {

View File

@ -29,18 +29,14 @@
#include "api/sequence_checker.h"
#include "modules/audio_device/include/audio_device.h"
#include "modules/audio_device/include/audio_device_defines.h"
#include "rtc_base/message_handler.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_message.h"
namespace rtc {
class Thread;
} // namespace rtc
class FakeAudioCaptureModule : public webrtc::AudioDeviceModule,
public rtc::MessageHandlerAutoCleanup {
class FakeAudioCaptureModule : public webrtc::AudioDeviceModule {
public:
typedef uint16_t Sample;
@ -152,9 +148,6 @@ class FakeAudioCaptureModule : public webrtc::AudioDeviceModule,
// End of functions inherited from webrtc::AudioDeviceModule.
// The following function is inherited from rtc::MessageHandler.
void OnMessage(rtc::Message* msg) override;
protected:
// The constructor is protected because the class needs to be created as a
// reference counted object (for memory managment reasons). It could be

View File

@ -11,11 +11,13 @@
#ifndef PC_TEST_FAKE_RTC_CERTIFICATE_GENERATOR_H_
#define PC_TEST_FAKE_RTC_CERTIFICATE_GENERATOR_H_
#include <memory>
#include <string>
#include <utility>
#include "absl/types/optional.h"
#include "api/peer_connection_interface.h"
#include "api/task_queue/task_queue_base.h"
#include "api/units/time_delta.h"
#include "rtc_base/rtc_certificate.h"
#include "rtc_base/rtc_certificate_generator.h"
@ -117,13 +119,8 @@ static const rtc::RTCCertificatePEM kEcdsaPems[] = {
"-----END CERTIFICATE-----\n")};
class FakeRTCCertificateGenerator
: public rtc::RTCCertificateGeneratorInterface,
public rtc::MessageHandlerAutoCleanup {
: public rtc::RTCCertificateGeneratorInterface {
public:
typedef rtc::TypedMessageData<
rtc::scoped_refptr<rtc::RTCCertificateGeneratorCallback> >
MessageData;
FakeRTCCertificateGenerator() : should_fail_(false), should_wait_(false) {}
void set_should_fail(bool should_fail) { should_fail_ = should_fail; }
@ -146,22 +143,20 @@ class FakeRTCCertificateGenerator
// The certificates are created from constant PEM strings and use its coded
// expiration time, we do not support modifying it.
RTC_DCHECK(!expires_ms);
MessageData* msg = new MessageData(
rtc::scoped_refptr<rtc::RTCCertificateGeneratorCallback>(callback));
uint32_t msg_id;
// Only supports RSA-1024-0x10001 and ECDSA-P256.
if (should_fail_) {
msg_id = MSG_FAILURE;
} else if (key_params.type() == rtc::KT_RSA) {
if (key_params.type() == rtc::KT_RSA) {
RTC_DCHECK_EQ(key_params.rsa_params().mod_size, 1024);
RTC_DCHECK_EQ(key_params.rsa_params().pub_exp, 0x10001);
msg_id = MSG_SUCCESS_RSA;
} else {
RTC_DCHECK_EQ(key_params.type(), rtc::KT_ECDSA);
RTC_DCHECK_EQ(key_params.ec_curve(), rtc::EC_NIST_P256);
msg_id = MSG_SUCCESS_ECDSA;
}
rtc::Thread::Current()->Post(RTC_FROM_HERE, this, msg_id, msg);
rtc::KeyType key_type = key_params.type();
webrtc::TaskQueueBase::Current()->PostTask(
[this, key_type, callback]() mutable {
GenerateCertificate(key_type, std::move(callback));
});
}
static rtc::scoped_refptr<rtc::RTCCertificate> GenerateCertificate() {
@ -177,12 +172,6 @@ class FakeRTCCertificateGenerator
}
private:
enum {
MSG_SUCCESS_RSA,
MSG_SUCCESS_ECDSA,
MSG_FAILURE,
};
const rtc::RTCCertificatePEM& get_pem(const rtc::KeyType& key_type) const {
switch (key_type) {
case rtc::KT_RSA:
@ -201,37 +190,30 @@ class FakeRTCCertificateGenerator
return get_pem(key_type).certificate();
}
// rtc::MessageHandler implementation.
void OnMessage(rtc::Message* msg) override {
void GenerateCertificate(
rtc::KeyType key_type,
rtc::scoped_refptr<rtc::RTCCertificateGeneratorCallback> callback) {
// If the certificate generation should be stalled, re-post this same
// message to the queue with a small delay so as to wait in a loop until
// set_should_wait(false) is called.
if (should_wait_) {
rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, 1, this,
msg->message_id, msg->pdata);
webrtc::TaskQueueBase::Current()->PostDelayedTask(
[this, key_type, callback = std::move(callback)]() mutable {
GenerateCertificate(key_type, std::move(callback));
},
webrtc::TimeDelta::Millis(1));
return;
}
MessageData* message_data = static_cast<MessageData*>(msg->pdata);
rtc::scoped_refptr<rtc::RTCCertificateGeneratorCallback> callback =
message_data->data();
rtc::scoped_refptr<rtc::RTCCertificate> certificate;
switch (msg->message_id) {
case MSG_SUCCESS_RSA:
case MSG_SUCCESS_ECDSA: {
rtc::KeyType key_type =
msg->message_id == MSG_SUCCESS_RSA ? rtc::KT_RSA : rtc::KT_ECDSA;
certificate = rtc::RTCCertificate::FromPEM(get_pem(key_type));
RTC_DCHECK(certificate);
++generated_certificates_;
callback->OnSuccess(certificate);
break;
}
case MSG_FAILURE:
++generated_failures_;
callback->OnFailure();
break;
if (should_fail_) {
++generated_failures_;
callback->OnFailure();
} else {
rtc::scoped_refptr<rtc::RTCCertificate> certificate =
rtc::RTCCertificate::FromPEM(get_pem(key_type));
RTC_DCHECK(certificate);
++generated_certificates_;
callback->OnSuccess(certificate);
}
delete message_data;
}
bool should_fail_;