| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <signal.h> | 5 #include <signal.h> |
| 6 | 6 |
| 7 #include <iostream> // NOLINT | 7 #include <iostream> // NOLINT |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include <X11/Xlib.h> | 37 #include <X11/Xlib.h> |
| 38 #include "media/tools/player_x11/gl_video_renderer.h" | 38 #include "media/tools/player_x11/gl_video_renderer.h" |
| 39 #include "media/tools/player_x11/x11_video_renderer.h" | 39 #include "media/tools/player_x11/x11_video_renderer.h" |
| 40 | 40 |
| 41 static Display* g_display = NULL; | 41 static Display* g_display = NULL; |
| 42 static Window g_window = 0; | 42 static Window g_window = 0; |
| 43 static bool g_running = false; | 43 static bool g_running = false; |
| 44 | 44 |
| 45 media::AudioManager* g_audio_manager = NULL; | 45 media::AudioManager* g_audio_manager = NULL; |
| 46 | 46 |
| 47 media::VideoRendererBase* g_video_renderer = NULL; |
| 48 |
| 47 scoped_refptr<media::FileDataSource> CreateFileDataSource( | 49 scoped_refptr<media::FileDataSource> CreateFileDataSource( |
| 48 const std::string& file_path) { | 50 const std::string& file_path) { |
| 49 scoped_refptr<media::FileDataSource> file_data_source( | 51 scoped_refptr<media::FileDataSource> file_data_source( |
| 50 new media::FileDataSource()); | 52 new media::FileDataSource()); |
| 51 CHECK(file_data_source->Initialize(base::FilePath(file_path))); | 53 CHECK(file_data_source->Initialize(base::FilePath(file_path))); |
| 52 return file_data_source; | 54 return file_data_source; |
| 53 } | 55 } |
| 54 | 56 |
| 55 // Initialize X11. Returns true if successful. This method creates the X11 | 57 // Initialize X11. Returns true if successful. This method creates the X11 |
| 56 // window. Further initialization is done in X11VideoRenderer. | 58 // window. Further initialization is done in X11VideoRenderer. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 74 XSelectInput(g_display, g_window, | 76 XSelectInput(g_display, g_window, |
| 75 ExposureMask | ButtonPressMask | KeyPressMask); | 77 ExposureMask | ButtonPressMask | KeyPressMask); |
| 76 XMapWindow(g_display, g_window); | 78 XMapWindow(g_display, g_window); |
| 77 return true; | 79 return true; |
| 78 } | 80 } |
| 79 | 81 |
| 80 void SetOpaque(bool /*opaque*/) { | 82 void SetOpaque(bool /*opaque*/) { |
| 81 } | 83 } |
| 82 | 84 |
| 83 typedef base::Callback<void(media::VideoFrame*)> PaintCB; | 85 typedef base::Callback<void(media::VideoFrame*)> PaintCB; |
| 84 void Paint(MessageLoop* message_loop, const PaintCB& paint_cb, | 86 void Paint(MessageLoop* message_loop, const PaintCB& paint_cb) { |
| 85 const scoped_refptr<media::VideoFrame>& video_frame) { | |
| 86 if (message_loop != MessageLoop::current()) { | 87 if (message_loop != MessageLoop::current()) { |
| 87 message_loop->PostTask(FROM_HERE, base::Bind( | 88 message_loop->PostTask(FROM_HERE, base::Bind( |
| 88 &Paint, message_loop, paint_cb, video_frame)); | 89 &Paint, message_loop, paint_cb)); |
| 89 return; | 90 return; |
| 90 } | 91 } |
| 91 | 92 |
| 92 paint_cb.Run(video_frame); | 93 scoped_refptr<media::VideoFrame> video_frame; |
| 94 g_video_renderer->GetCurrentFrame(&video_frame); |
| 95 if (video_frame) |
| 96 paint_cb.Run(video_frame); |
| 97 g_video_renderer->PutCurrentFrame(video_frame); |
| 93 } | 98 } |
| 94 | 99 |
| 95 static void OnBufferingState(media::Pipeline::BufferingState buffering_state) {} | 100 static void OnBufferingState(media::Pipeline::BufferingState buffering_state) {} |
| 96 | 101 |
| 97 // TODO(vrk): Re-enabled audio. (crbug.com/112159) | 102 // TODO(vrk): Re-enabled audio. (crbug.com/112159) |
| 98 bool InitPipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 103 bool InitPipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 99 const scoped_refptr<media::DataSource>& data_source, | 104 const scoped_refptr<media::DataSource>& data_source, |
| 100 const PaintCB& paint_cb, | 105 const PaintCB& paint_cb, |
| 101 bool /* enable_audio */, | 106 bool /* enable_audio */, |
| 102 scoped_refptr<media::Pipeline>* pipeline, | 107 scoped_refptr<media::Pipeline>* pipeline, |
| 103 MessageLoop* paint_message_loop) { | 108 MessageLoop* paint_message_loop) { |
| 104 // Create our filter factories. | 109 // Create our filter factories. |
| 105 scoped_ptr<media::FilterCollection> collection( | 110 scoped_ptr<media::FilterCollection> collection( |
| 106 new media::FilterCollection()); | 111 new media::FilterCollection()); |
| 107 collection->SetDemuxer(new media::FFmpegDemuxer(message_loop, data_source)); | 112 collection->SetDemuxer(new media::FFmpegDemuxer(message_loop, data_source)); |
| 108 collection->GetAudioDecoders()->push_back(new media::FFmpegAudioDecoder( | 113 collection->GetAudioDecoders()->push_back(new media::FFmpegAudioDecoder( |
| 109 message_loop)); | 114 message_loop)); |
| 110 collection->GetVideoDecoders()->push_back(new media::FFmpegVideoDecoder( | 115 collection->GetVideoDecoders()->push_back(new media::FFmpegVideoDecoder( |
| 111 message_loop)); | 116 message_loop)); |
| 112 | 117 |
| 113 // Create our video renderer and save a reference to it for painting. | 118 // Create our video renderer and save a reference to it for painting. |
| 114 scoped_ptr<media::VideoRenderer> video_renderer(new media::VideoRendererBase( | 119 g_video_renderer = new media::VideoRendererBase( |
| 115 message_loop, | 120 message_loop, |
| 116 media::SetDecryptorReadyCB(), | 121 media::SetDecryptorReadyCB(), |
| 117 base::Bind(&Paint, paint_message_loop, paint_cb), | 122 base::Bind(&Paint, paint_message_loop, paint_cb), |
| 118 base::Bind(&SetOpaque), | 123 base::Bind(&SetOpaque), |
| 119 true)); | 124 true); |
| 120 collection->SetVideoRenderer(video_renderer.Pass()); | 125 collection->AddVideoRenderer(g_video_renderer); |
| 121 | 126 |
| 122 scoped_ptr<media::AudioRenderer> audio_renderer(new media::AudioRendererImpl( | 127 collection->AddAudioRenderer(new media::AudioRendererImpl( |
| 123 message_loop, | 128 message_loop, |
| 124 new media::NullAudioSink(), | 129 new media::NullAudioSink(), |
| 125 media::SetDecryptorReadyCB())); | 130 media::SetDecryptorReadyCB())); |
| 126 collection->SetAudioRenderer(audio_renderer.Pass()); | |
| 127 | 131 |
| 128 // Create the pipeline and start it. | 132 // Create the pipeline and start it. |
| 129 *pipeline = new media::Pipeline(message_loop, new media::MediaLog()); | 133 *pipeline = new media::Pipeline(message_loop, new media::MediaLog()); |
| 130 media::PipelineStatusNotification note; | 134 media::PipelineStatusNotification note; |
| 131 (*pipeline)->Start( | 135 (*pipeline)->Start( |
| 132 collection.Pass(), base::Closure(), media::PipelineStatusCB(), | 136 collection.Pass(), base::Closure(), media::PipelineStatusCB(), |
| 133 note.Callback(), base::Bind(&OnBufferingState)); | 137 note.Callback(), base::Bind(&OnBufferingState)); |
| 134 | 138 |
| 135 // Wait until the pipeline is fully initialized. | 139 // Wait until the pipeline is fully initialized. |
| 136 note.Wait(); | 140 note.Wait(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 // Release callback which releases video renderer. Do this before cleaning up | 295 // Release callback which releases video renderer. Do this before cleaning up |
| 292 // X below since the video renderer has some X cleanup duties as well. | 296 // X below since the video renderer has some X cleanup duties as well. |
| 293 paint_cb.Reset(); | 297 paint_cb.Reset(); |
| 294 | 298 |
| 295 XDestroyWindow(g_display, g_window); | 299 XDestroyWindow(g_display, g_window); |
| 296 XCloseDisplay(g_display); | 300 XCloseDisplay(g_display); |
| 297 g_audio_manager = NULL; | 301 g_audio_manager = NULL; |
| 298 | 302 |
| 299 return 0; | 303 return 0; |
| 300 } | 304 } |
| OLD | NEW |