OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 13 #include "base/memory/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/adaptive_demuxer.h" | 22 #include "media/filters/adaptive_demuxer.h" |
23 #include "media/filters/audio_renderer_impl.h" | 23 #include "media/filters/audio_renderer_impl.h" |
24 #include "media/filters/ffmpeg_audio_decoder.h" | 24 #include "media/filters/ffmpeg_audio_decoder.h" |
25 #include "media/filters/ffmpeg_demuxer_factory.h" | 25 #include "media/filters/ffmpeg_demuxer_factory.h" |
26 #include "media/filters/ffmpeg_video_decoder.h" | 26 #include "media/filters/ffmpeg_video_decoder.h" |
27 #include "media/filters/file_data_source_factory.h" | 27 #include "media/filters/file_data_source_factory.h" |
28 #include "media/filters/null_audio_renderer.h" | 28 #include "media/filters/null_audio_renderer.h" |
29 #include "media/filters/omx_video_decoder.h" | |
30 | 29 |
31 // TODO(jiesun): implement different video decode contexts according to | 30 // TODO(jiesun): implement different video decode contexts according to |
32 // these flags. e.g. | 31 // these flags. e.g. |
33 // 1. system memory video decode context for x11 | 32 // 1. system memory video decode context for x11 |
34 // 2. gl texture video decode context for OpenGL. | 33 // 2. gl texture video decode context for OpenGL. |
35 // 3. gles texture video decode context for OpenGLES. | 34 // 3. gles texture video decode context for OpenGLES. |
36 // TODO(jiesun): add an uniform video renderer which take the video | 35 // TODO(jiesun): add an uniform video renderer which take the video |
37 // decode context object and delegate renderer request to these | 36 // decode context object and delegate renderer request to these |
38 // objects. i.e. Seperate "painter" and "pts scheduler". | 37 // objects. i.e. Seperate "painter" and "pts scheduler". |
39 #if defined(RENDERER_GL) | 38 #if defined(RENDERER_GL) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 ExposureMask | ButtonPressMask | KeyPressMask); | 87 ExposureMask | ButtonPressMask | KeyPressMask); |
89 XMapWindow(g_display, g_window); | 88 XMapWindow(g_display, g_window); |
90 return true; | 89 return true; |
91 } | 90 } |
92 | 91 |
93 bool InitPipeline(MessageLoop* message_loop, | 92 bool InitPipeline(MessageLoop* message_loop, |
94 const char* filename, bool enable_audio, | 93 const char* filename, bool enable_audio, |
95 scoped_refptr<media::PipelineImpl>* pipeline, | 94 scoped_refptr<media::PipelineImpl>* pipeline, |
96 MessageLoop* paint_message_loop, | 95 MessageLoop* paint_message_loop, |
97 media::MessageLoopFactory* message_loop_factory) { | 96 media::MessageLoopFactory* message_loop_factory) { |
98 // Initialize OpenMAX. | |
99 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
100 switches::kEnableOpenMax) && | |
101 !media::InitializeOpenMaxLibrary(FilePath())) { | |
102 std::cout << "Unable to initialize OpenMAX library."<< std::endl; | |
103 return false; | |
104 } | |
105 | |
106 // Load media libraries. | 97 // Load media libraries. |
107 if (!media::InitializeMediaLibrary(FilePath())) { | 98 if (!media::InitializeMediaLibrary(FilePath())) { |
108 std::cout << "Unable to initialize the media library." << std::endl; | 99 std::cout << "Unable to initialize the media library." << std::endl; |
109 return false; | 100 return false; |
110 } | 101 } |
111 | 102 |
112 // Create our filter factories. | 103 // Create our filter factories. |
113 scoped_ptr<media::FilterCollection> collection( | 104 scoped_ptr<media::FilterCollection> collection( |
114 new media::FilterCollection()); | 105 new media::FilterCollection()); |
115 collection->SetDemuxerFactory( | 106 collection->SetDemuxerFactory( |
116 new media::AdaptiveDemuxerFactory( | 107 new media::AdaptiveDemuxerFactory( |
117 new media::FFmpegDemuxerFactory( | 108 new media::FFmpegDemuxerFactory( |
118 new media::FileDataSourceFactory(), message_loop))); | 109 new media::FileDataSourceFactory(), message_loop))); |
119 collection->AddAudioDecoder(new media::FFmpegAudioDecoder( | 110 collection->AddAudioDecoder(new media::FFmpegAudioDecoder( |
120 message_loop_factory->GetMessageLoop("AudioDecoderThread"))); | 111 message_loop_factory->GetMessageLoop("AudioDecoderThread"))); |
121 if (CommandLine::ForCurrentProcess()->HasSwitch( | 112 collection->AddVideoDecoder(new media::FFmpegVideoDecoder( |
122 switches::kEnableOpenMax)) { | 113 message_loop_factory->GetMessageLoop("VideoDecoderThread"), |
123 collection->AddVideoDecoder(new media::OmxVideoDecoder( | 114 NULL)); |
124 message_loop_factory->GetMessageLoop("VideoDecoderThread"), | |
125 NULL)); | |
126 } else { | |
127 collection->AddVideoDecoder(new media::FFmpegVideoDecoder( | |
128 message_loop_factory->GetMessageLoop("VideoDecoderThread"), | |
129 NULL)); | |
130 } | |
131 collection->AddVideoRenderer(new Renderer(g_display, | 115 collection->AddVideoRenderer(new Renderer(g_display, |
132 g_window, | 116 g_window, |
133 paint_message_loop)); | 117 paint_message_loop)); |
134 | 118 |
135 if (enable_audio) | 119 if (enable_audio) |
136 collection->AddAudioRenderer(new media::AudioRendererImpl()); | 120 collection->AddAudioRenderer(new media::AudioRendererImpl()); |
137 else | 121 else |
138 collection->AddAudioRenderer(new media::NullAudioRenderer()); | 122 collection->AddAudioRenderer(new media::NullAudioRenderer()); |
139 | 123 |
140 // Create the pipeline and start it. | 124 // Create the pipeline and start it. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 NewRunnableFunction(PeriodicalUpdate, make_scoped_refptr(pipeline), | 211 NewRunnableFunction(PeriodicalUpdate, make_scoped_refptr(pipeline), |
228 message_loop, audio_only), 10); | 212 message_loop, audio_only), 10); |
229 } | 213 } |
230 | 214 |
231 int main(int argc, char** argv) { | 215 int main(int argc, char** argv) { |
232 // Read arguments. | 216 // Read arguments. |
233 if (argc == 1) { | 217 if (argc == 1) { |
234 std::cout << "Usage: " << argv[0] << " --file=FILE" << std::endl | 218 std::cout << "Usage: " << argv[0] << " --file=FILE" << std::endl |
235 << std::endl | 219 << std::endl |
236 << "Optional arguments:" << std::endl | 220 << "Optional arguments:" << std::endl |
237 << " [--enable-openmax]" | |
238 << " [--audio]" | 221 << " [--audio]" |
239 << " [--alsa-device=DEVICE]" << std::endl | 222 << " [--alsa-device=DEVICE]" << std::endl |
240 << " Press [ESC] to stop" << std::endl | 223 << " Press [ESC] to stop" << std::endl |
241 << " Press [SPACE] to toggle pause/play" << std::endl | 224 << " Press [SPACE] to toggle pause/play" << std::endl |
242 << " Press mouse left button to seek" << std::endl; | 225 << " Press mouse left button to seek" << std::endl; |
243 return 1; | 226 return 1; |
244 } | 227 } |
245 | 228 |
246 // Read command line. | 229 // Read command line. |
247 CommandLine::Init(argc, argv); | 230 CommandLine::Init(argc, argv); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 275 } |
293 | 276 |
294 // Cleanup tasks. | 277 // Cleanup tasks. |
295 message_loop_factory.reset(); | 278 message_loop_factory.reset(); |
296 | 279 |
297 thread->Stop(); | 280 thread->Stop(); |
298 XDestroyWindow(g_display, g_window); | 281 XDestroyWindow(g_display, g_window); |
299 XCloseDisplay(g_display); | 282 XCloseDisplay(g_display); |
300 return 0; | 283 return 0; |
301 } | 284 } |
OLD | NEW |