| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "media/audio/audio_manager.h" | 17 #include "media/audio/audio_manager.h" |
| 18 #include "media/audio/null_audio_sink.h" | 18 #include "media/audio/null_audio_sink.h" |
| 19 #include "media/base/audio_hardware_config.h" | 19 #include "media/base/audio_hardware_config.h" |
| 20 #include "media/base/bind_to_current_loop.h" |
| 20 #include "media/base/decryptor.h" | 21 #include "media/base/decryptor.h" |
| 21 #include "media/base/filter_collection.h" | 22 #include "media/base/filter_collection.h" |
| 22 #include "media/base/media.h" | 23 #include "media/base/media.h" |
| 23 #include "media/base/media_log.h" | 24 #include "media/base/media_log.h" |
| 24 #include "media/base/media_switches.h" | 25 #include "media/base/media_switches.h" |
| 25 #include "media/base/pipeline.h" | 26 #include "media/base/pipeline.h" |
| 26 #include "media/base/video_frame.h" | 27 #include "media/base/video_frame.h" |
| 27 #include "media/filters/audio_renderer_impl.h" | 28 #include "media/filters/audio_renderer_impl.h" |
| 28 #include "media/filters/ffmpeg_audio_decoder.h" | 29 #include "media/filters/ffmpeg_audio_decoder.h" |
| 29 #include "media/filters/ffmpeg_demuxer.h" | 30 #include "media/filters/ffmpeg_demuxer.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 BlackPixel(g_display, screen), | 73 BlackPixel(g_display, screen), |
| 73 BlackPixel(g_display, screen)); | 74 BlackPixel(g_display, screen)); |
| 74 XStoreName(g_display, g_window, "X11 Media Player"); | 75 XStoreName(g_display, g_window, "X11 Media Player"); |
| 75 | 76 |
| 76 XSelectInput(g_display, g_window, | 77 XSelectInput(g_display, g_window, |
| 77 ExposureMask | ButtonPressMask | KeyPressMask); | 78 ExposureMask | ButtonPressMask | KeyPressMask); |
| 78 XMapWindow(g_display, g_window); | 79 XMapWindow(g_display, g_window); |
| 79 return true; | 80 return true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 typedef base::Callback<void(media::VideoFrame*)> PaintCB; | |
| 83 void Paint(base::MessageLoop* message_loop, const PaintCB& paint_cb, | |
| 84 const scoped_refptr<media::VideoFrame>& video_frame) { | |
| 85 if (message_loop != base::MessageLoop::current()) { | |
| 86 message_loop->PostTask(FROM_HERE, base::Bind( | |
| 87 &Paint, message_loop, paint_cb, video_frame)); | |
| 88 return; | |
| 89 } | |
| 90 | |
| 91 paint_cb.Run(video_frame.get()); | |
| 92 } | |
| 93 | |
| 94 static void DoNothing() {} | 83 static void DoNothing() {} |
| 95 | 84 |
| 96 static void OnStatus(media::PipelineStatus status) {} | 85 static void OnStatus(media::PipelineStatus status) {} |
| 97 | 86 |
| 98 static void OnMetadata(media::PipelineMetadata metadata) {} | 87 static void OnMetadata(media::PipelineMetadata metadata) {} |
| 99 | 88 |
| 100 static void NeedKey(const std::string& type, | 89 static void NeedKey(const std::string& type, |
| 101 const std::vector<uint8>& init_data) { | 90 const std::vector<uint8>& init_data) { |
| 102 std::cout << "File is encrypted." << std::endl; | 91 std::cout << "File is encrypted." << std::endl; |
| 103 } | 92 } |
| 104 | 93 |
| 105 static void SaveStatusAndSignal(base::WaitableEvent* event, | 94 static void SaveStatusAndSignal(base::WaitableEvent* event, |
| 106 media::PipelineStatus* status_out, | 95 media::PipelineStatus* status_out, |
| 107 media::PipelineStatus status) { | 96 media::PipelineStatus status) { |
| 108 *status_out = status; | 97 *status_out = status; |
| 109 event->Signal(); | 98 event->Signal(); |
| 110 } | 99 } |
| 111 | 100 |
| 112 // TODO(vrk): Re-enabled audio. (crbug.com/112159) | 101 // TODO(vrk): Re-enabled audio. (crbug.com/112159) |
| 113 void InitPipeline( | 102 void InitPipeline( |
| 114 media::Pipeline* pipeline, | 103 media::Pipeline* pipeline, |
| 115 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 104 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 116 media::Demuxer* demuxer, | 105 media::Demuxer* demuxer, |
| 117 const PaintCB& paint_cb, | 106 const media::VideoRendererImpl::PaintCB& paint_cb, |
| 118 bool /* enable_audio */, | 107 bool /* enable_audio */) { |
| 119 base::MessageLoop* paint_message_loop) { | |
| 120 // Create our filter factories. | 108 // Create our filter factories. |
| 121 scoped_ptr<media::FilterCollection> collection( | 109 scoped_ptr<media::FilterCollection> collection( |
| 122 new media::FilterCollection()); | 110 new media::FilterCollection()); |
| 123 collection->SetDemuxer(demuxer); | 111 collection->SetDemuxer(demuxer); |
| 124 | 112 |
| 125 ScopedVector<media::VideoDecoder> video_decoders; | 113 ScopedVector<media::VideoDecoder> video_decoders; |
| 126 video_decoders.push_back(new media::FFmpegVideoDecoder(task_runner)); | 114 video_decoders.push_back(new media::FFmpegVideoDecoder(task_runner)); |
| 127 scoped_ptr<media::VideoRenderer> video_renderer(new media::VideoRendererImpl( | 115 scoped_ptr<media::VideoRenderer> video_renderer(new media::VideoRendererImpl( |
| 128 task_runner, | 116 task_runner, |
| 129 video_decoders.Pass(), | 117 video_decoders.Pass(), |
| 130 media::SetDecryptorReadyCB(), | 118 media::SetDecryptorReadyCB(), |
| 131 base::Bind(&Paint, paint_message_loop, paint_cb), | 119 paint_cb, |
| 132 true)); | 120 true)); |
| 133 collection->SetVideoRenderer(video_renderer.Pass()); | 121 collection->SetVideoRenderer(video_renderer.Pass()); |
| 134 | 122 |
| 135 ScopedVector<media::AudioDecoder> audio_decoders; | 123 ScopedVector<media::AudioDecoder> audio_decoders; |
| 136 audio_decoders.push_back(new media::FFmpegAudioDecoder(task_runner)); | 124 audio_decoders.push_back(new media::FFmpegAudioDecoder(task_runner)); |
| 137 media::AudioParameters out_params( | 125 media::AudioParameters out_params( |
| 138 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 126 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 139 media::CHANNEL_LAYOUT_STEREO, | 127 media::CHANNEL_LAYOUT_STEREO, |
| 140 44100, | 128 44100, |
| 141 16, | 129 16, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 258 |
| 271 // Initialize X11. | 259 // Initialize X11. |
| 272 if (!InitX11()) | 260 if (!InitX11()) |
| 273 return 1; | 261 return 1; |
| 274 | 262 |
| 275 // Initialize the pipeline thread and the pipeline. | 263 // Initialize the pipeline thread and the pipeline. |
| 276 base::MessageLoop message_loop; | 264 base::MessageLoop message_loop; |
| 277 base::Thread media_thread("MediaThread"); | 265 base::Thread media_thread("MediaThread"); |
| 278 media_thread.Start(); | 266 media_thread.Start(); |
| 279 | 267 |
| 280 PaintCB paint_cb; | 268 media::VideoRendererImpl::PaintCB paint_cb; |
| 281 if (command_line->HasSwitch("use-gl")) { | 269 if (command_line->HasSwitch("use-gl")) { |
| 282 paint_cb = base::Bind( | 270 paint_cb = media::BindToCurrentLoop(base::Bind( |
| 283 &GlVideoRenderer::Paint, new GlVideoRenderer(g_display, g_window)); | 271 &GlVideoRenderer::Paint, new GlVideoRenderer(g_display, g_window))); |
| 284 } else { | 272 } else { |
| 285 paint_cb = base::Bind( | 273 paint_cb = media::BindToCurrentLoop(base::Bind( |
| 286 &X11VideoRenderer::Paint, new X11VideoRenderer(g_display, g_window)); | 274 &X11VideoRenderer::Paint, new X11VideoRenderer(g_display, g_window))); |
| 287 } | 275 } |
| 288 | 276 |
| 289 scoped_ptr<media::DataSource> data_source(new DataSourceLogger( | 277 scoped_ptr<media::DataSource> data_source(new DataSourceLogger( |
| 290 CreateDataSource(filename), command_line->HasSwitch("streaming"))); | 278 CreateDataSource(filename), command_line->HasSwitch("streaming"))); |
| 291 scoped_ptr<media::Demuxer> demuxer(new media::FFmpegDemuxer( | 279 scoped_ptr<media::Demuxer> demuxer(new media::FFmpegDemuxer( |
| 292 media_thread.message_loop_proxy(), data_source.get(), | 280 media_thread.message_loop_proxy(), data_source.get(), |
| 293 base::Bind(&NeedKey), new media::MediaLog())); | 281 base::Bind(&NeedKey), new media::MediaLog())); |
| 294 | 282 |
| 295 media::Pipeline pipeline(media_thread.message_loop_proxy(), | 283 media::Pipeline pipeline(media_thread.message_loop_proxy(), |
| 296 new media::MediaLog()); | 284 new media::MediaLog()); |
| 297 InitPipeline(&pipeline, media_thread.message_loop_proxy(), demuxer.get(), | 285 InitPipeline(&pipeline, media_thread.message_loop_proxy(), demuxer.get(), |
| 298 paint_cb, command_line->HasSwitch("audio"), &message_loop); | 286 paint_cb, command_line->HasSwitch("audio")); |
| 299 | 287 |
| 300 // Main loop of the application. | 288 // Main loop of the application. |
| 301 g_running = true; | 289 g_running = true; |
| 302 | 290 |
| 303 message_loop.PostTask(FROM_HERE, base::Bind( | 291 message_loop.PostTask(FROM_HERE, base::Bind( |
| 304 &PeriodicalUpdate, base::Unretained(&pipeline), &message_loop)); | 292 &PeriodicalUpdate, base::Unretained(&pipeline), &message_loop)); |
| 305 message_loop.Run(); | 293 message_loop.Run(); |
| 306 | 294 |
| 307 // Cleanup tasks. | 295 // Cleanup tasks. |
| 308 media_thread.Stop(); | 296 media_thread.Stop(); |
| 309 | 297 |
| 310 // Release callback which releases video renderer. Do this before cleaning up | 298 // Release callback which releases video renderer. Do this before cleaning up |
| 311 // X below since the video renderer has some X cleanup duties as well. | 299 // X below since the video renderer has some X cleanup duties as well. |
| 312 paint_cb.Reset(); | 300 paint_cb.Reset(); |
| 313 | 301 |
| 314 XDestroyWindow(g_display, g_window); | 302 XDestroyWindow(g_display, g_window); |
| 315 XCloseDisplay(g_display); | 303 XCloseDisplay(g_display); |
| 316 g_audio_manager = NULL; | 304 g_audio_manager = NULL; |
| 317 | 305 |
| 318 return 0; | 306 return 0; |
| 319 } | 307 } |
| OLD | NEW |