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:
parent
29ff3efebf
commit
18454b7720
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
#include "api/video/i420_buffer.h"
|
#include "api/video/i420_buffer.h"
|
||||||
|
#include "rtc_base/logging.h"
|
||||||
#include "test/testsupport/file_utils.h"
|
#include "test/testsupport/file_utils.h"
|
||||||
#include "test/testsupport/frame_reader.h"
|
#include "test/testsupport/frame_reader.h"
|
||||||
|
|
||||||
@ -41,42 +42,47 @@ Y4mFrameReaderImpl::~Y4mFrameReaderImpl() {
|
|||||||
|
|
||||||
bool Y4mFrameReaderImpl::Init() {
|
bool Y4mFrameReaderImpl::Init() {
|
||||||
if (input_width_ <= 0 || input_height_ <= 0) {
|
if (input_width_ <= 0 || input_height_ <= 0) {
|
||||||
fprintf(stderr, "Frame width and height must be >0, was %d x %d\n",
|
RTC_LOG(LS_ERROR) << "Frame width and height must be positive. Was: "
|
||||||
input_width_, input_height_);
|
<< input_width_ << "x" << input_height_;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
input_file_ = fopen(input_filename_.c_str(), "rb");
|
input_file_ = fopen(input_filename_.c_str(), "rb");
|
||||||
if (input_file_ == nullptr) {
|
if (input_file_ == nullptr) {
|
||||||
fprintf(stderr, "Couldn't open input file for reading: %s\n",
|
RTC_LOG(LS_ERROR) << "Couldn't open input file: "
|
||||||
input_filename_.c_str());
|
<< input_filename_.c_str();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t source_file_size = GetFileSize(input_filename_);
|
size_t source_file_size = GetFileSize(input_filename_);
|
||||||
if (source_file_size <= 0u) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (fread(buffer_, 1, kFileHeaderSize, input_file_) < kFileHeaderSize) {
|
if (fread(buffer_, 1, kFileHeaderSize, input_file_) < kFileHeaderSize) {
|
||||||
fprintf(stderr, "Failed to read file header from input file: %s\n",
|
RTC_LOG(LS_ERROR) << "Couldn't read Y4M header from input file: "
|
||||||
input_filename_.c_str());
|
<< input_filename_.c_str();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Calculate total number of frames.
|
|
||||||
number_of_frames_ = static_cast<int>((source_file_size - kFileHeaderSize) /
|
number_of_frames_ = static_cast<int>((source_file_size - kFileHeaderSize) /
|
||||||
frame_length_in_bytes_);
|
frame_length_in_bytes_);
|
||||||
|
|
||||||
|
if (number_of_frames_ == 0) {
|
||||||
|
RTC_LOG(LS_ERROR) << "Input file " << input_filename_.c_str()
|
||||||
|
<< " is too small.";
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<I420Buffer> Y4mFrameReaderImpl::ReadFrame() {
|
rtc::scoped_refptr<I420Buffer> Y4mFrameReaderImpl::ReadFrame() {
|
||||||
if (input_file_ == nullptr) {
|
if (input_file_ == nullptr) {
|
||||||
fprintf(stderr,
|
RTC_LOG(LS_ERROR) << "Y4mFrameReaderImpl is not initialized.";
|
||||||
"Y4mFrameReaderImpl is not initialized (input file is NULL)\n");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (fread(buffer_, 1, kFrameHeaderSize, input_file_) < kFrameHeaderSize &&
|
if (fread(buffer_, 1, kFrameHeaderSize, input_file_) < kFrameHeaderSize &&
|
||||||
ferror(input_file_)) {
|
ferror(input_file_)) {
|
||||||
fprintf(stderr, "Failed to read frame header from input file: %s\n",
|
RTC_LOG(LS_ERROR) << "Couldn't read frame header from input file: "
|
||||||
input_filename_.c_str());
|
<< input_filename_.c_str();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return YuvFrameReaderImpl::ReadFrame();
|
return YuvFrameReaderImpl::ReadFrame();
|
||||||
|
|||||||
@ -8,11 +8,11 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "rtc_base/logging.h"
|
||||||
#include "test/testsupport/frame_writer.h"
|
#include "test/testsupport/frame_writer.h"
|
||||||
|
|
||||||
namespace webrtc {
|
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",
|
int bytes_written = fprintf(output_file_, "YUV4MPEG2 W%d H%d F%d:1 C420\n",
|
||||||
width_, height_, frame_rate_);
|
width_, height_, frame_rate_);
|
||||||
if (bytes_written < 0) {
|
if (bytes_written < 0) {
|
||||||
fprintf(stderr, "Failed to write Y4M file header to file %s\n",
|
RTC_LOG(LS_ERROR) << "Failed to write Y4M file header to file: "
|
||||||
output_filename_.c_str());
|
<< output_filename_.c_str();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -43,14 +43,13 @@ bool Y4mFrameWriterImpl::Init() {
|
|||||||
|
|
||||||
bool Y4mFrameWriterImpl::WriteFrame(const uint8_t* frame_buffer) {
|
bool Y4mFrameWriterImpl::WriteFrame(const uint8_t* frame_buffer) {
|
||||||
if (output_file_ == nullptr) {
|
if (output_file_ == nullptr) {
|
||||||
fprintf(stderr,
|
RTC_LOG(LS_ERROR) << "Y4mFrameWriterImpl is not initialized.";
|
||||||
"Y4mFrameWriterImpl is not initialized (output file is NULL)\n");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int bytes_written = fprintf(output_file_, "FRAME\n");
|
int bytes_written = fprintf(output_file_, "FRAME\n");
|
||||||
if (bytes_written < 0) {
|
if (bytes_written < 0) {
|
||||||
fprintf(stderr, "Failed to write Y4M frame header to file %s\n",
|
RTC_LOG(LS_ERROR) << "Couldn't write Y4M frame header to file: "
|
||||||
output_filename_.c_str());
|
<< output_filename_.c_str();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return YuvFrameWriterImpl::WriteFrame(frame_buffer);
|
return YuvFrameWriterImpl::WriteFrame(frame_buffer);
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
#include "api/video/i420_buffer.h"
|
#include "api/video/i420_buffer.h"
|
||||||
|
#include "rtc_base/logging.h"
|
||||||
#include "test/frame_utils.h"
|
#include "test/frame_utils.h"
|
||||||
#include "test/testsupport/file_utils.h"
|
#include "test/testsupport/file_utils.h"
|
||||||
#include "test/testsupport/frame_reader.h"
|
#include "test/testsupport/frame_reader.h"
|
||||||
@ -86,32 +87,38 @@ YuvFrameReaderImpl::~YuvFrameReaderImpl() {
|
|||||||
|
|
||||||
bool YuvFrameReaderImpl::Init() {
|
bool YuvFrameReaderImpl::Init() {
|
||||||
if (input_width_ <= 0 || input_height_ <= 0) {
|
if (input_width_ <= 0 || input_height_ <= 0) {
|
||||||
fprintf(stderr, "Frame width and height must be >0, was %d x %d\n",
|
RTC_LOG(LS_ERROR) << "Frame width and height must be positive. Was: "
|
||||||
input_width_, input_height_);
|
<< input_width_ << "x" << input_height_;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
input_file_ = fopen(input_filename_.c_str(), "rb");
|
input_file_ = fopen(input_filename_.c_str(), "rb");
|
||||||
if (input_file_ == nullptr) {
|
if (input_file_ == nullptr) {
|
||||||
fprintf(stderr, "Couldn't open input file for reading: %s\n",
|
RTC_LOG(LS_ERROR) << "Couldn't open input file: "
|
||||||
input_filename_.c_str());
|
<< input_filename_.c_str();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Calculate total number of frames.
|
// Calculate total number of frames.
|
||||||
size_t source_file_size = GetFileSize(input_filename_);
|
size_t source_file_size = GetFileSize(input_filename_);
|
||||||
if (source_file_size <= 0u) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
number_of_frames_ =
|
number_of_frames_ =
|
||||||
static_cast<int>(source_file_size / frame_length_in_bytes_);
|
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;
|
current_frame_index_ = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<I420Buffer> YuvFrameReaderImpl::ReadFrame() {
|
rtc::scoped_refptr<I420Buffer> YuvFrameReaderImpl::ReadFrame() {
|
||||||
if (input_file_ == nullptr) {
|
if (input_file_ == nullptr) {
|
||||||
fprintf(stderr,
|
RTC_LOG(LS_ERROR) << "YuvFrameReaderImpl is not initialized.";
|
||||||
"YuvFrameReaderImpl is not initialized (input file is NULL)\n");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,8 +149,8 @@ rtc::scoped_refptr<I420Buffer> YuvFrameReaderImpl::ReadFrame() {
|
|||||||
|
|
||||||
buffer = ReadI420Buffer(input_width_, input_height_, input_file_);
|
buffer = ReadI420Buffer(input_width_, input_height_, input_file_);
|
||||||
if (!buffer && ferror(input_file_)) {
|
if (!buffer && ferror(input_file_)) {
|
||||||
fprintf(stderr, "Error reading from input file: %s\n",
|
RTC_LOG(LS_ERROR) << "Couldn't read frame from file: "
|
||||||
input_filename_.c_str());
|
<< input_filename_.c_str();
|
||||||
}
|
}
|
||||||
} while (dropper_ &&
|
} while (dropper_ &&
|
||||||
dropper_->UpdateLevel() == DropperUtil::DropDecision::kDropframe);
|
dropper_->UpdateLevel() == DropperUtil::DropDecision::kDropframe);
|
||||||
|
|||||||
@ -8,12 +8,12 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
#include "rtc_base/logging.h"
|
||||||
#include "test/testsupport/frame_writer.h"
|
#include "test/testsupport/frame_writer.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -34,8 +34,7 @@ YuvFrameWriterImpl::~YuvFrameWriterImpl() {
|
|||||||
|
|
||||||
bool YuvFrameWriterImpl::Init() {
|
bool YuvFrameWriterImpl::Init() {
|
||||||
if (width_ <= 0 || height_ <= 0) {
|
if (width_ <= 0 || height_ <= 0) {
|
||||||
fprintf(stderr, "Frame width and height must be >0, was %d x %d\n", width_,
|
RTC_LOG(LS_ERROR) << "Frame width and height must be positive.";
|
||||||
height_);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
frame_length_in_bytes_ =
|
frame_length_in_bytes_ =
|
||||||
@ -43,8 +42,8 @@ bool YuvFrameWriterImpl::Init() {
|
|||||||
|
|
||||||
output_file_ = fopen(output_filename_.c_str(), "wb");
|
output_file_ = fopen(output_filename_.c_str(), "wb");
|
||||||
if (output_file_ == nullptr) {
|
if (output_file_ == nullptr) {
|
||||||
fprintf(stderr, "Couldn't open output file for writing: %s\n",
|
RTC_LOG(LS_ERROR) << "Couldn't open output file: "
|
||||||
output_filename_.c_str());
|
<< output_filename_.c_str();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -53,15 +52,14 @@ bool YuvFrameWriterImpl::Init() {
|
|||||||
bool YuvFrameWriterImpl::WriteFrame(const uint8_t* frame_buffer) {
|
bool YuvFrameWriterImpl::WriteFrame(const uint8_t* frame_buffer) {
|
||||||
RTC_DCHECK(frame_buffer);
|
RTC_DCHECK(frame_buffer);
|
||||||
if (output_file_ == nullptr) {
|
if (output_file_ == nullptr) {
|
||||||
fprintf(stderr,
|
RTC_LOG(LS_ERROR) << "YuvFrameWriterImpl is not initialized.";
|
||||||
"YuvFrameWriterImpl is not initialized (output file is NULL)\n");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t bytes_written =
|
size_t bytes_written =
|
||||||
fwrite(frame_buffer, 1, frame_length_in_bytes_, output_file_);
|
fwrite(frame_buffer, 1, frame_length_in_bytes_, output_file_);
|
||||||
if (bytes_written != frame_length_in_bytes_) {
|
if (bytes_written != frame_length_in_bytes_) {
|
||||||
fprintf(stderr, "Failed to write %zu bytes to file %s\n",
|
RTC_LOG(LS_ERROR) << "Cound't write frame to file: "
|
||||||
frame_length_in_bytes_, output_filename_.c_str());
|
<< output_filename_.c_str();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user