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" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 scoped_ptr<RTCVideoDecoder> RTCVideoDecoder::Create( | 113 scoped_ptr<RTCVideoDecoder> RTCVideoDecoder::Create( |
114 webrtc::VideoCodecType type, | 114 webrtc::VideoCodecType type, |
115 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories) { | 115 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories) { |
116 scoped_ptr<RTCVideoDecoder> decoder; | 116 scoped_ptr<RTCVideoDecoder> decoder; |
117 // Convert WebRTC codec type to media codec profile. | 117 // Convert WebRTC codec type to media codec profile. |
118 media::VideoCodecProfile profile; | 118 media::VideoCodecProfile profile; |
119 switch (type) { | 119 switch (type) { |
120 case webrtc::kVideoCodecVP8: | 120 case webrtc::kVideoCodecVP8: |
121 profile = media::VP8PROFILE_MAIN; | 121 profile = media::VP8PROFILE_MAIN; |
122 break; | 122 break; |
| 123 case webrtc::kVideoCodecH264: |
| 124 profile = media::H264PROFILE_MAIN; |
| 125 break; |
123 default: | 126 default: |
124 DVLOG(2) << "Video codec not supported:" << type; | 127 DVLOG(2) << "Video codec not supported:" << type; |
125 return decoder.Pass(); | 128 return decoder.Pass(); |
126 } | 129 } |
127 | 130 |
128 base::WaitableEvent waiter(true, false); | 131 base::WaitableEvent waiter(true, false); |
129 decoder.reset(new RTCVideoDecoder(factories)); | 132 decoder.reset(new RTCVideoDecoder(factories)); |
130 decoder->factories_->GetTaskRunner()->PostTask( | 133 decoder->factories_->GetTaskRunner()->PostTask( |
131 FROM_HERE, | 134 FROM_HERE, |
132 base::Bind(&RTCVideoDecoder::CreateVDA, | 135 base::Bind(&RTCVideoDecoder::CreateVDA, |
133 base::Unretained(decoder.get()), | 136 base::Unretained(decoder.get()), |
134 profile, | 137 profile, |
135 &waiter)); | 138 &waiter)); |
136 waiter.Wait(); | 139 waiter.Wait(); |
137 // vda can be NULL if VP8 is not supported. | 140 // vda can be NULL if VP8 is not supported. |
138 if (decoder->vda_ != NULL) { | 141 if (decoder->vda_ != NULL) { |
139 decoder->state_ = INITIALIZED; | 142 decoder->state_ = INITIALIZED; |
140 } else { | 143 } else { |
141 factories->GetTaskRunner()->DeleteSoon(FROM_HERE, decoder.release()); | 144 factories->GetTaskRunner()->DeleteSoon(FROM_HERE, decoder.release()); |
142 } | 145 } |
143 return decoder.Pass(); | 146 return decoder.Pass(); |
144 } | 147 } |
145 | 148 |
146 int32_t RTCVideoDecoder::InitDecode(const webrtc::VideoCodec* codecSettings, | 149 int32_t RTCVideoDecoder::InitDecode(const webrtc::VideoCodec* codecSettings, |
147 int32_t /*numberOfCores*/) { | 150 int32_t /*numberOfCores*/) { |
148 DVLOG(2) << "InitDecode"; | 151 DVLOG(2) << "InitDecode"; |
149 DCHECK_EQ(codecSettings->codecType, webrtc::kVideoCodecVP8); | 152 DCHECK(codecSettings->codecType == webrtc::kVideoCodecVP8 || |
150 if (codecSettings->codecSpecific.VP8.feedbackModeOn) { | 153 codecSettings->codecType == webrtc::kVideoCodecH264); |
| 154 if (codecSettings->codecType == webrtc::kVideoCodecVP8 && |
| 155 codecSettings->codecSpecific.VP8.feedbackModeOn) { |
151 LOG(ERROR) << "Feedback mode not supported"; | 156 LOG(ERROR) << "Feedback mode not supported"; |
152 return RecordInitDecodeUMA(WEBRTC_VIDEO_CODEC_ERROR); | 157 return RecordInitDecodeUMA(WEBRTC_VIDEO_CODEC_ERROR); |
153 } | 158 } |
154 | 159 |
155 base::AutoLock auto_lock(lock_); | 160 base::AutoLock auto_lock(lock_); |
156 if (state_ == UNINITIALIZED || state_ == DECODE_ERROR) { | 161 if (state_ == UNINITIALIZED || state_ == DECODE_ERROR) { |
157 LOG(ERROR) << "VDA is not initialized. state=" << state_; | 162 LOG(ERROR) << "VDA is not initialized. state=" << state_; |
158 return RecordInitDecodeUMA(WEBRTC_VIDEO_CODEC_UNINITIALIZED); | 163 return RecordInitDecodeUMA(WEBRTC_VIDEO_CODEC_UNINITIALIZED); |
159 } | 164 } |
160 // Create some shared memory if the queue is empty. | 165 // Create some shared memory if the queue is empty. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // change gracefully need to have their clients cover for them, and we do that | 206 // change gracefully need to have their clients cover for them, and we do that |
202 // here. | 207 // here. |
203 #ifdef ANDROID | 208 #ifdef ANDROID |
204 const bool kVDACanHandleMidstreamResize = false; | 209 const bool kVDACanHandleMidstreamResize = false; |
205 #else | 210 #else |
206 const bool kVDACanHandleMidstreamResize = true; | 211 const bool kVDACanHandleMidstreamResize = true; |
207 #endif | 212 #endif |
208 | 213 |
209 bool need_to_reset_for_midstream_resize = false; | 214 bool need_to_reset_for_midstream_resize = false; |
210 if (inputImage._frameType == webrtc::kKeyFrame) { | 215 if (inputImage._frameType == webrtc::kKeyFrame) { |
| 216 int width = inputImage._encodedWidth ? inputImage._encodedWidth : 640; |
| 217 int height = inputImage._encodedHeight ? inputImage._encodedHeight : 480; |
211 DVLOG(2) << "Got key frame. size=" << inputImage._encodedWidth << "x" | 218 DVLOG(2) << "Got key frame. size=" << inputImage._encodedWidth << "x" |
212 << inputImage._encodedHeight; | 219 << inputImage._encodedHeight; |
213 gfx::Size prev_frame_size = frame_size_; | 220 gfx::Size prev_frame_size = frame_size_; |
214 frame_size_.SetSize(inputImage._encodedWidth, inputImage._encodedHeight); | 221 frame_size_.SetSize(width, height); |
215 if (!kVDACanHandleMidstreamResize && !prev_frame_size.IsEmpty() && | 222 if (!kVDACanHandleMidstreamResize && !prev_frame_size.IsEmpty() && |
216 prev_frame_size != frame_size_) { | 223 prev_frame_size != frame_size_) { |
217 need_to_reset_for_midstream_resize = true; | 224 need_to_reset_for_midstream_resize = true; |
218 } | 225 } |
219 } else if (IsFirstBufferAfterReset(next_bitstream_buffer_id_, | 226 } else if (IsFirstBufferAfterReset(next_bitstream_buffer_id_, |
220 reset_bitstream_buffer_id_)) { | 227 reset_bitstream_buffer_id_)) { |
221 // TODO(wuchengli): VDA should handle it. Remove this when | 228 // TODO(wuchengli): VDA should handle it. Remove this when |
222 // http://crosbug.com/p/21913 is fixed. | 229 // http://crosbug.com/p/21913 is fixed. |
223 DVLOG(1) << "The first frame should be a key frame. Drop this."; | 230 DVLOG(1) << "The first frame should be a key frame. Drop this."; |
224 return WEBRTC_VIDEO_CODEC_ERROR; | 231 return WEBRTC_VIDEO_CODEC_ERROR; |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoDecoderInitDecodeSuccess", sample); | 808 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoDecoderInitDecodeSuccess", sample); |
802 return status; | 809 return status; |
803 } | 810 } |
804 | 811 |
805 void RTCVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 812 void RTCVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
806 const { | 813 const { |
807 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 814 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
808 } | 815 } |
809 | 816 |
810 } // namespace content | 817 } // namespace content |
OLD | NEW |