| 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" |
| 11 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 16 #include "media/base/callback.h" | 17 #include "media/base/callback.h" |
| 17 #include "media/base/filter_collection.h" | 18 #include "media/base/filter_collection.h" |
| 18 #include "media/base/media.h" | 19 #include "media/base/media.h" |
| 19 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
| 20 #include "media/base/message_loop_factory_impl.h" | 21 #include "media/base/message_loop_factory_impl.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 110 |
| 110 // Create the pipeline and start it. | 111 // Create the pipeline and start it. |
| 111 *pipeline = new media::PipelineImpl(message_loop); | 112 *pipeline = new media::PipelineImpl(message_loop); |
| 112 media::PipelineStatusNotification note; | 113 media::PipelineStatusNotification note; |
| 113 (*pipeline)->Start(collection.release(), filename, note.Callback()); | 114 (*pipeline)->Start(collection.release(), filename, note.Callback()); |
| 114 | 115 |
| 115 // Wait until the pipeline is fully initialized. | 116 // Wait until the pipeline is fully initialized. |
| 116 note.Wait(); | 117 note.Wait(); |
| 117 if (note.status() != media::PIPELINE_OK) { | 118 if (note.status() != media::PIPELINE_OK) { |
| 118 std::cout << "InitPipeline: " << note.status() << std::endl; | 119 std::cout << "InitPipeline: " << note.status() << std::endl; |
| 119 (*pipeline)->Stop(NULL); | 120 (*pipeline)->Stop(media::PipelineStatusCB()); |
| 120 return false; | 121 return false; |
| 121 } | 122 } |
| 122 | 123 |
| 123 // And start the playback. | 124 // And start the playback. |
| 124 (*pipeline)->SetPlaybackRate(1.0f); | 125 (*pipeline)->SetPlaybackRate(1.0f); |
| 125 return true; | 126 return true; |
| 126 } | 127 } |
| 127 | 128 |
| 128 void TerminateHandler(int signal) { | 129 void TerminateHandler(int signal) { |
| 129 g_running = false; | 130 g_running = false; |
| 130 } | 131 } |
| 131 | 132 |
| 132 void PeriodicalUpdate( | 133 void PeriodicalUpdate( |
| 133 media::PipelineImpl* pipeline, | 134 media::PipelineImpl* pipeline, |
| 134 MessageLoop* message_loop, | 135 MessageLoop* message_loop, |
| 135 bool audio_only) { | 136 bool audio_only) { |
| 136 if (!g_running) { | 137 if (!g_running) { |
| 137 // interrupt signal was received during last time period. | 138 // interrupt signal was received during last time period. |
| 138 // Quit message_loop only when pipeline is fully stopped. | 139 // Quit message_loop only when pipeline is fully stopped. |
| 139 MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); | 140 MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); |
| 140 pipeline->Stop(NewCallback(quitter, &MessageLoopQuitter::Quit)); | 141 pipeline->Stop(base::Bind(&MessageLoopQuitter::Quit, |
| 142 base::Unretained(quitter))); |
| 141 return; | 143 return; |
| 142 } | 144 } |
| 143 | 145 |
| 144 // Consume all the X events | 146 // Consume all the X events |
| 145 while (XPending(g_display)) { | 147 while (XPending(g_display)) { |
| 146 XEvent e; | 148 XEvent e; |
| 147 XNextEvent(g_display, &e); | 149 XNextEvent(g_display, &e); |
| 148 switch (e.type) { | 150 switch (e.type) { |
| 149 case ButtonPress: | 151 case ButtonPress: |
| 150 { | 152 { |
| 151 Window window; | 153 Window window; |
| 152 int x, y; | 154 int x, y; |
| 153 unsigned int width, height, border_width, depth; | 155 unsigned int width, height, border_width, depth; |
| 154 XGetGeometry(g_display, | 156 XGetGeometry(g_display, |
| 155 g_window, | 157 g_window, |
| 156 &window, | 158 &window, |
| 157 &x, | 159 &x, |
| 158 &y, | 160 &y, |
| 159 &width, | 161 &width, |
| 160 &height, | 162 &height, |
| 161 &border_width, | 163 &border_width, |
| 162 &depth); | 164 &depth); |
| 163 base::TimeDelta time = pipeline->GetMediaDuration(); | 165 base::TimeDelta time = pipeline->GetMediaDuration(); |
| 164 pipeline->Seek(time*e.xbutton.x/width, NULL); | 166 pipeline->Seek(time*e.xbutton.x/width, media::PipelineStatusCB()); |
| 165 } | 167 } |
| 166 break; | 168 break; |
| 167 case KeyPress: | 169 case KeyPress: |
| 168 { | 170 { |
| 169 KeySym key = XKeycodeToKeysym(g_display, e.xkey.keycode, 0); | 171 KeySym key = XKeycodeToKeysym(g_display, e.xkey.keycode, 0); |
| 170 if (key == XK_Escape) { | 172 if (key == XK_Escape) { |
| 171 g_running = false; | 173 g_running = false; |
| 172 // Quit message_loop only when pipeline is fully stopped. | 174 // Quit message_loop only when pipeline is fully stopped. |
| 173 MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); | 175 MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); |
| 174 pipeline->Stop(NewCallback(quitter, &MessageLoopQuitter::Quit)); | 176 pipeline->Stop(base::Bind(&MessageLoopQuitter::Quit, |
| 177 base::Unretained(quitter))); |
| 175 return; | 178 return; |
| 176 } else if (key == XK_space) { | 179 } else if (key == XK_space) { |
| 177 if (pipeline->GetPlaybackRate() < 0.01f) // paused | 180 if (pipeline->GetPlaybackRate() < 0.01f) // paused |
| 178 pipeline->SetPlaybackRate(1.0f); | 181 pipeline->SetPlaybackRate(1.0f); |
| 179 else | 182 else |
| 180 pipeline->SetPlaybackRate(0.0f); | 183 pipeline->SetPlaybackRate(0.0f); |
| 181 } | 184 } |
| 182 } | 185 } |
| 183 break; | 186 break; |
| 184 default: | 187 default: |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 259 } |
| 257 | 260 |
| 258 // Cleanup tasks. | 261 // Cleanup tasks. |
| 259 message_loop_factory.reset(); | 262 message_loop_factory.reset(); |
| 260 | 263 |
| 261 thread->Stop(); | 264 thread->Stop(); |
| 262 XDestroyWindow(g_display, g_window); | 265 XDestroyWindow(g_display, g_window); |
| 263 XCloseDisplay(g_display); | 266 XCloseDisplay(g_display); |
| 264 return 0; | 267 return 0; |
| 265 } | 268 } |
| OLD | NEW |