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 #include <iostream> | 5 #include <iostream> |
6 #include <signal.h> | 6 #include <signal.h> |
7 #include <X11/keysym.h> | 7 #include <X11/keysym.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 #include "media/tools/player_x11/x11_video_renderer.h" | 45 #include "media/tools/player_x11/x11_video_renderer.h" |
46 typedef X11VideoRenderer Renderer; | 46 typedef X11VideoRenderer Renderer; |
47 #else | 47 #else |
48 #error No video renderer defined. | 48 #error No video renderer defined. |
49 #endif | 49 #endif |
50 | 50 |
51 Display* g_display = NULL; | 51 Display* g_display = NULL; |
52 Window g_window = 0; | 52 Window g_window = 0; |
53 bool g_running = false; | 53 bool g_running = false; |
54 | 54 |
55 void Quit(MessageLoop* message_loop) { | 55 class MessageLoopQuitter { |
56 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 56 public: |
57 } | 57 MessageLoopQuitter(MessageLoop* loop) : loop_(loop) {} |
acolwell GONE FROM CHROMIUM
2011/03/15 23:43:55
explicit
Ami GONE FROM CHROMIUM
2011/03/16 00:01:02
Done.
| |
58 void Quit(media::PipelineStatus status) { | |
59 loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | |
60 delete this; | |
61 } | |
62 private: | |
63 MessageLoop* loop_; | |
acolwell GONE FROM CHROMIUM
2011/03/15 23:43:55
DISALLOW_COPY_AND_ASSIGN
Ami GONE FROM CHROMIUM
2011/03/16 00:01:02
Done.
| |
64 }; | |
58 | 65 |
59 // Initialize X11. Returns true if successful. This method creates the X11 | 66 // Initialize X11. Returns true if successful. This method creates the X11 |
60 // window. Further initialization is done in X11VideoRenderer. | 67 // window. Further initialization is done in X11VideoRenderer. |
61 bool InitX11() { | 68 bool InitX11() { |
62 g_display = XOpenDisplay(NULL); | 69 g_display = XOpenDisplay(NULL); |
63 if (!g_display) { | 70 if (!g_display) { |
64 std::cout << "Error - cannot open display" << std::endl; | 71 std::cout << "Error - cannot open display" << std::endl; |
65 return false; | 72 return false; |
66 } | 73 } |
67 | 74 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 126 } |
120 collection->AddVideoRenderer(new Renderer(g_display, | 127 collection->AddVideoRenderer(new Renderer(g_display, |
121 g_window, | 128 g_window, |
122 paint_message_loop)); | 129 paint_message_loop)); |
123 | 130 |
124 if (enable_audio) | 131 if (enable_audio) |
125 collection->AddAudioRenderer(new media::AudioRendererImpl()); | 132 collection->AddAudioRenderer(new media::AudioRendererImpl()); |
126 else | 133 else |
127 collection->AddAudioRenderer(new media::NullAudioRenderer()); | 134 collection->AddAudioRenderer(new media::NullAudioRenderer()); |
128 | 135 |
129 // Create and start the pipeline. | 136 // Create the pipeline and start it. |
130 *pipeline = new media::PipelineImpl(message_loop); | 137 *pipeline = new media::PipelineImpl(message_loop); |
131 (*pipeline)->Start(collection.release(), filename, NULL); | 138 media::PipelineStatusNotification note; |
139 (*pipeline)->Start(collection.release(), filename, note.Callback()); | |
132 | 140 |
133 // Wait until the pipeline is fully initialized. | 141 // Wait until the pipeline is fully initialized. |
134 while (true) { | 142 note.Wait(); |
135 base::PlatformThread::Sleep(100); | 143 if (note.status() != media::PIPELINE_OK) { |
136 if ((*pipeline)->IsInitialized()) | 144 std::cout << "InitPipeline: " << note.status() << std::endl; |
137 break; | 145 (*pipeline)->Stop(NULL); |
138 if ((*pipeline)->GetError() != media::PIPELINE_OK) { | 146 return false; |
139 std::cout << "InitPipeline: " << (*pipeline)->GetError() << std::endl; | |
140 (*pipeline)->Stop(NULL); | |
141 return false; | |
142 } | |
143 } | 147 } |
144 | 148 |
145 // And starts the playback. | 149 // And start the playback. |
146 (*pipeline)->SetPlaybackRate(1.0f); | 150 (*pipeline)->SetPlaybackRate(1.0f); |
147 return true; | 151 return true; |
148 } | 152 } |
149 | 153 |
150 void TerminateHandler(int signal) { | 154 void TerminateHandler(int signal) { |
151 g_running = false; | 155 g_running = false; |
152 } | 156 } |
153 | 157 |
154 void PeriodicalUpdate( | 158 void PeriodicalUpdate( |
155 media::PipelineImpl* pipeline, | 159 media::PipelineImpl* pipeline, |
156 MessageLoop* message_loop, | 160 MessageLoop* message_loop, |
157 bool audio_only) { | 161 bool audio_only) { |
158 if (!g_running) { | 162 if (!g_running) { |
159 // interrupt signal is received during lat time period. | 163 // interrupt signal was received during last time period. |
160 // Quit message_loop only when pipeline is fully stopped. | 164 // Quit message_loop only when pipeline is fully stopped. |
161 pipeline->Stop(media::TaskToCallbackAdapter::NewCallback( | 165 MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); |
162 NewRunnableFunction(Quit, message_loop))); | 166 pipeline->Stop(NewCallback(quitter, &MessageLoopQuitter::Quit)); |
163 return; | 167 return; |
164 } | 168 } |
165 | 169 |
166 // Consume all the X events | 170 // Consume all the X events |
167 while (XPending(g_display)) { | 171 while (XPending(g_display)) { |
168 XEvent e; | 172 XEvent e; |
169 XNextEvent(g_display, &e); | 173 XNextEvent(g_display, &e); |
170 switch (e.type) { | 174 switch (e.type) { |
171 case Expose: | 175 case Expose: |
172 if (!audio_only) { | 176 if (!audio_only) { |
(...skipping 19 matching lines...) Expand all Loading... | |
192 base::TimeDelta time = pipeline->GetMediaDuration(); | 196 base::TimeDelta time = pipeline->GetMediaDuration(); |
193 pipeline->Seek(time*e.xbutton.x/width, NULL); | 197 pipeline->Seek(time*e.xbutton.x/width, NULL); |
194 } | 198 } |
195 break; | 199 break; |
196 case KeyPress: | 200 case KeyPress: |
197 { | 201 { |
198 KeySym key = XKeycodeToKeysym(g_display, e.xkey.keycode, 0); | 202 KeySym key = XKeycodeToKeysym(g_display, e.xkey.keycode, 0); |
199 if (key == XK_Escape) { | 203 if (key == XK_Escape) { |
200 g_running = false; | 204 g_running = false; |
201 // Quit message_loop only when pipeline is fully stopped. | 205 // Quit message_loop only when pipeline is fully stopped. |
202 pipeline->Stop(media::TaskToCallbackAdapter::NewCallback( | 206 MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); |
203 NewRunnableFunction(Quit, message_loop))); | 207 pipeline->Stop(NewCallback(quitter, &MessageLoopQuitter::Quit)); |
204 return; | 208 return; |
205 } else if (key == XK_space) { | 209 } else if (key == XK_space) { |
206 if (pipeline->GetPlaybackRate() < 0.01f) // paused | 210 if (pipeline->GetPlaybackRate() < 0.01f) // paused |
207 pipeline->SetPlaybackRate(1.0f); | 211 pipeline->SetPlaybackRate(1.0f); |
208 else | 212 else |
209 pipeline->SetPlaybackRate(0.0f); | 213 pipeline->SetPlaybackRate(0.0f); |
210 } | 214 } |
211 } | 215 } |
212 break; | 216 break; |
213 default: | 217 default: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 } | 281 } |
278 | 282 |
279 // Cleanup tasks. | 283 // Cleanup tasks. |
280 message_loop_factory.reset(); | 284 message_loop_factory.reset(); |
281 | 285 |
282 thread->Stop(); | 286 thread->Stop(); |
283 XDestroyWindow(g_display, g_window); | 287 XDestroyWindow(g_display, g_window); |
284 XCloseDisplay(g_display); | 288 XCloseDisplay(g_display); |
285 return 0; | 289 return 0; |
286 } | 290 } |
OLD | NEW |