Delete rtc::File, usage replaced with FileWrapper
Bug: webrtc:6463
Change-Id: Ia0767a2e6bbacc43e63c30ed3bd3edb10ff6e645
Reviewed-on: https://webrtc-review.googlesource.com/c/121943
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26613}
diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn
index adf9255..84681ee 100644
--- a/modules/video_coding/BUILD.gn
+++ b/modules/video_coding/BUILD.gn
@@ -294,6 +294,7 @@
"../../rtc_base/experiments:quality_scaling_experiment",
"../../rtc_base/experiments:rate_control_settings",
"../../rtc_base/system:arch",
+ "../../rtc_base/system:file_wrapper",
"../../rtc_base/task_utils:repeating_task",
"../../system_wrappers",
"../../system_wrappers:field_trial",
diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
index 95381b0..01b09bf 100644
--- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
+++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
@@ -39,7 +39,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/cpu_time.h"
#include "rtc_base/event.h"
-#include "rtc_base/file.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/time_utils.h"
#include "system_wrappers/include/cpu_info.h"
@@ -617,8 +616,8 @@
std::to_string(simulcast_svc_idx);
if (config_.visualization_params.save_encoded_ivf) {
- rtc::File post_encode_file =
- rtc::File::Create(output_filename_base + ".ivf");
+ FileWrapper post_encode_file =
+ FileWrapper::OpenWriteOnly(output_filename_base + ".ivf");
encoded_frame_writers_.push_back(
IvfFileWriter::Wrap(std::move(post_encode_file), 0));
}
diff --git a/modules/video_coding/utility/ivf_file_writer.cc b/modules/video_coding/utility/ivf_file_writer.cc
index 225996a..f1dc1d6 100644
--- a/modules/video_coding/utility/ivf_file_writer.cc
+++ b/modules/video_coding/utility/ivf_file_writer.cc
@@ -24,7 +24,7 @@
const size_t kIvfHeaderSize = 32;
-IvfFileWriter::IvfFileWriter(rtc::File file, size_t byte_limit)
+IvfFileWriter::IvfFileWriter(FileWrapper file, size_t byte_limit)
: codec_type_(kVideoCodecGeneric),
bytes_written_(0),
byte_limit_(byte_limit),
@@ -42,14 +42,14 @@
Close();
}
-std::unique_ptr<IvfFileWriter> IvfFileWriter::Wrap(rtc::File file,
+std::unique_ptr<IvfFileWriter> IvfFileWriter::Wrap(FileWrapper file,
size_t byte_limit) {
return std::unique_ptr<IvfFileWriter>(
new IvfFileWriter(std::move(file), byte_limit));
}
bool IvfFileWriter::WriteHeader() {
- if (!file_.Seek(0)) {
+ if (!file_.Rewind()) {
RTC_LOG(LS_WARNING) << "Unable to rewind ivf output file.";
return false;
}
@@ -97,7 +97,7 @@
static_cast<uint32_t>(num_frames_));
ByteWriter<uint32_t>::WriteLittleEndian(&ivf_header[28], 0); // Reserved.
- if (file_.Write(ivf_header, kIvfHeaderSize) < kIvfHeaderSize) {
+ if (!file_.Write(ivf_header, kIvfHeaderSize)) {
RTC_LOG(LS_ERROR) << "Unable to write IVF header for ivf output file.";
return false;
}
@@ -133,7 +133,7 @@
bool IvfFileWriter::WriteFrame(const EncodedImage& encoded_image,
VideoCodecType codec_type) {
- if (!file_.IsOpen())
+ if (!file_.is_open())
return false;
if (num_frames_ == 0 && !InitFromFirstFrame(encoded_image, codec_type))
@@ -170,9 +170,8 @@
ByteWriter<uint32_t>::WriteLittleEndian(
&frame_header[0], static_cast<uint32_t>(encoded_image.size()));
ByteWriter<uint64_t>::WriteLittleEndian(&frame_header[4], timestamp);
- if (file_.Write(frame_header, kFrameHeaderSize) < kFrameHeaderSize ||
- file_.Write(encoded_image.data(), encoded_image.size()) <
- encoded_image.size()) {
+ if (!file_.Write(frame_header, kFrameHeaderSize) ||
+ !file_.Write(encoded_image.data(), encoded_image.size())) {
RTC_LOG(LS_ERROR) << "Unable to write frame to file.";
return false;
}
@@ -184,7 +183,7 @@
}
bool IvfFileWriter::Close() {
- if (!file_.IsOpen())
+ if (!file_.is_open())
return false;
if (num_frames_ == 0) {
diff --git a/modules/video_coding/utility/ivf_file_writer.h b/modules/video_coding/utility/ivf_file_writer.h
index 600ab8d..74b3362 100644
--- a/modules/video_coding/utility/ivf_file_writer.h
+++ b/modules/video_coding/utility/ivf_file_writer.h
@@ -18,7 +18,7 @@
#include "api/video/encoded_image.h"
#include "common_types.h" // NOLINT(build/include)
#include "rtc_base/constructor_magic.h"
-#include "rtc_base/file.h"
+#include "rtc_base/system/file_wrapper.h"
#include "rtc_base/time_utils.h"
namespace webrtc {
@@ -29,14 +29,15 @@
// Close or ~IvfFileWriter. If writing a frame would take the file above the
// |byte_limit| the file will be closed, the write (and all future writes)
// will fail. A |byte_limit| of 0 is equivalent to no limit.
- static std::unique_ptr<IvfFileWriter> Wrap(rtc::File file, size_t byte_limit);
+ static std::unique_ptr<IvfFileWriter> Wrap(FileWrapper file,
+ size_t byte_limit);
~IvfFileWriter();
bool WriteFrame(const EncodedImage& encoded_image, VideoCodecType codec_type);
bool Close();
private:
- explicit IvfFileWriter(rtc::File file, size_t byte_limit);
+ explicit IvfFileWriter(FileWrapper file, size_t byte_limit);
bool WriteHeader();
bool InitFromFirstFrame(const EncodedImage& encoded_image,
@@ -51,7 +52,7 @@
int64_t last_timestamp_;
bool using_capture_timestamps_;
rtc::TimestampWrapAroundHandler wrap_handler_;
- rtc::File file_;
+ FileWrapper file_;
RTC_DISALLOW_COPY_AND_ASSIGN(IvfFileWriter);
};
diff --git a/modules/video_coding/utility/ivf_file_writer_unittest.cc b/modules/video_coding/utility/ivf_file_writer_unittest.cc
index 82d604a..80a83d5 100644
--- a/modules/video_coding/utility/ivf_file_writer_unittest.cc
+++ b/modules/video_coding/utility/ivf_file_writer_unittest.cc
@@ -57,13 +57,13 @@
return true;
}
- void VerifyIvfHeader(rtc::File* file,
+ void VerifyIvfHeader(FileWrapper* file,
const uint8_t fourcc[4],
int width,
int height,
uint32_t num_frames,
bool use_capture_tims_ms) {
- ASSERT_TRUE(file->IsOpen());
+ ASSERT_TRUE(file->is_open());
uint8_t data[kHeaderSize];
ASSERT_EQ(static_cast<size_t>(kHeaderSize), file->Read(data, kHeaderSize));
@@ -81,7 +81,7 @@
EXPECT_EQ(0u, ByteReader<uint32_t>::ReadLittleEndian(&data[28]));
}
- void VerifyDummyTestFrames(rtc::File* file, uint32_t num_frames) {
+ void VerifyDummyTestFrames(FileWrapper* file, uint32_t num_frames) {
const int kMaxFrameSize = 4;
for (uint32_t i = 1; i <= num_frames; ++i) {
uint8_t frame_header[kFrameHeaderSize];
@@ -104,7 +104,8 @@
void RunBasicFileStructureTest(VideoCodecType codec_type,
const uint8_t fourcc[4],
bool use_capture_tims_ms) {
- file_writer_ = IvfFileWriter::Wrap(rtc::File::Open(file_name_), 0);
+ file_writer_ =
+ IvfFileWriter::Wrap(FileWrapper::OpenWriteOnly(file_name_), 0);
ASSERT_TRUE(file_writer_.get());
const int kWidth = 320;
const int kHeight = 240;
@@ -113,7 +114,7 @@
use_capture_tims_ms));
EXPECT_TRUE(file_writer_->Close());
- rtc::File out_file = rtc::File::Open(file_name_);
+ FileWrapper out_file = FileWrapper::OpenReadOnly(file_name_);
VerifyIvfHeader(&out_file, fourcc, kWidth, kHeight, kNumFrames,
use_capture_tims_ms);
VerifyDummyTestFrames(&out_file, kNumFrames);
@@ -163,7 +164,7 @@
const int kNumFramesToFit = 1;
file_writer_ = IvfFileWriter::Wrap(
- rtc::File::Open(file_name_),
+ FileWrapper::OpenWriteOnly(file_name_),
kHeaderSize +
kNumFramesToFit * (kFrameHeaderSize + sizeof(dummy_payload)));
ASSERT_TRUE(file_writer_.get());
@@ -172,7 +173,7 @@
kNumFramesToWrite, true));
ASSERT_FALSE(file_writer_->Close());
- rtc::File out_file = rtc::File::Open(file_name_);
+ FileWrapper out_file = FileWrapper::OpenReadOnly(file_name_);
VerifyIvfHeader(&out_file, fourcc, kWidth, kHeight, kNumFramesToFit, true);
VerifyDummyTestFrames(&out_file, kNumFramesToFit);
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index a47e6d2..c52baf1 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -105,8 +105,6 @@
"copy_on_write_buffer.h",
"event_tracer.cc",
"event_tracer.h",
- "file.cc",
- "file.h",
"flags.cc",
"flags.h",
"function_view.h",
@@ -140,13 +138,8 @@
"zero_memory.h",
]
- if (is_posix || is_fuchsia) {
- sources += [ "file_posix.cc" ]
- }
-
if (is_win) {
sources += [
- "file_win.cc",
"win/windows_version.cc",
"win/windows_version.h",
]
@@ -1253,7 +1246,6 @@
"critical_section_unittest.cc",
"event_tracer_unittest.cc",
"event_unittest.cc",
- "file_unittest.cc",
"function_view_unittest.cc",
"logging_unittest.cc",
"numerics/histogram_percentile_counter_unittest.cc",
diff --git a/rtc_base/file.cc b/rtc_base/file.cc
deleted file mode 100644
index a793500..0000000
--- a/rtc_base/file.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "rtc_base/file.h"
-
-namespace rtc {
-
-File::File(PlatformFile file) : file_(file) {}
-
-File::File() : file_(kInvalidPlatformFileValue) {}
-
-File::~File() {
- Close();
-}
-
-// static
-File File::Open(const std::string& path) {
- return File(OpenPlatformFile(path));
-}
-
-// static
-File File::Create(const std::string& path) {
- return File(CreatePlatformFile(path));
-}
-
-// static
-bool File::Remove(const std::string& path) {
- return RemoveFile(path);
-}
-
-File::File(File&& other) : file_(other.file_) {
- other.file_ = kInvalidPlatformFileValue;
-}
-
-File& File::operator=(File&& other) {
- Close();
- file_ = other.file_;
- other.file_ = kInvalidPlatformFileValue;
- return *this;
-}
-
-bool File::IsOpen() {
- return file_ != kInvalidPlatformFileValue;
-}
-
-} // namespace rtc
diff --git a/rtc_base/file.h b/rtc_base/file.h
deleted file mode 100644
index 42428fa..0000000
--- a/rtc_base/file.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef RTC_BASE_FILE_H_
-#define RTC_BASE_FILE_H_
-
-#include <stddef.h>
-#include <stdint.h>
-#include <string>
-
-#include "rtc_base/constructor_magic.h"
-#include "rtc_base/platform_file.h"
-
-namespace rtc {
-
-// This class wraps the platform specific APIs for simple file interactions.
-//
-// The various read and write methods are best effort, i.e. if an underlying
-// call does not manage to read/write all the data more calls will be performed,
-// until an error is detected or all data is read/written.
-class File {
- public:
- // Wraps the given PlatformFile. This class is then responsible for closing
- // the file, which will be done in the destructor if Close is never called.
- explicit File(PlatformFile);
- // The default constructor produces a closed file.
- File();
- ~File();
-
- File(File&& other);
- File& operator=(File&& other);
-
- // Open and Create give files with both reading and writing enabled.
- static File Open(const std::string& path);
- // If the file already exists it will be overwritten.
- static File Create(const std::string& path);
-
- // Remove a file in the file system.
- static bool Remove(const std::string& path);
-
- size_t Write(const uint8_t* data, size_t length);
- size_t Read(uint8_t* buffer, size_t length);
-
- // The current position in the file after a call to these methods is platform
- // dependent (MSVC gives position offset+length, most other
- // compilers/platforms do not alter the position), i.e. do not depend on it,
- // do a Seek before any subsequent Read/Write.
- size_t WriteAt(const uint8_t* data, size_t length, size_t offset);
- size_t ReadAt(uint8_t* buffer, size_t length, size_t offset);
-
- // Attempt to position the file at the given offset from the start.
- // Returns true if successful, false otherwise.
- bool Seek(size_t offset);
-
- // Attempt to close the file. Returns true if successful, false otherwise,
- // most notably when the file is already closed.
- bool Close();
-
- bool IsOpen();
-
- private:
- PlatformFile file_;
- RTC_DISALLOW_COPY_AND_ASSIGN(File);
-};
-
-} // namespace rtc
-
-#endif // RTC_BASE_FILE_H_
diff --git a/rtc_base/file_posix.cc b/rtc_base/file_posix.cc
deleted file mode 100644
index 4920192..0000000
--- a/rtc_base/file_posix.cc
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <limits>
-
-#include "rtc_base/checks.h"
-#include "rtc_base/file.h"
-#include "rtc_base/platform_file.h"
-
-namespace rtc {
-
-size_t File::Write(const uint8_t* data, size_t length) {
- size_t total_written = 0;
- do {
- ssize_t written;
- do {
- written = ::write(file_, data + total_written, length - total_written);
- } while (written == -1 && errno == EINTR);
- if (written == -1)
- break;
- total_written += written;
- } while (total_written < length);
- return total_written;
-}
-
-size_t File::Read(uint8_t* buffer, size_t length) {
- size_t total_read = 0;
- do {
- ssize_t read;
- do {
- read = ::read(file_, buffer + total_read, length - total_read);
- } while (read == -1 && errno == EINTR);
- if (read == -1)
- break;
- total_read += read;
- } while (total_read < length);
- return total_read;
-}
-
-size_t File::WriteAt(const uint8_t* data, size_t length, size_t offset) {
- size_t total_written = 0;
- do {
- ssize_t written;
- do {
- written = ::pwrite(file_, data + total_written, length - total_written,
- offset + total_written);
- } while (written == -1 && errno == EINTR);
- if (written == -1)
- break;
- total_written += written;
- } while (total_written < length);
- return total_written;
-}
-
-size_t File::ReadAt(uint8_t* buffer, size_t length, size_t offset) {
- size_t total_read = 0;
- do {
- ssize_t read;
- do {
- read = ::pread(file_, buffer + total_read, length - total_read,
- offset + total_read);
- } while (read == -1 && errno == EINTR);
- if (read == -1)
- break;
- total_read += read;
- } while (total_read < length);
- return total_read;
-}
-
-bool File::Seek(size_t offset) {
- RTC_DCHECK_LE(offset, std::numeric_limits<off_t>::max());
- return lseek(file_, static_cast<off_t>(offset), SEEK_SET) != -1;
-}
-
-bool File::Close() {
- if (file_ == rtc::kInvalidPlatformFileValue)
- return false;
- bool ret = close(file_) == 0;
- file_ = rtc::kInvalidPlatformFileValue;
- return ret;
-}
-
-} // namespace rtc
diff --git a/rtc_base/file_unittest.cc b/rtc_base/file_unittest.cc
deleted file mode 100644
index bd3a61b..0000000
--- a/rtc_base/file_unittest.cc
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright 2016 The WebRTC Project Authors. All rights reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include <string.h>
-#include <string>
-
-#include "rtc_base/file.h"
-#include "test/gtest.h"
-#include "test/testsupport/file_utils.h"
-
-#if defined(WEBRTC_WIN)
-
-#include "rtc_base/win32.h"
-
-#else // if defined(WEBRTC_WIN)
-
-#include <errno.h>
-
-#endif
-
-namespace rtc {
-
-int LastError() {
-#if defined(WEBRTC_WIN)
- return ::GetLastError();
-#else
- return errno;
-#endif
-}
-
-bool VerifyBuffer(uint8_t* buffer, size_t length, uint8_t start_value) {
- for (size_t i = 0; i < length; ++i) {
- uint8_t val = start_value++;
- EXPECT_EQ(val, buffer[i]);
- if (buffer[i] != val)
- return false;
- }
- // Prevent the same buffer from being verified multiple times simply
- // because some operation that should have written to it failed
- memset(buffer, 0, length);
- return true;
-}
-
-class FileTest : public ::testing::Test {
- protected:
- std::string path_;
- void SetUp() override {
- path_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), "test_file");
- ASSERT_FALSE(path_.empty());
- }
- void TearDown() override { RemoveFile(path_); }
-};
-
-TEST_F(FileTest, DefaultConstructor) {
- File file;
- uint8_t buffer[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
-
- EXPECT_FALSE(file.IsOpen());
- EXPECT_EQ(0u, file.Write(buffer, 10));
- EXPECT_FALSE(file.Seek(0));
- EXPECT_EQ(0u, file.Read(buffer, 10));
- EXPECT_EQ(0u, file.WriteAt(buffer, 10, 0));
- EXPECT_EQ(0u, file.ReadAt(buffer, 10, 0));
- EXPECT_FALSE(file.Close());
-}
-
-TEST_F(FileTest, DoubleClose) {
- File file = File::Open(path_);
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
-
- EXPECT_TRUE(file.Close());
- EXPECT_FALSE(file.Close());
-}
-
-TEST_F(FileTest, SimpleReadWrite) {
- File file = File::Open(path_);
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
-
- uint8_t data[100] = {0};
- uint8_t out[100] = {0};
- for (int i = 0; i < 100; ++i) {
- data[i] = i;
- }
-
- EXPECT_EQ(10u, file.Write(data, 10));
-
- EXPECT_TRUE(file.Seek(0));
- EXPECT_EQ(10u, file.Read(out, 10));
- EXPECT_TRUE(VerifyBuffer(out, 10, 0));
-
- EXPECT_TRUE(file.Seek(0));
- EXPECT_EQ(100u, file.Write(data, 100));
-
- EXPECT_TRUE(file.Seek(0));
- EXPECT_EQ(100u, file.Read(out, 100));
- EXPECT_TRUE(VerifyBuffer(out, 100, 0));
-
- EXPECT_TRUE(file.Seek(1));
- EXPECT_EQ(50u, file.Write(data, 50));
- EXPECT_EQ(50u, file.Write(data + 50, 50));
-
- EXPECT_TRUE(file.Seek(1));
- EXPECT_EQ(100u, file.Read(out, 100));
- EXPECT_TRUE(VerifyBuffer(out, 100, 0));
-}
-
-TEST_F(FileTest, ReadWriteClose) {
- File file = File::Open(path_);
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
-
- uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- uint8_t out[10] = {0};
- EXPECT_EQ(10u, file.Write(data, 10));
- EXPECT_TRUE(file.Close());
-
- File file2 = File::Open(path_);
- ASSERT_TRUE(file2.IsOpen()) << "Error: " << LastError();
- EXPECT_EQ(10u, file2.Read(out, 10));
- EXPECT_TRUE(VerifyBuffer(out, 10, 0));
-}
-
-TEST_F(FileTest, RandomAccessRead) {
- File file = File::Open(path_);
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
-
- uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- uint8_t out[10] = {0};
- EXPECT_EQ(10u, file.Write(data, 10));
-
- EXPECT_EQ(4u, file.ReadAt(out, 4, 0));
- EXPECT_TRUE(VerifyBuffer(out, 4, 0));
-
- EXPECT_EQ(4u, file.ReadAt(out, 4, 4));
- EXPECT_TRUE(VerifyBuffer(out, 4, 4));
-
- EXPECT_EQ(5u, file.ReadAt(out, 5, 5));
- EXPECT_TRUE(VerifyBuffer(out, 5, 5));
-}
-
-TEST_F(FileTest, RandomAccessReadWrite) {
- File file = File::Open(path_);
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
-
- uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- uint8_t out[10] = {0};
- EXPECT_EQ(10u, file.Write(data, 10));
- EXPECT_TRUE(file.Seek(4));
-
- EXPECT_EQ(4u, file.WriteAt(data, 4, 4));
- EXPECT_EQ(4u, file.ReadAt(out, 4, 4));
- EXPECT_TRUE(VerifyBuffer(out, 4, 0));
-
- EXPECT_EQ(2u, file.WriteAt(data, 2, 8));
- EXPECT_EQ(2u, file.ReadAt(out, 2, 8));
- EXPECT_TRUE(VerifyBuffer(out, 2, 0));
-}
-
-TEST_F(FileTest, ShouldBeAbleToRemoveFile) {
- {
- File file = File::Open(path_);
- ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
- }
-
- ASSERT_TRUE(File::Remove(path_)) << "Error: " << LastError();
-}
-
-} // namespace rtc
diff --git a/rtc_base/file_win.cc b/rtc_base/file_win.cc
deleted file mode 100644
index d7580aa..0000000
--- a/rtc_base/file_win.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "rtc_base/file.h"
-
-#include <io.h>
-#include <windows.h>
-
-#include <limits>
-
-#include "rtc_base/checks.h"
-
-namespace rtc {
-
-size_t File::Write(const uint8_t* data, size_t length) {
- RTC_DCHECK_LT(length, std::numeric_limits<DWORD>::max());
- size_t total_written = 0;
- do {
- DWORD written;
- if (!::WriteFile(file_, data + total_written,
- static_cast<DWORD>(length - total_written), &written,
- nullptr)) {
- break;
- }
- total_written += written;
- } while (total_written < length);
- return total_written;
-}
-
-size_t File::Read(uint8_t* buffer, size_t length) {
- RTC_DCHECK_LT(length, std::numeric_limits<DWORD>::max());
- size_t total_read = 0;
- do {
- DWORD read;
- if (!::ReadFile(file_, buffer + total_read,
- static_cast<DWORD>(length - total_read), &read, nullptr)) {
- break;
- }
- total_read += read;
- } while (total_read < length);
- return total_read;
-}
-
-size_t File::WriteAt(const uint8_t* data, size_t length, size_t offset) {
- RTC_DCHECK_LT(length, std::numeric_limits<DWORD>::max());
- size_t total_written = 0;
- do {
- DWORD written;
-
- LARGE_INTEGER offset_li;
- offset_li.QuadPart = offset + total_written;
-
- OVERLAPPED overlapped = {0};
- overlapped.Offset = offset_li.LowPart;
- overlapped.OffsetHigh = offset_li.HighPart;
-
- if (!::WriteFile(file_, data + total_written,
- static_cast<DWORD>(length - total_written), &written,
- &overlapped)) {
- break;
- }
-
- total_written += written;
- } while (total_written < length);
- return total_written;
-}
-
-size_t File::ReadAt(uint8_t* buffer, size_t length, size_t offset) {
- RTC_DCHECK_LT(length, std::numeric_limits<DWORD>::max());
- size_t total_read = 0;
- do {
- DWORD read;
-
- LARGE_INTEGER offset_li;
- offset_li.QuadPart = offset + total_read;
-
- OVERLAPPED overlapped = {0};
- overlapped.Offset = offset_li.LowPart;
- overlapped.OffsetHigh = offset_li.HighPart;
-
- if (!::ReadFile(file_, buffer + total_read,
- static_cast<DWORD>(length - total_read), &read,
- &overlapped)) {
- break;
- }
-
- total_read += read;
- } while (total_read < length);
- return total_read;
-}
-
-bool File::Seek(size_t offset) {
- LARGE_INTEGER distance;
- distance.QuadPart = offset;
- return SetFilePointerEx(file_, distance, nullptr, FILE_BEGIN) != 0;
-}
-
-bool File::Close() {
- if (file_ == kInvalidPlatformFileValue)
- return false;
- bool ret = CloseHandle(file_) != 0;
- file_ = kInvalidPlatformFileValue;
- return ret;
-}
-
-} // namespace rtc
diff --git a/rtc_base/system/file_wrapper.h b/rtc_base/system/file_wrapper.h
index 8a3adc5..4f5d511 100644
--- a/rtc_base/system/file_wrapper.h
+++ b/rtc_base/system/file_wrapper.h
@@ -71,7 +71,6 @@
// Seeks to the beginning of file. Returns true on success, false on failure,
// e.g., if the underlying file isn't seekable.
- // TODO(nisse): Delete this method.
bool Rewind();
// Returns number of bytes read. Short count indicates EOF or error.
diff --git a/test/BUILD.gn b/test/BUILD.gn
index fa0f4c7..254b165 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -310,6 +310,7 @@
deps = [
":fileutils",
"../rtc_base:rtc_base_approved",
+ "../rtc_base/system:file_wrapper",
]
}
@@ -361,6 +362,7 @@
"../modules/video_capture",
"../modules/video_coding:simulcast_test_fixture_impl",
"../rtc_base:rtc_base_approved",
+ "../rtc_base/system:file_wrapper",
"../test:single_threaded_task_queue",
"pc/e2e:e2e_unittests",
"scenario:scenario_unittests",
diff --git a/test/testsupport/test_artifacts.cc b/test/testsupport/test_artifacts.cc
index f45a92d..b417745 100644
--- a/test/testsupport/test_artifacts.cc
+++ b/test/testsupport/test_artifacts.cc
@@ -12,9 +12,9 @@
#include <string.h>
-#include "rtc_base/file.h"
#include "rtc_base/flags.h"
#include "rtc_base/logging.h"
+#include "rtc_base/system/file_wrapper.h"
#include "test/testsupport/file_utils.h"
namespace {
@@ -53,10 +53,10 @@
return false;
}
- rtc::File output =
- rtc::File::Create(JoinFilename(FLAG_test_artifacts_dir, filename));
+ FileWrapper output = FileWrapper::OpenWriteOnly(
+ JoinFilename(FLAG_test_artifacts_dir, filename));
- return output.IsOpen() && output.Write(buffer, length) == length;
+ return output.is_open() && output.Write(buffer, length);
}
bool WriteToTestArtifactsDir(const char* filename, const std::string& content) {
diff --git a/test/testsupport/test_artifacts_unittest.cc b/test/testsupport/test_artifacts_unittest.cc
index 41c188d..2c3667b 100644
--- a/test/testsupport/test_artifacts_unittest.cc
+++ b/test/testsupport/test_artifacts_unittest.cc
@@ -13,8 +13,8 @@
#include <string.h>
#include <string>
-#include "rtc_base/file.h"
#include "rtc_base/flags.h"
+#include "rtc_base/system/file_wrapper.h"
#include "test/gtest.h"
#include "test/testsupport/file_utils.h"
@@ -41,9 +41,9 @@
const char* content = "some-contents";
if (WriteToTestArtifactsDir(filename, content)) {
std::string out_file = JoinFilename(FLAG_test_artifacts_dir, filename);
- rtc::File input = rtc::File::Open(out_file);
- EXPECT_TRUE(input.IsOpen());
- EXPECT_TRUE(input.Seek(0));
+ FileWrapper input = FileWrapper::OpenReadOnly(out_file);
+ EXPECT_TRUE(input.is_open());
+ EXPECT_TRUE(input.Rewind());
uint8_t buffer[32];
EXPECT_EQ(input.Read(buffer, strlen(content)), strlen(content));
buffer[strlen(content)] = 0;
@@ -51,7 +51,7 @@
std::string(reinterpret_cast<char*>(buffer)));
input.Close();
- EXPECT_TRUE(rtc::File::Remove(out_file));
+ EXPECT_TRUE(RemoveFile(out_file));
}
}
diff --git a/video/frame_dumping_decoder.cc b/video/frame_dumping_decoder.cc
index 097bd01..f42edce 100644
--- a/video/frame_dumping_decoder.cc
+++ b/video/frame_dumping_decoder.cc
@@ -13,14 +13,13 @@
#include <utility>
#include "modules/video_coding/include/video_codec_interface.h"
-#include "rtc_base/file.h"
namespace webrtc {
FrameDumpingDecoder::FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder,
- rtc::PlatformFile file)
+ FileWrapper file)
: decoder_(std::move(decoder)),
- writer_(IvfFileWriter::Wrap(rtc::File(file),
+ writer_(IvfFileWriter::Wrap(std::move(file),
/* byte_limit= */ 100000000)) {}
FrameDumpingDecoder::~FrameDumpingDecoder() = default;
diff --git a/video/frame_dumping_decoder.h b/video/frame_dumping_decoder.h
index 836c8d8..9f3ed89 100644
--- a/video/frame_dumping_decoder.h
+++ b/video/frame_dumping_decoder.h
@@ -19,15 +19,13 @@
#include "api/video_codecs/video_decoder.h"
#include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/utility/ivf_file_writer.h"
-#include "rtc_base/platform_file.h"
namespace webrtc {
// A decoder wrapper that writes the encoded frames to a file.
class FrameDumpingDecoder : public VideoDecoder {
public:
- FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder,
- rtc::PlatformFile file);
+ FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder, FileWrapper file);
~FrameDumpingDecoder() override;
int32_t InitDecode(const VideoCodec* codec_settings,
diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc
index 2f3d2bb..8349566 100644
--- a/video/video_quality_test.cc
+++ b/video/video_quality_test.cc
@@ -87,11 +87,11 @@
public:
QualityTestVideoEncoder(std::unique_ptr<VideoEncoder> encoder,
VideoAnalyzer* analyzer,
- std::vector<rtc::PlatformFile> files)
+ std::vector<FileWrapper> files)
: encoder_(std::move(encoder)), analyzer_(analyzer) {
- for (rtc::PlatformFile file : files) {
+ for (FileWrapper& file : files) {
writers_.push_back(
- IvfFileWriter::Wrap(rtc::File(file), /* byte_limit= */ 100000000));
+ IvfFileWriter::Wrap(std::move(file), /* byte_limit= */ 100000000));
}
}
// Implement VideoEncoder
@@ -182,7 +182,7 @@
std::string path =
params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
decoder = absl::make_unique<FrameDumpingDecoder>(
- std::move(decoder), rtc::CreatePlatformFile(path));
+ std::move(decoder), FileWrapper::OpenWriteOnly(path));
}
return decoder;
}
@@ -208,15 +208,16 @@
sb << send_logs_++;
std::string prefix =
params_.logging.encoded_frame_base_path + "." + sb.str() + ".send.";
+ std::vector<FileWrapper> files;
+ files.push_back(FileWrapper::OpenWriteOnly(prefix + "1.ivf"));
+ files.push_back(FileWrapper::OpenWriteOnly(prefix + "2.ivf"));
+ files.push_back(FileWrapper::OpenWriteOnly(prefix + "3.ivf"));
+
encoder = absl::make_unique<QualityTestVideoEncoder>(
- std::move(encoder), analyzer,
- std::vector<rtc::PlatformFile>(
- {rtc::CreatePlatformFile(prefix + "1.ivf"),
- rtc::CreatePlatformFile(prefix + "2.ivf"),
- rtc::CreatePlatformFile(prefix + "3.ivf")}));
+ std::move(encoder), analyzer, std::move(files));
} else if (analyzer) {
encoder = absl::make_unique<QualityTestVideoEncoder>(
- std::move(encoder), analyzer, std::vector<rtc::PlatformFile>());
+ std::move(encoder), analyzer, std::vector<FileWrapper>());
}
return encoder;
diff --git a/video/video_receive_stream.cc b/video/video_receive_stream.cc
index 4e6444a..92f1571 100644
--- a/video/video_receive_stream.cc
+++ b/video/video_receive_stream.cc
@@ -319,7 +319,7 @@
ssb << decoded_output_file << "/webrtc_receive_stream_"
<< this->config_.rtp.local_ssrc << ".ivf";
video_decoder = absl::make_unique<FrameDumpingDecoder>(
- std::move(video_decoder), rtc::CreatePlatformFile(ssb.str()));
+ std::move(video_decoder), FileWrapper::OpenWriteOnly(ssb.str()));
}
video_decoders_.push_back(std::move(video_decoder));
diff --git a/video/video_replay.cc b/video/video_replay.cc
index 6cfb8c1..a0621aa 100644
--- a/video/video_replay.cc
+++ b/video/video_replay.cc
@@ -23,7 +23,6 @@
#include "media/engine/internal_decoder_factory.h"
#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/checks.h"
-#include "rtc_base/file.h"
#include "rtc_base/flags.h"
#include "rtc_base/string_to_number.h"
#include "rtc_base/strings/json.h"