Chromium Code Reviews| 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/gpu_video_decoder.h" | 5 #include "media/filters/gpu_video_decoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} | 30 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} |
| 31 | 31 |
| 32 GpuVideoDecoder::BufferPair::BufferPair( | 32 GpuVideoDecoder::BufferPair::BufferPair( |
| 33 SHMBuffer* s, const scoped_refptr<DecoderBuffer>& b) | 33 SHMBuffer* s, const scoped_refptr<DecoderBuffer>& b) |
| 34 : shm_buffer(s), buffer(b) { | 34 : shm_buffer(s), buffer(b) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 GpuVideoDecoder::BufferPair::~BufferPair() {} | 37 GpuVideoDecoder::BufferPair::~BufferPair() {} |
| 38 | 38 |
| 39 GpuVideoDecoder::BufferData::BufferData( | |
| 40 int32 bbid, base::TimeDelta ts, const gfx::Size& natural_size) | |
| 41 : bitstream_buffer_id(bbid), timestamp(ts), natural_size(natural_size) { | |
|
Ami GONE FROM CHROMIUM
2012/08/02 00:16:14
natural_size is a self-assignment here.
acolwell GONE FROM CHROMIUM
2012/08/02 02:16:30
oops.. Done
| |
| 42 } | |
| 43 | |
| 44 GpuVideoDecoder::BufferData::~BufferData() {} | |
| 45 | |
| 39 GpuVideoDecoder::GpuVideoDecoder( | 46 GpuVideoDecoder::GpuVideoDecoder( |
| 40 MessageLoop* message_loop, | 47 MessageLoop* message_loop, |
| 41 MessageLoop* vda_loop, | 48 MessageLoop* vda_loop, |
| 42 const scoped_refptr<Factories>& factories) | 49 const scoped_refptr<Factories>& factories) |
| 43 : gvd_loop_proxy_(message_loop->message_loop_proxy()), | 50 : gvd_loop_proxy_(message_loop->message_loop_proxy()), |
| 44 vda_loop_proxy_(vda_loop->message_loop_proxy()), | 51 vda_loop_proxy_(vda_loop->message_loop_proxy()), |
| 45 factories_(factories), | 52 factories_(factories), |
| 46 state_(kNormal), | 53 state_(kNormal), |
| 47 demuxer_read_in_progress_(false), | 54 demuxer_read_in_progress_(false), |
| 48 decoder_texture_target_(0), | 55 decoder_texture_target_(0), |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 258 } |
| 252 | 259 |
| 253 size_t size = buffer->GetDataSize(); | 260 size_t size = buffer->GetDataSize(); |
| 254 SHMBuffer* shm_buffer = GetSHM(size); | 261 SHMBuffer* shm_buffer = GetSHM(size); |
| 255 memcpy(shm_buffer->shm->memory(), buffer->GetData(), size); | 262 memcpy(shm_buffer->shm->memory(), buffer->GetData(), size); |
| 256 BitstreamBuffer bitstream_buffer( | 263 BitstreamBuffer bitstream_buffer( |
| 257 next_bitstream_buffer_id_++, shm_buffer->shm->handle(), size); | 264 next_bitstream_buffer_id_++, shm_buffer->shm->handle(), size); |
| 258 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair( | 265 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair( |
| 259 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; | 266 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; |
| 260 DCHECK(inserted); | 267 DCHECK(inserted); |
| 261 RecordBufferTimeData(bitstream_buffer, *buffer); | 268 RecordBufferData(bitstream_buffer, *buffer); |
| 262 | 269 |
| 263 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 270 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 264 &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer)); | 271 &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer)); |
| 265 } | 272 } |
| 266 | 273 |
| 267 void GpuVideoDecoder::RecordBufferTimeData( | 274 void GpuVideoDecoder::RecordBufferData( |
| 268 const BitstreamBuffer& bitstream_buffer, const Buffer& buffer) { | 275 const BitstreamBuffer& bitstream_buffer, const Buffer& buffer) { |
| 269 input_buffer_time_data_.push_front(BufferTimeData( | 276 input_buffer_time_data_.push_front(BufferData( |
| 270 bitstream_buffer.id(), buffer.GetTimestamp())); | 277 bitstream_buffer.id(), buffer.GetTimestamp(), natural_size_)); |
| 271 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but | 278 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but |
| 272 // that's too small for some pathological B-frame test videos. The cost of | 279 // that's too small for some pathological B-frame test videos. The cost of |
| 273 // using too-high a value is low (192 bits per extra slot). | 280 // using too-high a value is low (192 bits per extra slot). |
| 274 static const size_t kMaxInputBufferTimeDataSize = 128; | 281 static const size_t kMaxInputBufferDataSize = 128; |
| 275 // Pop from the back of the list, because that's the oldest and least likely | 282 // Pop from the back of the list, because that's the oldest and least likely |
| 276 // to be useful in the future data. | 283 // to be useful in the future data. |
| 277 if (input_buffer_time_data_.size() > kMaxInputBufferTimeDataSize) | 284 if (input_buffer_time_data_.size() > kMaxInputBufferDataSize) |
| 278 input_buffer_time_data_.pop_back(); | 285 input_buffer_time_data_.pop_back(); |
| 279 } | 286 } |
| 280 | 287 |
| 281 base::TimeDelta GpuVideoDecoder::GetBufferTimestamp(int32 id) { | 288 void GpuVideoDecoder::GetBufferData(int32 id, base::TimeDelta* timestamp, |
| 282 for (std::list<BufferTimeData>::const_iterator it = | 289 gfx::Size* natural_size) { |
| 290 for (std::list<BufferData>::const_iterator it = | |
| 283 input_buffer_time_data_.begin(); it != input_buffer_time_data_.end(); | 291 input_buffer_time_data_.begin(); it != input_buffer_time_data_.end(); |
| 284 ++it) { | 292 ++it) { |
| 285 if (it->first == id) | 293 if (it->bitstream_buffer_id != id) |
| 286 return it->second; | 294 continue; |
| 295 *timestamp = it->timestamp; | |
| 296 *natural_size = it->natural_size; | |
| 297 return; | |
| 287 } | 298 } |
| 288 NOTREACHED() << "Missing bitstreambuffer id: " << id; | 299 NOTREACHED() << "Missing bitstreambuffer id: " << id; |
| 289 return kNoTimestamp(); | |
| 290 } | |
| 291 | |
| 292 const gfx::Size& GpuVideoDecoder::natural_size() { | |
| 293 return natural_size_; | |
| 294 } | 300 } |
| 295 | 301 |
| 296 bool GpuVideoDecoder::HasAlpha() const { | 302 bool GpuVideoDecoder::HasAlpha() const { |
| 297 return true; | 303 return true; |
| 298 } | 304 } |
| 299 | 305 |
| 300 void GpuVideoDecoder::PrepareForShutdownHack() { | 306 void GpuVideoDecoder::PrepareForShutdownHack() { |
| 301 if (!gvd_loop_proxy_->BelongsToCurrentThread()) { | 307 if (!gvd_loop_proxy_->BelongsToCurrentThread()) { |
| 302 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 308 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 303 &GpuVideoDecoder::PrepareForShutdownHack, this)); | 309 &GpuVideoDecoder::PrepareForShutdownHack, this)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 std::map<int32, PictureBuffer>::iterator it = | 375 std::map<int32, PictureBuffer>::iterator it = |
| 370 picture_buffers_in_decoder_.find(picture.picture_buffer_id()); | 376 picture_buffers_in_decoder_.find(picture.picture_buffer_id()); |
| 371 if (it == picture_buffers_in_decoder_.end()) { | 377 if (it == picture_buffers_in_decoder_.end()) { |
| 372 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id(); | 378 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id(); |
| 373 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 379 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 374 return; | 380 return; |
| 375 } | 381 } |
| 376 const PictureBuffer& pb = it->second; | 382 const PictureBuffer& pb = it->second; |
| 377 | 383 |
| 378 // Update frame's timestamp. | 384 // Update frame's timestamp. |
| 379 base::TimeDelta timestamp = GetBufferTimestamp(picture.bitstream_buffer_id()); | 385 base::TimeDelta timestamp; |
| 386 gfx::Size natural_size; | |
| 387 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &natural_size); | |
| 380 DCHECK(decoder_texture_target_); | 388 DCHECK(decoder_texture_target_); |
| 381 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( | 389 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( |
| 382 pb.texture_id(), decoder_texture_target_, pb.size().width(), | 390 pb.texture_id(), decoder_texture_target_, pb.size().width(), |
| 383 pb.size().height(), timestamp, | 391 pb.size().height(), natural_size, timestamp, |
| 384 base::Bind(&GpuVideoDecoder::ReusePictureBuffer, this, | 392 base::Bind(&GpuVideoDecoder::ReusePictureBuffer, this, |
| 385 picture.picture_buffer_id()))); | 393 picture.picture_buffer_id()))); |
| 386 | 394 |
| 387 EnqueueFrameAndTriggerFrameDelivery(frame); | 395 EnqueueFrameAndTriggerFrameDelivery(frame); |
| 388 } | 396 } |
| 389 | 397 |
| 390 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( | 398 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( |
| 391 const scoped_refptr<VideoFrame>& frame) { | 399 const scoped_refptr<VideoFrame>& frame) { |
| 392 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 400 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
| 393 | 401 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 | 555 |
| 548 error_occured_ = true; | 556 error_occured_ = true; |
| 549 | 557 |
| 550 if (!pending_read_cb_.is_null()) { | 558 if (!pending_read_cb_.is_null()) { |
| 551 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); | 559 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); |
| 552 return; | 560 return; |
| 553 } | 561 } |
| 554 } | 562 } |
| 555 | 563 |
| 556 } // namespace media | 564 } // namespace media |
| OLD | NEW |