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

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

Issue 6628020: Cleaning up src/media to be consistent with static versus anonymous namespaces. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: fix namespaces Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This tool can be used to measure performace of video frame scaling 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. 6 // code. It times performance of the scaler with and without filtering.
7 // It also measures performance of the Skia scaler for comparison. 7 // It also measures performance of the Skia scaler for comparison.
8 8
9 #include <iostream> 9 #include <iostream>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/scoped_vector.h" 13 #include "base/scoped_vector.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "media/base/video_frame.h" 17 #include "media/base/video_frame.h"
18 #include "media/base/yuv_convert.h" 18 #include "media/base/yuv_convert.h"
19 #include "skia/ext/platform_canvas.h" 19 #include "skia/ext/platform_canvas.h"
20 20
21 using base::TimeDelta; 21 using base::TimeDelta;
22 using base::TimeTicks; 22 using base::TimeTicks;
23 using media::VideoFrame; 23 using media::VideoFrame;
24 24
25 namespace { 25 static int source_width = 1280;
26 static int source_height = 720;
27 static int dest_width = 1366;
28 static int dest_height = 768;
29 static int num_frames = 500;
30 static int num_buffers = 50;
26 31
27 int source_width = 1280; 32 static double BenchmarkSkia() {
28 int source_height = 720;
29 int dest_width = 1366;
30 int dest_height = 768;
31 int num_frames = 500;
32 int num_buffers = 50;
33
34 double BenchmarkSkia() {
35 std::vector<scoped_refptr<VideoFrame> > source_frames; 33 std::vector<scoped_refptr<VideoFrame> > source_frames;
36 ScopedVector<SkBitmap> dest_frames; 34 ScopedVector<SkBitmap> dest_frames;
37 for (int i = 0; i < num_buffers; i++) { 35 for (int i = 0; i < num_buffers; i++) {
38 scoped_refptr<VideoFrame> source_frame; 36 scoped_refptr<VideoFrame> source_frame;
39 VideoFrame::CreateBlackFrame(source_width, source_height, &source_frame); 37 VideoFrame::CreateBlackFrame(source_width, source_height, &source_frame);
40 source_frames.push_back(source_frame); 38 source_frames.push_back(source_frame);
41 39
42 SkBitmap* bitmap = new SkBitmap(); 40 SkBitmap* bitmap = new SkBitmap();
43 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 41 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
44 dest_width, dest_height); 42 dest_width, dest_height);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 SkIntToScalar(dest_height) / 78 SkIntToScalar(dest_height) /
81 SkIntToScalar(source_height)); 79 SkIntToScalar(source_height));
82 SkPaint paint; 80 SkPaint paint;
83 paint.setFlags(SkPaint::kFilterBitmap_Flag); 81 paint.setFlags(SkPaint::kFilterBitmap_Flag);
84 canvas.drawBitmapMatrix(bitmap, matrix, &paint); 82 canvas.drawBitmapMatrix(bitmap, matrix, &paint);
85 } 83 }
86 TimeTicks end = TimeTicks::HighResNow(); 84 TimeTicks end = TimeTicks::HighResNow();
87 return static_cast<double>((end - start).InMilliseconds()) / num_frames; 85 return static_cast<double>((end - start).InMilliseconds()) / num_frames;
88 } 86 }
89 87
90 double BenchmarkRGBToYUV() { 88 static double BenchmarkRGBToYUV() {
91 int rgb_stride = source_width * 4; 89 int rgb_stride = source_width * 4;
92 scoped_array<uint8> rgb_frame(new uint8[rgb_stride * source_height]); 90 scoped_array<uint8> rgb_frame(new uint8[rgb_stride * source_height]);
93 91
94 int y_stride = source_width; 92 int y_stride = source_width;
95 int uv_stride = source_width / 2; 93 int uv_stride = source_width / 2;
96 scoped_array<uint8> y_plane(new uint8[y_stride * source_height]); 94 scoped_array<uint8> y_plane(new uint8[y_stride * source_height]);
97 scoped_array<uint8> u_plane(new uint8[uv_stride * source_height / 2]); 95 scoped_array<uint8> u_plane(new uint8[uv_stride * source_height / 2]);
98 scoped_array<uint8> v_plane(new uint8[uv_stride * source_height / 2]); 96 scoped_array<uint8> v_plane(new uint8[uv_stride * source_height / 2]);
99 97
100 TimeTicks start = TimeTicks::HighResNow(); 98 TimeTicks start = TimeTicks::HighResNow();
101 99
102 for (int i = 0; i < num_frames; ++i) { 100 for (int i = 0; i < num_frames; ++i) {
103 media::ConvertRGB32ToYUV(rgb_frame.get(), 101 media::ConvertRGB32ToYUV(rgb_frame.get(),
104 y_plane.get(), 102 y_plane.get(),
105 u_plane.get(), 103 u_plane.get(),
106 v_plane.get(), 104 v_plane.get(),
107 source_width, 105 source_width,
108 source_height, 106 source_height,
109 rgb_stride, 107 rgb_stride,
110 y_stride, 108 y_stride,
111 uv_stride); 109 uv_stride);
112 } 110 }
113 111
114 TimeTicks end = TimeTicks::HighResNow(); 112 TimeTicks end = TimeTicks::HighResNow();
115 return static_cast<double>((end - start).InMilliseconds()) / num_frames; 113 return static_cast<double>((end - start).InMilliseconds()) / num_frames;
116 } 114 }
117 115
118 double BenchmarkFilter(media::ScaleFilter filter) { 116 static double BenchmarkFilter(media::ScaleFilter filter) {
119 std::vector<scoped_refptr<VideoFrame> > source_frames; 117 std::vector<scoped_refptr<VideoFrame> > source_frames;
120 std::vector<scoped_refptr<VideoFrame> > dest_frames; 118 std::vector<scoped_refptr<VideoFrame> > dest_frames;
121 119
122 for (int i = 0; i < num_buffers; i++) { 120 for (int i = 0; i < num_buffers; i++) {
123 scoped_refptr<VideoFrame> source_frame; 121 scoped_refptr<VideoFrame> source_frame;
124 VideoFrame::CreateBlackFrame(source_width, source_height, &source_frame); 122 VideoFrame::CreateBlackFrame(source_width, source_height, &source_frame);
125 source_frames.push_back(source_frame); 123 source_frames.push_back(source_frame);
126 124
127 scoped_refptr<VideoFrame> dest_frame; 125 scoped_refptr<VideoFrame> dest_frame;
128 VideoFrame::CreateFrame(VideoFrame::RGB32, 126 VideoFrame::CreateFrame(VideoFrame::RGB32,
(...skipping 22 matching lines...) Expand all
151 source_frame->stride(VideoFrame::kUPlane), 149 source_frame->stride(VideoFrame::kUPlane),
152 dest_frame->stride(0), 150 dest_frame->stride(0),
153 media::YV12, 151 media::YV12,
154 media::ROTATE_0, 152 media::ROTATE_0,
155 filter); 153 filter);
156 } 154 }
157 TimeTicks end = TimeTicks::HighResNow(); 155 TimeTicks end = TimeTicks::HighResNow();
158 return static_cast<double>((end - start).InMilliseconds()) / num_frames; 156 return static_cast<double>((end - start).InMilliseconds()) / num_frames;
159 } 157 }
160 158
161 } // namespace
162
163 int main(int argc, const char** argv) { 159 int main(int argc, const char** argv) {
164 CommandLine::Init(argc, argv); 160 CommandLine::Init(argc, argv);
165 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 161 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
166 162
167 if (!cmd_line->args().empty()) { 163 if (!cmd_line->args().empty()) {
168 std::cerr << "Usage: " << argv[0] << " [OPTIONS]\n" 164 std::cerr << "Usage: " << argv[0] << " [OPTIONS]\n"
169 << " --frames=N " 165 << " --frames=N "
170 << "Number of frames\n" 166 << "Number of frames\n"
171 << " --buffers=N " 167 << " --buffers=N "
172 << "Number of buffers\n" 168 << "Number of buffers\n"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 << BenchmarkFilter(media::FILTER_BILINEAR_V) 231 << BenchmarkFilter(media::FILTER_BILINEAR_V)
236 << "ms/frame" << std::endl; 232 << "ms/frame" << std::endl;
237 std::cout << "Bilinear Horizontal: " 233 std::cout << "Bilinear Horizontal: "
238 << BenchmarkFilter(media::FILTER_BILINEAR_H) 234 << BenchmarkFilter(media::FILTER_BILINEAR_H)
239 << "ms/frame" << std::endl; 235 << "ms/frame" << std::endl;
240 std::cout << "Bilinear: " << BenchmarkFilter(media::FILTER_BILINEAR) 236 std::cout << "Bilinear: " << BenchmarkFilter(media::FILTER_BILINEAR)
241 << "ms/frame" << std::endl; 237 << "ms/frame" << std::endl;
242 238
243 return 0; 239 return 0;
244 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698