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 "media/filters/gpu_video_accelerator_factories.h" |
17 #include "third_party/webrtc/system_wrappers/interface/ref_count.h" | 17 #include "third_party/webrtc/system_wrappers/interface/ref_count.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 const int32 RTCVideoDecoder::ID_LAST = 0x3FFFFFFF; | 21 const int32 RTCVideoDecoder::ID_LAST = 0x3FFFFFFF; |
22 const int32 RTCVideoDecoder::ID_HALF = 0x20000000; | 22 const int32 RTCVideoDecoder::ID_HALF = 0x20000000; |
23 const int32 RTCVideoDecoder::ID_INVALID = -1; | 23 const int32 RTCVideoDecoder::ID_INVALID = -1; |
24 | 24 |
25 // Maximum number of concurrent VDA::Decode() operations RVD will maintain. | 25 // Maximum number of concurrent VDA::Decode() operations RVD will maintain. |
26 // 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... |
62 timestamp(timestamp), | 62 timestamp(timestamp), |
63 width(width), | 63 width(width), |
64 height(height), | 64 height(height), |
65 size(size) {} | 65 size(size) {} |
66 | 66 |
67 RTCVideoDecoder::BufferData::BufferData() {} | 67 RTCVideoDecoder::BufferData::BufferData() {} |
68 | 68 |
69 RTCVideoDecoder::BufferData::~BufferData() {} | 69 RTCVideoDecoder::BufferData::~BufferData() {} |
70 | 70 |
71 RTCVideoDecoder::RTCVideoDecoder( | 71 RTCVideoDecoder::RTCVideoDecoder( |
72 const scoped_refptr<media::GpuVideoDecoderFactories>& factories) | 72 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories) |
73 : weak_factory_(this), | 73 : weak_factory_(this), |
74 weak_this_(weak_factory_.GetWeakPtr()), | 74 weak_this_(weak_factory_.GetWeakPtr()), |
75 factories_(factories), | 75 factories_(factories), |
76 vda_loop_proxy_(factories->GetMessageLoop()), | 76 vda_loop_proxy_(factories->GetMessageLoop()), |
77 decoder_texture_target_(0), | 77 decoder_texture_target_(0), |
78 next_picture_buffer_id_(0), | 78 next_picture_buffer_id_(0), |
79 state_(UNINITIALIZED), | 79 state_(UNINITIALIZED), |
80 decode_complete_callback_(NULL), | 80 decode_complete_callback_(NULL), |
81 num_shm_buffers_(0), | 81 num_shm_buffers_(0), |
82 next_bitstream_buffer_id_(0), | 82 next_bitstream_buffer_id_(0), |
(...skipping 29 matching lines...) Expand all Loading... |
112 for (std::deque<std::pair<webrtc::EncodedImage, BufferData> >::iterator it = | 112 for (std::deque<std::pair<webrtc::EncodedImage, BufferData> >::iterator it = |
113 pending_buffers_.begin(); | 113 pending_buffers_.begin(); |
114 it != pending_buffers_.end(); | 114 it != pending_buffers_.end(); |
115 ++it) { | 115 ++it) { |
116 delete[] it->first._buffer; | 116 delete[] it->first._buffer; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 scoped_ptr<RTCVideoDecoder> RTCVideoDecoder::Create( | 120 scoped_ptr<RTCVideoDecoder> RTCVideoDecoder::Create( |
121 webrtc::VideoCodecType type, | 121 webrtc::VideoCodecType type, |
122 const scoped_refptr<media::GpuVideoDecoderFactories>& factories) { | 122 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories) { |
123 scoped_ptr<RTCVideoDecoder> decoder; | 123 scoped_ptr<RTCVideoDecoder> decoder; |
124 // Convert WebRTC codec type to media codec profile. | 124 // Convert WebRTC codec type to media codec profile. |
125 media::VideoCodecProfile profile; | 125 media::VideoCodecProfile profile; |
126 switch (type) { | 126 switch (type) { |
127 case webrtc::kVideoCodecVP8: | 127 case webrtc::kVideoCodecVP8: |
128 profile = media::VP8PROFILE_MAIN; | 128 profile = media::VP8PROFILE_MAIN; |
129 break; | 129 break; |
130 default: | 130 default: |
131 DVLOG(2) << "Video codec not supported:" << type; | 131 DVLOG(2) << "Video codec not supported:" << type; |
132 return decoder.Pass(); | 132 return decoder.Pass(); |
133 } | 133 } |
134 | 134 |
135 decoder.reset(new RTCVideoDecoder(factories)); | 135 decoder.reset(new RTCVideoDecoder(factories)); |
136 decoder->vda_ | 136 decoder->vda_ = |
137 .reset(factories->CreateVideoDecodeAccelerator(profile, decoder.get())); | 137 factories->CreateVideoDecodeAccelerator(profile, decoder.get()).Pass(); |
138 // vda can be NULL if VP8 is not supported. | 138 // vda can be NULL if VP8 is not supported. |
139 if (decoder->vda_ != NULL) { | 139 if (decoder->vda_ != NULL) { |
140 decoder->state_ = INITIALIZED; | 140 decoder->state_ = INITIALIZED; |
141 } else { | 141 } else { |
142 factories->GetMessageLoop()->DeleteSoon(FROM_HERE, decoder.release()); | 142 factories->GetMessageLoop()->DeleteSoon(FROM_HERE, decoder.release()); |
143 } | 143 } |
144 return decoder.Pass(); | 144 return decoder.Pass(); |
145 } | 145 } |
146 | 146 |
147 int32_t RTCVideoDecoder::InitDecode(const webrtc::VideoCodec* codecSettings, | 147 int32_t RTCVideoDecoder::InitDecode(const webrtc::VideoCodec* codecSettings, |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 0, // sync_point | 397 0, // sync_point |
398 media::BindToCurrentLoop( | 398 media::BindToCurrentLoop( |
399 base::Bind(&RTCVideoDecoder::ReusePictureBuffer, | 399 base::Bind(&RTCVideoDecoder::ReusePictureBuffer, |
400 weak_this_, | 400 weak_this_, |
401 picture.picture_buffer_id()))), | 401 picture.picture_buffer_id()))), |
402 decoder_texture_target_, | 402 decoder_texture_target_, |
403 pb.size(), | 403 pb.size(), |
404 visible_rect, | 404 visible_rect, |
405 natural_size, | 405 natural_size, |
406 timestamp_ms, | 406 timestamp_ms, |
407 base::Bind(&media::GpuVideoDecoderFactories::ReadPixels, | 407 base::Bind(&media::GpuVideoAcceleratorFactories::ReadPixels, |
408 factories_, | 408 factories_, |
409 pb.texture_id(), | 409 pb.texture_id(), |
410 decoder_texture_target_, | 410 decoder_texture_target_, |
411 natural_size), | 411 natural_size), |
412 base::Closure()); | 412 base::Closure()); |
413 } | 413 } |
414 | 414 |
415 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { | 415 void RTCVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) { |
416 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; | 416 DVLOG(3) << "NotifyEndOfBitstreamBuffer. id=" << id; |
417 DCHECK(vda_loop_proxy_->BelongsToCurrentThread()); | 417 DCHECK(vda_loop_proxy_->BelongsToCurrentThread()); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 continue; | 732 continue; |
733 *timestamp = it->timestamp; | 733 *timestamp = it->timestamp; |
734 *width = it->width; | 734 *width = it->width; |
735 *height = it->height; | 735 *height = it->height; |
736 return; | 736 return; |
737 } | 737 } |
738 NOTREACHED() << "Missing bitstream buffer id: " << bitstream_buffer_id; | 738 NOTREACHED() << "Missing bitstream buffer id: " << bitstream_buffer_id; |
739 } | 739 } |
740 | 740 |
741 } // namespace content | 741 } // namespace content |
OLD | NEW |