OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> | 5 #include <iostream> |
6 #include <signal.h> | 6 #include <signal.h> |
7 #include <X11/keysym.h> | 7 #include <X11/keysym.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "media/base/callback.h" | 16 #include "media/base/callback.h" |
17 #include "media/base/filter_collection.h" | 17 #include "media/base/filter_collection.h" |
18 #include "media/base/media.h" | 18 #include "media/base/media.h" |
19 #include "media/base/media_switches.h" | 19 #include "media/base/media_switches.h" |
20 #include "media/base/message_loop_factory_impl.h" | 20 #include "media/base/message_loop_factory_impl.h" |
21 #include "media/base/pipeline_impl.h" | 21 #include "media/base/pipeline_impl.h" |
22 #include "media/filters/audio_renderer_impl.h" | 22 #include "media/filters/audio_renderer_impl.h" |
23 #include "media/filters/ffmpeg_audio_decoder.h" | 23 #include "media/filters/ffmpeg_audio_decoder.h" |
24 #include "media/filters/ffmpeg_demuxer.h" | 24 #include "media/filters/ffmpeg_demuxer_factory.h" |
25 #include "media/filters/ffmpeg_video_decoder.h" | 25 #include "media/filters/ffmpeg_video_decoder.h" |
26 #include "media/filters/file_data_source_factory.h" | 26 #include "media/filters/file_data_source_factory.h" |
27 #include "media/filters/null_audio_renderer.h" | 27 #include "media/filters/null_audio_renderer.h" |
28 #include "media/filters/omx_video_decoder.h" | 28 #include "media/filters/omx_video_decoder.h" |
29 | 29 |
30 // TODO(jiesun): implement different video decode contexts according to | 30 // TODO(jiesun): implement different video decode contexts according to |
31 // these flags. e.g. | 31 // these flags. e.g. |
32 // 1. system memory video decode context for x11 | 32 // 1. system memory video decode context for x11 |
33 // 2. gl texture video decode context for OpenGL. | 33 // 2. gl texture video decode context for OpenGL. |
34 // 3. gles texture video decode context for OpenGLES. | 34 // 3. gles texture video decode context for OpenGLES. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 // Load media libraries. | 97 // Load media libraries. |
98 if (!media::InitializeMediaLibrary(FilePath())) { | 98 if (!media::InitializeMediaLibrary(FilePath())) { |
99 std::cout << "Unable to initialize the media library." << std::endl; | 99 std::cout << "Unable to initialize the media library." << std::endl; |
100 return false; | 100 return false; |
101 } | 101 } |
102 | 102 |
103 // Create our filter factories. | 103 // Create our filter factories. |
104 scoped_ptr<media::FilterCollection> collection( | 104 scoped_ptr<media::FilterCollection> collection( |
105 new media::FilterCollection()); | 105 new media::FilterCollection()); |
106 collection->SetDataSourceFactory(new media::FileDataSourceFactory()); | 106 collection->SetDemuxerFactory(new media::FFmpegDemuxerFactory( |
107 collection->AddDemuxer(new media::FFmpegDemuxer( | 107 new media::FileDataSourceFactory(), message_loop)); |
108 message_loop_factory->GetMessageLoop("DemuxThread"))); | |
109 collection->AddAudioDecoder(new media::FFmpegAudioDecoder( | 108 collection->AddAudioDecoder(new media::FFmpegAudioDecoder( |
110 message_loop_factory->GetMessageLoop("AudioDecoderThread"))); | 109 message_loop_factory->GetMessageLoop("AudioDecoderThread"))); |
111 if (CommandLine::ForCurrentProcess()->HasSwitch( | 110 if (CommandLine::ForCurrentProcess()->HasSwitch( |
112 switches::kEnableOpenMax)) { | 111 switches::kEnableOpenMax)) { |
113 collection->AddVideoDecoder(new media::OmxVideoDecoder( | 112 collection->AddVideoDecoder(new media::OmxVideoDecoder( |
114 message_loop_factory->GetMessageLoop("VideoDecoderThread"), | 113 message_loop_factory->GetMessageLoop("VideoDecoderThread"), |
115 NULL)); | 114 NULL)); |
116 } else { | 115 } else { |
117 collection->AddVideoDecoder(new media::FFmpegVideoDecoder( | 116 collection->AddVideoDecoder(new media::FFmpegVideoDecoder( |
118 message_loop_factory->GetMessageLoop("VideoDecoderThread"), | 117 message_loop_factory->GetMessageLoop("VideoDecoderThread"), |
119 NULL)); | 118 NULL)); |
120 } | 119 } |
121 collection->AddVideoRenderer(new Renderer(g_display, | 120 collection->AddVideoRenderer(new Renderer(g_display, |
122 g_window, | 121 g_window, |
123 paint_message_loop)); | 122 paint_message_loop)); |
124 | 123 |
125 if (enable_audio) | 124 if (enable_audio) |
126 collection->AddAudioRenderer(new media::AudioRendererImpl()); | 125 collection->AddAudioRenderer(new media::AudioRendererImpl()); |
127 else | 126 else |
128 collection->AddAudioRenderer(new media::NullAudioRenderer()); | 127 collection->AddAudioRenderer(new media::NullAudioRenderer()); |
129 | 128 |
130 // Creates the pipeline and start it. | 129 // Create and start the pipeline. |
131 *pipeline = new media::PipelineImpl(message_loop); | 130 *pipeline = new media::PipelineImpl(message_loop); |
132 (*pipeline)->Start(collection.release(), filename, NULL); | 131 (*pipeline)->Start(collection.release(), filename, NULL); |
133 | 132 |
134 // Wait until the pipeline is fully initialized. | 133 // Wait until the pipeline is fully initialized. |
135 while (true) { | 134 while (true) { |
136 base::PlatformThread::Sleep(100); | 135 base::PlatformThread::Sleep(100); |
137 if ((*pipeline)->IsInitialized()) | 136 if ((*pipeline)->IsInitialized()) |
138 break; | 137 break; |
139 if ((*pipeline)->GetError() != media::PIPELINE_OK) { | 138 if ((*pipeline)->GetError() != media::PIPELINE_OK) { |
| 139 std::cout << "InitPipeline: " << (*pipeline)->GetError() << std::endl; |
140 (*pipeline)->Stop(NULL); | 140 (*pipeline)->Stop(NULL); |
141 return false; | 141 return false; |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 // And starts the playback. | 145 // And starts the playback. |
146 (*pipeline)->SetPlaybackRate(1.0f); | 146 (*pipeline)->SetPlaybackRate(1.0f); |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 | 278 |
279 // Cleanup tasks. | 279 // Cleanup tasks. |
280 message_loop_factory.reset(); | 280 message_loop_factory.reset(); |
281 | 281 |
282 thread->Stop(); | 282 thread->Stop(); |
283 XDestroyWindow(g_display, g_window); | 283 XDestroyWindow(g_display, g_window); |
284 XCloseDisplay(g_display); | 284 XCloseDisplay(g_display); |
285 return 0; | 285 return 0; |
286 } | 286 } |
OLD | NEW |