Replace printf with RTC_LOG in YUV readers/writers

Bug: none
Change-Id: I70027a850b750067e0f7622fccfa724406974a1a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251866
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Andrey Logvin <landrey@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36028}
This commit is contained in:
Sergey Silkin 2022-02-18 11:54:28 +01:00 committed by WebRTC LUCI CQ
parent 29ff3efebf
commit 18454b7720
4 changed files with 47 additions and 37 deletions

View File

@ -14,6 +14,7 @@
#include "api/scoped_refptr.h"
#include "api/video/i420_buffer.h"
#include "rtc_base/logging.h"
#include "test/testsupport/file_utils.h"
#include "test/testsupport/frame_reader.h"
@ -41,42 +42,47 @@ Y4mFrameReaderImpl::~Y4mFrameReaderImpl() {
bool Y4mFrameReaderImpl::Init() {
if (input_width_ <= 0 || input_height_ <= 0) {
fprintf(stderr, "Frame width and height must be >0, was %d x %d\n",
input_width_, input_height_);
RTC_LOG(LS_ERROR) << "Frame width and height must be positive. Was: "
<< input_width_ << "x" << input_height_;
return false;
}
input_file_ = fopen(input_filename_.c_str(), "rb");
if (input_file_ == nullptr) {
fprintf(stderr, "Couldn't open input file for reading: %s\n",
input_filename_.c_str());
RTC_LOG(LS_ERROR) << "Couldn't open input file: "
<< input_filename_.c_str();
return false;
}
size_t source_file_size = GetFileSize(input_filename_);
if (source_file_size <= 0u) {
fprintf(stderr, "Found empty file: %s\n", input_filename_.c_str());
RTC_LOG(LS_ERROR) << "Input file " << input_filename_.c_str()
<< " is empty.";
return false;
}
if (fread(buffer_, 1, kFileHeaderSize, input_file_) < kFileHeaderSize) {
fprintf(stderr, "Failed to read file header from input file: %s\n",
input_filename_.c_str());
RTC_LOG(LS_ERROR) << "Couldn't read Y4M header from input file: "
<< input_filename_.c_str();
return false;
}
// Calculate total number of frames.
number_of_frames_ = static_cast<int>((source_file_size - kFileHeaderSize) /
frame_length_in_bytes_);
if (number_of_frames_ == 0) {
RTC_LOG(LS_ERROR) << "Input file " << input_filename_.c_str()
<< " is too small.";
}
return true;
}
rtc::scoped_refptr<I420Buffer> Y4mFrameReaderImpl::ReadFrame() {
if (input_file_ == nullptr) {
fprintf(stderr,
"Y4mFrameReaderImpl is not initialized (input file is NULL)\n");
RTC_LOG(LS_ERROR) << "Y4mFrameReaderImpl is not initialized.";
return nullptr;
}
if (fread(buffer_, 1, kFrameHeaderSize, input_file_) < kFrameHeaderSize &&
ferror(input_file_)) {
fprintf(stderr, "Failed to read frame header from input file: %s\n",
input_filename_.c_str());
RTC_LOG(LS_ERROR) << "Couldn't read frame header from input file: "
<< input_filename_.c_str();
return nullptr;
}
return YuvFrameReaderImpl::ReadFrame();

View File

@ -8,11 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdint.h>
#include <stdio.h>
#include <string>
#include "rtc_base/logging.h"
#include "test/testsupport/frame_writer.h"
namespace webrtc {
@ -34,8 +34,8 @@ bool Y4mFrameWriterImpl::Init() {
int bytes_written = fprintf(output_file_, "YUV4MPEG2 W%d H%d F%d:1 C420\n",
width_, height_, frame_rate_);
if (bytes_written < 0) {
fprintf(stderr, "Failed to write Y4M file header to file %s\n",
output_filename_.c_str());
RTC_LOG(LS_ERROR) << "Failed to write Y4M file header to file: "
<< output_filename_.c_str();
return false;
}
return true;
@ -43,14 +43,13 @@ bool Y4mFrameWriterImpl::Init() {
bool Y4mFrameWriterImpl::WriteFrame(const uint8_t* frame_buffer) {
if (output_file_ == nullptr) {
fprintf(stderr,
"Y4mFrameWriterImpl is not initialized (output file is NULL)\n");
RTC_LOG(LS_ERROR) << "Y4mFrameWriterImpl is not initialized.";
return false;
}
int bytes_written = fprintf(output_file_, "FRAME\n");
if (bytes_written < 0) {
fprintf(stderr, "Failed to write Y4M frame header to file %s\n",
output_filename_.c_str());
RTC_LOG(LS_ERROR) << "Couldn't write Y4M frame header to file: "
<< output_filename_.c_str();
return false;
}
return YuvFrameWriterImpl::WriteFrame(frame_buffer);

View File

@ -14,6 +14,7 @@
#include "api/scoped_refptr.h"
#include "api/video/i420_buffer.h"
#include "rtc_base/logging.h"
#include "test/frame_utils.h"
#include "test/testsupport/file_utils.h"
#include "test/testsupport/frame_reader.h"
@ -86,32 +87,38 @@ YuvFrameReaderImpl::~YuvFrameReaderImpl() {
bool YuvFrameReaderImpl::Init() {
if (input_width_ <= 0 || input_height_ <= 0) {
fprintf(stderr, "Frame width and height must be >0, was %d x %d\n",
input_width_, input_height_);
RTC_LOG(LS_ERROR) << "Frame width and height must be positive. Was: "
<< input_width_ << "x" << input_height_;
return false;
}
input_file_ = fopen(input_filename_.c_str(), "rb");
if (input_file_ == nullptr) {
fprintf(stderr, "Couldn't open input file for reading: %s\n",
input_filename_.c_str());
RTC_LOG(LS_ERROR) << "Couldn't open input file: "
<< input_filename_.c_str();
return false;
}
// Calculate total number of frames.
size_t source_file_size = GetFileSize(input_filename_);
if (source_file_size <= 0u) {
fprintf(stderr, "Found empty file: %s\n", input_filename_.c_str());
RTC_LOG(LS_ERROR) << "Input file " << input_filename_.c_str()
<< " is empty.";
return false;
}
number_of_frames_ =
static_cast<int>(source_file_size / frame_length_in_bytes_);
if (number_of_frames_ == 0) {
RTC_LOG(LS_ERROR) << "Input file " << input_filename_.c_str()
<< " is too small.";
}
current_frame_index_ = 0;
return true;
}
rtc::scoped_refptr<I420Buffer> YuvFrameReaderImpl::ReadFrame() {
if (input_file_ == nullptr) {
fprintf(stderr,
"YuvFrameReaderImpl is not initialized (input file is NULL)\n");
RTC_LOG(LS_ERROR) << "YuvFrameReaderImpl is not initialized.";
return nullptr;
}
@ -142,8 +149,8 @@ rtc::scoped_refptr<I420Buffer> YuvFrameReaderImpl::ReadFrame() {
buffer = ReadI420Buffer(input_width_, input_height_, input_file_);
if (!buffer && ferror(input_file_)) {
fprintf(stderr, "Error reading from input file: %s\n",
input_filename_.c_str());
RTC_LOG(LS_ERROR) << "Couldn't read frame from file: "
<< input_filename_.c_str();
}
} while (dropper_ &&
dropper_->UpdateLevel() == DropperUtil::DropDecision::kDropframe);

View File

@ -8,12 +8,12 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdint.h>
#include <stdio.h>
#include <string>
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "test/testsupport/frame_writer.h"
namespace webrtc {
@ -34,8 +34,7 @@ YuvFrameWriterImpl::~YuvFrameWriterImpl() {
bool YuvFrameWriterImpl::Init() {
if (width_ <= 0 || height_ <= 0) {
fprintf(stderr, "Frame width and height must be >0, was %d x %d\n", width_,
height_);
RTC_LOG(LS_ERROR) << "Frame width and height must be positive.";
return false;
}
frame_length_in_bytes_ =
@ -43,8 +42,8 @@ bool YuvFrameWriterImpl::Init() {
output_file_ = fopen(output_filename_.c_str(), "wb");
if (output_file_ == nullptr) {
fprintf(stderr, "Couldn't open output file for writing: %s\n",
output_filename_.c_str());
RTC_LOG(LS_ERROR) << "Couldn't open output file: "
<< output_filename_.c_str();
return false;
}
return true;
@ -53,15 +52,14 @@ bool YuvFrameWriterImpl::Init() {
bool YuvFrameWriterImpl::WriteFrame(const uint8_t* frame_buffer) {
RTC_DCHECK(frame_buffer);
if (output_file_ == nullptr) {
fprintf(stderr,
"YuvFrameWriterImpl is not initialized (output file is NULL)\n");
RTC_LOG(LS_ERROR) << "YuvFrameWriterImpl is not initialized.";
return false;
}
size_t bytes_written =
fwrite(frame_buffer, 1, frame_length_in_bytes_, output_file_);
if (bytes_written != frame_length_in_bytes_) {
fprintf(stderr, "Failed to write %zu bytes to file %s\n",
frame_length_in_bytes_, output_filename_.c_str());
RTC_LOG(LS_ERROR) << "Cound't write frame to file: "
<< output_filename_.c_str();
return false;
}
return true;