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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 state_(kNormal), | 51 state_(kNormal), |
52 demuxer_read_in_progress_(false), | 52 demuxer_read_in_progress_(false), |
53 decoder_texture_target_(0), | 53 decoder_texture_target_(0), |
54 next_picture_buffer_id_(0), | 54 next_picture_buffer_id_(0), |
55 next_bitstream_buffer_id_(0), | 55 next_bitstream_buffer_id_(0), |
56 shutting_down_(false), | 56 shutting_down_(false), |
57 error_occured_(false) { | 57 error_occured_(false) { |
58 DCHECK(gvd_loop_proxy_ && factories_); | 58 DCHECK(gvd_loop_proxy_ && factories_); |
59 } | 59 } |
60 | 60 |
61 GpuVideoDecoder::~GpuVideoDecoder() { | |
62 DCHECK(!vda_); // Stop should have been already called. | |
63 DCHECK(pending_read_cb_.is_null()); | |
64 for (size_t i = 0; i < available_shm_segments_.size(); ++i) { | |
65 available_shm_segments_[i]->shm->Close(); | |
66 delete available_shm_segments_[i]; | |
67 } | |
68 available_shm_segments_.clear(); | |
69 for (std::map<int32, BufferPair>::iterator it = | |
70 bitstream_buffers_in_decoder_.begin(); | |
71 it != bitstream_buffers_in_decoder_.end(); ++it) { | |
72 it->second.shm_buffer->shm->Close(); | |
73 } | |
74 bitstream_buffers_in_decoder_.clear(); | |
75 } | |
76 | |
77 void GpuVideoDecoder::Reset(const base::Closure& closure) { | 61 void GpuVideoDecoder::Reset(const base::Closure& closure) { |
78 if (!gvd_loop_proxy_->BelongsToCurrentThread() || | 62 if (!gvd_loop_proxy_->BelongsToCurrentThread() || |
79 state_ == kDrainingDecoder) { | 63 state_ == kDrainingDecoder) { |
80 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 64 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
81 &GpuVideoDecoder::Reset, this, closure)); | 65 &GpuVideoDecoder::Reset, this, closure)); |
82 return; | 66 return; |
83 } | 67 } |
84 | 68 |
85 // Throw away any already-decoded, not-yet-delivered frames. | 69 // Throw away any already-decoded, not-yet-delivered frames. |
86 ready_video_frames_.clear(); | 70 ready_video_frames_.clear(); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 bitstream_buffers_in_decoder_.erase(it); | 449 bitstream_buffers_in_decoder_.erase(it); |
466 | 450 |
467 if (!pending_read_cb_.is_null() && pending_reset_cb_.is_null() && | 451 if (!pending_read_cb_.is_null() && pending_reset_cb_.is_null() && |
468 state_ != kDrainingDecoder && | 452 state_ != kDrainingDecoder && |
469 bitstream_buffers_in_decoder_.empty()) { | 453 bitstream_buffers_in_decoder_.empty()) { |
470 DCHECK(ready_video_frames_.empty()); | 454 DCHECK(ready_video_frames_.empty()); |
471 EnsureDemuxOrDecode(); | 455 EnsureDemuxOrDecode(); |
472 } | 456 } |
473 } | 457 } |
474 | 458 |
| 459 GpuVideoDecoder::~GpuVideoDecoder() { |
| 460 DCHECK(!vda_); // Stop should have been already called. |
| 461 DCHECK(pending_read_cb_.is_null()); |
| 462 for (size_t i = 0; i < available_shm_segments_.size(); ++i) { |
| 463 available_shm_segments_[i]->shm->Close(); |
| 464 delete available_shm_segments_[i]; |
| 465 } |
| 466 available_shm_segments_.clear(); |
| 467 for (std::map<int32, BufferPair>::iterator it = |
| 468 bitstream_buffers_in_decoder_.begin(); |
| 469 it != bitstream_buffers_in_decoder_.end(); ++it) { |
| 470 it->second.shm_buffer->shm->Close(); |
| 471 } |
| 472 bitstream_buffers_in_decoder_.clear(); |
| 473 } |
| 474 |
475 void GpuVideoDecoder::EnsureDemuxOrDecode() { | 475 void GpuVideoDecoder::EnsureDemuxOrDecode() { |
476 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 476 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
477 if (demuxer_read_in_progress_) | 477 if (demuxer_read_in_progress_) |
478 return; | 478 return; |
479 demuxer_read_in_progress_ = true; | 479 demuxer_read_in_progress_ = true; |
480 demuxer_stream_->Read(base::Bind( | 480 demuxer_stream_->Read(base::Bind( |
481 &GpuVideoDecoder::RequestBufferDecode, this)); | 481 &GpuVideoDecoder::RequestBufferDecode, this)); |
482 } | 482 } |
483 | 483 |
484 void GpuVideoDecoder::NotifyFlushDone() { | 484 void GpuVideoDecoder::NotifyFlushDone() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 528 |
529 error_occured_ = true; | 529 error_occured_ = true; |
530 | 530 |
531 if (!pending_read_cb_.is_null()) { | 531 if (!pending_read_cb_.is_null()) { |
532 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); | 532 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); |
533 return; | 533 return; |
534 } | 534 } |
535 } | 535 } |
536 | 536 |
537 } // namespace media | 537 } // namespace media |
OLD | NEW |