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