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}
This commit is contained in:
Niels Möller
2019-02-08 16:40:53 +01:00
committed by Commit Bot
parent 9f3aabb5ad
commit b7edf69e9a
20 changed files with 50 additions and 569 deletions

View File

@ -294,6 +294,7 @@ rtc_source_set("video_coding_utility") {
"../../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",

View File

@ -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 @@ void VideoCodecTestFixtureImpl::SetUpAndInitObjects(
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));
}

View File

@ -24,7 +24,7 @@ namespace webrtc {
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 @@ IvfFileWriter::~IvfFileWriter() {
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 @@ bool IvfFileWriter::WriteHeader() {
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::InitFromFirstFrame(const EncodedImage& encoded_image,
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 @@ bool IvfFileWriter::WriteFrame(const EncodedImage& encoded_image,
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::WriteFrame(const EncodedImage& encoded_image,
}
bool IvfFileWriter::Close() {
if (!file_.IsOpen())
if (!file_.is_open())
return false;
if (num_frames_ == 0) {

View File

@ -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 @@ class IvfFileWriter {
// 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 @@ class IvfFileWriter {
int64_t last_timestamp_;
bool using_capture_timestamps_;
rtc::TimestampWrapAroundHandler wrap_handler_;
rtc::File file_;
FileWrapper file_;
RTC_DISALLOW_COPY_AND_ASSIGN(IvfFileWriter);
};

View File

@ -57,13 +57,13 @@ class IvfFileWriterTest : public ::testing::Test {
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 @@ class IvfFileWriterTest : public ::testing::Test {
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 @@ class IvfFileWriterTest : public ::testing::Test {
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 @@ class IvfFileWriterTest : public ::testing::Test {
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 @@ TEST_F(IvfFileWriterTest, ClosesWhenReachesLimit) {
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 @@ TEST_F(IvfFileWriterTest, ClosesWhenReachesLimit) {
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);