| 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> | |
| 6 #include <signal.h> | |
| 7 #include <X11/keysym.h> | 5 #include <X11/keysym.h> |
| 8 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
| 7 #include <signal.h> |
| 8 |
| 9 #include <iostream> // NOLINT |
| 9 | 10 |
| 10 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "media/audio/audio_manager.h" |
| 17 #include "media/base/filter_collection.h" | 19 #include "media/base/filter_collection.h" |
| 18 #include "media/base/media.h" | 20 #include "media/base/media.h" |
| 19 #include "media/base/media_log.h" | 21 #include "media/base/media_log.h" |
| 20 #include "media/base/media_switches.h" | 22 #include "media/base/media_switches.h" |
| 21 #include "media/base/message_loop_factory_impl.h" | 23 #include "media/base/message_loop_factory_impl.h" |
| 22 #include "media/base/pipeline_impl.h" | 24 #include "media/base/pipeline_impl.h" |
| 23 #include "media/filters/ffmpeg_audio_decoder.h" | 25 #include "media/filters/ffmpeg_audio_decoder.h" |
| 24 #include "media/filters/ffmpeg_demuxer_factory.h" | 26 #include "media/filters/ffmpeg_demuxer_factory.h" |
| 25 #include "media/filters/ffmpeg_video_decoder.h" | 27 #include "media/filters/ffmpeg_video_decoder.h" |
| 26 #include "media/filters/file_data_source_factory.h" | 28 #include "media/filters/file_data_source_factory.h" |
| 27 #include "media/filters/null_audio_renderer.h" | 29 #include "media/filters/null_audio_renderer.h" |
| 28 #include "media/filters/reference_audio_renderer.h" | 30 #include "media/filters/reference_audio_renderer.h" |
| 29 #include "media/tools/player_x11/gl_video_renderer.h" | 31 #include "media/tools/player_x11/gl_video_renderer.h" |
| 30 #include "media/tools/player_x11/x11_video_renderer.h" | 32 #include "media/tools/player_x11/x11_video_renderer.h" |
| 31 | 33 |
| 32 static Display* g_display = NULL; | 34 static Display* g_display = NULL; |
| 33 static Window g_window = 0; | 35 static Window g_window = 0; |
| 34 static bool g_running = false; | 36 static bool g_running = false; |
| 35 | 37 |
| 38 AudioManager* g_audio_manager = NULL; |
| 39 |
| 36 class MessageLoopQuitter { | 40 class MessageLoopQuitter { |
| 37 public: | 41 public: |
| 38 explicit MessageLoopQuitter(MessageLoop* loop) : loop_(loop) {} | 42 explicit MessageLoopQuitter(MessageLoop* loop) : loop_(loop) {} |
| 39 void Quit(media::PipelineStatus status) { | 43 void Quit(media::PipelineStatus status) { |
| 40 loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 44 loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 41 delete this; | 45 delete this; |
| 42 } | 46 } |
| 43 private: | 47 private: |
| 44 MessageLoop* loop_; | 48 MessageLoop* loop_; |
| 45 DISALLOW_COPY_AND_ASSIGN(MessageLoopQuitter); | 49 DISALLOW_COPY_AND_ASSIGN(MessageLoopQuitter); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 message_loop_factory->GetMessageLoop("VideoDecoderThread"))); | 99 message_loop_factory->GetMessageLoop("VideoDecoderThread"))); |
| 96 | 100 |
| 97 if (use_gl) { | 101 if (use_gl) { |
| 98 collection->AddVideoRenderer( | 102 collection->AddVideoRenderer( |
| 99 new GlVideoRenderer(g_display, g_window, paint_message_loop)); | 103 new GlVideoRenderer(g_display, g_window, paint_message_loop)); |
| 100 } else { | 104 } else { |
| 101 collection->AddVideoRenderer( | 105 collection->AddVideoRenderer( |
| 102 new X11VideoRenderer(g_display, g_window, paint_message_loop)); | 106 new X11VideoRenderer(g_display, g_window, paint_message_loop)); |
| 103 } | 107 } |
| 104 | 108 |
| 105 if (enable_audio) | 109 if (enable_audio) { |
| 106 collection->AddAudioRenderer(new media::ReferenceAudioRenderer()); | 110 collection->AddAudioRenderer( |
| 107 else | 111 new media::ReferenceAudioRenderer(g_audio_manager)); |
| 112 } else { |
| 108 collection->AddAudioRenderer(new media::NullAudioRenderer()); | 113 collection->AddAudioRenderer(new media::NullAudioRenderer()); |
| 114 } |
| 109 | 115 |
| 110 // Create the pipeline and start it. | 116 // Create the pipeline and start it. |
| 111 *pipeline = new media::PipelineImpl(message_loop, new media::MediaLog()); | 117 *pipeline = new media::PipelineImpl(message_loop, new media::MediaLog()); |
| 112 media::PipelineStatusNotification note; | 118 media::PipelineStatusNotification note; |
| 113 (*pipeline)->Start(collection.release(), filename, note.Callback()); | 119 (*pipeline)->Start(collection.release(), filename, note.Callback()); |
| 114 | 120 |
| 115 // Wait until the pipeline is fully initialized. | 121 // Wait until the pipeline is fully initialized. |
| 116 note.Wait(); | 122 note.Wait(); |
| 117 if (note.status() != media::PIPELINE_OK) { | 123 if (note.status() != media::PIPELINE_OK) { |
| 118 std::cout << "InitPipeline: " << note.status() << std::endl; | 124 std::cout << "InitPipeline: " << note.status() << std::endl; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 { | 175 { |
| 170 KeySym key = XKeycodeToKeysym(g_display, e.xkey.keycode, 0); | 176 KeySym key = XKeycodeToKeysym(g_display, e.xkey.keycode, 0); |
| 171 if (key == XK_Escape) { | 177 if (key == XK_Escape) { |
| 172 g_running = false; | 178 g_running = false; |
| 173 // Quit message_loop only when pipeline is fully stopped. | 179 // Quit message_loop only when pipeline is fully stopped. |
| 174 MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); | 180 MessageLoopQuitter* quitter = new MessageLoopQuitter(message_loop); |
| 175 pipeline->Stop(base::Bind(&MessageLoopQuitter::Quit, | 181 pipeline->Stop(base::Bind(&MessageLoopQuitter::Quit, |
| 176 base::Unretained(quitter))); | 182 base::Unretained(quitter))); |
| 177 return; | 183 return; |
| 178 } else if (key == XK_space) { | 184 } else if (key == XK_space) { |
| 179 if (pipeline->GetPlaybackRate() < 0.01f) // paused | 185 if (pipeline->GetPlaybackRate() < 0.01f) // paused |
| 180 pipeline->SetPlaybackRate(1.0f); | 186 pipeline->SetPlaybackRate(1.0f); |
| 181 else | 187 else |
| 182 pipeline->SetPlaybackRate(0.0f); | 188 pipeline->SetPlaybackRate(0.0f); |
| 183 } | 189 } |
| 184 } | 190 } |
| 185 break; | 191 break; |
| 186 default: | 192 default: |
| 187 break; | 193 break; |
| 188 } | 194 } |
| 189 } | 195 } |
| 190 | 196 |
| 191 message_loop->PostDelayedTask(FROM_HERE, base::Bind( | 197 message_loop->PostDelayedTask(FROM_HERE, base::Bind( |
| 192 &PeriodicalUpdate, make_scoped_refptr(pipeline), | 198 &PeriodicalUpdate, make_scoped_refptr(pipeline), |
| 193 message_loop, audio_only), 10); | 199 message_loop, audio_only), 10); |
| 194 } | 200 } |
| 195 | 201 |
| 196 int main(int argc, char** argv) { | 202 int main(int argc, char** argv) { |
| 203 scoped_refptr<AudioManager> audio_manager(AudioManager::Create()); |
| 204 g_audio_manager = audio_manager.get(); |
| 205 |
| 197 // Read arguments. | 206 // Read arguments. |
| 198 if (argc == 1) { | 207 if (argc == 1) { |
| 199 std::cout << "Usage: " << argv[0] << " --file=FILE" << std::endl | 208 std::cout << "Usage: " << argv[0] << " --file=FILE" << std::endl |
| 200 << std::endl | 209 << std::endl |
| 201 << "Optional arguments:" << std::endl | 210 << "Optional arguments:" << std::endl |
| 202 << " [--audio]" | 211 << " [--audio]" |
| 203 << " [--alsa-device=DEVICE]" | 212 << " [--alsa-device=DEVICE]" |
| 204 << " [--use-gl]" << std::endl | 213 << " [--use-gl]" << std::endl |
| 205 << " Press [ESC] to stop" << std::endl | 214 << " Press [ESC] to stop" << std::endl |
| 206 << " Press [SPACE] to toggle pause/play" << std::endl | 215 << " Press [SPACE] to toggle pause/play" << std::endl |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 message_loop_factory.get())) { | 254 message_loop_factory.get())) { |
| 246 // Main loop of the application. | 255 // Main loop of the application. |
| 247 g_running = true; | 256 g_running = true; |
| 248 | 257 |
| 249 // Check if video is present. | 258 // Check if video is present. |
| 250 audio_only = !pipeline->HasVideo(); | 259 audio_only = !pipeline->HasVideo(); |
| 251 | 260 |
| 252 message_loop.PostTask(FROM_HERE, base::Bind( | 261 message_loop.PostTask(FROM_HERE, base::Bind( |
| 253 &PeriodicalUpdate, pipeline, &message_loop, audio_only)); | 262 &PeriodicalUpdate, pipeline, &message_loop, audio_only)); |
| 254 message_loop.Run(); | 263 message_loop.Run(); |
| 255 } else{ | 264 } else { |
| 256 std::cout << "Pipeline initialization failed..." << std::endl; | 265 std::cout << "Pipeline initialization failed..." << std::endl; |
| 257 } | 266 } |
| 258 | 267 |
| 259 // Cleanup tasks. | 268 // Cleanup tasks. |
| 260 message_loop_factory.reset(); | 269 message_loop_factory.reset(); |
| 261 | 270 |
| 262 thread->Stop(); | 271 thread->Stop(); |
| 263 XDestroyWindow(g_display, g_window); | 272 XDestroyWindow(g_display, g_window); |
| 264 XCloseDisplay(g_display); | 273 XCloseDisplay(g_display); |
| 274 g_audio_manager = NULL; |
| 275 |
| 265 return 0; | 276 return 0; |
| 266 } | 277 } |
| OLD | NEW |