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

Side by Side Diff: media/tools/scaler_bench/scaler_bench.cc

Issue 1518034: scaler_bench - benchmark for video scaling code. (Closed)
Patch Set: - Created 10 years, 8 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 unified diff | Download patch
« no previous file with comments | « media/tools/scaler_bench/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This tool can be used to measure performace of video frame scaling
6 // code. It times performance of the scaler with and without filtering.
7 // It also measures performance of the Skia scaler for comparison.
8
9 #include <iostream>
10 #include <vector>
11
12 #include "base/command_line.h"
13 #include "base/scoped_vector.h"
14 #include "base/time.h"
15 #include "media/base/video_frame.h"
16 #include "media/base/yuv_convert.h"
17 #include "skia/ext/platform_canvas.h"
18
19 using base::TimeDelta;
20 using base::TimeTicks;
21 using media::VideoFrame;
22 using std::vector;
23
24 namespace {
25
26 int source_width = 1280;
27 int source_height = 720;
28 int dest_width = 1366;
29 int dest_height = 768;
30 int num_frames = 500;
31 int num_buffers = 50;
32
33 double BenchmarkSkia() {
34 vector< scoped_refptr<VideoFrame> > source_frames;
35 ScopedVector<SkBitmap> dest_frames;
36 for (int i = 0; i < num_buffers; i++) {
37 scoped_refptr<VideoFrame> source_frame;
38 VideoFrame::CreateBlackFrame(source_width, source_height, &source_frame);
39 source_frames.push_back(source_frame);
40
41 SkBitmap* bitmap = new SkBitmap();
42 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
43 dest_width, dest_height);
44 bitmap->allocPixels();
45 dest_frames.push_back(bitmap);
46 }
47
48 SkBitmap bitmap;
49 bitmap.setConfig(SkBitmap::kARGB_8888_Config, source_width, source_height);
50 bitmap.allocPixels();
51
52 TimeTicks start = TimeTicks::HighResNow();
53 for (int i = 0; i < num_frames; i++) {
54 scoped_refptr<VideoFrame> source_frame = source_frames[i % num_buffers];
55 SkBitmap* dest_bitmap = dest_frames[i % num_buffers];
56
57 bitmap.lockPixels();
58 media::ConvertYUVToRGB32(source_frame->data(VideoFrame::kYPlane),
59 source_frame->data(VideoFrame::kUPlane),
60 source_frame->data(VideoFrame::kVPlane),
61 static_cast<uint8*>(bitmap.getPixels()),
62 source_width,
63 source_height,
64 source_frame->stride(VideoFrame::kYPlane),
65 source_frame->stride(VideoFrame::kUPlane),
66 bitmap.rowBytes(),
67 media::YV12);
68 bitmap.unlockPixels();
69
70 SkCanvas canvas(*dest_bitmap);
71 SkRect rect;
72 rect.set(0, 0, SkIntToScalar(dest_width),
73 SkIntToScalar(dest_height));
74 canvas.clipRect(rect);
75 SkMatrix matrix;
76 matrix.reset();
77 matrix.preScale(SkIntToScalar(dest_width) /
78 SkIntToScalar(source_width),
79 SkIntToScalar(dest_height) /
80 SkIntToScalar(source_height));
81 SkPaint paint;
82 paint.setFlags(SkPaint::kFilterBitmap_Flag);
83 canvas.drawBitmapMatrix(bitmap, matrix, &paint);
84 }
85 TimeTicks end = TimeTicks::HighResNow();
86 return static_cast<double>((end - start).InMilliseconds()) / num_frames;
87 }
88
89 double BenchmarkFilter(media::ScaleFilter filter) {
90 vector< scoped_refptr<VideoFrame> > source_frames;
91 vector< scoped_refptr<VideoFrame> > dest_frames;
92
93 for (int i = 0; i < num_buffers; i++) {
94 scoped_refptr<VideoFrame> source_frame;
95 VideoFrame::CreateBlackFrame(source_width, source_height, &source_frame);
96 source_frames.push_back(source_frame);
97
98 scoped_refptr<VideoFrame> dest_frame;
99 VideoFrame::CreateFrame(VideoFrame::RGB32,
100 dest_width,
101 dest_height,
102 TimeDelta::FromSeconds(0),
103 TimeDelta::FromSeconds(0),
104 &dest_frame);
105 dest_frames.push_back(dest_frame);
106 }
107
108 TimeTicks start = TimeTicks::HighResNow();
109 for (int i = 0; i < num_frames; i++) {
110 scoped_refptr<VideoFrame> source_frame = source_frames[i % num_buffers];
111 scoped_refptr<VideoFrame> dest_frame = dest_frames[i % num_buffers];
112
113 media::ScaleYUVToRGB32(source_frame->data(VideoFrame::kYPlane),
114 source_frame->data(VideoFrame::kUPlane),
115 source_frame->data(VideoFrame::kVPlane),
116 dest_frame->data(0),
117 source_width,
118 source_height,
119 dest_width,
120 dest_height,
121 source_frame->stride(VideoFrame::kYPlane),
122 source_frame->stride(VideoFrame::kUPlane),
123 dest_frame->stride(0),
124 media::YV12,
125 media::ROTATE_0,
126 filter);
127 }
128 TimeTicks end = TimeTicks::HighResNow();
129 return static_cast<double>((end - start).InMilliseconds()) / num_frames;
130 }
131
132 } // namespace
133
134 int main(int argc, const char** argv) {
135 CommandLine::Init(argc, argv);
136 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
137
138 if (!cmd_line->GetLooseValues().empty()) {
139 std::cerr << "Usage: " << argv[0] << " [OPTIONS]\n"
140 << " --frames=N "
141 << "Number of frames\n"
142 << " --buffers=N "
143 << "Number of buffers\n"
144 << " --src-w=N "
145 << "Width of the source image\n"
146 << " --src-h=N "
147 << "Height of the source image\n"
148 << " --dest-w=N "
149 << "Width of the destination image\n"
150 << " --dest-h=N "
151 << "Height of the destination image\n"
152 << std::endl;
153 return 1;
154 }
155
156 std::string source_width_param(cmd_line->GetSwitchValueASCII("src-w"));
157 if (!source_width_param.empty() &&
158 !StringToInt(source_width_param, &source_width)) {
159 source_width = 0;
160 }
161
162 std::string source_height_param(cmd_line->GetSwitchValueASCII("src-h"));
163 if (!source_height_param.empty() &&
164 !StringToInt(source_height_param, &source_height)) {
165 source_height = 0;
166 }
167
168 std::string dest_width_param(cmd_line->GetSwitchValueASCII("dst-w"));
169 if (!dest_width_param.empty() &&
170 !StringToInt(dest_width_param, &dest_width)) {
171 dest_width = 0;
172 }
173
174 std::string dest_height_param(cmd_line->GetSwitchValueASCII("dst-h"));
175 if (!dest_height_param.empty() &&
176 !StringToInt(dest_height_param, &dest_height)) {
177 dest_height = 0;
178 }
179
180 std::string frames_param(cmd_line->GetSwitchValueASCII("frames"));
181 if (!frames_param.empty() &&
182 !StringToInt(frames_param, &num_frames)) {
183 num_frames = 0;
184 }
185
186 std::string buffers_param(cmd_line->GetSwitchValueASCII("buffers"));
187 if (!buffers_param.empty() &&
188 !StringToInt(buffers_param, &num_buffers)) {
189 num_buffers = 0;
190 }
191
192 std::cout << "Source image size: " << source_width
193 << "x" << source_height << std::endl;
194 std::cout << "Destination image size: " << dest_width
195 << "x" << dest_height << std::endl;
196 std::cout << "Number of frames: " << num_frames << std::endl;
197 std::cout << "Number of buffers: " << num_buffers << std::endl;
198
199 std::cout << "Skia: " << BenchmarkSkia()
200 << "ms/frame" << std::endl;
201 std::cout << "No filtering: " << BenchmarkFilter(media::FILTER_NONE)
202 << "ms/frame" << std::endl;
203 std::cout << "Bilinear: " << BenchmarkFilter(media::FILTER_BILINEAR)
204 << "ms/frame" << std::endl;
205
206 return 0;
207 }
OLDNEW
« no previous file with comments | « media/tools/scaler_bench/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698