OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/media/rtc_video_decoder.h" | 5 #include "content/renderer/media/rtc_video_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/safe_numerics.h" | 11 #include "base/safe_numerics.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
14 #include "content/child/child_thread.h" | 14 #include "content/child/child_thread.h" |
15 #include "media/base/bind_to_loop.h" | 15 #include "media/base/bind_to_loop.h" |
| 16 #include "media/filters/gpu_video_decoder_factories.h" |
16 #include "third_party/webrtc/system_wrappers/interface/ref_count.h" | 17 #include "third_party/webrtc/system_wrappers/interface/ref_count.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 const int32 RTCVideoDecoder::ID_LAST = 0x3FFFFFFF; | 21 const int32 RTCVideoDecoder::ID_LAST = 0x3FFFFFFF; |
21 const int32 RTCVideoDecoder::ID_HALF = 0x20000000; | 22 const int32 RTCVideoDecoder::ID_HALF = 0x20000000; |
22 const int32 RTCVideoDecoder::ID_INVALID = -1; | 23 const int32 RTCVideoDecoder::ID_INVALID = -1; |
23 | 24 |
24 // Maximum number of concurrent VDA::Decode() operations RVD will maintain. | 25 // Maximum number of concurrent VDA::Decode() operations RVD will maintain. |
25 // Higher values allow better pipelining in the GPU, but also require more | 26 // Higher values allow better pipelining in the GPU, but also require more |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 timestamp(timestamp), | 62 timestamp(timestamp), |
62 width(width), | 63 width(width), |
63 height(height), | 64 height(height), |
64 size(size) {} | 65 size(size) {} |
65 | 66 |
66 RTCVideoDecoder::BufferData::BufferData() {} | 67 RTCVideoDecoder::BufferData::BufferData() {} |
67 | 68 |
68 RTCVideoDecoder::BufferData::~BufferData() {} | 69 RTCVideoDecoder::BufferData::~BufferData() {} |
69 | 70 |
70 RTCVideoDecoder::RTCVideoDecoder( | 71 RTCVideoDecoder::RTCVideoDecoder( |
71 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories) | 72 const scoped_refptr<media::GpuVideoDecoderFactories>& factories) |
72 : weak_factory_(this), | 73 : weak_factory_(this), |
73 weak_this_(weak_factory_.GetWeakPtr()), | 74 weak_this_(weak_factory_.GetWeakPtr()), |
74 factories_(factories), | 75 factories_(factories), |
75 vda_loop_proxy_(factories_->GetMessageLoop()), | 76 vda_loop_proxy_(factories_->GetMessageLoop()), |
76 create_shm_thread_("CreateSHMThread"), | 77 create_shm_thread_("CreateSHMThread"), |
77 decoder_texture_target_(0), | 78 decoder_texture_target_(0), |
78 next_picture_buffer_id_(0), | 79 next_picture_buffer_id_(0), |
79 state_(UNINITIALIZED), | 80 state_(UNINITIALIZED), |
80 decode_complete_callback_(NULL), | 81 decode_complete_callback_(NULL), |
81 num_shm_buffers_(0), | 82 num_shm_buffers_(0), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Delete WebRTC input buffers. | 122 // Delete WebRTC input buffers. |
122 for (std::deque<std::pair<webrtc::EncodedImage, BufferData> >::iterator it = | 123 for (std::deque<std::pair<webrtc::EncodedImage, BufferData> >::iterator it = |
123 pending_buffers_.begin(); | 124 pending_buffers_.begin(); |
124 it != pending_buffers_.end(); | 125 it != pending_buffers_.end(); |
125 ++it) { | 126 ++it) { |
126 delete[] it->first._buffer; | 127 delete[] it->first._buffer; |
127 } | 128 } |
128 } | 129 } |
129 | 130 |
130 scoped_ptr<RTCVideoDecoder> RTCVideoDecoder::Create( | 131 scoped_ptr<RTCVideoDecoder> RTCVideoDecoder::Create( |
131 const scoped_refptr<media::GpuVideoDecoder::Factories>& factories) { | 132 const scoped_refptr<media::GpuVideoDecoderFactories>& factories) { |
132 scoped_ptr<RTCVideoDecoder> decoder(new RTCVideoDecoder(factories)); | 133 scoped_ptr<RTCVideoDecoder> decoder(new RTCVideoDecoder(factories)); |
133 decoder->vda_.reset(factories->CreateVideoDecodeAccelerator( | 134 decoder->vda_.reset(factories->CreateVideoDecodeAccelerator( |
134 media::VP8PROFILE_MAIN, decoder.get())); | 135 media::VP8PROFILE_MAIN, decoder.get())); |
135 // vda can be NULL if VP8 is not supported. | 136 // vda can be NULL if VP8 is not supported. |
136 if (decoder->vda_ != NULL) { | 137 if (decoder->vda_ != NULL) { |
137 decoder->state_ = INITIALIZED; | 138 decoder->state_ = INITIALIZED; |
138 } else { | 139 } else { |
139 factories->GetMessageLoop()->DeleteSoon(FROM_HERE, decoder.release()); | 140 factories->GetMessageLoop()->DeleteSoon(FROM_HERE, decoder.release()); |
140 } | 141 } |
141 return decoder.Pass(); | 142 return decoder.Pass(); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 0, // sync_point | 388 0, // sync_point |
388 media::BindToCurrentLoop( | 389 media::BindToCurrentLoop( |
389 base::Bind(&RTCVideoDecoder::ReusePictureBuffer, | 390 base::Bind(&RTCVideoDecoder::ReusePictureBuffer, |
390 weak_this_, | 391 weak_this_, |
391 picture.picture_buffer_id()))), | 392 picture.picture_buffer_id()))), |
392 decoder_texture_target_, | 393 decoder_texture_target_, |
393 pb.size(), | 394 pb.size(), |
394 visible_rect, | 395 visible_rect, |
395 natural_size, | 396 natural_size, |
396 timestamp_ms, | 397 timestamp_ms, |
397 base::Bind(&media::GpuVideoDecoder::Factories::ReadPixels, | 398 base::Bind(&media::GpuVideoDecoderFactories::ReadPixels, |
398 factories_, | 399 factories_, |
399 pb.texture_id(), | 400 pb.texture_id(), |
400 decoder_texture_target_, | 401 decoder_texture_target_, |
401 natural_size), | 402 natural_size), |
402 base::Closure()); | 403 base::Closure()); |
403 } | 404 } |
404 | 405 |
405 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { | 406 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { |
406 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; | 407 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; |
407 DCHECK(vda_loop_proxy_->BelongsToCurrentThread()); | 408 DCHECK(vda_loop_proxy_->BelongsToCurrentThread()); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 continue; | 728 continue; |
728 *timestamp = it->timestamp; | 729 *timestamp = it->timestamp; |
729 *width = it->width; | 730 *width = it->width; |
730 *height = it->height; | 731 *height = it->height; |
731 return; | 732 return; |
732 } | 733 } |
733 NOTREACHED() << "Missing bitstream buffer id: " << bitstream_buffer_id; | 734 NOTREACHED() << "Missing bitstream buffer id: " << bitstream_buffer_id; |
734 } | 735 } |
735 | 736 |
736 } // namespace content | 737 } // namespace content |
OLD | NEW |