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

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

Issue 2724005: player_x11 : change X/GL thread to message loop for injecting task (Closed)
Patch Set: fixing nits Created 10 years, 6 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 #include <iostream> 5 #include <iostream>
6 #include <signal.h> 6 #include <signal.h>
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 // And starts the playback. 117 // And starts the playback.
118 (*pipeline)->SetPlaybackRate(1.0f); 118 (*pipeline)->SetPlaybackRate(1.0f);
119 return true; 119 return true;
120 } 120 }
121 121
122 void TerminateHandler(int signal) { 122 void TerminateHandler(int signal) {
123 g_running = false; 123 g_running = false;
124 } 124 }
125 125
126 void PeriodicalUpdate(MessageLoop* message_loop, bool audio_only) {
127 if (!g_running) {
128 message_loop->Quit();
129 return;
130 }
131
132 // Consume all the X events
133 while (XPending(g_display)) {
134 XEvent e;
135 XNextEvent(g_display, &e);
136 if (e.type == Expose) {
137 if (!audio_only) {
138 // Tell the renderer to paint.
139 DCHECK(Renderer::instance());
140 Renderer::instance()->Paint();
141 }
142 } else if (e.type == ButtonPress) {
143 g_running = false;
144 message_loop->Quit();
145 return;
146 }
147 }
148
149 message_loop->PostDelayedTask(FROM_HERE,
150 NewRunnableFunction(PeriodicalUpdate, message_loop, audio_only), 10);
151 }
152
126 int main(int argc, char** argv) { 153 int main(int argc, char** argv) {
127 // Read arguments. 154 // Read arguments.
128 if (argc == 1) { 155 if (argc == 1) {
129 std::cout << "Usage: " << argv[0] << " --file=FILE" << std::endl 156 std::cout << "Usage: " << argv[0] << " --file=FILE" << std::endl
130 << std::endl 157 << std::endl
131 << "Optional arguments:" << std::endl 158 << "Optional arguments:" << std::endl
132 << " [--enable-openmax]" 159 << " [--enable-openmax]"
133 << " [--audio]" 160 << " [--audio]"
134 << " [--alsa-device=DEVICE]" << std::endl; 161 << " [--alsa-device=DEVICE]" << std::endl;
135 return 1; 162 return 1;
(...skipping 21 matching lines...) Expand all
157 thread.reset(new base::Thread("PipelineThread")); 184 thread.reset(new base::Thread("PipelineThread"));
158 thread->Start(); 185 thread->Start();
159 if (InitPipeline(thread->message_loop(), filename.c_str(), 186 if (InitPipeline(thread->message_loop(), filename.c_str(),
160 enable_audio, &pipeline)) { 187 enable_audio, &pipeline)) {
161 // Main loop of the application. 188 // Main loop of the application.
162 g_running = true; 189 g_running = true;
163 190
164 // Check if video is present. 191 // Check if video is present.
165 audio_only = !pipeline->IsRendered(media::mime_type::kMajorTypeVideo); 192 audio_only = !pipeline->IsRendered(media::mime_type::kMajorTypeVideo);
166 193
167 while (g_running) { 194 MessageLoop message_loop;
168 if (XPending(g_display)) { 195 if (!audio_only) {
169 XEvent e; 196 // Tell the renderer to paint.
170 XNextEvent(g_display, &e); 197 DCHECK(Renderer::instance());
171 if (e.type == Expose) { 198 Renderer::instance()->set_glx_thread_message_loop(&message_loop);
172 if (!audio_only) { 199 }
173 // Tell the renderer to paint.
174 DCHECK(Renderer::instance());
175 Renderer::instance()->Paint();
176 }
177 } else if (e.type == ButtonPress) {
178 // Stop the playback.
179 break;
180 }
181 } else {
182 // If there's no event in the queue, make an expose event.
183 XEvent event;
184 event.type = Expose;
185 XSendEvent(g_display, g_window, true, ExposureMask, &event);
186 200
187 // TODO(hclam): It is rather arbitrary to sleep for 10ms and wait 201 message_loop.PostTask(FROM_HERE,
188 // for the next event. We should submit an expose event when 202 NewRunnableFunction(PeriodicalUpdate, &message_loop, audio_only));
189 // a frame is available but not firing an expose event every 10ms. 203 message_loop.Run();
190 usleep(10000); 204
191 }
192 }
193 pipeline->Stop(NULL); 205 pipeline->Stop(NULL);
194 } else{ 206 } else{
195 std::cout << "Pipeline initialization failed..." << std::endl; 207 std::cout << "Pipeline initialization failed..." << std::endl;
196 } 208 }
197 209
198 // Cleanup tasks. 210 // Cleanup tasks.
199 thread->Stop(); 211 thread->Stop();
200 XDestroyWindow(g_display, g_window); 212 XDestroyWindow(g_display, g_window);
201 XCloseDisplay(g_display); 213 XCloseDisplay(g_display);
202 return 0; 214 return 0;
203 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698