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 "media/filters/omx_video_decoder.h" | 5 #include "media/filters/omx_video_decoder.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/waitable_event.h" | 8 #include "base/waitable_event.h" |
9 #include "media/base/factory.h" | 9 #include "media/base/factory.h" |
10 #include "media/base/filter_host.h" | 10 #include "media/base/filter_host.h" |
| 11 #include "media/base/limits.h" |
11 #include "media/ffmpeg/ffmpeg_common.h" | 12 #include "media/ffmpeg/ffmpeg_common.h" |
12 #include "media/filters/ffmpeg_interfaces.h" | 13 #include "media/filters/ffmpeg_interfaces.h" |
13 #include "media/filters/omx_video_decode_engine.h" | 14 #include "media/filters/omx_video_decode_engine.h" |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 | 17 |
17 // static | 18 // static |
18 FilterFactory* OmxVideoDecoder::CreateFactory() { | 19 FilterFactory* OmxVideoDecoder::CreateFactory() { |
19 return new FilterFactoryImpl1<OmxVideoDecoder, OmxVideoDecodeEngine*>( | 20 return new FilterFactoryImpl1<OmxVideoDecoder, OmxVideoDecodeEngine*>( |
20 new OmxVideoDecodeEngine()); | 21 new OmxVideoDecodeEngine()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // TODO(ajwong): This is a total hack. Make async. | 76 // TODO(ajwong): This is a total hack. Make async. |
76 base::WaitableEvent event(false, false); | 77 base::WaitableEvent event(false, false); |
77 omx_engine_->Stop(NewCallback(&event, &base::WaitableEvent::Signal)); | 78 omx_engine_->Stop(NewCallback(&event, &base::WaitableEvent::Signal)); |
78 event.Wait(); | 79 event.Wait(); |
79 } | 80 } |
80 | 81 |
81 void OmxVideoDecoder::DoInitialize(DemuxerStream* demuxer_stream, | 82 void OmxVideoDecoder::DoInitialize(DemuxerStream* demuxer_stream, |
82 FilterCallback* callback) { | 83 FilterCallback* callback) { |
83 DCHECK_EQ(message_loop(), MessageLoop::current()); | 84 DCHECK_EQ(message_loop(), MessageLoop::current()); |
84 | 85 |
| 86 // Get the AVStream by querying for the provider interface. |
| 87 AVStreamProvider* av_stream_provider; |
| 88 if (!demuxer_stream->QueryInterface(&av_stream_provider)) { |
| 89 return; |
| 90 } |
| 91 AVStream* av_stream = av_stream_provider->GetAVStream(); |
| 92 |
| 93 width_ = av_stream->codec->width; |
| 94 height_ = av_stream->codec->height; |
| 95 if (width_ > Limits::kMaxDimension || |
| 96 height_ > Limits::kMaxDimension || |
| 97 (width_ * height_) > Limits::kMaxCanvas) { |
| 98 return; |
| 99 } |
| 100 |
85 // Sets the output format. | 101 // Sets the output format. |
86 if (supports_egl_image_) { | 102 if (supports_egl_image_) { |
87 media_format_.SetAsString(MediaFormat::kMimeType, | 103 media_format_.SetAsString(MediaFormat::kMimeType, |
88 mime_type::kUncompressedVideoEglImage); | 104 mime_type::kUncompressedVideoEglImage); |
89 } | 105 } |
| 106 else { |
| 107 media_format_.SetAsString(MediaFormat::kMimeType, |
| 108 mime_type::kUncompressedVideo); |
| 109 } |
| 110 |
| 111 media_format_.SetAsInteger(MediaFormat::kWidth, width_); |
| 112 media_format_.SetAsInteger(MediaFormat::kHeight, height_); |
90 | 113 |
91 // Savs the demuxer stream. | 114 // Savs the demuxer stream. |
92 demuxer_stream_ = demuxer_stream; | 115 demuxer_stream_ = demuxer_stream; |
93 | 116 |
94 // Get the AVStream by querying for the provider interface. | |
95 AVStreamProvider* av_stream_provider; | |
96 if (!demuxer_stream->QueryInterface(&av_stream_provider)) | |
97 return; | |
98 AVStream* av_stream = av_stream_provider->GetAVStream(); | |
99 | |
100 // Initialize the decode engine. | 117 // Initialize the decode engine. |
101 omx_engine_->Initialize( | 118 omx_engine_->Initialize( |
102 message_loop(), | 119 message_loop(), |
103 av_stream, | 120 av_stream, |
104 NewCallback(this, &OmxVideoDecoder::EmptyBufferCallback), | 121 NewCallback(this, &OmxVideoDecoder::EmptyBufferCallback), |
105 NewCallback(this, &OmxVideoDecoder::FillBufferCallback), | 122 NewCallback(this, &OmxVideoDecoder::FillBufferCallback), |
106 NewRunnableMethod(this, &OmxVideoDecoder::InitCompleteTask, callback)); | 123 NewRunnableMethod(this, &OmxVideoDecoder::InitCompleteTask, callback)); |
107 } | 124 } |
108 | 125 |
109 void OmxVideoDecoder::FillBufferCallback(scoped_refptr<VideoFrame> frame) { | 126 void OmxVideoDecoder::FillBufferCallback(scoped_refptr<VideoFrame> frame) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // TODO(hclam): Query this number from |omx_engine_|. | 170 // TODO(hclam): Query this number from |omx_engine_|. |
154 const int kDemuxPackets = 2; | 171 const int kDemuxPackets = 2; |
155 DCHECK(demuxer_stream_); | 172 DCHECK(demuxer_stream_); |
156 for (int i = 0; i < kDemuxPackets; ++i) { | 173 for (int i = 0; i < kDemuxPackets; ++i) { |
157 demuxer_stream_->Read( | 174 demuxer_stream_->Read( |
158 NewCallback(this, &OmxVideoDecoder::DemuxCompleteTask)); | 175 NewCallback(this, &OmxVideoDecoder::DemuxCompleteTask)); |
159 } | 176 } |
160 } | 177 } |
161 | 178 |
162 } // namespace media | 179 } // namespace media |
OLD | NEW |