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) { | |
220 DCHECK(task_runner_->BelongsToCurrentThread()); | 219 DCHECK(task_runner_->BelongsToCurrentThread()); |
221 DCHECK(config.IsValidConfig()); | 220 DCHECK(config.IsValidConfig()); |
222 DCHECK(!config.is_encrypted()); | 221 DCHECK(!config.is_encrypted()); |
223 DCHECK(decode_cb_.is_null()); | 222 DCHECK(decode_cb_.is_null()); |
224 | 223 |
225 if (!ConfigureDecoder(config)) { | 224 if (!ConfigureDecoder(config)) { |
226 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 225 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
227 return; | 226 return; |
228 } | 227 } |
229 | 228 |
230 // Success! | 229 // Success! |
231 config_ = config; | 230 config_ = config; |
232 state_ = kNormal; | 231 state_ = kNormal; |
233 output_cb_ = BindToCurrentLoop(output_cb); | |
234 status_cb.Run(PIPELINE_OK); | 232 status_cb.Run(PIPELINE_OK); |
235 } | 233 } |
236 | 234 |
237 static vpx_codec_ctx* InitializeVpxContext(vpx_codec_ctx* context, | 235 static vpx_codec_ctx* InitializeVpxContext(vpx_codec_ctx* context, |
238 const VideoDecoderConfig& config) { | 236 const VideoDecoderConfig& config) { |
239 context = new vpx_codec_ctx(); | 237 context = new vpx_codec_ctx(); |
240 vpx_codec_dec_cfg_t vpx_config = {0}; | 238 vpx_codec_dec_cfg_t vpx_config = {0}; |
241 vpx_config.w = config.coded_size().width(); | 239 vpx_config.w = config.coded_size().width(); |
242 vpx_config.h = config.coded_size().height(); | 240 vpx_config.h = config.coded_size().height(); |
243 vpx_config.threads = GetThreadCount(config); | 241 vpx_config.threads = GetThreadCount(config); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 void VpxVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 307 void VpxVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
310 const DecodeCB& decode_cb) { | 308 const DecodeCB& decode_cb) { |
311 DCHECK(task_runner_->BelongsToCurrentThread()); | 309 DCHECK(task_runner_->BelongsToCurrentThread()); |
312 DCHECK(!decode_cb.is_null()); | 310 DCHECK(!decode_cb.is_null()); |
313 CHECK_NE(state_, kUninitialized); | 311 CHECK_NE(state_, kUninitialized); |
314 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; | 312 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; |
315 | 313 |
316 decode_cb_ = BindToCurrentLoop(decode_cb); | 314 decode_cb_ = BindToCurrentLoop(decode_cb); |
317 | 315 |
318 if (state_ == kError) { | 316 if (state_ == kError) { |
319 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); | 317 base::ResetAndReturn(&decode_cb_).Run(kDecodeError, NULL); |
320 return; | 318 return; |
321 } | 319 } |
322 | 320 |
323 // Return empty frames if decoding has finished. | 321 // Return empty frames if decoding has finished. |
324 if (state_ == kDecodeFinished) { | 322 if (state_ == kDecodeFinished) { |
325 base::ResetAndReturn(&decode_cb_).Run(kOk); | 323 base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEOSFrame()); |
326 return; | 324 return; |
327 } | 325 } |
328 | 326 |
329 DecodeBuffer(buffer); | 327 DecodeBuffer(buffer); |
330 } | 328 } |
331 | 329 |
332 void VpxVideoDecoder::Reset(const base::Closure& closure) { | 330 void VpxVideoDecoder::Reset(const base::Closure& closure) { |
333 DCHECK(task_runner_->BelongsToCurrentThread()); | 331 DCHECK(task_runner_->BelongsToCurrentThread()); |
334 DCHECK(decode_cb_.is_null()); | 332 DCHECK(decode_cb_.is_null()); |
335 | 333 |
(...skipping 11 matching lines...) Expand all Loading... |
347 DCHECK(task_runner_->BelongsToCurrentThread()); | 345 DCHECK(task_runner_->BelongsToCurrentThread()); |
348 DCHECK_NE(state_, kUninitialized); | 346 DCHECK_NE(state_, kUninitialized); |
349 DCHECK_NE(state_, kDecodeFinished); | 347 DCHECK_NE(state_, kDecodeFinished); |
350 DCHECK_NE(state_, kError); | 348 DCHECK_NE(state_, kError); |
351 DCHECK(!decode_cb_.is_null()); | 349 DCHECK(!decode_cb_.is_null()); |
352 DCHECK(buffer); | 350 DCHECK(buffer); |
353 | 351 |
354 // Transition to kDecodeFinished on the first end of stream buffer. | 352 // Transition to kDecodeFinished on the first end of stream buffer. |
355 if (state_ == kNormal && buffer->end_of_stream()) { | 353 if (state_ == kNormal && buffer->end_of_stream()) { |
356 state_ = kDecodeFinished; | 354 state_ = kDecodeFinished; |
357 output_cb_.Run(VideoFrame::CreateEOSFrame()); | 355 base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEOSFrame()); |
358 base::ResetAndReturn(&decode_cb_).Run(kOk); | |
359 return; | 356 return; |
360 } | 357 } |
361 | 358 |
362 scoped_refptr<VideoFrame> video_frame; | 359 scoped_refptr<VideoFrame> video_frame; |
363 if (!VpxDecode(buffer, &video_frame)) { | 360 if (!VpxDecode(buffer, &video_frame)) { |
364 state_ = kError; | 361 state_ = kError; |
365 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); | 362 base::ResetAndReturn(&decode_cb_).Run(kDecodeError, NULL); |
366 return; | 363 return; |
367 } | 364 } |
368 | 365 |
369 base::ResetAndReturn(&decode_cb_).Run(kOk); | 366 // If we didn't get a frame we need more data. |
| 367 if (!video_frame.get()) { |
| 368 base::ResetAndReturn(&decode_cb_).Run(kNotEnoughData, NULL); |
| 369 return; |
| 370 } |
370 | 371 |
371 if (video_frame) | 372 base::ResetAndReturn(&decode_cb_).Run(kOk, 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); | 507 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); |
508 return; | 508 return; |
509 } | 509 } |
510 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], | 510 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
511 vpx_image->stride[VPX_PLANE_Y], | 511 vpx_image->stride[VPX_PLANE_Y], |
512 vpx_image->d_h, | 512 vpx_image->d_h, |
513 video_frame->get()); | 513 video_frame->get()); |
514 } | 514 } |
515 | 515 |
516 } // namespace media | 516 } // namespace media |
OLD | NEW |