Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include <deque> | |
| 6 #include <iostream> | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 | |
| 10 #include "app/gfx/gl/gl_bindings.h" | |
| 11 #include "app/gfx/gl/gl_context.h" | |
| 12 #include "app/gfx/gl/gl_implementation.h" | |
| 13 #include "base/at_exit.h" | |
| 14 #include "base/command_line.h" | |
| 15 #include "base/scoped_ptr.h" | |
| 16 #include "base/string_number_conversions.h" | |
| 17 #include "base/time.h" | |
| 18 #include "gfx/native_widget_types.h" | |
| 19 #include "media/base/callback.h" | |
| 20 #include "media/base/video_frame.h" | |
| 21 #include "media/tools/shader_bench/gl_painter.h" | |
| 22 #include "media/tools/shader_bench/painter.h" | |
| 23 #include "media/tools/shader_bench/window.h" | |
| 24 | |
| 25 #if defined(OS_LINUX) | |
| 26 #include <gtk/gtk.h> | |
| 27 #endif | |
| 28 | |
| 29 static const int kNumFramesToPaint = 500; | |
| 30 | |
| 31 unsigned long CalculateYUVFrameSize(FILE* file_handle, unsigned int num_frames) { | |
|
Alpha Left Google
2010/11/15 20:43:51
nit: 80 chars.
Alpha Left Google
2010/11/15 20:43:51
in general don't need unsigned unless necessary, j
Alpha Left Google
2010/11/15 20:43:51
use uint64 for file size and for frame size just i
| |
| 32 fseek(file_handle, 0, SEEK_END); | |
| 33 unsigned long file_size = ftell(file_handle); | |
| 34 rewind(file_handle); | |
| 35 return file_size / num_frames; | |
| 36 } | |
| 37 | |
| 38 void GetFrames(std::string file_name, | |
| 39 std::deque<scoped_refptr<media::VideoFrame> >& out_frames, | |
|
Alpha Left Google
2010/11/15 20:43:51
output object use * instead of reference
also out
| |
| 40 int width, int height, int num_frames) { | |
| 41 FILE* file_handle = fopen(file_name.c_str(), "rb"); | |
| 42 if (!file_handle) { | |
| 43 printf("Could not open %s\n", file_name.c_str()); | |
| 44 exit(1); | |
| 45 } | |
| 46 | |
| 47 unsigned long frame_size = CalculateYUVFrameSize(file_handle, num_frames); | |
| 48 | |
| 49 for (int i = 0; i < num_frames; i++) { | |
| 50 scoped_refptr<media::VideoFrame> video_frame; | |
| 51 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | |
| 52 width, | |
| 53 height, | |
| 54 base::TimeDelta(), | |
| 55 base::TimeDelta(), | |
| 56 &video_frame); | |
| 57 unsigned long bytes_read = | |
|
Alpha Left Google
2010/11/15 20:43:51
use int
| |
| 58 fread(video_frame->data(0), 1, frame_size, file_handle); | |
| 59 | |
| 60 if (bytes_read != frame_size) { | |
| 61 printf("Could not read %s\n", file_name.c_str()); | |
| 62 fclose(file_handle); | |
| 63 exit(1); | |
| 64 } | |
| 65 out_frames.push_back(video_frame); | |
| 66 } | |
| 67 | |
| 68 fclose(file_handle); | |
| 69 } | |
| 70 | |
| 71 void RunTest(std::deque<scoped_refptr<media::VideoFrame> >& frames, | |
| 72 media::Window* window) { | |
| 73 base::TimeTicks start = base::TimeTicks::HighResNow(); | |
| 74 for (int i = 0; i < kNumFramesToPaint; i++) | |
| 75 window->Paint(); | |
|
Alpha Left Google
2010/11/15 20:43:51
This block of code won't actually measure how fast
| |
| 76 base::TimeTicks end = base::TimeTicks::HighResNow(); | |
| 77 | |
| 78 printf("Printed %d frames in %f ms\n", kNumFramesToPaint, | |
| 79 static_cast<double>((end - start).InMilliseconds()) / kNumFramesToPaint ); | |
| 80 } | |
| 81 | |
| 82 int main(int argc, char** argv) { | |
| 83 // Read command line. | |
| 84 #if defined(OS_LINUX) | |
| 85 gtk_init(&argc, &argv); | |
| 86 #endif | |
| 87 CommandLine::Init(argc, argv); | |
| 88 | |
| 89 // Determine file name. | |
| 90 std::string file_name = | |
| 91 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("file"); | |
| 92 | |
| 93 // Determine number of frames. | |
| 94 int num_frames = 0; | |
| 95 std::string str_num_frames = | |
| 96 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("frames"); | |
| 97 base::StringToInt(str_num_frames, &num_frames); | |
| 98 | |
| 99 // Determine video dimensions. | |
| 100 int width = 0; | |
| 101 int height = 0; | |
| 102 std::string dimensions = | |
| 103 CommandLine::ForCurrentProcess()->GetSwitchValueASCII("wxh"); | |
| 104 int x_index = dimensions.find('x'); | |
| 105 std::string str_width = dimensions.substr(0, x_index); | |
| 106 std::string str_height = | |
| 107 dimensions.substr(x_index + 1, dimensions.length() - x_index - 1); | |
| 108 base::StringToInt(str_width, &width); | |
| 109 base::StringToInt(str_height, &height); | |
| 110 | |
| 111 // Process files. | |
| 112 std::deque<scoped_refptr<media::VideoFrame> > frames; | |
| 113 GetFrames(file_name, frames, width, height, num_frames); | |
|
scherkus (not reviewing)
2010/11/12 07:45:53
just to make sure.. we load everything into memory
| |
| 114 | |
| 115 // Initialize window and graphics context. | |
| 116 base::AtExitManager at_exit_manager; | |
| 117 gfx::GLContext::InitializeOneOff(); | |
| 118 media::Window* window = new media::Window(width, height); | |
| 119 gfx::GLContext* context = | |
| 120 gfx::GLContext::CreateViewGLContext(window->PluginWindow(), false); | |
| 121 context->MakeCurrent(); | |
| 122 | |
| 123 // Paint and benchmark. | |
| 124 GLPainter* gl_painter = new GLPainter(); | |
| 125 gl_painter->LoadFrames(&frames); | |
| 126 gl_painter->SetGLContext(context); | |
| 127 gl_painter->Initialize(width, height); | |
| 128 window->SetPainter(gl_painter); | |
| 129 printf("Running GL shader tests..."); | |
| 130 RunTest(frames, window); | |
| 131 | |
| 132 delete gl_painter; | |
| 133 delete window; | |
| 134 return 0; | |
| 135 } | |
| OLD | NEW |