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 "media/filters/vpx_video_decoder.h" | 5 #include "media/filters/vpx_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 vpx_codec_(NULL), | 208 vpx_codec_(NULL), |
209 vpx_codec_alpha_(NULL) {} | 209 vpx_codec_alpha_(NULL) {} |
210 | 210 |
211 VpxVideoDecoder::~VpxVideoDecoder() { | 211 VpxVideoDecoder::~VpxVideoDecoder() { |
212 DCHECK_EQ(kUninitialized, state_); | 212 DCHECK_EQ(kUninitialized, state_); |
213 CloseDecoder(); | 213 CloseDecoder(); |
214 } | 214 } |
215 | 215 |
216 void VpxVideoDecoder::Initialize(const VideoDecoderConfig& config, | 216 void VpxVideoDecoder::Initialize(const VideoDecoderConfig& config, |
217 bool low_delay, | 217 bool low_delay, |
218 const PipelineStatusCB& status_cb) { | 218 const PipelineStatusCB& status_cb, |
| 219 const OutputCB& output_cb) { |
219 DCHECK(task_runner_->BelongsToCurrentThread()); | 220 DCHECK(task_runner_->BelongsToCurrentThread()); |
220 DCHECK(config.IsValidConfig()); | 221 DCHECK(config.IsValidConfig()); |
221 DCHECK(!config.is_encrypted()); | 222 DCHECK(!config.is_encrypted()); |
222 DCHECK(decode_cb_.is_null()); | 223 DCHECK(decode_cb_.is_null()); |
223 | 224 |
224 if (!ConfigureDecoder(config)) { | 225 if (!ConfigureDecoder(config)) { |
225 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 226 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
226 return; | 227 return; |
227 } | 228 } |
228 | 229 |
229 // Success! | 230 // Success! |
230 config_ = config; | 231 config_ = config; |
231 state_ = kNormal; | 232 state_ = kNormal; |
| 233 output_cb_ = output_cb; |
232 status_cb.Run(PIPELINE_OK); | 234 status_cb.Run(PIPELINE_OK); |
233 } | 235 } |
234 | 236 |
235 static vpx_codec_ctx* InitializeVpxContext(vpx_codec_ctx* context, | 237 static vpx_codec_ctx* InitializeVpxContext(vpx_codec_ctx* context, |
236 const VideoDecoderConfig& config) { | 238 const VideoDecoderConfig& config) { |
237 context = new vpx_codec_ctx(); | 239 context = new vpx_codec_ctx(); |
238 vpx_codec_dec_cfg_t vpx_config = {0}; | 240 vpx_codec_dec_cfg_t vpx_config = {0}; |
239 vpx_config.w = config.coded_size().width(); | 241 vpx_config.w = config.coded_size().width(); |
240 vpx_config.h = config.coded_size().height(); | 242 vpx_config.h = config.coded_size().height(); |
241 vpx_config.threads = GetThreadCount(config); | 243 vpx_config.threads = GetThreadCount(config); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 void VpxVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 309 void VpxVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
308 const DecodeCB& decode_cb) { | 310 const DecodeCB& decode_cb) { |
309 DCHECK(task_runner_->BelongsToCurrentThread()); | 311 DCHECK(task_runner_->BelongsToCurrentThread()); |
310 DCHECK(!decode_cb.is_null()); | 312 DCHECK(!decode_cb.is_null()); |
311 CHECK_NE(state_, kUninitialized); | 313 CHECK_NE(state_, kUninitialized); |
312 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; | 314 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; |
313 | 315 |
314 decode_cb_ = BindToCurrentLoop(decode_cb); | 316 decode_cb_ = BindToCurrentLoop(decode_cb); |
315 | 317 |
316 if (state_ == kError) { | 318 if (state_ == kError) { |
317 base::ResetAndReturn(&decode_cb_).Run(kDecodeError, NULL); | 319 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); |
318 return; | 320 return; |
319 } | 321 } |
320 | 322 |
321 // Return empty frames if decoding has finished. | 323 // Return empty frames if decoding has finished. |
322 if (state_ == kDecodeFinished) { | 324 if (state_ == kDecodeFinished) { |
323 base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEOSFrame()); | 325 base::ResetAndReturn(&decode_cb_).Run(kOk); |
324 return; | 326 return; |
325 } | 327 } |
326 | 328 |
327 DecodeBuffer(buffer); | 329 DecodeBuffer(buffer); |
328 } | 330 } |
329 | 331 |
330 void VpxVideoDecoder::Reset(const base::Closure& closure) { | 332 void VpxVideoDecoder::Reset(const base::Closure& closure) { |
331 DCHECK(task_runner_->BelongsToCurrentThread()); | 333 DCHECK(task_runner_->BelongsToCurrentThread()); |
332 DCHECK(decode_cb_.is_null()); | 334 DCHECK(decode_cb_.is_null()); |
333 | 335 |
(...skipping 11 matching lines...) Expand all Loading... |
345 DCHECK(task_runner_->BelongsToCurrentThread()); | 347 DCHECK(task_runner_->BelongsToCurrentThread()); |
346 DCHECK_NE(state_, kUninitialized); | 348 DCHECK_NE(state_, kUninitialized); |
347 DCHECK_NE(state_, kDecodeFinished); | 349 DCHECK_NE(state_, kDecodeFinished); |
348 DCHECK_NE(state_, kError); | 350 DCHECK_NE(state_, kError); |
349 DCHECK(!decode_cb_.is_null()); | 351 DCHECK(!decode_cb_.is_null()); |
350 DCHECK(buffer); | 352 DCHECK(buffer); |
351 | 353 |
352 // Transition to kDecodeFinished on the first end of stream buffer. | 354 // Transition to kDecodeFinished on the first end of stream buffer. |
353 if (state_ == kNormal && buffer->end_of_stream()) { | 355 if (state_ == kNormal && buffer->end_of_stream()) { |
354 state_ = kDecodeFinished; | 356 state_ = kDecodeFinished; |
355 base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEOSFrame()); | 357 output_cb_.Run(VideoFrame::CreateEOSFrame()); |
| 358 base::ResetAndReturn(&decode_cb_).Run(kOk); |
356 return; | 359 return; |
357 } | 360 } |
358 | 361 |
359 scoped_refptr<VideoFrame> video_frame; | 362 scoped_refptr<VideoFrame> video_frame; |
360 if (!VpxDecode(buffer, &video_frame)) { | 363 if (!VpxDecode(buffer, &video_frame)) { |
361 state_ = kError; | 364 state_ = kError; |
362 base::ResetAndReturn(&decode_cb_).Run(kDecodeError, NULL); | 365 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); |
363 return; | 366 return; |
364 } | 367 } |
365 | 368 |
366 // If we didn't get a frame we need more data. | 369 base::ResetAndReturn(&decode_cb_).Run(kOk); |
367 if (!video_frame.get()) { | |
368 base::ResetAndReturn(&decode_cb_).Run(kNotEnoughData, NULL); | |
369 return; | |
370 } | |
371 | 370 |
372 base::ResetAndReturn(&decode_cb_).Run(kOk, video_frame); | 371 if (video_frame) |
| 372 output_cb_.Run(video_frame); |
373 } | 373 } |
374 | 374 |
375 bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, | 375 bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, |
376 scoped_refptr<VideoFrame>* video_frame) { | 376 scoped_refptr<VideoFrame>* video_frame) { |
377 DCHECK(video_frame); | 377 DCHECK(video_frame); |
378 DCHECK(!buffer->end_of_stream()); | 378 DCHECK(!buffer->end_of_stream()); |
379 | 379 |
380 // Pass |buffer| to libvpx. | 380 // Pass |buffer| to libvpx. |
381 int64 timestamp = buffer->timestamp().InMicroseconds(); | 381 int64 timestamp = buffer->timestamp().InMicroseconds(); |
382 void* user_priv = reinterpret_cast<void*>(×tamp); | 382 void* user_priv = reinterpret_cast<void*>(×tamp); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); | 495 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); |
496 return; | 496 return; |
497 } | 497 } |
498 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], | 498 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
499 vpx_image->stride[VPX_PLANE_Y], | 499 vpx_image->stride[VPX_PLANE_Y], |
500 vpx_image->d_h, | 500 vpx_image->d_h, |
501 video_frame->get()); | 501 video_frame->get()); |
502 } | 502 } |
503 | 503 |
504 } // namespace media | 504 } // namespace media |
OLD | NEW |