Change StartAecDump methods to work with FILE* and FileWrapper

Bug: webrtc:6463
Change-Id: Id275975decb9b2876021ced19ee9f279b07bea53
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/140283
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Alex Loiko <aleloi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28233}
This commit is contained in:
Niels Möller 2019-06-11 14:04:16 +02:00 committed by Commit Bot
parent 7742b21839
commit e8e4dc4c8b
17 changed files with 45 additions and 39 deletions

View File

@ -56,6 +56,7 @@ PROXY_METHOD2(rtc::scoped_refptr<AudioTrackInterface>,
CreateAudioTrack,
const std::string&,
AudioSourceInterface*)
PROXY_METHOD2(bool, StartAecDump, FILE*, int64_t)
PROXY_METHOD2(bool, StartAecDump, rtc::PlatformFile, int64_t)
PROXY_METHOD0(void, StopAecDump)
END_PROXY_MAP()

View File

@ -67,6 +67,8 @@
#ifndef API_PEER_CONNECTION_INTERFACE_H_
#define API_PEER_CONNECTION_INTERFACE_H_
#include <stdio.h>
#include <memory>
#include <string>
#include <vector>
@ -1405,6 +1407,12 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
// reached, logging is stopped automatically. If max_size_bytes is set to a
// value <= 0, no limit will be used, and logging will continue until the
// StopAecDump function is called.
// TODO(webrtc:6463): Delete default implementation when downstream mocks
// classes are updated.
virtual bool StartAecDump(FILE* file, int64_t max_size_bytes) {
return false;
}
// TODO(webrtc:6463): Deprecated; PlatformFile will soon be deleted.
virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
// Stops logging the AEC dump.

View File

@ -95,6 +95,7 @@ rtc_static_library("rtc_media_base") {
"../rtc_base:sanitizer",
"../rtc_base:stringutils",
"../rtc_base/synchronization:sequence_checker",
"../rtc_base/system:file_wrapper",
"../rtc_base/system:rtc_export",
"../rtc_base/third_party/sigslot",
"//third_party/abseil-cpp/absl/algorithm:container",

View File

@ -542,7 +542,7 @@ void FakeVoiceEngine::SetSendCodecs(const std::vector<AudioCodec>& codecs) {
int FakeVoiceEngine::GetInputLevel() {
return 0;
}
bool FakeVoiceEngine::StartAecDump(rtc::PlatformFile file,
bool FakeVoiceEngine::StartAecDump(webrtc::FileWrapper file,
int64_t max_size_bytes) {
return false;
}

View File

@ -526,7 +526,7 @@ class FakeVoiceEngine : public VoiceEngineInterface {
void SetRecvCodecs(const std::vector<AudioCodec>& codecs);
void SetSendCodecs(const std::vector<AudioCodec>& codecs);
int GetInputLevel();
bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) override;
bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes) override;
void StopAecDump() override;
bool StartRtcEventLog(rtc::PlatformFile file, int64_t max_size_bytes);
void StopRtcEventLog();

View File

@ -28,7 +28,7 @@
#include "media/base/codec.h"
#include "media/base/media_channel.h"
#include "media/base/video_common.h"
#include "rtc_base/platform_file.h"
#include "rtc_base/system/file_wrapper.h"
namespace webrtc {
class AudioDeviceModule;
@ -80,7 +80,8 @@ class VoiceEngineInterface {
// Starts AEC dump using existing file, a maximum file size in bytes can be
// specified. Logging is stopped just before the size limit is exceeded.
// If max_size_bytes is set to a value <= 0, no limit will be used.
virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
virtual bool StartAecDump(webrtc::FileWrapper file,
int64_t max_size_bytes) = 0;
// Stops recording AEC dump.
virtual void StopAecDump() = 0;

View File

@ -574,11 +574,11 @@ void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel* channel) {
channels_.erase(it);
}
bool WebRtcVoiceEngine::StartAecDump(rtc::PlatformFile file,
bool WebRtcVoiceEngine::StartAecDump(webrtc::FileWrapper file,
int64_t max_size_bytes) {
RTC_DCHECK(worker_thread_checker_.IsCurrent());
auto aec_dump = webrtc::AecDumpFactory::Create(
file, max_size_bytes, low_priority_worker_queue_.get());
std::move(file), max_size_bytes, low_priority_worker_queue_.get());
if (!aec_dump) {
return false;
}

View File

@ -78,7 +78,7 @@ class WebRtcVoiceEngine final : public VoiceEngineInterface {
// specified. When the maximum file size is reached, logging is stopped and
// the file is closed. If max_size_bytes is set to <= 0, no limit will be
// used.
bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) override;
bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes) override;
// Stops AEC dump.
void StopAecDump() override;

View File

@ -15,7 +15,6 @@
#include <string>
#include "modules/audio_processing/include/aec_dump.h"
#include "rtc_base/platform_file.h"
#include "rtc_base/system/file_wrapper.h"
#include "rtc_base/system/rtc_export.h"
@ -33,11 +32,7 @@ class RTC_EXPORT AecDumpFactory {
// responsibility for |handle| and closes it in the destructor. A
// non-null return value indicates that the file has been
// sucessfully opened.
static std::unique_ptr<AecDump> Create(webrtc::FileWrapper&& file,
int64_t max_log_size_bytes,
rtc::TaskQueue* worker_queue);
// TODO(webrtc:6463): Deprecated. Delete, together with the PlatformFile type.
static std::unique_ptr<AecDump> Create(rtc::PlatformFile file,
static std::unique_ptr<AecDump> Create(webrtc::FileWrapper file,
int64_t max_log_size_bytes,
rtc::TaskQueue* worker_queue);
static std::unique_ptr<AecDump> Create(std::string file_name,

View File

@ -216,7 +216,7 @@ std::unique_ptr<WriteToFileTask> AecDumpImpl::CreateWriteToFileTask() {
&num_bytes_left_for_log_);
}
std::unique_ptr<AecDump> AecDumpFactory::Create(webrtc::FileWrapper&& file,
std::unique_ptr<AecDump> AecDumpFactory::Create(webrtc::FileWrapper file,
int64_t max_log_size_bytes,
rtc::TaskQueue* worker_queue) {
RTC_DCHECK(worker_queue);
@ -227,13 +227,6 @@ std::unique_ptr<AecDump> AecDumpFactory::Create(webrtc::FileWrapper&& file,
worker_queue);
}
std::unique_ptr<AecDump> AecDumpFactory::Create(rtc::PlatformFile file,
int64_t max_log_size_bytes,
rtc::TaskQueue* worker_queue) {
return Create(FileWrapper(rtc::FdopenPlatformFileForWriting(file)),
max_log_size_bytes, worker_queue);
}
std::unique_ptr<AecDump> AecDumpFactory::Create(std::string file_name,
int64_t max_log_size_bytes,
rtc::TaskQueue* worker_queue) {
@ -246,4 +239,5 @@ std::unique_ptr<AecDump> AecDumpFactory::Create(FILE* handle,
rtc::TaskQueue* worker_queue) {
return Create(FileWrapper(handle), max_log_size_bytes, worker_queue);
}
} // namespace webrtc

View File

@ -13,13 +13,7 @@
namespace webrtc {
std::unique_ptr<AecDump> AecDumpFactory::Create(webrtc::FileWrapper&& file,
int64_t max_log_size_bytes,
rtc::TaskQueue* worker_queue) {
return nullptr;
}
std::unique_ptr<AecDump> AecDumpFactory::Create(rtc::PlatformFile file,
std::unique_ptr<AecDump> AecDumpFactory::Create(webrtc::FileWrapper file,
int64_t max_log_size_bytes,
rtc::TaskQueue* worker_queue) {
return nullptr;

View File

@ -1581,14 +1581,14 @@ TEST_F(ApmTest, DebugDumpFromFileHandle) {
const std::string filename =
test::TempFilename(test::OutputPath(), "debug_aec");
FILE* fid = fopen(filename.c_str(), "w");
ASSERT_TRUE(fid);
FileWrapper f = FileWrapper::OpenWriteOnly(filename.c_str());
ASSERT_TRUE(f.is_open());
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
// Stopping without having started should be OK.
apm_->DetachAecDump();
auto aec_dump = AecDumpFactory::Create(fid, -1, &worker_queue);
auto aec_dump = AecDumpFactory::Create(std::move(f), -1, &worker_queue);
EXPECT_TRUE(aec_dump);
apm_->AttachAecDump(std::move(aec_dump));
EXPECT_EQ(apm_->kNoError, apm_->ProcessReverseStream(revframe_));
@ -1596,14 +1596,12 @@ TEST_F(ApmTest, DebugDumpFromFileHandle) {
apm_->DetachAecDump();
// Verify the file has been written.
fid = fopen(filename.c_str(), "r");
FILE* fid = fopen(filename.c_str(), "r");
ASSERT_TRUE(fid != NULL);
// Clean it up.
ASSERT_EQ(0, fclose(fid));
ASSERT_EQ(0, remove(filename.c_str()));
#else
ASSERT_EQ(0, fclose(fid));
#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
}

View File

@ -100,6 +100,7 @@ rtc_static_library("rtc_pc_base") {
"../rtc_base:deprecation",
"../rtc_base:rtc_task_queue",
"../rtc_base:stringutils",
"../rtc_base/system:file_wrapper",
"../rtc_base/third_party/base64",
"../rtc_base/third_party/sigslot",
"../system_wrappers:metrics",
@ -229,6 +230,7 @@ rtc_static_library("peerconnection") {
"../rtc_base:checks",
"../rtc_base:rtc_base_approved",
"../rtc_base:safe_minmax",
"../rtc_base/system:file_wrapper",
"../rtc_base/system:rtc_export",
"../rtc_base/third_party/base64",
"../rtc_base/third_party/sigslot",

View File

@ -358,10 +358,10 @@ void ChannelManager::DestroyRtpDataChannel(RtpDataChannel* data_channel) {
data_channels_.erase(it);
}
bool ChannelManager::StartAecDump(rtc::PlatformFile file,
bool ChannelManager::StartAecDump(webrtc::FileWrapper file,
int64_t max_size_bytes) {
return worker_thread_->Invoke<bool>(RTC_FROM_HERE, [&] {
return media_engine_->voice().StartAecDump(file, max_size_bytes);
return media_engine_->voice().StartAecDump(std::move(file), max_size_bytes);
});
}

View File

@ -28,7 +28,7 @@
#include "pc/channel.h"
#include "pc/rtp_transport_internal.h"
#include "pc/session_description.h"
#include "rtc_base/platform_file.h"
#include "rtc_base/system/file_wrapper.h"
#include "rtc_base/thread.h"
namespace cricket {
@ -153,7 +153,7 @@ class ChannelManager final {
// Starts AEC dump using existing file, with a specified maximum file size in
// bytes. When the limit is reached, logging will stop and the file will be
// closed. If max_size_bytes is set to <= 0, no limit will be used.
bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes);
bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes);
// Stops recording AEC dump.
void StopAecDump();

View File

@ -37,6 +37,7 @@
#include "pc/video_track.h"
#include "rtc_base/bind.h"
#include "rtc_base/checks.h"
#include "rtc_base/system/file_wrapper.h"
#include "system_wrappers/include/field_trial.h"
namespace webrtc {
@ -208,10 +209,20 @@ PeerConnectionFactory::CreateAudioSource(const cricket::AudioOptions& options) {
return source;
}
bool PeerConnectionFactory::StartAecDump(FILE* file, int64_t max_size_bytes) {
RTC_DCHECK(signaling_thread_->IsCurrent());
return channel_manager_->StartAecDump(FileWrapper(file), max_size_bytes);
}
bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file,
int64_t max_size_bytes) {
RTC_DCHECK(signaling_thread_->IsCurrent());
return channel_manager_->StartAecDump(file, max_size_bytes);
FILE* f = rtc::FdopenPlatformFileForWriting(file);
if (!f) {
rtc::ClosePlatformFile(file);
return false;
}
return StartAecDump(f, max_size_bytes);
}
void PeerConnectionFactory::StopAecDump() {

View File

@ -69,6 +69,7 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
const std::string& id,
AudioSourceInterface* audio_source) override;
bool StartAecDump(FILE* file, int64_t max_size_bytes) override;
bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) override;
void StopAecDump() override;