diff --git a/api/peer_connection_factory_proxy.h b/api/peer_connection_factory_proxy.h index 620f1ca172..b61a78291c 100644 --- a/api/peer_connection_factory_proxy.h +++ b/api/peer_connection_factory_proxy.h @@ -56,6 +56,7 @@ PROXY_METHOD2(rtc::scoped_refptr, 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() diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h index ceec13ab0c..0b2bfa473e 100644 --- a/api/peer_connection_interface.h +++ b/api/peer_connection_interface.h @@ -67,6 +67,8 @@ #ifndef API_PEER_CONNECTION_INTERFACE_H_ #define API_PEER_CONNECTION_INTERFACE_H_ +#include + #include #include #include @@ -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. diff --git a/media/BUILD.gn b/media/BUILD.gn index 6627eea13a..6dee916f3d 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -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", diff --git a/media/base/fake_media_engine.cc b/media/base/fake_media_engine.cc index 358b51c7de..ab398ce4a9 100644 --- a/media/base/fake_media_engine.cc +++ b/media/base/fake_media_engine.cc @@ -542,7 +542,7 @@ void FakeVoiceEngine::SetSendCodecs(const std::vector& 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; } diff --git a/media/base/fake_media_engine.h b/media/base/fake_media_engine.h index b42f896b80..f3c77411d7 100644 --- a/media/base/fake_media_engine.h +++ b/media/base/fake_media_engine.h @@ -526,7 +526,7 @@ class FakeVoiceEngine : public VoiceEngineInterface { void SetRecvCodecs(const std::vector& codecs); void SetSendCodecs(const std::vector& 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(); diff --git a/media/base/media_engine.h b/media/base/media_engine.h index 9bc49f95f1..bf4fd3cc25 100644 --- a/media/base/media_engine.h +++ b/media/base/media_engine.h @@ -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; diff --git a/media/engine/webrtc_voice_engine.cc b/media/engine/webrtc_voice_engine.cc index 0635c9f3db..46e219f1e9 100644 --- a/media/engine/webrtc_voice_engine.cc +++ b/media/engine/webrtc_voice_engine.cc @@ -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; } diff --git a/media/engine/webrtc_voice_engine.h b/media/engine/webrtc_voice_engine.h index aaa2778a21..a4c8baa37f 100644 --- a/media/engine/webrtc_voice_engine.h +++ b/media/engine/webrtc_voice_engine.h @@ -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; diff --git a/modules/audio_processing/aec_dump/aec_dump_factory.h b/modules/audio_processing/aec_dump/aec_dump_factory.h index 2a800a9418..429a8a5881 100644 --- a/modules/audio_processing/aec_dump/aec_dump_factory.h +++ b/modules/audio_processing/aec_dump/aec_dump_factory.h @@ -15,7 +15,6 @@ #include #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 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 Create(rtc::PlatformFile file, + static std::unique_ptr Create(webrtc::FileWrapper file, int64_t max_log_size_bytes, rtc::TaskQueue* worker_queue); static std::unique_ptr Create(std::string file_name, diff --git a/modules/audio_processing/aec_dump/aec_dump_impl.cc b/modules/audio_processing/aec_dump/aec_dump_impl.cc index ebd0f575c3..ba15336c08 100644 --- a/modules/audio_processing/aec_dump/aec_dump_impl.cc +++ b/modules/audio_processing/aec_dump/aec_dump_impl.cc @@ -216,7 +216,7 @@ std::unique_ptr AecDumpImpl::CreateWriteToFileTask() { &num_bytes_left_for_log_); } -std::unique_ptr AecDumpFactory::Create(webrtc::FileWrapper&& file, +std::unique_ptr 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 AecDumpFactory::Create(webrtc::FileWrapper&& file, worker_queue); } -std::unique_ptr 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 AecDumpFactory::Create(std::string file_name, int64_t max_log_size_bytes, rtc::TaskQueue* worker_queue) { @@ -246,4 +239,5 @@ std::unique_ptr AecDumpFactory::Create(FILE* handle, rtc::TaskQueue* worker_queue) { return Create(FileWrapper(handle), max_log_size_bytes, worker_queue); } + } // namespace webrtc diff --git a/modules/audio_processing/aec_dump/null_aec_dump_factory.cc b/modules/audio_processing/aec_dump/null_aec_dump_factory.cc index 14e7c037cf..126adeb4eb 100644 --- a/modules/audio_processing/aec_dump/null_aec_dump_factory.cc +++ b/modules/audio_processing/aec_dump/null_aec_dump_factory.cc @@ -13,13 +13,7 @@ namespace webrtc { -std::unique_ptr AecDumpFactory::Create(webrtc::FileWrapper&& file, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) { - return nullptr; -} - -std::unique_ptr AecDumpFactory::Create(rtc::PlatformFile file, +std::unique_ptr AecDumpFactory::Create(webrtc::FileWrapper file, int64_t max_log_size_bytes, rtc::TaskQueue* worker_queue) { return nullptr; diff --git a/modules/audio_processing/audio_processing_unittest.cc b/modules/audio_processing/audio_processing_unittest.cc index 1c1d741b3f..2c23cb3b37 100644 --- a/modules/audio_processing/audio_processing_unittest.cc +++ b/modules/audio_processing/audio_processing_unittest.cc @@ -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 } diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 65f968af47..b4573d9a39 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -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", diff --git a/pc/channel_manager.cc b/pc/channel_manager.cc index 55f526800c..0023a2f6e4 100644 --- a/pc/channel_manager.cc +++ b/pc/channel_manager.cc @@ -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(RTC_FROM_HERE, [&] { - return media_engine_->voice().StartAecDump(file, max_size_bytes); + return media_engine_->voice().StartAecDump(std::move(file), max_size_bytes); }); } diff --git a/pc/channel_manager.h b/pc/channel_manager.h index 34f9013d73..cae812f3c5 100644 --- a/pc/channel_manager.h +++ b/pc/channel_manager.h @@ -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(); diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc index b2b12b0dbd..e3da4cfce6 100644 --- a/pc/peer_connection_factory.cc +++ b/pc/peer_connection_factory.cc @@ -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() { diff --git a/pc/peer_connection_factory.h b/pc/peer_connection_factory.h index 9b2ce67e39..6f68a26c77 100644 --- a/pc/peer_connection_factory.h +++ b/pc/peer_connection_factory.h @@ -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;