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 "media/filters/ffmpeg_video_decoder.h" | 5 #include "media/filters/ffmpeg_video_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "media/base/demuxer_stream.h" | 9 #include "media/base/demuxer_stream.h" |
10 #include "media/base/filter_host.h" | 10 #include "media/base/filter_host.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return; | 124 return; |
125 } | 125 } |
126 | 126 |
127 decode_engine_->Flush(); | 127 decode_engine_->Flush(); |
128 pts_stream_.Flush(); | 128 pts_stream_.Flush(); |
129 state_ = kNormal; | 129 state_ = kNormal; |
130 callback.Run(); | 130 callback.Run(); |
131 } | 131 } |
132 | 132 |
133 void FFmpegVideoDecoder::Read(const ReadCB& callback) { | 133 void FFmpegVideoDecoder::Read(const ReadCB& callback) { |
134 // TODO(scherkus): forced task post since VideoRendererBase::FrameReady() will | 134 // Complete operation asynchronously on different stack of execution as per |
135 // call Read() on FFmpegVideoDecoder's thread as we executed |read_cb_|. | 135 // the API contract of VideoDecoder::Read() |
136 message_loop_->PostTask(FROM_HERE, base::Bind( | 136 message_loop_->PostTask(FROM_HERE, base::Bind( |
137 &FFmpegVideoDecoder::DoRead, this, callback)); | 137 &FFmpegVideoDecoder::DoRead, this, callback)); |
138 } | 138 } |
139 | 139 |
140 const gfx::Size& FFmpegVideoDecoder::natural_size() { | 140 const gfx::Size& FFmpegVideoDecoder::natural_size() { |
141 return natural_size_; | 141 return natural_size_; |
142 } | 142 } |
143 | 143 |
144 void FFmpegVideoDecoder::DoRead(const ReadCB& callback) { | 144 void FFmpegVideoDecoder::DoRead(const ReadCB& callback) { |
145 DCHECK_EQ(MessageLoop::current(), message_loop_); | 145 DCHECK_EQ(MessageLoop::current(), message_loop_); |
146 CHECK(!callback.is_null()); | 146 DCHECK(!callback.is_null()); |
147 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; | 147 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; |
148 | 148 |
149 // This can happen during shutdown after Stop() has been called. | 149 // This can happen during shutdown after Stop() has been called. |
150 if (state_ == kUninitialized) { | 150 if (state_ == kUninitialized) { |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
154 // Return empty frames if decoding has finished. | 154 // Return empty frames if decoding has finished. |
155 if (state_ == kDecodeFinished) { | 155 if (state_ == kDecodeFinished) { |
156 callback.Run(VideoFrame::CreateEmptyFrame()); | 156 callback.Run(VideoFrame::CreateEmptyFrame()); |
157 return; | 157 return; |
158 } | 158 } |
159 | 159 |
160 read_cb_ = callback; | 160 read_cb_ = callback; |
161 ReadFromDemuxerStream(); | 161 ReadFromDemuxerStream(); |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 void FFmpegVideoDecoder::ReadFromDemuxerStream() { | 165 void FFmpegVideoDecoder::ReadFromDemuxerStream() { |
166 DCHECK_NE(state_, kUninitialized); | 166 DCHECK_NE(state_, kUninitialized); |
167 DCHECK_NE(state_, kDecodeFinished); | 167 DCHECK_NE(state_, kDecodeFinished); |
168 DCHECK(!read_cb_.is_null()); | 168 DCHECK(!read_cb_.is_null()); |
169 | 169 |
170 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this)); | 170 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this)); |
171 } | 171 } |
172 | 172 |
173 void FFmpegVideoDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) { | 173 void FFmpegVideoDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) { |
174 // TODO(scherkus): forced task post since FFmpegDemuxerStream::Read() can | 174 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read |
175 // immediately execute our callback on FFmpegVideoDecoder's thread. | 175 // callback on the same execution stack so we can get rid of forced task post. |
176 message_loop_->PostTask(FROM_HERE, base::Bind( | 176 message_loop_->PostTask(FROM_HERE, base::Bind( |
177 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); | 177 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); |
178 } | 178 } |
179 | 179 |
180 void FFmpegVideoDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& buffer) { | 180 void FFmpegVideoDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& buffer) { |
181 DCHECK_EQ(MessageLoop::current(), message_loop_); | 181 DCHECK_EQ(MessageLoop::current(), message_loop_); |
182 DCHECK_NE(state_, kUninitialized); | 182 DCHECK_NE(state_, kUninitialized); |
183 DCHECK_NE(state_, kDecodeFinished); | 183 DCHECK_NE(state_, kDecodeFinished); |
184 DCHECK(!read_cb_.is_null()); | 184 DCHECK(!read_cb_.is_null()); |
185 | 185 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 void FFmpegVideoDecoder::DeliverFrame( | 259 void FFmpegVideoDecoder::DeliverFrame( |
260 const scoped_refptr<VideoFrame>& video_frame) { | 260 const scoped_refptr<VideoFrame>& video_frame) { |
261 // Reset the callback before running to protect against reentrancy. | 261 // Reset the callback before running to protect against reentrancy. |
262 ReadCB read_cb = read_cb_; | 262 ReadCB read_cb = read_cb_; |
263 read_cb_.Reset(); | 263 read_cb_.Reset(); |
264 read_cb.Run(video_frame); | 264 read_cb.Run(video_frame); |
265 } | 265 } |
266 | 266 |
267 } // namespace media | 267 } // namespace media |
OLD | NEW |