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