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 "content/common/gpu/media/dxva_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" |
6 | 6 |
7 #if !defined(OS_WIN) | 7 #if !defined(OS_WIN) |
8 #error This file should only be built on Windows. | 8 #error This file should only be built on Windows. |
9 #endif // !defined(OS_WIN) | 9 #endif // !defined(OS_WIN) |
10 | 10 |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 FlushInternal(); | 551 FlushInternal(); |
552 } | 552 } |
553 | 553 |
554 void DXVAVideoDecodeAccelerator::ReusePictureBuffer( | 554 void DXVAVideoDecodeAccelerator::ReusePictureBuffer( |
555 int32 picture_buffer_id) { | 555 int32 picture_buffer_id) { |
556 DCHECK(CalledOnValidThread()); | 556 DCHECK(CalledOnValidThread()); |
557 | 557 |
558 RETURN_AND_NOTIFY_ON_FAILURE((state_ != kUninitialized), | 558 RETURN_AND_NOTIFY_ON_FAILURE((state_ != kUninitialized), |
559 "Invalid state: " << state_, ILLEGAL_STATE,); | 559 "Invalid state: " << state_, ILLEGAL_STATE,); |
560 | 560 |
561 if (output_picture_buffers_.empty()) | 561 if (output_picture_buffers_.empty() && stale_output_picture_buffers_.empty()) |
562 return; | 562 return; |
563 | 563 |
564 OutputBuffers::iterator it = output_picture_buffers_.find(picture_buffer_id); | 564 OutputBuffers::iterator it = output_picture_buffers_.find(picture_buffer_id); |
565 RETURN_AND_NOTIFY_ON_FAILURE(it != output_picture_buffers_.end(), | 565 // If we didn't find the picture id in the |output_picture_buffers_| map we |
566 "Invalid picture id: " << picture_buffer_id, INVALID_ARGUMENT,); | 566 // try the |stale_output_picture_buffers_| map, as this may have been an |
| 567 // output picture buffer from before a resolution change, that at resolution |
| 568 // change time had yet to be displayed. The client is calling us back to tell |
| 569 // us that we can now recycle this picture buffer, so if we were waiting to |
| 570 // dispose of it we now can. |
| 571 if (it == output_picture_buffers_.end()) { |
| 572 it = stale_output_picture_buffers_.find(picture_buffer_id); |
| 573 RETURN_AND_NOTIFY_ON_FAILURE(it != stale_output_picture_buffers_.end(), |
| 574 "Invalid picture id: " << picture_buffer_id, INVALID_ARGUMENT,); |
| 575 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 576 base::Bind(&DXVAVideoDecodeAccelerator::DeferredDismissStaleBuffer, |
| 577 weak_this_factory_.GetWeakPtr(), picture_buffer_id)); |
| 578 return; |
| 579 } |
567 | 580 |
568 it->second->ReusePictureBuffer(); | 581 it->second->ReusePictureBuffer(); |
569 ProcessPendingSamples(); | 582 ProcessPendingSamples(); |
570 | 583 |
571 if (state_ == kFlushing && pending_output_samples_.empty()) | 584 if (state_ == kFlushing && pending_output_samples_.empty()) |
572 FlushInternal(); | 585 FlushInternal(); |
573 } | 586 } |
574 | 587 |
575 void DXVAVideoDecodeAccelerator::Flush() { | 588 void DXVAVideoDecodeAccelerator::Flush() { |
576 DCHECK(CalledOnValidThread()); | 589 DCHECK(CalledOnValidThread()); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 if (state_ != kUninitialized) { | 1002 if (state_ != kUninitialized) { |
990 Invalidate(); | 1003 Invalidate(); |
991 } | 1004 } |
992 } | 1005 } |
993 | 1006 |
994 void DXVAVideoDecodeAccelerator::Invalidate() { | 1007 void DXVAVideoDecodeAccelerator::Invalidate() { |
995 if (state_ == kUninitialized) | 1008 if (state_ == kUninitialized) |
996 return; | 1009 return; |
997 weak_this_factory_.InvalidateWeakPtrs(); | 1010 weak_this_factory_.InvalidateWeakPtrs(); |
998 output_picture_buffers_.clear(); | 1011 output_picture_buffers_.clear(); |
| 1012 stale_output_picture_buffers_.clear(); |
999 pending_output_samples_.clear(); | 1013 pending_output_samples_.clear(); |
1000 pending_input_buffers_.clear(); | 1014 pending_input_buffers_.clear(); |
1001 decoder_.Release(); | 1015 decoder_.Release(); |
1002 MFShutdown(); | 1016 MFShutdown(); |
1003 state_ = kUninitialized; | 1017 state_ = kUninitialized; |
1004 } | 1018 } |
1005 | 1019 |
1006 void DXVAVideoDecodeAccelerator::NotifyInputBufferRead(int input_buffer_id) { | 1020 void DXVAVideoDecodeAccelerator::NotifyInputBufferRead(int input_buffer_id) { |
1007 if (client_) | 1021 if (client_) |
1008 client_->NotifyEndOfBitstreamBuffer(input_buffer_id); | 1022 client_->NotifyEndOfBitstreamBuffer(input_buffer_id); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 base::Bind(&DXVAVideoDecodeAccelerator::NotifyInputBufferRead, | 1179 base::Bind(&DXVAVideoDecodeAccelerator::NotifyInputBufferRead, |
1166 weak_this_factory_.GetWeakPtr(), | 1180 weak_this_factory_.GetWeakPtr(), |
1167 input_buffer_id)); | 1181 input_buffer_id)); |
1168 } | 1182 } |
1169 | 1183 |
1170 void DXVAVideoDecodeAccelerator::HandleResolutionChanged(int width, | 1184 void DXVAVideoDecodeAccelerator::HandleResolutionChanged(int width, |
1171 int height) { | 1185 int height) { |
1172 base::MessageLoop::current()->PostTask( | 1186 base::MessageLoop::current()->PostTask( |
1173 FROM_HERE, | 1187 FROM_HERE, |
1174 base::Bind(&DXVAVideoDecodeAccelerator::DismissStaleBuffers, | 1188 base::Bind(&DXVAVideoDecodeAccelerator::DismissStaleBuffers, |
1175 weak_this_factory_.GetWeakPtr(), | 1189 weak_this_factory_.GetWeakPtr())); |
1176 output_picture_buffers_)); | |
1177 | 1190 |
1178 base::MessageLoop::current()->PostTask( | 1191 base::MessageLoop::current()->PostTask( |
1179 FROM_HERE, | 1192 FROM_HERE, |
1180 base::Bind(&DXVAVideoDecodeAccelerator::RequestPictureBuffers, | 1193 base::Bind(&DXVAVideoDecodeAccelerator::RequestPictureBuffers, |
1181 weak_this_factory_.GetWeakPtr(), | 1194 weak_this_factory_.GetWeakPtr(), |
1182 width, | 1195 width, |
1183 height)); | 1196 height)); |
| 1197 } |
| 1198 |
| 1199 void DXVAVideoDecodeAccelerator::DismissStaleBuffers() { |
| 1200 OutputBuffers::iterator index; |
| 1201 |
| 1202 for (index = output_picture_buffers_.begin(); |
| 1203 index != output_picture_buffers_.end(); |
| 1204 ++index) { |
| 1205 if (index->second->available()) { |
| 1206 DVLOG(1) << "Dismissing picture id: " << index->second->id(); |
| 1207 client_->DismissPictureBuffer(index->second->id()); |
| 1208 } else { |
| 1209 // Move to |stale_output_picture_buffers_| for deferred deletion. |
| 1210 stale_output_picture_buffers_.insert( |
| 1211 std::make_pair(index->first, index->second)); |
| 1212 } |
| 1213 } |
1184 | 1214 |
1185 output_picture_buffers_.clear(); | 1215 output_picture_buffers_.clear(); |
1186 } | 1216 } |
1187 | 1217 |
1188 void DXVAVideoDecodeAccelerator::DismissStaleBuffers( | 1218 void DXVAVideoDecodeAccelerator::DeferredDismissStaleBuffer( |
1189 const OutputBuffers& picture_buffers) { | 1219 int32 picture_buffer_id) { |
1190 OutputBuffers::const_iterator index; | 1220 OutputBuffers::iterator it = stale_output_picture_buffers_.find( |
1191 | 1221 picture_buffer_id); |
1192 for (index = picture_buffers.begin(); | 1222 DCHECK(it != stale_output_picture_buffers_.end()); |
1193 index != picture_buffers.end(); | 1223 DVLOG(1) << "Dismissing picture id: " << it->second->id(); |
1194 ++index) { | 1224 client_->DismissPictureBuffer(it->second->id()); |
1195 DVLOG(1) << "Dismissing picture id: " << index->second->id(); | 1225 stale_output_picture_buffers_.erase(it); |
1196 client_->DismissPictureBuffer(index->second->id()); | |
1197 } | |
1198 } | 1226 } |
1199 | 1227 |
1200 } // namespace content | 1228 } // namespace content |
OLD | NEW |