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 <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 23 matching lines...) Expand all Loading... | |
| 34 // Size of shared-memory segments we allocate. Since we reuse them we let them | 34 // Size of shared-memory segments we allocate. Since we reuse them we let them |
| 35 // be on the beefy side. | 35 // be on the beefy side. |
| 36 static const size_t kSharedMemorySegmentBytes = 100 << 10; | 36 static const size_t kSharedMemorySegmentBytes = 100 << 10; |
| 37 | 37 |
| 38 GpuVideoDecoder::SHMBuffer::SHMBuffer(base::SharedMemory* m, size_t s) | 38 GpuVideoDecoder::SHMBuffer::SHMBuffer(base::SharedMemory* m, size_t s) |
| 39 : shm(m), size(s) { | 39 : shm(m), size(s) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} | 42 GpuVideoDecoder::SHMBuffer::~SHMBuffer() {} |
| 43 | 43 |
| 44 GpuVideoDecoder::BufferPair::BufferPair( | 44 GpuVideoDecoder::PendingDecodeBuffer::PendingDecodeBuffer( |
| 45 SHMBuffer* s, const scoped_refptr<DecoderBuffer>& b) | 45 SHMBuffer* s, |
| 46 : shm_buffer(s), buffer(b) { | 46 const scoped_refptr<DecoderBuffer>& b, |
| 47 const DecodeCB& done_cb) | |
| 48 : shm_buffer(s), buffer(b), done_cb(done_cb) { | |
| 47 } | 49 } |
| 48 | 50 |
| 49 GpuVideoDecoder::BufferPair::~BufferPair() {} | 51 GpuVideoDecoder::PendingDecodeBuffer::~PendingDecodeBuffer() {} |
| 50 | 52 |
| 51 GpuVideoDecoder::BufferData::BufferData( | 53 GpuVideoDecoder::BufferData::BufferData( |
| 52 int32 bbid, base::TimeDelta ts, const gfx::Rect& vr, const gfx::Size& ns) | 54 int32 bbid, base::TimeDelta ts, const gfx::Rect& vr, const gfx::Size& ns) |
| 53 : bitstream_buffer_id(bbid), timestamp(ts), visible_rect(vr), | 55 : bitstream_buffer_id(bbid), timestamp(ts), visible_rect(vr), |
| 54 natural_size(ns) { | 56 natural_size(ns) { |
| 55 } | 57 } |
| 56 | 58 |
| 57 GpuVideoDecoder::BufferData::~BufferData() {} | 59 GpuVideoDecoder::BufferData::~BufferData() {} |
| 58 | 60 |
| 59 GpuVideoDecoder::GpuVideoDecoder( | 61 GpuVideoDecoder::GpuVideoDecoder( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 73 | 75 |
| 74 void GpuVideoDecoder::Reset(const base::Closure& closure) { | 76 void GpuVideoDecoder::Reset(const base::Closure& closure) { |
| 75 DVLOG(3) << "Reset()"; | 77 DVLOG(3) << "Reset()"; |
| 76 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 78 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 77 | 79 |
| 78 if (state_ == kDrainingDecoder) { | 80 if (state_ == kDrainingDecoder) { |
| 79 base::MessageLoop::current()->PostTask( | 81 base::MessageLoop::current()->PostTask( |
| 80 FROM_HERE, | 82 FROM_HERE, |
| 81 base::Bind( | 83 base::Bind( |
| 82 &GpuVideoDecoder::Reset, weak_factory_.GetWeakPtr(), closure)); | 84 &GpuVideoDecoder::Reset, weak_factory_.GetWeakPtr(), closure)); |
| 83 // NOTE: if we're deferring Reset() until a Flush() completes, return | |
| 84 // queued pictures to the VDA so they can be used to finish that Flush(). | |
| 85 if (pending_decode_cb_.is_null()) | |
| 86 ready_video_frames_.clear(); | |
| 87 return; | 85 return; |
| 88 } | 86 } |
| 89 | 87 |
| 90 // Throw away any already-decoded, not-yet-delivered frames. | |
| 91 ready_video_frames_.clear(); | |
| 92 | |
| 93 if (!vda_) { | 88 if (!vda_) { |
| 94 base::MessageLoop::current()->PostTask(FROM_HERE, closure); | 89 base::MessageLoop::current()->PostTask(FROM_HERE, closure); |
| 95 return; | 90 return; |
| 96 } | 91 } |
| 97 | 92 |
| 98 if (!pending_decode_cb_.is_null()) | |
| 99 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame()); | |
| 100 | |
| 101 DCHECK(pending_reset_cb_.is_null()); | 93 DCHECK(pending_reset_cb_.is_null()); |
| 102 pending_reset_cb_ = BindToCurrentLoop(closure); | 94 pending_reset_cb_ = BindToCurrentLoop(closure); |
| 103 | 95 |
| 104 vda_->Reset(); | 96 vda_->Reset(); |
| 105 } | 97 } |
| 106 | 98 |
| 107 void GpuVideoDecoder::Stop() { | 99 void GpuVideoDecoder::Stop() { |
| 108 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 100 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 109 if (vda_) | 101 if (vda_) |
| 110 DestroyVDA(); | 102 DestroyVDA(); |
| 111 if (!pending_decode_cb_.is_null()) | 103 DCHECK(bitstream_buffers_in_decoder_.empty()); |
| 112 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame()); | |
| 113 if (!pending_reset_cb_.is_null()) | 104 if (!pending_reset_cb_.is_null()) |
| 114 base::ResetAndReturn(&pending_reset_cb_).Run(); | 105 base::ResetAndReturn(&pending_reset_cb_).Run(); |
| 115 } | 106 } |
| 116 | 107 |
| 117 static bool IsCodedSizeSupported(const gfx::Size& coded_size) { | 108 static bool IsCodedSizeSupported(const gfx::Size& coded_size) { |
| 118 // Only non-Windows, Ivy Bridge+ platforms can support more than 1920x1080. | 109 // Only non-Windows, Ivy Bridge+ platforms can support more than 1920x1080. |
| 119 // We test against 1088 to account for 16x16 macroblocks. | 110 // We test against 1088 to account for 16x16 macroblocks. |
| 120 if (coded_size.width() <= 1920 && coded_size.height() <= 1088) | 111 if (coded_size.width() <= 1920 && coded_size.height() <= 1088) |
| 121 return true; | 112 return true; |
| 122 | 113 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 136 static void ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB( | 127 static void ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB( |
| 137 const PipelineStatusCB& cb, | 128 const PipelineStatusCB& cb, |
| 138 PipelineStatus status) { | 129 PipelineStatus status) { |
| 139 UMA_HISTOGRAM_ENUMERATION( | 130 UMA_HISTOGRAM_ENUMERATION( |
| 140 "Media.GpuVideoDecoderInitializeStatus", status, PIPELINE_STATUS_MAX + 1); | 131 "Media.GpuVideoDecoderInitializeStatus", status, PIPELINE_STATUS_MAX + 1); |
| 141 cb.Run(status); | 132 cb.Run(status); |
| 142 } | 133 } |
| 143 | 134 |
| 144 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, | 135 void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, |
| 145 bool live_mode, | 136 bool live_mode, |
| 146 const PipelineStatusCB& orig_status_cb) { | 137 const PipelineStatusCB& orig_status_cb, |
| 138 const OutputCB& output_cb) { | |
| 147 DVLOG(3) << "Initialize()"; | 139 DVLOG(3) << "Initialize()"; |
| 148 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 140 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 149 DCHECK(config.IsValidConfig()); | 141 DCHECK(config.IsValidConfig()); |
| 150 DCHECK(!config.is_encrypted()); | 142 DCHECK(!config.is_encrypted()); |
| 151 | 143 |
| 152 PipelineStatusCB status_cb = | 144 PipelineStatusCB status_cb = |
| 153 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, | 145 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, |
| 154 BindToCurrentLoop(orig_status_cb)); | 146 BindToCurrentLoop(orig_status_cb)); |
| 155 | 147 |
| 156 bool previously_initialized = config_.IsValidConfig(); | 148 bool previously_initialized = config_.IsValidConfig(); |
| 157 DVLOG(1) << "(Re)initializing GVD with config: " | 149 DVLOG(1) << "(Re)initializing GVD with config: " |
| 158 << config.AsHumanReadableString(); | 150 << config.AsHumanReadableString(); |
| 159 | 151 |
| 160 // TODO(posciak): destroy and create a new VDA on codec/profile change | 152 // TODO(posciak): destroy and create a new VDA on codec/profile change |
| 161 // (http://crbug.com/260224). | 153 // (http://crbug.com/260224). |
| 162 if (previously_initialized && (config_.profile() != config.profile())) { | 154 if (previously_initialized && (config_.profile() != config.profile())) { |
| 163 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; | 155 DVLOG(1) << "Codec or profile changed, cannot reinitialize."; |
| 164 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 156 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
| 165 return; | 157 return; |
| 166 } | 158 } |
| 167 | 159 |
| 168 if (!IsCodedSizeSupported(config.coded_size())) { | 160 if (!IsCodedSizeSupported(config.coded_size())) { |
| 169 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 161 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
| 170 return; | 162 return; |
| 171 } | 163 } |
| 172 | 164 |
| 173 config_ = config; | 165 config_ = config; |
| 174 needs_bitstream_conversion_ = (config.codec() == kCodecH264); | 166 needs_bitstream_conversion_ = (config.codec() == kCodecH264); |
| 167 output_cb_ = output_cb; | |
| 175 | 168 |
| 176 if (previously_initialized) { | 169 if (previously_initialized) { |
| 177 // Reinitialization with a different config (but same codec and profile). | 170 // Reinitialization with a different config (but same codec and profile). |
| 178 // VDA should handle it by detecting this in-stream by itself, | 171 // VDA should handle it by detecting this in-stream by itself, |
| 179 // no need to notify it. | 172 // no need to notify it. |
| 180 status_cb.Run(PIPELINE_OK); | 173 status_cb.Run(PIPELINE_OK); |
| 181 return; | 174 return; |
| 182 } | 175 } |
| 183 | 176 |
| 184 vda_ = factories_->CreateVideoDecodeAccelerator().Pass(); | 177 vda_ = factories_->CreateVideoDecodeAccelerator().Pass(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 ++it) { | 209 ++it) { |
| 217 assigned_picture_buffers_.erase(it->first); | 210 assigned_picture_buffers_.erase(it->first); |
| 218 } | 211 } |
| 219 DestroyPictureBuffers(&assigned_picture_buffers_); | 212 DestroyPictureBuffers(&assigned_picture_buffers_); |
| 220 } | 213 } |
| 221 | 214 |
| 222 void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 215 void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 223 const DecodeCB& decode_cb) { | 216 const DecodeCB& decode_cb) { |
| 224 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 217 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 225 DCHECK(pending_reset_cb_.is_null()); | 218 DCHECK(pending_reset_cb_.is_null()); |
| 226 DCHECK(pending_decode_cb_.is_null()); | |
| 227 | |
| 228 pending_decode_cb_ = BindToCurrentLoop(decode_cb); | |
| 229 | 219 |
| 230 if (state_ == kError || !vda_) { | 220 if (state_ == kError || !vda_) { |
| 231 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL); | 221 decode_cb.Run(kDecodeError); |
|
xhwang
2014/05/29 22:15:14
VideoDecoder API says that |decode_cb| should not
Sergey Ulanov
2014/06/03 00:08:11
Thanks for catching it. Added BindToCurrentLoop().
| |
| 232 return; | 222 return; |
| 233 } | 223 } |
| 234 | 224 |
| 235 switch (state_) { | 225 switch (state_) { |
| 236 case kDecoderDrained: | 226 case kDecoderDrained: |
| 237 if (!ready_video_frames_.empty()) { | |
| 238 EnqueueFrameAndTriggerFrameDelivery(NULL); | |
| 239 return; | |
| 240 } | |
| 241 state_ = kNormal; | 227 state_ = kNormal; |
| 242 // Fall-through. | 228 // Fall-through. |
| 243 case kNormal: | 229 case kNormal: |
| 244 break; | 230 break; |
| 245 case kDrainingDecoder: | 231 case kDrainingDecoder: |
| 246 DCHECK(buffer->end_of_stream()); | |
| 247 // Do nothing. Will be satisfied either by a PictureReady or | |
| 248 // NotifyFlushDone below. | |
| 249 return; | |
| 250 case kError: | 232 case kError: |
| 251 NOTREACHED(); | 233 NOTREACHED(); |
| 252 return; | 234 return; |
| 253 } | 235 } |
| 254 | 236 |
| 237 DCHECK_EQ(state_, kNormal); | |
| 238 | |
| 255 if (buffer->end_of_stream()) { | 239 if (buffer->end_of_stream()) { |
| 256 if (state_ == kNormal) { | 240 state_ = kDrainingDecoder; |
| 257 state_ = kDrainingDecoder; | 241 flush_cb_ = decode_cb; |
|
xhwang
2014/05/29 22:15:14
hmm, now I see why it's called |flush_cb_|.... Thi
Sergey Ulanov
2014/06/03 00:08:11
See my previous comments about flushing. When flus
| |
| 258 vda_->Flush(); | 242 vda_->Flush(); |
| 259 // If we have ready frames, go ahead and process them to ensure that the | |
| 260 // Flush operation does not block in the VDA due to lack of picture | |
| 261 // buffers. | |
| 262 if (!ready_video_frames_.empty()) | |
| 263 EnqueueFrameAndTriggerFrameDelivery(NULL); | |
| 264 } | |
| 265 return; | 243 return; |
| 266 } | 244 } |
| 267 | 245 |
| 268 size_t size = buffer->data_size(); | 246 size_t size = buffer->data_size(); |
| 269 SHMBuffer* shm_buffer = GetSHM(size); | 247 SHMBuffer* shm_buffer = GetSHM(size); |
| 270 if (!shm_buffer) { | 248 if (!shm_buffer) { |
| 271 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL); | 249 decode_cb.Run(kDecodeError); |
|
xhwang
2014/05/29 22:15:14
ditto
Sergey Ulanov
2014/06/03 00:08:11
Done.
| |
| 272 return; | 250 return; |
| 273 } | 251 } |
| 274 | 252 |
| 275 memcpy(shm_buffer->shm->memory(), buffer->data(), size); | 253 memcpy(shm_buffer->shm->memory(), buffer->data(), size); |
| 276 BitstreamBuffer bitstream_buffer( | 254 BitstreamBuffer bitstream_buffer( |
| 277 next_bitstream_buffer_id_, shm_buffer->shm->handle(), size); | 255 next_bitstream_buffer_id_, shm_buffer->shm->handle(), size); |
| 278 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. | 256 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. |
| 279 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; | 257 next_bitstream_buffer_id_ = (next_bitstream_buffer_id_ + 1) & 0x3FFFFFFF; |
| 280 bool inserted = bitstream_buffers_in_decoder_.insert(std::make_pair( | 258 bool inserted = bitstream_buffers_in_decoder_ |
| 281 bitstream_buffer.id(), BufferPair(shm_buffer, buffer))).second; | 259 .insert(std::make_pair( |
| 260 bitstream_buffer.id(), | |
| 261 PendingDecodeBuffer(shm_buffer, buffer, decode_cb))) | |
| 262 .second; | |
|
xhwang
2014/05/29 22:15:14
hmm... this can be improved :) We can do it later
Sergey Ulanov
2014/06/03 00:08:11
reformatted this code to make it more readable.
| |
| 282 DCHECK(inserted); | 263 DCHECK(inserted); |
| 264 DCHECK_LE(static_cast<int>(bitstream_buffers_in_decoder_.size()), | |
| 265 kMaxInFlightDecodes); | |
| 283 RecordBufferData(bitstream_buffer, *buffer.get()); | 266 RecordBufferData(bitstream_buffer, *buffer.get()); |
| 284 | 267 |
| 285 vda_->Decode(bitstream_buffer); | 268 vda_->Decode(bitstream_buffer); |
| 286 | |
| 287 if (!ready_video_frames_.empty()) { | |
| 288 EnqueueFrameAndTriggerFrameDelivery(NULL); | |
| 289 return; | |
| 290 } | |
| 291 | |
| 292 if (CanMoreDecodeWorkBeDone()) | |
| 293 base::ResetAndReturn(&pending_decode_cb_).Run(kNotEnoughData, NULL); | |
| 294 } | |
| 295 | |
| 296 bool GpuVideoDecoder::CanMoreDecodeWorkBeDone() { | |
| 297 return bitstream_buffers_in_decoder_.size() < kMaxInFlightDecodes; | |
| 298 } | 269 } |
| 299 | 270 |
| 300 void GpuVideoDecoder::RecordBufferData(const BitstreamBuffer& bitstream_buffer, | 271 void GpuVideoDecoder::RecordBufferData(const BitstreamBuffer& bitstream_buffer, |
| 301 const DecoderBuffer& buffer) { | 272 const DecoderBuffer& buffer) { |
| 302 input_buffer_data_.push_front(BufferData(bitstream_buffer.id(), | 273 input_buffer_data_.push_front(BufferData(bitstream_buffer.id(), |
| 303 buffer.timestamp(), | 274 buffer.timestamp(), |
| 304 config_.visible_rect(), | 275 config_.visible_rect(), |
| 305 config_.natural_size())); | 276 config_.natural_size())); |
| 306 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but | 277 // Why this value? Because why not. avformat.h:MAX_REORDER_DELAY is 16, but |
| 307 // that's too small for some pathological B-frame test videos. The cost of | 278 // that's too small for some pathological B-frame test videos. The cost of |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 331 | 302 |
| 332 bool GpuVideoDecoder::NeedsBitstreamConversion() const { | 303 bool GpuVideoDecoder::NeedsBitstreamConversion() const { |
| 333 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 304 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 334 return needs_bitstream_conversion_; | 305 return needs_bitstream_conversion_; |
| 335 } | 306 } |
| 336 | 307 |
| 337 bool GpuVideoDecoder::CanReadWithoutStalling() const { | 308 bool GpuVideoDecoder::CanReadWithoutStalling() const { |
| 338 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 309 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 339 return | 310 return |
| 340 next_picture_buffer_id_ == 0 || // Decode() will ProvidePictureBuffers(). | 311 next_picture_buffer_id_ == 0 || // Decode() will ProvidePictureBuffers(). |
| 341 available_pictures_ > 0 || !ready_video_frames_.empty(); | 312 available_pictures_ > 0; |
| 313 } | |
| 314 | |
| 315 int GpuVideoDecoder::GetMaxDecodeRequests() const { | |
| 316 return kMaxInFlightDecodes; | |
| 342 } | 317 } |
| 343 | 318 |
| 344 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, | 319 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, |
| 345 const gfx::Size& size, | 320 const gfx::Size& size, |
| 346 uint32 texture_target) { | 321 uint32 texture_target) { |
| 347 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " | 322 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " |
| 348 << size.width() << "x" << size.height() << ")"; | 323 << size.width() << "x" << size.height() << ")"; |
| 349 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 324 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 350 | 325 |
| 351 std::vector<uint32> texture_ids; | 326 std::vector<uint32> texture_ids; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 timestamp, | 439 timestamp, |
| 465 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect))); | 440 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect))); |
| 466 CHECK_GT(available_pictures_, 0); | 441 CHECK_GT(available_pictures_, 0); |
| 467 --available_pictures_; | 442 --available_pictures_; |
| 468 bool inserted = | 443 bool inserted = |
| 469 picture_buffers_at_display_.insert(std::make_pair( | 444 picture_buffers_at_display_.insert(std::make_pair( |
| 470 picture.picture_buffer_id(), | 445 picture.picture_buffer_id(), |
| 471 pb.texture_id())).second; | 446 pb.texture_id())).second; |
| 472 DCHECK(inserted); | 447 DCHECK(inserted); |
| 473 | 448 |
| 474 EnqueueFrameAndTriggerFrameDelivery(frame); | 449 DeliverFrame(frame); |
| 475 } | 450 } |
| 476 | 451 |
| 477 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( | 452 void GpuVideoDecoder::DeliverFrame( |
| 478 const scoped_refptr<VideoFrame>& frame) { | 453 const scoped_refptr<VideoFrame>& frame) { |
| 479 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 454 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 480 | 455 |
| 481 // During a pending vda->Reset(), we don't accumulate frames. Drop it on the | 456 // During a pending vda->Reset(), we don't accumulate frames. Drop it on the |
| 482 // floor and return. | 457 // floor and return. |
| 483 if (!pending_reset_cb_.is_null()) | 458 if (!pending_reset_cb_.is_null()) |
| 484 return; | 459 return; |
| 485 | 460 |
| 486 if (frame.get()) | 461 output_cb_.Run(frame); |
| 487 ready_video_frames_.push_back(frame); | |
| 488 else | |
| 489 DCHECK(!ready_video_frames_.empty()); | |
| 490 | |
| 491 if (pending_decode_cb_.is_null()) | |
| 492 return; | |
| 493 | |
| 494 base::ResetAndReturn(&pending_decode_cb_) | |
| 495 .Run(kOk, ready_video_frames_.front()); | |
| 496 ready_video_frames_.pop_front(); | |
| 497 } | 462 } |
| 498 | 463 |
| 499 // static | 464 // static |
| 500 void GpuVideoDecoder::ReleaseMailbox( | 465 void GpuVideoDecoder::ReleaseMailbox( |
| 501 base::WeakPtr<GpuVideoDecoder> decoder, | 466 base::WeakPtr<GpuVideoDecoder> decoder, |
| 502 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | 467 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, |
| 503 int64 picture_buffer_id, | 468 int64 picture_buffer_id, |
| 504 uint32 texture_id, | 469 uint32 texture_id, |
| 505 const std::vector<uint32>& release_sync_points) { | 470 const std::vector<uint32>& release_sync_points) { |
| 506 DCHECK(factories->GetTaskRunner()->BelongsToCurrentThread()); | 471 DCHECK(factories->GetTaskRunner()->BelongsToCurrentThread()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 | 524 |
| 560 void GpuVideoDecoder::PutSHM(SHMBuffer* shm_buffer) { | 525 void GpuVideoDecoder::PutSHM(SHMBuffer* shm_buffer) { |
| 561 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 526 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 562 available_shm_segments_.push_back(shm_buffer); | 527 available_shm_segments_.push_back(shm_buffer); |
| 563 } | 528 } |
| 564 | 529 |
| 565 void GpuVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { | 530 void GpuVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { |
| 566 DVLOG(3) << "NotifyEndOfBitstreamBuffer(" << id << ")"; | 531 DVLOG(3) << "NotifyEndOfBitstreamBuffer(" << id << ")"; |
| 567 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 532 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 568 | 533 |
| 569 std::map<int32, BufferPair>::iterator it = | 534 std::map<int32, PendingDecodeBuffer>::iterator it = |
| 570 bitstream_buffers_in_decoder_.find(id); | 535 bitstream_buffers_in_decoder_.find(id); |
| 571 if (it == bitstream_buffers_in_decoder_.end()) { | 536 if (it == bitstream_buffers_in_decoder_.end()) { |
| 572 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 537 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 573 NOTREACHED() << "Missing bitstream buffer: " << id; | 538 NOTREACHED() << "Missing bitstream buffer: " << id; |
| 574 return; | 539 return; |
| 575 } | 540 } |
| 576 | 541 |
| 577 PutSHM(it->second.shm_buffer); | 542 PutSHM(it->second.shm_buffer); |
| 543 it->second.done_cb.Run(state_ == kError ? kDecodeError : kOk); | |
| 578 bitstream_buffers_in_decoder_.erase(it); | 544 bitstream_buffers_in_decoder_.erase(it); |
| 579 | |
| 580 if (pending_reset_cb_.is_null() && state_ != kDrainingDecoder && | |
| 581 CanMoreDecodeWorkBeDone() && !pending_decode_cb_.is_null()) { | |
| 582 base::ResetAndReturn(&pending_decode_cb_).Run(kNotEnoughData, NULL); | |
| 583 } | |
| 584 } | 545 } |
| 585 | 546 |
| 586 GpuVideoDecoder::~GpuVideoDecoder() { | 547 GpuVideoDecoder::~GpuVideoDecoder() { |
| 587 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 548 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 588 // Stop should have been already called. | 549 // Stop should have been already called. |
| 589 DCHECK(!vda_.get() && assigned_picture_buffers_.empty()); | 550 DCHECK(!vda_.get() && assigned_picture_buffers_.empty()); |
| 590 DCHECK(pending_decode_cb_.is_null()); | 551 DCHECK(bitstream_buffers_in_decoder_.empty()); |
| 591 for (size_t i = 0; i < available_shm_segments_.size(); ++i) { | 552 for (size_t i = 0; i < available_shm_segments_.size(); ++i) { |
| 592 available_shm_segments_[i]->shm->Close(); | 553 available_shm_segments_[i]->shm->Close(); |
| 593 delete available_shm_segments_[i]; | 554 delete available_shm_segments_[i]; |
| 594 } | 555 } |
| 595 available_shm_segments_.clear(); | 556 available_shm_segments_.clear(); |
| 596 for (std::map<int32, BufferPair>::iterator it = | 557 for (std::map<int32, PendingDecodeBuffer>::iterator it = |
| 597 bitstream_buffers_in_decoder_.begin(); | 558 bitstream_buffers_in_decoder_.begin(); |
| 598 it != bitstream_buffers_in_decoder_.end(); ++it) { | 559 it != bitstream_buffers_in_decoder_.end(); ++it) { |
| 599 it->second.shm_buffer->shm->Close(); | 560 it->second.shm_buffer->shm->Close(); |
| 600 } | 561 } |
| 601 bitstream_buffers_in_decoder_.clear(); | 562 bitstream_buffers_in_decoder_.clear(); |
| 602 } | 563 } |
| 603 | 564 |
| 604 void GpuVideoDecoder::NotifyFlushDone() { | 565 void GpuVideoDecoder::NotifyFlushDone() { |
| 605 DVLOG(3) << "NotifyFlushDone()"; | 566 DVLOG(3) << "NotifyFlushDone()"; |
| 606 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 567 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 607 DCHECK_EQ(state_, kDrainingDecoder); | 568 DCHECK_EQ(state_, kDrainingDecoder); |
| 608 state_ = kDecoderDrained; | 569 state_ = kDecoderDrained; |
| 609 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame()); | 570 DeliverFrame(VideoFrame::CreateEOSFrame()); |
| 571 base::ResetAndReturn(&flush_cb_).Run(kOk); | |
| 610 } | 572 } |
| 611 | 573 |
| 612 void GpuVideoDecoder::NotifyResetDone() { | 574 void GpuVideoDecoder::NotifyResetDone() { |
| 613 DVLOG(3) << "NotifyResetDone()"; | 575 DVLOG(3) << "NotifyResetDone()"; |
| 614 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 576 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 615 DCHECK(ready_video_frames_.empty()); | 577 DCHECK(bitstream_buffers_in_decoder_.empty()); |
| 616 | 578 |
| 617 // This needs to happen after the Reset() on vda_ is done to ensure pictures | 579 // This needs to happen after the Reset() on vda_ is done to ensure pictures |
| 618 // delivered during the reset can find their time data. | 580 // delivered during the reset can find their time data. |
| 619 input_buffer_data_.clear(); | 581 input_buffer_data_.clear(); |
| 620 | 582 |
| 621 if (!pending_reset_cb_.is_null()) | 583 if (!pending_reset_cb_.is_null()) |
| 622 base::ResetAndReturn(&pending_reset_cb_).Run(); | 584 base::ResetAndReturn(&pending_reset_cb_).Run(); |
| 623 | |
| 624 if (!pending_decode_cb_.is_null()) | |
| 625 EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEOSFrame()); | |
| 626 } | 585 } |
| 627 | 586 |
| 628 void GpuVideoDecoder::NotifyError(media::VideoDecodeAccelerator::Error error) { | 587 void GpuVideoDecoder::NotifyError(media::VideoDecodeAccelerator::Error error) { |
| 629 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 588 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 630 if (!vda_) | 589 if (!vda_) |
| 631 return; | 590 return; |
| 632 | 591 |
| 592 state_ = kError; | |
| 593 | |
| 633 DLOG(ERROR) << "VDA Error: " << error; | 594 DLOG(ERROR) << "VDA Error: " << error; |
| 634 DestroyVDA(); | 595 DestroyVDA(); |
| 635 | |
| 636 state_ = kError; | |
| 637 | |
| 638 if (!pending_decode_cb_.is_null()) { | |
| 639 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL); | |
| 640 return; | |
| 641 } | |
| 642 } | 596 } |
| 643 | 597 |
| 644 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 598 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 645 const { | 599 const { |
| 646 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 600 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 647 } | 601 } |
| 648 | 602 |
| 649 } // namespace media | 603 } // namespace media |
| OLD | NEW |