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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 GpuVideoDecoder::PendingDecoderBuffer::PendingDecoderBuffer( | 46 GpuVideoDecoder::PendingDecoderBuffer::PendingDecoderBuffer( |
47 SHMBuffer* s, | 47 SHMBuffer* s, |
48 const scoped_refptr<DecoderBuffer>& b, | 48 const scoped_refptr<DecoderBuffer>& b, |
49 const DecodeCB& done_cb) | 49 const DecodeCB& done_cb) |
50 : shm_buffer(s), buffer(b), done_cb(done_cb) { | 50 : shm_buffer(s), buffer(b), done_cb(done_cb) { |
51 } | 51 } |
52 | 52 |
53 GpuVideoDecoder::PendingDecoderBuffer::~PendingDecoderBuffer() {} | 53 GpuVideoDecoder::PendingDecoderBuffer::~PendingDecoderBuffer() {} |
54 | 54 |
55 GpuVideoDecoder::BufferData::BufferData( | 55 GpuVideoDecoder::BufferData::BufferData( |
56 int32 bbid, base::TimeDelta ts, const gfx::Rect& vr, const gfx::Size& ns) | 56 int32 bbid, base::TimeDelta ts) |
57 : bitstream_buffer_id(bbid), timestamp(ts), visible_rect(vr), | 57 : bitstream_buffer_id(bbid), timestamp(ts) { |
58 natural_size(ns) { | |
59 } | 58 } |
60 | 59 |
61 GpuVideoDecoder::BufferData::~BufferData() {} | 60 GpuVideoDecoder::BufferData::~BufferData() {} |
62 | 61 |
63 GpuVideoDecoder::GpuVideoDecoder( | 62 GpuVideoDecoder::GpuVideoDecoder( |
64 const scoped_refptr<GpuVideoAcceleratorFactories>& factories, | 63 const scoped_refptr<GpuVideoAcceleratorFactories>& factories, |
65 const scoped_refptr<MediaLog>& media_log) | 64 const scoped_refptr<MediaLog>& media_log) |
66 : needs_bitstream_conversion_(false), | 65 : needs_bitstream_conversion_(false), |
67 factories_(factories), | 66 factories_(factories), |
68 state_(kNormal), | 67 state_(kNormal), |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 DCHECK_LE(static_cast<int>(bitstream_buffers_in_decoder_.size()), | 268 DCHECK_LE(static_cast<int>(bitstream_buffers_in_decoder_.size()), |
270 kMaxInFlightDecodes); | 269 kMaxInFlightDecodes); |
271 RecordBufferData(bitstream_buffer, *buffer.get()); | 270 RecordBufferData(bitstream_buffer, *buffer.get()); |
272 | 271 |
273 vda_->Decode(bitstream_buffer); | 272 vda_->Decode(bitstream_buffer); |
274 } | 273 } |
275 | 274 |
276 void GpuVideoDecoder::RecordBufferData(const BitstreamBuffer& bitstream_buffer, | 275 void GpuVideoDecoder::RecordBufferData(const BitstreamBuffer& bitstream_buffer, |
277 const DecoderBuffer& buffer) { | 276 const DecoderBuffer& buffer) { |
278 input_buffer_data_.push_front(BufferData(bitstream_buffer.id(), | 277 input_buffer_data_.push_front(BufferData(bitstream_buffer.id(), |
279 buffer.timestamp(), | 278 buffer.timestamp())); |
280 config_.visible_rect(), | |
281 config_.natural_size())); | |
282 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but | 279 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but |
283 // that's too small for some pathological B-frame test videos. The cost of | 280 // that's too small for some pathological B-frame test videos. The cost of |
284 // using too-high a value is low (192 bits per extra slot). | 281 // using too-high a value is low (192 bits per extra slot). |
285 static const size_t kMaxInputBufferDataSize = 128; | 282 static const size_t kMaxInputBufferDataSize = 128; |
286 // Pop from the back of the list, because that's the oldest and least likely | 283 // Pop from the back of the list, because that's the oldest and least likely |
287 // to be useful in the future data. | 284 // to be useful in the future data. |
288 if (input_buffer_data_.size() > kMaxInputBufferDataSize) | 285 if (input_buffer_data_.size() > kMaxInputBufferDataSize) |
289 input_buffer_data_.pop_back(); | 286 input_buffer_data_.pop_back(); |
290 } | 287 } |
291 | 288 |
292 void GpuVideoDecoder::GetBufferData(int32 id, base::TimeDelta* timestamp, | 289 void GpuVideoDecoder::GetBufferData(int32 id, base::TimeDelta* timestamp) { |
293 gfx::Rect* visible_rect, | |
294 gfx::Size* natural_size) { | |
295 for (std::list<BufferData>::const_iterator it = | 290 for (std::list<BufferData>::const_iterator it = |
296 input_buffer_data_.begin(); it != input_buffer_data_.end(); | 291 input_buffer_data_.begin(); it != input_buffer_data_.end(); |
297 ++it) { | 292 ++it) { |
298 if (it->bitstream_buffer_id != id) | 293 if (it->bitstream_buffer_id != id) |
299 continue; | 294 continue; |
300 *timestamp = it->timestamp; | 295 *timestamp = it->timestamp; |
301 *visible_rect = it->visible_rect; | |
302 *natural_size = it->natural_size; | |
303 return; | 296 return; |
304 } | 297 } |
305 NOTREACHED() << "Missing bitstreambuffer id: " << id; | 298 NOTREACHED() << "Missing bitstreambuffer id: " << id; |
306 } | 299 } |
307 | 300 |
308 bool GpuVideoDecoder::NeedsBitstreamConversion() const { | 301 bool GpuVideoDecoder::NeedsBitstreamConversion() const { |
309 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 302 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
310 return needs_bitstream_conversion_; | 303 return needs_bitstream_conversion_; |
311 } | 304 } |
312 | 305 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 assigned_picture_buffers_.find(picture.picture_buffer_id()); | 410 assigned_picture_buffers_.find(picture.picture_buffer_id()); |
418 if (it == assigned_picture_buffers_.end()) { | 411 if (it == assigned_picture_buffers_.end()) { |
419 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id(); | 412 NOTREACHED() << "Missing picture buffer: " << picture.picture_buffer_id(); |
420 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 413 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
421 return; | 414 return; |
422 } | 415 } |
423 const PictureBuffer& pb = it->second; | 416 const PictureBuffer& pb = it->second; |
424 | 417 |
425 // Update frame's timestamp. | 418 // Update frame's timestamp. |
426 base::TimeDelta timestamp; | 419 base::TimeDelta timestamp; |
427 gfx::Rect visible_rect; | 420 gfx::Rect visible_rect(picture.size()); |
Pawel Osciak
2014/08/10 00:02:22
Please do not make any changes to this class. Unfo
kcwu
2014/08/12 04:48:06
Done.
| |
428 gfx::Size natural_size; | 421 gfx::Size natural_size(picture.size()); |
429 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, | 422 GetBufferData(picture.bitstream_buffer_id(), ×tamp); |
430 &natural_size); | |
431 DCHECK(decoder_texture_target_); | 423 DCHECK(decoder_texture_target_); |
432 | 424 |
433 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( | 425 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( |
434 make_scoped_ptr(new gpu::MailboxHolder( | 426 make_scoped_ptr(new gpu::MailboxHolder( |
435 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), | 427 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), |
436 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReleaseMailbox, | 428 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReleaseMailbox, |
437 weak_factory_.GetWeakPtr(), | 429 weak_factory_.GetWeakPtr(), |
438 factories_, | 430 factories_, |
439 picture.picture_buffer_id(), | 431 picture.picture_buffer_id(), |
440 pb.texture_id())), | 432 pb.texture_id())), |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 DLOG(ERROR) << "VDA Error: " << error; | 594 DLOG(ERROR) << "VDA Error: " << error; |
603 DestroyVDA(); | 595 DestroyVDA(); |
604 } | 596 } |
605 | 597 |
606 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 598 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
607 const { | 599 const { |
608 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 600 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
609 } | 601 } |
610 | 602 |
611 } // namespace media | 603 } // namespace media |
OLD | NEW |