Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Unified Diff: webrtc/test/frame_generator.cc

Issue 2342783003: Reland of Update test code to use I420Buffer when writing pixel data. (Closed)
Patch Set: Attempt to fix int/size_t issue. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/test/fake_texture_frame.h ('k') | webrtc/test/testsupport/metrics/video_metrics.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/test/frame_generator.cc
diff --git a/webrtc/test/frame_generator.cc b/webrtc/test/frame_generator.cc
index ed7e95a12679d2abc36da2e56a4e194206c7d198..4bfb9ea01f3150622821356bf6865c3f02ec4764 100644
--- a/webrtc/test/frame_generator.cc
+++ b/webrtc/test/frame_generator.cc
@@ -18,6 +18,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/system_wrappers/include/clock.h"
+#include "libyuv/convert.h"
namespace webrtc {
namespace test {
@@ -26,35 +27,41 @@ namespace {
class ChromaGenerator : public FrameGenerator {
public:
ChromaGenerator(size_t width, size_t height)
- : angle_(0.0), width_(width), height_(height) {
- assert(width > 0);
- assert(height > 0);
+ : width_(width), height_(height), angle_(0.0) {
+ RTC_CHECK(width_ > 0);
+ RTC_CHECK(height_ > 0);
+ half_width_ = (width_ + 1) / 2;
+ y_size_ = width_ * height_;
+ uv_size_ = half_width_ * ((height_ + 1) / 2);
}
VideoFrame* NextFrame() override {
- frame_.CreateEmptyFrame(static_cast<int>(width_),
- static_cast<int>(height_),
- static_cast<int>(width_),
- static_cast<int>((width_ + 1) / 2),
- static_cast<int>((width_ + 1) / 2));
angle_ += 30.0;
uint8_t u = fabs(sin(angle_)) * 0xFF;
uint8_t v = fabs(cos(angle_)) * 0xFF;
- memset(frame_.video_frame_buffer()->MutableDataY(), 0x80,
- frame_.allocated_size(kYPlane));
- memset(frame_.video_frame_buffer()->MutableDataU(), u,
- frame_.allocated_size(kUPlane));
- memset(frame_.video_frame_buffer()->MutableDataV(), v,
- frame_.allocated_size(kVPlane));
- return &frame_;
+ // Ensure stride == width.
+ rtc::scoped_refptr<I420Buffer> buffer(I420Buffer::Create(
+ static_cast<int>(width_), static_cast<int>(height_),
+ static_cast<int>(width_), static_cast<int>(half_width_),
+ static_cast<int>(half_width_)));
+
+ memset(buffer->MutableDataY(), 0x80, y_size_);
+ memset(buffer->MutableDataU(), u, uv_size_);
+ memset(buffer->MutableDataV(), v, uv_size_);
+
+ frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0));
+ return frame_.get();
}
private:
double angle_;
size_t width_;
size_t height_;
- VideoFrame frame_;
+ size_t half_width_;
+ size_t y_size_;
+ size_t uv_size_;
+ std::unique_ptr<VideoFrame> frame_;
};
class YuvFileGenerator : public FrameGenerator {
@@ -89,15 +96,13 @@ class YuvFileGenerator : public FrameGenerator {
if (++current_display_count_ >= frame_display_count_)
current_display_count_ = 0;
- // If this is the last repeatition of this frame, it's OK to use the
- // original instance, otherwise use a copy.
- if (current_display_count_ == frame_display_count_)
- return &last_read_frame_;
-
- temp_frame_copy_.CopyFrame(last_read_frame_);
- return &temp_frame_copy_;
+ temp_frame_.reset(
+ new VideoFrame(last_read_buffer_, 0, 0, webrtc::kVideoRotation_0));
+ return temp_frame_.get();
}
+ // TODO(nisse): Have a frame reader in one place. And read directly
+ // into the planes of an I420Buffer, the extra copying below is silly.
void ReadNextFrame() {
size_t bytes_read =
fread(frame_buffer_.get(), 1, frame_size_, files_[file_index_]);
@@ -110,14 +115,21 @@ class YuvFileGenerator : public FrameGenerator {
assert(bytes_read >= frame_size_);
}
- last_read_frame_.CreateEmptyFrame(
+ size_t half_width = (width_ + 1) / 2;
+ size_t size_y = width_ * height_;
+ size_t size_uv = half_width * ((height_ + 1) / 2);
+ last_read_buffer_ = I420Buffer::Create(
static_cast<int>(width_), static_cast<int>(height_),
- static_cast<int>(width_), static_cast<int>((width_ + 1) / 2),
- static_cast<int>((width_ + 1) / 2));
-
- ConvertToI420(kI420, frame_buffer_.get(), 0, 0, static_cast<int>(width_),
- static_cast<int>(height_), 0, kVideoRotation_0,
- &last_read_frame_);
+ static_cast<int>(width_), static_cast<int>(half_width),
+ static_cast<int>(half_width));
+ libyuv::I420Copy(
+ frame_buffer_.get(), static_cast<int>(width_),
+ frame_buffer_.get() + size_y, static_cast<int>(half_width),
+ frame_buffer_.get() + size_y + size_uv, static_cast<int>(half_width),
+ last_read_buffer_->MutableDataY(), last_read_buffer_->StrideY(),
+ last_read_buffer_->MutableDataU(), last_read_buffer_->StrideU(),
+ last_read_buffer_->MutableDataV(), last_read_buffer_->StrideV(),
+ static_cast<int>(width_), static_cast<int>(height_));
}
private:
@@ -129,8 +141,8 @@ class YuvFileGenerator : public FrameGenerator {
const std::unique_ptr<uint8_t[]> frame_buffer_;
const int frame_display_count_;
int current_display_count_;
- VideoFrame last_read_frame_;
- VideoFrame temp_frame_copy_;
+ rtc::scoped_refptr<I420Buffer> last_read_buffer_;
+ std::unique_ptr<VideoFrame> temp_frame_;
};
class ScrollingImageFrameGenerator : public FrameGenerator {
« no previous file with comments | « webrtc/test/fake_texture_frame.h ('k') | webrtc/test/testsupport/metrics/video_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698