OLD | NEW |
1 // Copyright (c) 2011 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 // The bulk of this file is support code; sorry about that. Here's an overview | 5 // The bulk of this file is support code; sorry about that. Here's an overview |
6 // to hopefully help readers of this code: | 6 // to hopefully help readers of this code: |
7 // - RenderingHelper is charged with interacting with X11, EGL, and GLES2. | 7 // - RenderingHelper is charged with interacting with X11, EGL, and GLES2. |
8 // - ClientState is an enum for the state of the decode client used by the test. | 8 // - ClientState is an enum for the state of the decode client used by the test. |
9 // - ClientStateNotification is a barrier abstraction that allows the test code | 9 // - ClientStateNotification is a barrier abstraction that allows the test code |
10 // to be written sequentially and wait for the decode client to see certain | 10 // to be written sequentially and wait for the decode client to see certain |
(...skipping 10 matching lines...) Expand all Loading... |
21 // Include gtest.h out of order because <X11/X.h> #define's Bool & None, which | 21 // Include gtest.h out of order because <X11/X.h> #define's Bool & None, which |
22 // gtest uses as struct names (inside a namespace). This means that | 22 // gtest uses as struct names (inside a namespace). This means that |
23 // #include'ing gtest after anything that pulls in X.h fails to compile. | 23 // #include'ing gtest after anything that pulls in X.h fails to compile. |
24 // This is http://code.google.com/p/googletest/issues/detail?id=371 | 24 // This is http://code.google.com/p/googletest/issues/detail?id=371 |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 #include "base/at_exit.h" | 27 #include "base/at_exit.h" |
28 #include "base/bind.h" | 28 #include "base/bind.h" |
29 #include "base/command_line.h" | 29 #include "base/command_line.h" |
30 #include "base/file_util.h" | 30 #include "base/file_util.h" |
| 31 #include "base/process_util.h" |
31 #include "base/stl_util.h" | 32 #include "base/stl_util.h" |
32 #include "base/string_number_conversions.h" | 33 #include "base/string_number_conversions.h" |
33 #include "base/string_split.h" | 34 #include "base/string_split.h" |
34 #include "base/stringize_macros.h" | 35 #include "base/stringize_macros.h" |
35 #include "base/synchronization/condition_variable.h" | 36 #include "base/synchronization/condition_variable.h" |
36 #include "base/synchronization/lock.h" | 37 #include "base/synchronization/lock.h" |
37 #include "base/synchronization/waitable_event.h" | 38 #include "base/synchronization/waitable_event.h" |
38 #include "base/threading/thread.h" | 39 #include "base/threading/thread.h" |
| 40 #include "base/utf_string_conversions.h" |
| 41 |
| 42 #if (!defined(OS_CHROMEOS) || !defined(ARCH_CPU_ARMEL)) && !defined(OS_WIN) |
| 43 #error The VideoAccelerator tests are only supported on cros/ARM/Windows. |
| 44 #endif |
| 45 |
| 46 #if defined(OS_WIN) |
| 47 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" |
| 48 #else // OS_WIN |
39 #include "content/common/gpu/media/omx_video_decode_accelerator.h" | 49 #include "content/common/gpu/media/omx_video_decode_accelerator.h" |
| 50 #endif // defined(OS_WIN) |
| 51 |
40 #include "third_party/angle/include/EGL/egl.h" | 52 #include "third_party/angle/include/EGL/egl.h" |
41 #include "third_party/angle/include/GLES2/gl2.h" | 53 #include "third_party/angle/include/GLES2/gl2.h" |
42 | 54 |
43 #if !defined(OS_CHROMEOS) || !defined(ARCH_CPU_ARMEL) | |
44 #error This test (and OmxVideoDecodeAccelerator) are only supported on cros/ARM! | |
45 #endif | |
46 | |
47 using media::VideoDecodeAccelerator; | 55 using media::VideoDecodeAccelerator; |
48 | 56 |
49 namespace { | 57 namespace { |
50 | 58 |
51 // Values optionally filled in from flags; see main() below. | 59 // Values optionally filled in from flags; see main() below. |
52 // The syntax of this variable is: | 60 // The syntax of this variable is: |
53 // filename:width:height:numframes:numNALUs:minFPSwithRender:minFPSnoRender | 61 // filename:width:height:numframes:numNALUs:minFPSwithRender:minFPSnoRender |
54 // where only the first field is required. Value details: | 62 // where only the first field is required. Value details: |
55 // - |filename| must be an h264 Annex B (NAL) stream. | 63 // - |filename| must be an h264 Annex B (NAL) stream. |
56 // - |width| and |height| are in pixels. | 64 // - |width| and |height| are in pixels. |
57 // - |numframes| is the number of picture frames in the file. | 65 // - |numframes| is the number of picture frames in the file. |
58 // - |numNALUs| is the number of NAL units in the stream. | 66 // - |numNALUs| is the number of NAL units in the stream. |
59 // - |minFPSwithRender| and |minFPSnoRender| are minimum frames/second speeds | 67 // - |minFPSwithRender| and |minFPSnoRender| are minimum frames/second speeds |
60 // expected to be achieved with and without rendering to the screen, resp. | 68 // expected to be achieved with and without rendering to the screen, resp. |
61 // (the latter tests just decode speed). | 69 // (the latter tests just decode speed). |
62 // - |profile| is the media::H264Profile set during Initialization. | 70 // - |profile| is the media::H264Profile set during Initialization. |
63 // An empty value for a numeric field means "ignore". | 71 // An empty value for a numeric field means "ignore". |
64 const char* test_video_data = "test-25fps.h264:320:240:250:258:50:175:1"; | 72 const FilePath::CharType* test_video_data = |
| 73 FILE_PATH_LITERAL("test-25fps.h264:320:240:250:258:50:175:1"); |
65 | 74 |
66 // Parse |data| into its constituent parts and set the various output fields | 75 // Parse |data| into its constituent parts and set the various output fields |
67 // accordingly. CHECK-fails on unexpected or missing required data. | 76 // accordingly. CHECK-fails on unexpected or missing required data. |
68 // Unspecified optional fields are set to -1. | 77 // Unspecified optional fields are set to -1. |
69 void ParseTestVideoData(std::string data, | 78 void ParseTestVideoData(FilePath::StringType data, |
70 std::string* file_name, | 79 FilePath::StringType* file_name, |
71 int* width, int* height, | 80 int* width, int* height, |
72 int* num_frames, | 81 int* num_frames, |
73 int* num_NALUs, | 82 int* num_NALUs, |
74 int* min_fps_render, | 83 int* min_fps_render, |
75 int* min_fps_no_render, | 84 int* min_fps_no_render, |
76 int* profile) { | 85 int* profile) { |
77 std::vector<std::string> elements; | 86 std::vector<FilePath::StringType> elements; |
78 base::SplitString(data, ':', &elements); | 87 base::SplitString(data, ':', &elements); |
79 CHECK_GE(elements.size(), 1U) << data; | 88 CHECK_GE(elements.size(), 1U) << data; |
80 CHECK_LE(elements.size(), 8U) << data; | 89 CHECK_LE(elements.size(), 8U) << data; |
81 *file_name = elements[0]; | 90 *file_name = elements[0]; |
82 *width = *height = *num_frames = *num_NALUs = -1; | 91 *width = *height = *num_frames = *num_NALUs = -1; |
83 *min_fps_render = *min_fps_no_render = -1; | 92 *min_fps_render = *min_fps_no_render = -1; |
84 *profile = -1; | 93 *profile = -1; |
85 if (!elements[1].empty()) | 94 if (!elements[1].empty()) |
86 CHECK(base::StringToInt(elements[1], width)); | 95 CHECK(base::StringToInt(elements[1], width)); |
87 if (!elements[2].empty()) | 96 if (!elements[2].empty()) |
88 CHECK(base::StringToInt(elements[2], height)); | 97 CHECK(base::StringToInt(elements[2], height)); |
89 if (!elements[3].empty()) | 98 if (!elements[3].empty()) |
90 CHECK(base::StringToInt(elements[3], num_frames)); | 99 CHECK(base::StringToInt(elements[3], num_frames)); |
91 if (!elements[4].empty()) | 100 if (!elements[4].empty()) |
92 CHECK(base::StringToInt(elements[4], num_NALUs)); | 101 CHECK(base::StringToInt(elements[4], num_NALUs)); |
93 if (!elements[5].empty()) | 102 if (!elements[5].empty()) |
94 CHECK(base::StringToInt(elements[5], min_fps_render)); | 103 CHECK(base::StringToInt(elements[5], min_fps_render)); |
95 if (!elements[6].empty()) | 104 if (!elements[6].empty()) |
96 CHECK(base::StringToInt(elements[6], min_fps_no_render)); | 105 CHECK(base::StringToInt(elements[6], min_fps_no_render)); |
97 if (!elements[7].empty()) | 106 if (!elements[7].empty()) |
98 CHECK(base::StringToInt(elements[7], profile)); | 107 CHECK(base::StringToInt(elements[7], profile)); |
99 } | 108 } |
100 | 109 |
101 | 110 // Provides functionality for managing EGL, GLES2 and UI resources. |
102 // Helper for managing X11, EGL, and GLES2 resources. Xlib is not thread-safe, | 111 // This class is not thread safe and thus all the methods of this class |
103 // and GL state is thread-specific, so all the methods of this class (except for | 112 // (except for ctor/dtor) ensure they're being run on a single thread. |
104 // ctor/dtor) ensure they're being run on a single thread. | |
105 // | |
106 // TODO(fischman): consider moving this into media/ if we can de-dup some of the | |
107 // code that ends up getting copy/pasted all over the place (esp. the GL setup | |
108 // code). | |
109 class RenderingHelper { | 113 class RenderingHelper { |
110 public: | 114 public: |
111 explicit RenderingHelper(); | 115 RenderingHelper(); |
112 ~RenderingHelper(); | 116 ~RenderingHelper(); |
113 | 117 |
114 // Initialize all structures to prepare to render to one or more windows of | 118 // Initialize all structures to prepare to render to one or more windows of |
115 // the specified dimensions. CHECK-fails if any initialization step fails. | 119 // the specified dimensions. CHECK-fails if any initialization step fails. |
116 // After this returns, texture creation and rendering can be requested. This | 120 // After this returns, texture creation and rendering can be requested. This |
117 // method can be called multiple times, in which case all previously-acquired | 121 // method can be called multiple times, in which case all previously-acquired |
118 // resources and initializations are discarded. If |suppress_swap_to_display| | 122 // resources and initializations are discarded. If |suppress_swap_to_display| |
119 // then all the usual work is done, except for the final swap of the EGL | 123 // then all the usual work is done, except for the final swap of the EGL |
120 // surface to the display. This cuts test times over 50% so is worth doing | 124 // surface to the display. This cuts test times over 50% so is worth doing |
121 // when testing non-rendering-related aspects. | 125 // when testing non-rendering-related aspects. |
122 void Initialize(bool suppress_swap_to_display, int num_windows, | 126 void Initialize(bool suppress_swap_to_display, int num_windows, int width, |
123 int width, int height, base::WaitableEvent* done); | 127 int height, base::WaitableEvent* done); |
124 | 128 |
125 // Undo the effects of Initialize() and signal |*done|. | 129 // Undo the effects of Initialize() and signal |*done|. |
126 void UnInitialize(base::WaitableEvent* done); | 130 void UnInitialize(base::WaitableEvent* done); |
127 | 131 |
128 // Return a newly-created GLES2 texture id rendering to a specific window, and | 132 // Return a newly-created GLES2 texture id rendering to a specific window, and |
129 // signal |*done|. | 133 // signal |*done|. |
130 void CreateTexture(int window_id, GLuint* texture_id, | 134 void CreateTexture(int window_id, GLuint* texture_id, |
131 base::WaitableEvent* done); | 135 base::WaitableEvent* done); |
132 | 136 |
133 // Render |texture_id| to the screen (unless |suppress_swap_to_display_|). | 137 // Render |texture_id| to the screen (unless |suppress_swap_to_display_|). |
134 void RenderTexture(GLuint texture_id); | 138 void RenderTexture(GLuint texture_id); |
135 | 139 |
136 // Delete |texture_id|. | 140 // Delete |texture_id|. |
137 void DeleteTexture(GLuint texture_id); | 141 void DeleteTexture(GLuint texture_id); |
138 | 142 |
| 143 // Platform specific Init/Uninit. |
| 144 void PlatformInitialize(); |
| 145 void PlatformUnInitialize(); |
| 146 |
| 147 // Platform specific window creation. |
| 148 EGLNativeWindowType PlatformCreateWindow(int top_left_x, int top_left_y); |
| 149 |
| 150 // Platform specific display surface returned here. |
| 151 EGLDisplay PlatformGetDisplay(); |
| 152 |
139 EGLDisplay egl_display() { return egl_display_; } | 153 EGLDisplay egl_display() { return egl_display_; } |
| 154 |
140 EGLContext egl_context() { return egl_context_; } | 155 EGLContext egl_context() { return egl_context_; } |
| 156 |
141 MessageLoop* message_loop() { return message_loop_; } | 157 MessageLoop* message_loop() { return message_loop_; } |
142 | 158 |
143 private: | 159 protected: |
144 // Zero-out internal state. Helper for ctor & UnInitialize(). | |
145 void Clear(); | 160 void Clear(); |
146 | 161 |
147 bool suppress_swap_to_display_; | 162 // We ensure all operations are carried out on the same thread by remembering |
| 163 // where we were Initialized. |
| 164 MessageLoop* message_loop_; |
148 int width_; | 165 int width_; |
149 int height_; | 166 int height_; |
150 Display* x_display_; | 167 bool suppress_swap_to_display_; |
151 std::vector<Window> x_windows_; | 168 |
152 EGLDisplay egl_display_; | 169 EGLDisplay egl_display_; |
153 EGLContext egl_context_; | 170 EGLContext egl_context_; |
154 std::vector<EGLSurface> egl_surfaces_; | 171 std::vector<EGLSurface> egl_surfaces_; |
155 std::map<GLuint, int> texture_id_to_surface_index_; | 172 std::map<GLuint, int> texture_id_to_surface_index_; |
156 // We ensure all operations are carried out on the same thread by remembering | 173 |
157 // where we were Initialized. | 174 #if defined(OS_WIN) |
158 MessageLoop* message_loop_; | 175 std::vector<HWND> windows_; |
| 176 #else // OS_WIN |
| 177 Display* x_display_; |
| 178 std::vector<Window> x_windows_; |
| 179 #endif // OS_WIN |
159 }; | 180 }; |
160 | 181 |
161 RenderingHelper::RenderingHelper() { | 182 RenderingHelper::RenderingHelper() { |
162 Clear(); | 183 Clear(); |
163 } | 184 } |
164 | 185 |
165 RenderingHelper::~RenderingHelper() { | 186 RenderingHelper::~RenderingHelper() { |
166 CHECK_EQ(width_, 0) << "Must call UnInitialize before dtor."; | 187 CHECK_EQ(width_, 0) << "Must call UnInitialize before dtor."; |
167 } | 188 Clear(); |
168 | |
169 void RenderingHelper::Clear() { | |
170 suppress_swap_to_display_ = false; | |
171 width_ = 0; | |
172 height_ = 0; | |
173 x_display_ = NULL; | |
174 x_windows_.clear(); | |
175 egl_display_ = EGL_NO_DISPLAY; | |
176 egl_context_ = EGL_NO_CONTEXT; | |
177 egl_surfaces_.clear(); | |
178 texture_id_to_surface_index_.clear(); | |
179 message_loop_ = NULL; | |
180 } | 189 } |
181 | 190 |
182 // Helper for Shader creation. | 191 // Helper for Shader creation. |
183 static void CreateShader( | 192 static void CreateShader( |
184 GLuint program, GLenum type, const char* source, int size) { | 193 GLuint program, GLenum type, const char* source, int size) { |
185 GLuint shader = glCreateShader(type); | 194 GLuint shader = glCreateShader(type); |
186 glShaderSource(shader, 1, &source, &size); | 195 glShaderSource(shader, 1, &source, &size); |
187 glCompileShader(shader); | 196 glCompileShader(shader); |
188 int result = GL_FALSE; | 197 int result = GL_FALSE; |
189 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); | 198 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); |
190 if (!result) { | 199 if (!result) { |
191 char log[4096]; | 200 char log[4096]; |
192 glGetShaderInfoLog(shader, arraysize(log), NULL, log); | 201 glGetShaderInfoLog(shader, arraysize(log), NULL, log); |
193 LOG(FATAL) << log; | 202 LOG(FATAL) << log; |
194 } | 203 } |
195 glAttachShader(program, shader); | 204 glAttachShader(program, shader); |
196 glDeleteShader(shader); | 205 glDeleteShader(shader); |
197 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 206 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
198 } | 207 } |
199 | 208 |
200 void RenderingHelper::Initialize( | 209 void RenderingHelper::Initialize( |
201 bool suppress_swap_to_display, | 210 bool suppress_swap_to_display, |
202 int num_windows, | 211 int num_windows, |
203 int width, int height, | 212 int width, |
| 213 int height, |
204 base::WaitableEvent* done) { | 214 base::WaitableEvent* done) { |
205 // Use width_ != 0 as a proxy for the class having already been | 215 // Use width_ != 0 as a proxy for the class having already been |
206 // Initialize()'d, and UnInitialize() before continuing. | 216 // Initialize()'d, and UnInitialize() before continuing. |
207 if (width_) { | 217 if (width_) { |
208 base::WaitableEvent done(false, false); | 218 base::WaitableEvent done(false, false); |
209 UnInitialize(&done); | 219 UnInitialize(&done); |
210 done.Wait(); | 220 done.Wait(); |
211 } | 221 } |
212 | 222 |
213 suppress_swap_to_display_ = suppress_swap_to_display; | 223 suppress_swap_to_display_ = suppress_swap_to_display; |
214 CHECK_GT(width, 0); | 224 CHECK_GT(width, 0); |
215 CHECK_GT(height, 0); | 225 CHECK_GT(height, 0); |
216 width_ = width; | 226 width_ = width; |
217 height_ = height; | 227 height_ = height; |
218 message_loop_ = MessageLoop::current(); | 228 message_loop_ = MessageLoop::current(); |
219 CHECK_GT(num_windows, 0); | 229 CHECK_GT(num_windows, 0); |
220 | 230 |
221 // Per-display X11 & EGL initialization. | 231 PlatformInitialize(); |
222 CHECK(x_display_ = XOpenDisplay(NULL)); | |
223 int depth = DefaultDepth(x_display_, DefaultScreen(x_display_)); | |
224 XSetWindowAttributes window_attributes; | |
225 window_attributes.background_pixel = | |
226 BlackPixel(x_display_, DefaultScreen(x_display_)); | |
227 window_attributes.override_redirect = true; | |
228 | 232 |
229 egl_display_ = eglGetDisplay(x_display_); | 233 egl_display_ = PlatformGetDisplay(); |
| 234 |
230 EGLint major; | 235 EGLint major; |
231 EGLint minor; | 236 EGLint minor; |
232 CHECK(eglInitialize(egl_display_, &major, &minor)) << eglGetError(); | 237 CHECK(eglInitialize(egl_display_, &major, &minor)) << eglGetError(); |
233 static EGLint rgba8888[] = { | 238 static EGLint rgba8888[] = { |
234 EGL_RED_SIZE, 8, | 239 EGL_RED_SIZE, 8, |
235 EGL_GREEN_SIZE, 8, | 240 EGL_GREEN_SIZE, 8, |
236 EGL_BLUE_SIZE, 8, | 241 EGL_BLUE_SIZE, 8, |
237 EGL_ALPHA_SIZE, 8, | 242 EGL_ALPHA_SIZE, 8, |
238 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, | 243 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
239 EGL_NONE, | 244 EGL_NONE, |
240 }; | 245 }; |
241 EGLConfig egl_config; | 246 EGLConfig egl_config; |
242 int num_configs; | 247 int num_configs; |
243 CHECK(eglChooseConfig(egl_display_, rgba8888, &egl_config, 1, &num_configs)) | 248 CHECK(eglChooseConfig(egl_display_, rgba8888, &egl_config, 1, &num_configs)) |
244 << eglGetError(); | 249 << eglGetError(); |
245 CHECK_GE(num_configs, 1); | 250 CHECK_GE(num_configs, 1); |
246 static EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; | 251 static EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; |
247 egl_context_ = eglCreateContext( | 252 egl_context_ = eglCreateContext( |
248 egl_display_, egl_config, EGL_NO_CONTEXT, context_attribs); | 253 egl_display_, egl_config, EGL_NO_CONTEXT, context_attribs); |
249 CHECK_NE(egl_context_, EGL_NO_CONTEXT) << eglGetError(); | 254 CHECK_NE(egl_context_, EGL_NO_CONTEXT) << eglGetError(); |
250 | 255 |
251 // Per-window/surface X11 & EGL initialization. | 256 // Per-window/surface X11 & EGL initialization. |
252 for (int i = 0; i < num_windows; ++i) { | 257 for (int i = 0; i < num_windows; ++i) { |
253 // Arrange X windows whimsically, with some padding. | 258 // Arrange X windows whimsically, with some padding. |
254 int top_left_x = (width + 20) * (i % 4); | 259 int top_left_x = (width + 20) * (i % 4); |
255 int top_left_y = (height + 12) * (i % 3); | 260 int top_left_y = (height + 12) * (i % 3); |
256 Window x_window = XCreateWindow( | |
257 x_display_, DefaultRootWindow(x_display_), | |
258 top_left_x, top_left_y, width_, height_, | |
259 0 /* border width */, | |
260 depth, CopyFromParent /* class */, CopyFromParent /* visual */, | |
261 (CWBackPixel | CWOverrideRedirect), &window_attributes); | |
262 x_windows_.push_back(x_window); | |
263 XStoreName(x_display_, x_window, "OmxVideoDecodeAcceleratorTest"); | |
264 XSelectInput(x_display_, x_window, ExposureMask); | |
265 XMapWindow(x_display_, x_window); | |
266 | 261 |
| 262 EGLNativeWindowType window = PlatformCreateWindow(top_left_x, top_left_y); |
267 EGLSurface egl_surface = | 263 EGLSurface egl_surface = |
268 eglCreateWindowSurface(egl_display_, egl_config, x_window, NULL); | 264 eglCreateWindowSurface(egl_display_, egl_config, window, NULL); |
269 egl_surfaces_.push_back(egl_surface); | 265 egl_surfaces_.push_back(egl_surface); |
270 CHECK_NE(egl_surface, EGL_NO_SURFACE); | 266 CHECK_NE(egl_surface, EGL_NO_SURFACE); |
271 } | 267 } |
272 CHECK(eglMakeCurrent(egl_display_, egl_surfaces_[0], | 268 CHECK(eglMakeCurrent(egl_display_, egl_surfaces_[0], |
273 egl_surfaces_[0], egl_context_)) << eglGetError(); | 269 egl_surfaces_[0], egl_context_)) << eglGetError(); |
274 | 270 |
275 // GLES2 initialization. Note: This is pretty much copy/pasted from | |
276 // media/tools/player_x11/gles_video_renderer.cc, with some simplification | |
277 // applied. | |
278 static const float kVertices[] = | 271 static const float kVertices[] = |
279 { -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f, }; | 272 { -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f, }; |
280 static const float kTextureCoordsEgl[] = { 0, 1, 0, 0, 1, 1, 1, 0, }; | 273 static const float kTextureCoordsEgl[] = { 0, 1, 0, 0, 1, 1, 1, 0, }; |
281 static const char kVertexShader[] = STRINGIZE( | 274 static const char kVertexShader[] = STRINGIZE( |
282 varying vec2 interp_tc; | 275 varying vec2 interp_tc; |
283 attribute vec4 in_pos; | 276 attribute vec4 in_pos; |
284 attribute vec2 in_tc; | 277 attribute vec2 in_tc; |
285 void main() { | 278 void main() { |
286 interp_tc = in_tc; | 279 interp_tc = in_tc; |
287 gl_Position = in_pos; | 280 gl_Position = in_pos; |
(...skipping 24 matching lines...) Expand all Loading... |
312 glDeleteProgram(program); | 305 glDeleteProgram(program); |
313 | 306 |
314 glUniform1i(glGetUniformLocation(program, "tex"), 0); | 307 glUniform1i(glGetUniformLocation(program, "tex"), 0); |
315 int pos_location = glGetAttribLocation(program, "in_pos"); | 308 int pos_location = glGetAttribLocation(program, "in_pos"); |
316 glEnableVertexAttribArray(pos_location); | 309 glEnableVertexAttribArray(pos_location); |
317 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); | 310 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); |
318 int tc_location = glGetAttribLocation(program, "in_tc"); | 311 int tc_location = glGetAttribLocation(program, "in_tc"); |
319 glEnableVertexAttribArray(tc_location); | 312 glEnableVertexAttribArray(tc_location); |
320 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, | 313 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, |
321 kTextureCoordsEgl); | 314 kTextureCoordsEgl); |
322 | |
323 done->Signal(); | 315 done->Signal(); |
324 } | 316 } |
325 | 317 |
326 void RenderingHelper::UnInitialize(base::WaitableEvent* done) { | 318 void RenderingHelper::UnInitialize(base::WaitableEvent* done) { |
327 CHECK_EQ(MessageLoop::current(), message_loop_); | 319 CHECK_EQ(MessageLoop::current(), message_loop_); |
328 // Destroy resources acquired in Initialize, in reverse-acquisition order. | |
329 CHECK(eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, | 320 CHECK(eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, |
330 EGL_NO_CONTEXT)) << eglGetError(); | 321 EGL_NO_CONTEXT)) << eglGetError(); |
331 CHECK(eglDestroyContext(egl_display_, egl_context_)); | 322 CHECK(eglDestroyContext(egl_display_, egl_context_)); |
332 for (size_t i = 0; i < egl_surfaces_.size(); ++i) | 323 for (size_t i = 0; i < egl_surfaces_.size(); ++i) |
333 CHECK(eglDestroySurface(egl_display_, egl_surfaces_[i])); | 324 CHECK(eglDestroySurface(egl_display_, egl_surfaces_[i])); |
334 CHECK(eglTerminate(egl_display_)); | 325 CHECK(eglTerminate(egl_display_)); |
335 for (size_t i = 0; i < x_windows_.size(); ++i) { | |
336 CHECK(XUnmapWindow(x_display_, x_windows_[i])); | |
337 CHECK(XDestroyWindow(x_display_, x_windows_[i])); | |
338 } | |
339 // Mimic newly-created object. | |
340 Clear(); | 326 Clear(); |
341 done->Signal(); | 327 done->Signal(); |
342 } | 328 } |
343 | 329 |
| 330 void RenderingHelper::Clear() { |
| 331 suppress_swap_to_display_ = false; |
| 332 width_ = 0; |
| 333 height_ = 0; |
| 334 texture_id_to_surface_index_.clear(); |
| 335 message_loop_ = NULL; |
| 336 egl_display_ = EGL_NO_DISPLAY; |
| 337 egl_context_ = EGL_NO_CONTEXT; |
| 338 egl_surfaces_.clear(); |
| 339 PlatformUnInitialize(); |
| 340 } |
| 341 |
344 void RenderingHelper::CreateTexture(int window_id, GLuint* texture_id, | 342 void RenderingHelper::CreateTexture(int window_id, GLuint* texture_id, |
345 base::WaitableEvent* done) { | 343 base::WaitableEvent* done) { |
346 if (MessageLoop::current() != message_loop_) { | 344 if (MessageLoop::current() != message_loop_) { |
347 message_loop_->PostTask( | 345 message_loop_->PostTask( |
348 FROM_HERE, | 346 FROM_HERE, |
349 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this), | 347 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this), |
350 window_id, texture_id, done)); | 348 window_id, texture_id, done)); |
351 return; | 349 return; |
352 } | 350 } |
353 CHECK(eglMakeCurrent(egl_display_, egl_surfaces_[window_id], | 351 CHECK(eglMakeCurrent(egl_display_, egl_surfaces_[window_id], |
(...skipping 29 matching lines...) Expand all Loading... |
383 eglSwapBuffers(egl_display_, egl_surfaces_[window_id]); | 381 eglSwapBuffers(egl_display_, egl_surfaces_[window_id]); |
384 } | 382 } |
385 CHECK_EQ(static_cast<int>(eglGetError()), EGL_SUCCESS); | 383 CHECK_EQ(static_cast<int>(eglGetError()), EGL_SUCCESS); |
386 } | 384 } |
387 | 385 |
388 void RenderingHelper::DeleteTexture(GLuint texture_id) { | 386 void RenderingHelper::DeleteTexture(GLuint texture_id) { |
389 glDeleteTextures(1, &texture_id); | 387 glDeleteTextures(1, &texture_id); |
390 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 388 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
391 } | 389 } |
392 | 390 |
| 391 #if defined(OS_WIN) |
| 392 void RenderingHelper::PlatformInitialize() {} |
| 393 |
| 394 void RenderingHelper::PlatformUnInitialize() { |
| 395 for (size_t i = 0; i < windows_.size(); ++i) { |
| 396 DestroyWindow(windows_[i]); |
| 397 } |
| 398 windows_.clear(); |
| 399 } |
| 400 |
| 401 EGLNativeWindowType RenderingHelper::PlatformCreateWindow( |
| 402 int top_left_x, int top_left_y) { |
| 403 HWND window = CreateWindowEx(0, L"Static", L"VideoDecodeAcceleratorTest", |
| 404 WS_OVERLAPPEDWINDOW | WS_VISIBLE, top_left_x, |
| 405 top_left_y, width_, height_, NULL, NULL, NULL, |
| 406 NULL); |
| 407 CHECK(window != NULL); |
| 408 windows_.push_back(window); |
| 409 return window; |
| 410 } |
| 411 |
| 412 EGLDisplay RenderingHelper::PlatformGetDisplay() { |
| 413 return eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 414 } |
| 415 |
| 416 #else // OS_WIN |
| 417 |
| 418 void RenderingHelper::PlatformInitialize() { |
| 419 CHECK(x_display_ = XOpenDisplay(NULL)); |
| 420 } |
| 421 |
| 422 void RenderingHelper::PlatformUnInitialize() { |
| 423 // Destroy resources acquired in Initialize, in reverse-acquisition order. |
| 424 for (size_t i = 0; i < x_windows_.size(); ++i) { |
| 425 CHECK(XUnmapWindow(x_display_, x_windows_[i])); |
| 426 CHECK(XDestroyWindow(x_display_, x_windows_[i])); |
| 427 } |
| 428 // Mimic newly created object. |
| 429 x_display_ = NULL; |
| 430 x_windows_.clear(); |
| 431 } |
| 432 |
| 433 EGLDisplay RenderingHelper::PlatformGetDisplay() { |
| 434 return eglGetDisplay(x_display_); |
| 435 } |
| 436 |
| 437 EGLNativeWindowType RenderingHelper::PlatformCreateWindow(int top_left_x, |
| 438 int top_left_y) { |
| 439 int depth = DefaultDepth(x_display_, DefaultScreen(x_display_)); |
| 440 |
| 441 XSetWindowAttributes window_attributes; |
| 442 window_attributes.background_pixel = |
| 443 BlackPixel(x_display_, DefaultScreen(x_display_)); |
| 444 window_attributes.override_redirect = true; |
| 445 |
| 446 Window x_window = XCreateWindow( |
| 447 x_display_, DefaultRootWindow(x_display_), |
| 448 top_left_x, top_left_y, width_, height_, |
| 449 0 /* border width */, |
| 450 depth, CopyFromParent /* class */, CopyFromParent /* visual */, |
| 451 (CWBackPixel | CWOverrideRedirect), &window_attributes); |
| 452 x_windows_.push_back(x_window); |
| 453 XStoreName(x_display_, x_window, "VideoDecodeAcceleratorTest"); |
| 454 XSelectInput(x_display_, x_window, ExposureMask); |
| 455 XMapWindow(x_display_, x_window); |
| 456 return x_window; |
| 457 } |
| 458 |
| 459 #endif // OS_WIN |
| 460 |
393 // State of the EglRenderingVDAClient below. Order matters here as the test | 461 // State of the EglRenderingVDAClient below. Order matters here as the test |
394 // makes assumptions about it. | 462 // makes assumptions about it. |
395 enum ClientState { | 463 enum ClientState { |
396 CS_CREATED, | 464 CS_CREATED, |
397 CS_DECODER_SET, | 465 CS_DECODER_SET, |
398 CS_INITIALIZED, | 466 CS_INITIALIZED, |
399 CS_FLUSHING, | 467 CS_FLUSHING, |
400 CS_FLUSHED, | 468 CS_FLUSHED, |
401 CS_DONE, | 469 CS_DONE, |
402 CS_RESETTING, | 470 CS_RESETTING, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 584 |
517 RenderingHelper* rendering_helper_; | 585 RenderingHelper* rendering_helper_; |
518 int rendering_window_id_; | 586 int rendering_window_id_; |
519 std::string encoded_data_; | 587 std::string encoded_data_; |
520 const int num_NALUs_per_decode_; | 588 const int num_NALUs_per_decode_; |
521 const int num_in_flight_decodes_; | 589 const int num_in_flight_decodes_; |
522 int outstanding_decodes_; | 590 int outstanding_decodes_; |
523 size_t encoded_data_next_pos_to_decode_; | 591 size_t encoded_data_next_pos_to_decode_; |
524 int next_bitstream_buffer_id_; | 592 int next_bitstream_buffer_id_; |
525 ClientStateNotification* note_; | 593 ClientStateNotification* note_; |
526 scoped_refptr<OmxVideoDecodeAccelerator> decoder_; | 594 scoped_refptr<VideoDecodeAccelerator> decoder_; |
527 std::set<int> outstanding_texture_ids_; | 595 std::set<int> outstanding_texture_ids_; |
528 int reset_after_frame_num_; | 596 int reset_after_frame_num_; |
529 int delete_decoder_state_; | 597 int delete_decoder_state_; |
530 ClientState state_; | 598 ClientState state_; |
531 int num_decoded_frames_; | 599 int num_decoded_frames_; |
532 int num_done_bitstream_buffers_; | 600 int num_done_bitstream_buffers_; |
533 PictureBufferById picture_buffers_by_id_; | 601 PictureBufferById picture_buffers_by_id_; |
534 base::TimeTicks initialize_done_ticks_; | 602 base::TimeTicks initialize_done_ticks_; |
535 base::TimeTicks last_frame_delivered_ticks_; | 603 base::TimeTicks last_frame_delivered_ticks_; |
536 int profile_; | 604 int profile_; |
(...skipping 25 matching lines...) Expand all Loading... |
562 | 630 |
563 EglRenderingVDAClient::~EglRenderingVDAClient() { | 631 EglRenderingVDAClient::~EglRenderingVDAClient() { |
564 DeleteDecoder(); // Clean up in case of expected error. | 632 DeleteDecoder(); // Clean up in case of expected error. |
565 CHECK(decoder_deleted()); | 633 CHECK(decoder_deleted()); |
566 STLDeleteValues(&picture_buffers_by_id_); | 634 STLDeleteValues(&picture_buffers_by_id_); |
567 SetState(CS_DESTROYED); | 635 SetState(CS_DESTROYED); |
568 } | 636 } |
569 | 637 |
570 void EglRenderingVDAClient::CreateDecoder() { | 638 void EglRenderingVDAClient::CreateDecoder() { |
571 CHECK(decoder_deleted()); | 639 CHECK(decoder_deleted()); |
572 decoder_ = new OmxVideoDecodeAccelerator(this); | 640 #if defined(OS_WIN) |
573 decoder_->SetEglState(egl_display(), egl_context()); | 641 scoped_refptr<DXVAVideoDecodeAccelerator> decoder = |
| 642 new DXVAVideoDecodeAccelerator(this, base::GetCurrentProcessHandle()); |
| 643 #else // OS_WIN |
| 644 scoped_refptr<OmxVideoDecodeAccelerator> decoder = |
| 645 new OmxVideoDecodeAccelerator(this); |
| 646 decoder->SetEglState(egl_display(), egl_context()); |
| 647 #endif // OS_WIN |
| 648 decoder_ = decoder.release(); |
574 SetState(CS_DECODER_SET); | 649 SetState(CS_DECODER_SET); |
575 if (decoder_deleted()) | 650 if (decoder_deleted()) |
576 return; | 651 return; |
577 | 652 |
578 // Configure the decoder. | 653 // Configure the decoder. |
579 media::VideoDecodeAccelerator::Profile profile = media::H264PROFILE_BASELINE; | 654 media::VideoDecodeAccelerator::Profile profile = media::H264PROFILE_BASELINE; |
580 if (profile_ != -1) | 655 if (profile_ != -1) |
581 profile = static_cast<media::VideoDecodeAccelerator::Profile>(profile_); | 656 profile = static_cast<media::VideoDecodeAccelerator::Profile>(profile_); |
582 CHECK(decoder_->Initialize(profile)); | 657 CHECK(decoder_->Initialize(profile)); |
583 } | 658 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 return 0; | 853 return 0; |
779 return num_decoded_frames_ / delta.InSecondsF(); | 854 return num_decoded_frames_ / delta.InSecondsF(); |
780 } | 855 } |
781 | 856 |
782 // Test parameters: | 857 // Test parameters: |
783 // - Number of NALUs per Decode() call. | 858 // - Number of NALUs per Decode() call. |
784 // - Number of concurrent decoders. | 859 // - Number of concurrent decoders. |
785 // - Number of concurrent in-flight Decode() calls per decoder. | 860 // - Number of concurrent in-flight Decode() calls per decoder. |
786 // - reset_after_frame_num: see EglRenderingVDAClient ctor. | 861 // - reset_after_frame_num: see EglRenderingVDAClient ctor. |
787 // - delete_decoder_phase: see EglRenderingVDAClient ctor. | 862 // - delete_decoder_phase: see EglRenderingVDAClient ctor. |
788 class OmxVideoDecodeAcceleratorTest | 863 class VideoDecodeAcceleratorTest |
789 : public ::testing::TestWithParam< | 864 : public ::testing::TestWithParam< |
790 Tuple5<int, int, int, ResetPoint, ClientState> > { | 865 Tuple5<int, int, int, ResetPoint, ClientState> > { |
791 }; | 866 }; |
792 | 867 |
793 // Wait for |note| to report a state and if it's not |expected_state| then | 868 // Wait for |note| to report a state and if it's not |expected_state| then |
794 // assert |client| has deleted its decoder. | 869 // assert |client| has deleted its decoder. |
795 static void AssertWaitForStateOrDeleted(ClientStateNotification* note, | 870 static void AssertWaitForStateOrDeleted(ClientStateNotification* note, |
796 EglRenderingVDAClient* client, | 871 EglRenderingVDAClient* client, |
797 ClientState expected_state) { | 872 ClientState expected_state) { |
798 ClientState state = note->Wait(); | 873 ClientState state = note->Wait(); |
799 if (state == expected_state) return; | 874 if (state == expected_state) return; |
800 ASSERT_TRUE(client->decoder_deleted()) | 875 ASSERT_TRUE(client->decoder_deleted()) |
801 << "Decoder not deleted but Wait() returned " << state | 876 << "Decoder not deleted but Wait() returned " << state |
802 << ", instead of " << expected_state; | 877 << ", instead of " << expected_state; |
803 } | 878 } |
804 | 879 |
805 // We assert a minimal number of concurrent decoders we expect to succeed. | 880 // We assert a minimal number of concurrent decoders we expect to succeed. |
806 // Different platforms can support more concurrent decoders, so we don't assert | 881 // Different platforms can support more concurrent decoders, so we don't assert |
807 // failure above this. | 882 // failure above this. |
808 enum { kMinSupportedNumConcurrentDecoders = 3 }; | 883 enum { kMinSupportedNumConcurrentDecoders = 3 }; |
809 | 884 |
810 // Test the most straightforward case possible: data is decoded from a single | 885 // Test the most straightforward case possible: data is decoded from a single |
811 // chunk and rendered to the screen. | 886 // chunk and rendered to the screen. |
812 TEST_P(OmxVideoDecodeAcceleratorTest, TestSimpleDecode) { | 887 TEST_P(VideoDecodeAcceleratorTest, TestSimpleDecode) { |
813 // Can be useful for debugging VLOGs from OVDA. | 888 // Can be useful for debugging VLOGs from OVDA. |
814 // logging::SetMinLogLevel(-1); | 889 // logging::SetMinLogLevel(-1); |
815 | 890 |
816 // Required for Thread to work. Not used otherwise. | 891 // Required for Thread to work. Not used otherwise. |
817 base::ShadowingAtExitManager at_exit_manager; | 892 base::ShadowingAtExitManager at_exit_manager; |
818 | 893 |
819 const int num_NALUs_per_decode = GetParam().a; | 894 const int num_NALUs_per_decode = GetParam().a; |
820 const size_t num_concurrent_decoders = GetParam().b; | 895 const size_t num_concurrent_decoders = GetParam().b; |
821 const size_t num_in_flight_decodes = GetParam().c; | 896 const size_t num_in_flight_decodes = GetParam().c; |
822 const int reset_after_frame_num = GetParam().d; | 897 const int reset_after_frame_num = GetParam().d; |
823 const int delete_decoder_state = GetParam().e; | 898 const int delete_decoder_state = GetParam().e; |
824 | 899 |
825 std::string test_video_file; | 900 FilePath::StringType test_video_file; |
826 int frame_width, frame_height; | 901 int frame_width, frame_height; |
827 int num_frames, num_NALUs, min_fps_render, min_fps_no_render, profile; | 902 int num_frames, num_NALUs, min_fps_render, min_fps_no_render, profile; |
828 ParseTestVideoData(test_video_data, &test_video_file, &frame_width, | 903 ParseTestVideoData(test_video_data, &test_video_file, &frame_width, |
829 &frame_height, &num_frames, &num_NALUs, | 904 &frame_height, &num_frames, &num_NALUs, |
830 &min_fps_render, &min_fps_no_render, &profile); | 905 &min_fps_render, &min_fps_no_render, &profile); |
831 min_fps_render /= num_concurrent_decoders; | 906 min_fps_render /= num_concurrent_decoders; |
832 min_fps_no_render /= num_concurrent_decoders; | 907 min_fps_no_render /= num_concurrent_decoders; |
833 | 908 |
834 // If we reset mid-stream and start playback over, account for frames that are | 909 // If we reset mid-stream and start playback over, account for frames that are |
835 // decoded twice in our expectations. | 910 // decoded twice in our expectations. |
836 if (num_frames > 0 && reset_after_frame_num >= 0) | 911 if (num_frames > 0 && reset_after_frame_num >= 0) |
837 num_frames += reset_after_frame_num; | 912 num_frames += reset_after_frame_num; |
838 | 913 |
839 // Suppress EGL surface swapping in all but a few tests, to cut down overall | 914 // Suppress EGL surface swapping in all but a few tests, to cut down overall |
840 // test runtime. | 915 // test runtime. |
841 const bool suppress_swap_to_display = num_NALUs_per_decode > 1; | 916 const bool suppress_swap_to_display = num_NALUs_per_decode > 1; |
842 | 917 |
843 std::vector<ClientStateNotification*> notes(num_concurrent_decoders, NULL); | 918 std::vector<ClientStateNotification*> notes(num_concurrent_decoders, NULL); |
844 std::vector<EglRenderingVDAClient*> clients(num_concurrent_decoders, NULL); | 919 std::vector<EglRenderingVDAClient*> clients(num_concurrent_decoders, NULL); |
845 | 920 |
846 // Read in the video data. | 921 // Read in the video data. |
847 std::string data_str; | 922 std::string data_str; |
848 CHECK(file_util::ReadFileToString(FilePath(test_video_file), &data_str)); | 923 CHECK(file_util::ReadFileToString(FilePath(test_video_file), &data_str)); |
849 | 924 |
850 // Initialize the rendering helper. | 925 // Initialize the rendering helper. |
851 base::Thread rendering_thread("EglRenderingVDAClientThread"); | 926 base::Thread rendering_thread("EglRenderingVDAClientThread"); |
852 rendering_thread.Start(); | 927 base::Thread::Options options; |
| 928 options.message_loop_type = MessageLoop::TYPE_DEFAULT; |
| 929 #if defined(OS_WIN) |
| 930 // For windows the decoding thread initializes the media foundation decoder |
| 931 // which uses COM. We need the thread to be a UI thread. |
| 932 options.message_loop_type = MessageLoop::TYPE_UI; |
| 933 #endif // OS_WIN |
| 934 |
| 935 rendering_thread.StartWithOptions(options); |
853 RenderingHelper rendering_helper; | 936 RenderingHelper rendering_helper; |
854 | 937 |
855 base::WaitableEvent done(false, false); | 938 base::WaitableEvent done(false, false); |
856 rendering_thread.message_loop()->PostTask( | 939 rendering_thread.message_loop()->PostTask( |
857 FROM_HERE, | 940 FROM_HERE, |
858 base::Bind(&RenderingHelper::Initialize, | 941 base::Bind(&RenderingHelper::Initialize, |
859 base::Unretained(&rendering_helper), | 942 base::Unretained(&rendering_helper), |
860 suppress_swap_to_display, num_concurrent_decoders, | 943 suppress_swap_to_display, num_concurrent_decoders, |
861 frame_width, frame_height, &done)); | 944 frame_width, frame_height, &done)); |
862 done.Wait(); | 945 done.Wait(); |
(...skipping 19 matching lines...) Expand all Loading... |
882 // Then wait for all the decodes to finish. | 965 // Then wait for all the decodes to finish. |
883 bool saw_init_failure = false; | 966 bool saw_init_failure = false; |
884 for (size_t i = 0; i < num_concurrent_decoders; ++i) { | 967 for (size_t i = 0; i < num_concurrent_decoders; ++i) { |
885 ClientStateNotification* note = notes[i]; | 968 ClientStateNotification* note = notes[i]; |
886 ClientState state = note->Wait(); | 969 ClientState state = note->Wait(); |
887 if (state != CS_INITIALIZED) { | 970 if (state != CS_INITIALIZED) { |
888 saw_init_failure = true; | 971 saw_init_failure = true; |
889 // We expect initialization to fail only when more than the supported | 972 // We expect initialization to fail only when more than the supported |
890 // number of decoders is instantiated. Assert here that something else | 973 // number of decoders is instantiated. Assert here that something else |
891 // didn't trigger failure. | 974 // didn't trigger failure. |
892 ASSERT_GT(num_concurrent_decoders, kMinSupportedNumConcurrentDecoders); | 975 ASSERT_GT(num_concurrent_decoders, |
| 976 static_cast<size_t>(kMinSupportedNumConcurrentDecoders)); |
893 continue; | 977 continue; |
894 } | 978 } |
895 ASSERT_EQ(state, CS_INITIALIZED); | 979 ASSERT_EQ(state, CS_INITIALIZED); |
896 // InitializeDone kicks off decoding inside the client, so we just need to | 980 // InitializeDone kicks off decoding inside the client, so we just need to |
897 // wait for Flush. | 981 // wait for Flush. |
898 ASSERT_NO_FATAL_FAILURE( | 982 ASSERT_NO_FATAL_FAILURE( |
899 AssertWaitForStateOrDeleted(note, clients[i], CS_FLUSHING)); | 983 AssertWaitForStateOrDeleted(note, clients[i], CS_FLUSHING)); |
900 ASSERT_NO_FATAL_FAILURE( | 984 ASSERT_NO_FATAL_FAILURE( |
901 AssertWaitForStateOrDeleted(note, clients[i], CS_FLUSHED)); | 985 AssertWaitForStateOrDeleted(note, clients[i], CS_FLUSHED)); |
902 // FlushDone requests Reset(). | 986 // FlushDone requests Reset(). |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 base::Bind(&RenderingHelper::UnInitialize, | 1024 base::Bind(&RenderingHelper::UnInitialize, |
941 base::Unretained(&rendering_helper), | 1025 base::Unretained(&rendering_helper), |
942 &done)); | 1026 &done)); |
943 done.Wait(); | 1027 done.Wait(); |
944 rendering_thread.Stop(); | 1028 rendering_thread.Stop(); |
945 }; | 1029 }; |
946 | 1030 |
947 // Test that Reset() mid-stream works fine and doesn't affect decoding even when | 1031 // Test that Reset() mid-stream works fine and doesn't affect decoding even when |
948 // Decode() calls are made during the reset. | 1032 // Decode() calls are made during the reset. |
949 INSTANTIATE_TEST_CASE_P( | 1033 INSTANTIATE_TEST_CASE_P( |
950 MidStreamReset, OmxVideoDecodeAcceleratorTest, | 1034 MidStreamReset, VideoDecodeAcceleratorTest, |
951 ::testing::Values( | 1035 ::testing::Values( |
952 MakeTuple(1, 1, 1, static_cast<ResetPoint>(100), CS_RESET))); | 1036 MakeTuple(1, 1, 1, static_cast<ResetPoint>(100), CS_RESET))); |
953 | 1037 |
954 // Test that Destroy() mid-stream works fine (primarily this is testing that no | 1038 // Test that Destroy() mid-stream works fine (primarily this is testing that no |
955 // crashes occur). | 1039 // crashes occur). |
956 INSTANTIATE_TEST_CASE_P( | 1040 INSTANTIATE_TEST_CASE_P( |
957 TearDownTiming, OmxVideoDecodeAcceleratorTest, | 1041 TearDownTiming, VideoDecodeAcceleratorTest, |
958 ::testing::Values( | 1042 ::testing::Values( |
959 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_DECODER_SET), | 1043 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_DECODER_SET), |
960 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_INITIALIZED), | 1044 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_INITIALIZED), |
961 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_FLUSHING), | 1045 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_FLUSHING), |
962 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_FLUSHED), | 1046 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_FLUSHED), |
963 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_RESETTING), | 1047 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_RESETTING), |
964 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_RESET), | 1048 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_RESET), |
965 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, static_cast<ClientState>(-1)), | 1049 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, static_cast<ClientState>(-1)), |
966 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, static_cast<ClientState>(-10)), | 1050 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, static_cast<ClientState>(-10)), |
967 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, | 1051 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, |
968 static_cast<ClientState>(-100)))); | 1052 static_cast<ClientState>(-100)))); |
969 | 1053 |
970 // Test that decoding various variation works: multiple concurrent decoders and | 1054 // Test that decoding various variation works: multiple concurrent decoders and |
971 // multiple NALUs per Decode() call. | 1055 // multiple NALUs per Decode() call. |
972 INSTANTIATE_TEST_CASE_P( | 1056 INSTANTIATE_TEST_CASE_P( |
973 DecodeVariations, OmxVideoDecodeAcceleratorTest, | 1057 DecodeVariations, VideoDecodeAcceleratorTest, |
974 ::testing::Values( | 1058 ::testing::Values( |
975 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_RESET), | 1059 MakeTuple(1, 1, 1, END_OF_STREAM_RESET, CS_RESET), |
976 MakeTuple(1, 1, 10, END_OF_STREAM_RESET, CS_RESET), | 1060 MakeTuple(1, 1, 10, END_OF_STREAM_RESET, CS_RESET), |
977 MakeTuple(1, 1, 15, END_OF_STREAM_RESET, CS_RESET), // Tests queuing. | 1061 MakeTuple(1, 1, 15, END_OF_STREAM_RESET, CS_RESET), // Tests queuing. |
978 MakeTuple(1, 3, 1, END_OF_STREAM_RESET, CS_RESET), | 1062 MakeTuple(1, 3, 1, END_OF_STREAM_RESET, CS_RESET), |
979 MakeTuple(2, 1, 1, END_OF_STREAM_RESET, CS_RESET), | 1063 MakeTuple(2, 1, 1, END_OF_STREAM_RESET, CS_RESET), |
980 MakeTuple(3, 1, 1, END_OF_STREAM_RESET, CS_RESET), | 1064 MakeTuple(3, 1, 1, END_OF_STREAM_RESET, CS_RESET), |
981 MakeTuple(5, 1, 1, END_OF_STREAM_RESET, CS_RESET), | 1065 MakeTuple(5, 1, 1, END_OF_STREAM_RESET, CS_RESET), |
982 MakeTuple(8, 1, 1, END_OF_STREAM_RESET, CS_RESET), | 1066 MakeTuple(8, 1, 1, END_OF_STREAM_RESET, CS_RESET), |
983 // TODO(fischman): decoding more than 15 NALUs at once breaks decode - | 1067 // TODO(fischman): decoding more than 15 NALUs at once breaks decode - |
984 // visual artifacts are introduced as well as spurious frames are | 1068 // visual artifacts are introduced as well as spurious frames are |
985 // delivered (more pictures are returned than NALUs are fed to the | 1069 // delivered (more pictures are returned than NALUs are fed to the |
986 // decoder). Increase the "15" below when | 1070 // decoder). Increase the "15" below when |
987 // http://code.google.com/p/chrome-os-partner/issues/detail?id=4378 is | 1071 // http://code.google.com/p/chrome-os-partner/issues/detail?id=4378 is |
988 // fixed. | 1072 // fixed. |
989 MakeTuple(15, 1, 1, END_OF_STREAM_RESET, CS_RESET))); | 1073 MakeTuple(15, 1, 1, END_OF_STREAM_RESET, CS_RESET))); |
990 | 1074 |
991 // Find out how many concurrent decoders can go before we exhaust system | 1075 // Find out how many concurrent decoders can go before we exhaust system |
992 // resources. | 1076 // resources. |
993 INSTANTIATE_TEST_CASE_P( | 1077 INSTANTIATE_TEST_CASE_P( |
994 ResourceExhaustion, OmxVideoDecodeAcceleratorTest, | 1078 ResourceExhaustion, VideoDecodeAcceleratorTest, |
995 ::testing::Values( | 1079 ::testing::Values( |
996 // +0 hack below to promote enum to int. | 1080 // +0 hack below to promote enum to int. |
997 MakeTuple(1, kMinSupportedNumConcurrentDecoders + 0, 1, | 1081 MakeTuple(1, kMinSupportedNumConcurrentDecoders + 0, 1, |
998 END_OF_STREAM_RESET, CS_RESET), | 1082 END_OF_STREAM_RESET, CS_RESET), |
999 MakeTuple(1, kMinSupportedNumConcurrentDecoders + 1, 1, | 1083 MakeTuple(1, kMinSupportedNumConcurrentDecoders + 1, 1, |
1000 END_OF_STREAM_RESET, CS_RESET))); | 1084 END_OF_STREAM_RESET, CS_RESET))); |
1001 | 1085 |
1002 // TODO(fischman, vrk): add more tests! In particular: | 1086 // TODO(fischman, vrk): add more tests! In particular: |
1003 // - Test life-cycle: Seek/Stop/Pause/Play/RePlay for a single decoder. | 1087 // - Test life-cycle: Seek/Stop/Pause/Play/RePlay for a single decoder. |
1004 // - Test alternate configurations | 1088 // - Test alternate configurations |
1005 // - Test failure conditions. | 1089 // - Test failure conditions. |
1006 // - Test frame size changes mid-stream | 1090 // - Test frame size changes mid-stream |
1007 | 1091 |
1008 } // namespace | 1092 } // namespace |
1009 | 1093 |
1010 int main(int argc, char **argv) { | 1094 int main(int argc, char **argv) { |
1011 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. | 1095 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. |
1012 CommandLine cmd_line(argc, argv); // Must run after InitGoogleTest. | 1096 CommandLine::Init(argc, argv); |
1013 CommandLine::SwitchMap switches = cmd_line.GetSwitches(); | 1097 |
| 1098 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 1099 DCHECK(cmd_line); |
| 1100 |
| 1101 CommandLine::SwitchMap switches = cmd_line->GetSwitches(); |
1014 for (CommandLine::SwitchMap::const_iterator it = switches.begin(); | 1102 for (CommandLine::SwitchMap::const_iterator it = switches.begin(); |
1015 it != switches.end(); ++it) { | 1103 it != switches.end(); ++it) { |
1016 if (it->first == "test_video_data") { | 1104 if (it->first == "test_video_data") { |
1017 test_video_data = it->second.c_str(); | 1105 test_video_data = it->second.c_str(); |
1018 continue; | |
1019 } | 1106 } |
1020 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1107 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
1021 } | 1108 } |
1022 | 1109 #if defined(OS_WIN) |
| 1110 DXVAVideoDecodeAccelerator::PreSandboxInitialization(); |
| 1111 #endif // OS_WIN |
1023 return RUN_ALL_TESTS(); | 1112 return RUN_ALL_TESTS(); |
1024 } | 1113 } |
OLD | NEW |