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

Unified Diff: content/common/gpu/media/video_encode_accelerator_unittest.cc

Issue 1286983002: Save both original frame and output frame into files if the absolute differences is larger than the… Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | content/content_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/gpu/media/video_encode_accelerator_unittest.cc
diff --git a/content/common/gpu/media/video_encode_accelerator_unittest.cc b/content/common/gpu/media/video_encode_accelerator_unittest.cc
index ad1a5742c1edbf959dd06edd5ee48561369c6165..a9ccfcc2c9ba3923737fe6ee635f568b3a3cfd16 100644
--- a/content/common/gpu/media/video_encode_accelerator_unittest.cc
+++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc
@@ -32,12 +32,14 @@
#include "media/base/test_data_util.h"
#include "media/base/video_decoder.h"
#include "media/base/video_frame.h"
+#include "media/base/yuv_convert.h"
#include "media/filters/ffmpeg_glue.h"
#include "media/filters/ffmpeg_video_decoder.h"
#include "media/filters/h264_parser.h"
#include "media/video/fake_video_encode_accelerator.h"
#include "media/video/video_encode_accelerator.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/codec/png_codec.h"
#if defined(OS_CHROMEOS)
#if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC))
@@ -615,18 +617,22 @@ class VideoFrameQualityValidator {
void InitializeCB(bool success);
void DecodeDone(media::VideoDecoder::Status status);
void CheckOutputFrame(const scoped_refptr<media::VideoFrame>& output_frame);
-
+ void SaveFrameToFile(const scoped_refptr<media::VideoFrame>& frame,
+ base::FilePath filename);
scoped_ptr<media::FFmpegVideoDecoder> decoder_;
media::VideoDecoder::DecodeCB decode_cb_;
std::queue<scoped_refptr<media::VideoFrame>> origin_frames_;
+
+ int frame_id_;
};
VideoFrameQualityValidator::VideoFrameQualityValidator()
: decoder_(new media::FFmpegVideoDecoder(
base::MessageLoop::current()->task_runner())),
decode_cb_(base::Bind(&VideoFrameQualityValidator::DecodeDone,
- base::Unretained(this))) {
+ base::Unretained(this))),
+ frame_id_(0) {
decoder_->set_decode_nalus(true);
}
@@ -635,6 +641,7 @@ void VideoFrameQualityValidator::Initialize(
const gfx::Rect& visible_size,
const media::VideoCodecProfile profile) {
media::FFmpegGlue::InitializeFFmpeg();
+ media::InitializeCPUSpecificYUVConversions();
gfx::Size natural_size(visible_size.size());
media::VideoDecoderConfig config;
@@ -677,6 +684,7 @@ void VideoFrameQualityValidator::CheckOutputFrame(
const scoped_refptr<media::VideoFrame>& output_frame) {
scoped_refptr<media::VideoFrame> origin_frame = origin_frames_.front();
origin_frames_.pop();
+ frame_id_++;
gfx::Size visible_size = origin_frame->visible_rect().size();
int planes[] = {media::VideoFrame::kYPlane,
@@ -700,8 +708,45 @@ void VideoFrameQualityValidator::CheckOutputFrame(
}
// Divide the difference by the size of frame
difference /= media::VideoFrame::AllocationSize(kInputFormat, visible_size);
+
+ // Save both origin and output frames to files if its difference is larger
+ // than kDecodeSimilarityThreshold
CHECK(difference < kDecodeSimilarityThreshold)
Owen Lin 2015/08/12 08:07:48 I thought we will crash at CHECK and then no outpu
<< "differrence = " << difference << " > kDecodeSimilarityThreshold";
+ if (difference >= kDecodeSimilarityThreshold) {
+ std::string filename =
+ base::StringPrintf("%.4d_origin_frame.png", frame_id_);
+ SaveFrameToFile(origin_frame, base::FilePath::FromUTF8Unsafe(filename));
+ filename = base::StringPrintf("%.4d_output_frame.png", frame_id_);
+ SaveFrameToFile(output_frame, base::FilePath::FromUTF8Unsafe(filename));
+ }
+}
+
+void VideoFrameQualityValidator::SaveFrameToFile(
+ const scoped_refptr<media::VideoFrame>& frame,
+ base::FilePath filename) {
Owen Lin 2015/08/12 08:07:48 const base::FilePath &
+ size_t row_bytes = frame->coded_size().width() * 4u;
Owen Lin 2015/08/12 08:07:48 use visible size for rgb_bytes.
+ uint8* rgb_pixels = reinterpret_cast<uint8*>(
Owen Lin 2015/08/12 08:07:48 How do you free the rgb_pixels
+ base::AlignedAlloc(row_bytes * frame->coded_size().height() +
+ media::VideoFrame::kFrameSizePadding,
+ media::VideoFrame::kFrameAddressAlignment));
+ media::ConvertYUVToRGB32(
+ frame->data(media::VideoFrame::kYPlane),
+ frame->data(media::VideoFrame::kUPlane),
+ frame->data(media::VideoFrame::kVPlane), rgb_pixels,
+ frame->visible_rect().width(), frame->visible_rect().height(),
+ frame->stride(media::VideoFrame::kYPlane),
+ frame->stride(media::VideoFrame::kUPlane), row_bytes, media::YV12);
+
+ std::vector<unsigned char> png_output;
+ bool success = gfx::PNGCodec::Encode(
+ rgb_pixels, gfx::PNGCodec::FORMAT_RGBA, frame->coded_size(),
+ base::checked_cast<int>(row_bytes), true,
+ std::vector<gfx::PNGCodec::Comment>(), &png_output);
+ if (success) {
Owen Lin 2015/08/12 08:07:48 CHECK(gfx::PNGCodec::...);
+ base::WriteFile(filename, reinterpret_cast<char*>(&*png_output.begin()),
+ base::checked_cast<int>(png_output.size()));
+ }
}
class VEAClient : public VideoEncodeAccelerator::Client {
« no previous file with comments | « no previous file | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698