| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 | 95 |
| 96 static void OnBufferingState(media::Pipeline::BufferingState buffering_state) {} | 96 static void OnBufferingState(media::Pipeline::BufferingState buffering_state) {} |
| 97 | 97 |
| 98 static void NeedKey(const std::string& type, scoped_ptr<uint8[]> init_data, | 98 static void NeedKey(const std::string& type, scoped_ptr<uint8[]> init_data, |
| 99 int init_data_size) { | 99 int init_data_size) { |
| 100 std::cout << "File is encrypted." << std::endl; | 100 std::cout << "File is encrypted." << std::endl; |
| 101 } | 101 } |
| 102 | 102 |
| 103 // TODO(vrk): Re-enabled audio. (crbug.com/112159) | 103 // TODO(vrk): Re-enabled audio. (crbug.com/112159) |
| 104 bool InitPipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 104 void InitPipeline(media::Pipeline* pipeline, |
| 105 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 105 media::Demuxer* demuxer, | 106 media::Demuxer* demuxer, |
| 106 const PaintCB& paint_cb, | 107 const PaintCB& paint_cb, |
| 107 bool /* enable_audio */, | 108 bool /* enable_audio */, |
| 108 scoped_refptr<media::Pipeline>* pipeline, | |
| 109 base::MessageLoop* paint_message_loop) { | 109 base::MessageLoop* paint_message_loop) { |
| 110 // Create our filter factories. | 110 // Create our filter factories. |
| 111 scoped_ptr<media::FilterCollection> collection( | 111 scoped_ptr<media::FilterCollection> collection( |
| 112 new media::FilterCollection()); | 112 new media::FilterCollection()); |
| 113 collection->SetDemuxer(demuxer); | 113 collection->SetDemuxer(demuxer); |
| 114 | 114 |
| 115 ScopedVector<media::VideoDecoder> video_decoders; | 115 ScopedVector<media::VideoDecoder> video_decoders; |
| 116 video_decoders.push_back(new media::FFmpegVideoDecoder(message_loop)); | 116 video_decoders.push_back(new media::FFmpegVideoDecoder(message_loop)); |
| 117 scoped_ptr<media::VideoRenderer> video_renderer(new media::VideoRendererBase( | 117 scoped_ptr<media::VideoRenderer> video_renderer(new media::VideoRendererBase( |
| 118 message_loop, | 118 message_loop, |
| 119 video_decoders.Pass(), | 119 video_decoders.Pass(), |
| 120 media::SetDecryptorReadyCB(), | 120 media::SetDecryptorReadyCB(), |
| 121 base::Bind(&Paint, paint_message_loop, paint_cb), | 121 base::Bind(&Paint, paint_message_loop, paint_cb), |
| 122 base::Bind(&SetOpaque), | 122 base::Bind(&SetOpaque), |
| 123 true)); | 123 true)); |
| 124 collection->SetVideoRenderer(video_renderer.Pass()); | 124 collection->SetVideoRenderer(video_renderer.Pass()); |
| 125 | 125 |
| 126 ScopedVector<media::AudioDecoder> audio_decoders; | 126 ScopedVector<media::AudioDecoder> audio_decoders; |
| 127 audio_decoders.push_back(new media::FFmpegAudioDecoder(message_loop)); | 127 audio_decoders.push_back(new media::FFmpegAudioDecoder(message_loop)); |
| 128 scoped_ptr<media::AudioRenderer> audio_renderer(new media::AudioRendererImpl( | 128 scoped_ptr<media::AudioRenderer> audio_renderer(new media::AudioRendererImpl( |
| 129 message_loop, | 129 message_loop, |
| 130 new media::NullAudioSink(message_loop), | 130 new media::NullAudioSink(message_loop), |
| 131 audio_decoders.Pass(), | 131 audio_decoders.Pass(), |
| 132 media::SetDecryptorReadyCB())); | 132 media::SetDecryptorReadyCB())); |
| 133 collection->SetAudioRenderer(audio_renderer.Pass()); | 133 collection->SetAudioRenderer(audio_renderer.Pass()); |
| 134 | 134 |
| 135 // Create the pipeline and start it. | 135 // Create the pipeline and start it. |
| 136 *pipeline = new media::Pipeline(message_loop, new media::MediaLog()); | |
| 137 media::PipelineStatusNotification note; | 136 media::PipelineStatusNotification note; |
| 138 (*pipeline)->Start( | 137 pipeline->Start( |
| 139 collection.Pass(), base::Closure(), media::PipelineStatusCB(), | 138 collection.Pass(), base::Closure(), media::PipelineStatusCB(), |
| 140 note.Callback(), base::Bind(&OnBufferingState), base::Closure()); | 139 note.Callback(), base::Bind(&OnBufferingState), base::Closure()); |
| 141 | 140 |
| 142 // Wait until the pipeline is fully initialized. | 141 // Wait until the pipeline is fully initialized. |
| 143 note.Wait(); | 142 note.Wait(); |
| 144 if (note.status() != media::PIPELINE_OK) { | 143 CHECK_EQ(note.status(), media::PIPELINE_OK) |
| 145 std::cout << "InitPipeline: " << note.status() << std::endl; | 144 << "Pipeline initialization failed"; |
| 146 (*pipeline)->Stop(base::Closure()); | |
| 147 return false; | |
| 148 } | |
| 149 | 145 |
| 150 // And start the playback. | 146 // And start the playback. |
| 151 (*pipeline)->SetPlaybackRate(1.0f); | 147 pipeline->SetPlaybackRate(1.0f); |
| 152 return true; | |
| 153 } | 148 } |
| 154 | 149 |
| 155 void TerminateHandler(int signal) { | 150 void TerminateHandler(int signal) { |
| 156 g_running = false; | 151 g_running = false; |
| 157 } | 152 } |
| 158 | 153 |
| 159 void PeriodicalUpdate( | 154 void PeriodicalUpdate( |
| 160 media::Pipeline* pipeline, | 155 media::Pipeline* pipeline, |
| 161 base::MessageLoop* message_loop, | 156 base::MessageLoop* message_loop, |
| 162 bool audio_only) { | 157 bool audio_only) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 202 } |
| 208 break; | 203 break; |
| 209 default: | 204 default: |
| 210 break; | 205 break; |
| 211 } | 206 } |
| 212 } | 207 } |
| 213 | 208 |
| 214 message_loop->PostDelayedTask( | 209 message_loop->PostDelayedTask( |
| 215 FROM_HERE, | 210 FROM_HERE, |
| 216 base::Bind(&PeriodicalUpdate, | 211 base::Bind(&PeriodicalUpdate, |
| 217 make_scoped_refptr(pipeline), | 212 base::Unretained(pipeline), |
| 218 message_loop, | 213 message_loop, |
| 219 audio_only), | 214 audio_only), |
| 220 base::TimeDelta::FromMilliseconds(10)); | 215 base::TimeDelta::FromMilliseconds(10)); |
| 221 } | 216 } |
| 222 | 217 |
| 223 int main(int argc, char** argv) { | 218 int main(int argc, char** argv) { |
| 224 base::AtExitManager at_exit; | 219 base::AtExitManager at_exit; |
| 225 media::InitializeMediaLibraryForTesting(); | 220 media::InitializeMediaLibraryForTesting(); |
| 226 | 221 |
| 227 CommandLine::Init(argc, argv); | 222 CommandLine::Init(argc, argv); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 257 signal(SIGINT, &TerminateHandler); | 252 signal(SIGINT, &TerminateHandler); |
| 258 | 253 |
| 259 // Initialize X11. | 254 // Initialize X11. |
| 260 if (!InitX11()) | 255 if (!InitX11()) |
| 261 return 1; | 256 return 1; |
| 262 | 257 |
| 263 // Initialize the pipeline thread and the pipeline. | 258 // Initialize the pipeline thread and the pipeline. |
| 264 base::MessageLoop message_loop; | 259 base::MessageLoop message_loop; |
| 265 base::Thread media_thread("MediaThread"); | 260 base::Thread media_thread("MediaThread"); |
| 266 media_thread.Start(); | 261 media_thread.Start(); |
| 267 scoped_refptr<media::Pipeline> pipeline; | |
| 268 | 262 |
| 269 PaintCB paint_cb; | 263 PaintCB paint_cb; |
| 270 if (command_line->HasSwitch("use-gl")) { | 264 if (command_line->HasSwitch("use-gl")) { |
| 271 paint_cb = base::Bind( | 265 paint_cb = base::Bind( |
| 272 &GlVideoRenderer::Paint, new GlVideoRenderer(g_display, g_window)); | 266 &GlVideoRenderer::Paint, new GlVideoRenderer(g_display, g_window)); |
| 273 } else { | 267 } else { |
| 274 paint_cb = base::Bind( | 268 paint_cb = base::Bind( |
| 275 &X11VideoRenderer::Paint, new X11VideoRenderer(g_display, g_window)); | 269 &X11VideoRenderer::Paint, new X11VideoRenderer(g_display, g_window)); |
| 276 } | 270 } |
| 277 | 271 |
| 278 scoped_refptr<media::DataSource> data_source( | 272 scoped_refptr<media::DataSource> data_source( |
| 279 new DataSourceLogger(CreateFileDataSource(filename), | 273 new DataSourceLogger(CreateFileDataSource(filename), |
| 280 command_line->HasSwitch("streaming"))); | 274 command_line->HasSwitch("streaming"))); |
| 281 scoped_ptr<media::Demuxer> demuxer(new media::FFmpegDemuxer( | 275 scoped_ptr<media::Demuxer> demuxer(new media::FFmpegDemuxer( |
| 282 media_thread.message_loop_proxy(), data_source, base::Bind(&NeedKey))); | 276 media_thread.message_loop_proxy(), data_source, base::Bind(&NeedKey))); |
| 283 | 277 |
| 284 if (InitPipeline(media_thread.message_loop_proxy(), demuxer.get(), | 278 media::Pipeline pipeline(media_thread.message_loop_proxy(), |
| 285 paint_cb, command_line->HasSwitch("audio"), | 279 new media::MediaLog()); |
| 286 &pipeline, &message_loop)) { | 280 InitPipeline(&pipeline, media_thread.message_loop_proxy(), demuxer.get(), |
| 287 // Main loop of the application. | 281 paint_cb, command_line->HasSwitch("audio"), &message_loop); |
| 288 g_running = true; | 282 // Main loop of the application. |
| 283 g_running = true; |
| 289 | 284 |
| 290 message_loop.PostTask(FROM_HERE, base::Bind( | 285 message_loop.PostTask(FROM_HERE, base::Bind( |
| 291 &PeriodicalUpdate, pipeline, &message_loop, !pipeline->HasVideo())); | 286 &PeriodicalUpdate, base::Unretained(&pipeline), &message_loop, |
| 292 message_loop.Run(); | 287 !pipeline.HasVideo())); |
| 293 } else { | 288 message_loop.Run(); |
| 294 std::cout << "Pipeline initialization failed..." << std::endl; | |
| 295 } | |
| 296 | 289 |
| 297 // Cleanup tasks. | 290 // Cleanup tasks. |
| 298 media_thread.Stop(); | 291 media_thread.Stop(); |
| 299 | 292 |
| 300 // Release callback which releases video renderer. Do this before cleaning up | 293 // Release callback which releases video renderer. Do this before cleaning up |
| 301 // X below since the video renderer has some X cleanup duties as well. | 294 // X below since the video renderer has some X cleanup duties as well. |
| 302 paint_cb.Reset(); | 295 paint_cb.Reset(); |
| 303 | 296 |
| 304 XDestroyWindow(g_display, g_window); | 297 XDestroyWindow(g_display, g_window); |
| 305 XCloseDisplay(g_display); | 298 XCloseDisplay(g_display); |
| 306 g_audio_manager = NULL; | 299 g_audio_manager = NULL; |
| 307 | 300 |
| 308 return 0; | 301 return 0; |
| 309 } | 302 } |
| OLD | NEW |