OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 private: | 129 private: |
130 webrtc::SimulcastEncoderAdapter* const adapter_; | 130 webrtc::SimulcastEncoderAdapter* const adapter_; |
131 const size_t stream_idx_; | 131 const size_t stream_idx_; |
132 }; | 132 }; |
133 | 133 |
134 } // namespace | 134 } // namespace |
135 | 135 |
136 namespace webrtc { | 136 namespace webrtc { |
137 | 137 |
138 SimulcastEncoderAdapter::SimulcastEncoderAdapter(VideoEncoderFactory* factory) | 138 SimulcastEncoderAdapter::SimulcastEncoderAdapter(VideoEncoderFactory* factory) |
139 : factory_(factory), encoded_complete_callback_(NULL) { | 139 : factory_(factory), |
| 140 encoded_complete_callback_(NULL), |
| 141 implementation_name_("SimulcastEncoderAdapter") { |
140 memset(&codec_, 0, sizeof(webrtc::VideoCodec)); | 142 memset(&codec_, 0, sizeof(webrtc::VideoCodec)); |
141 } | 143 } |
142 | 144 |
143 SimulcastEncoderAdapter::~SimulcastEncoderAdapter() { | 145 SimulcastEncoderAdapter::~SimulcastEncoderAdapter() { |
144 Release(); | 146 Release(); |
145 } | 147 } |
146 | 148 |
147 int SimulcastEncoderAdapter::Release() { | 149 int SimulcastEncoderAdapter::Release() { |
148 // TODO(pbos): Keep the last encoder instance but call ::Release() on it, then | 150 // TODO(pbos): Keep the last encoder instance but call ::Release() on it, then |
149 // re-use this instance in ::InitEncode(). This means that changing | 151 // re-use this instance in ::InitEncode(). This means that changing |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 187 } |
186 | 188 |
187 codec_ = *inst; | 189 codec_ = *inst; |
188 | 190 |
189 // Special mode when screensharing on a single stream. | 191 // Special mode when screensharing on a single stream. |
190 if (number_of_streams == 1 && inst->mode == kScreensharing) { | 192 if (number_of_streams == 1 && inst->mode == kScreensharing) { |
191 screensharing_tl_factory_.reset(new ScreenshareTemporalLayersFactory()); | 193 screensharing_tl_factory_.reset(new ScreenshareTemporalLayersFactory()); |
192 codec_.codecSpecific.VP8.tl_factory = screensharing_tl_factory_.get(); | 194 codec_.codecSpecific.VP8.tl_factory = screensharing_tl_factory_.get(); |
193 } | 195 } |
194 | 196 |
| 197 std::string implementation_name; |
195 // Create |number_of_streams| of encoder instances and init them. | 198 // Create |number_of_streams| of encoder instances and init them. |
196 for (int i = 0; i < number_of_streams; ++i) { | 199 for (int i = 0; i < number_of_streams; ++i) { |
197 VideoCodec stream_codec; | 200 VideoCodec stream_codec; |
198 bool send_stream = true; | 201 bool send_stream = true; |
199 if (!doing_simulcast) { | 202 if (!doing_simulcast) { |
200 stream_codec = codec_; | 203 stream_codec = codec_; |
201 stream_codec.numberOfSimulcastStreams = 1; | 204 stream_codec.numberOfSimulcastStreams = 1; |
202 } else { | 205 } else { |
203 bool highest_resolution_stream = (i == (number_of_streams - 1)); | 206 bool highest_resolution_stream = (i == (number_of_streams - 1)); |
204 PopulateStreamCodec(&codec_, i, number_of_streams, | 207 PopulateStreamCodec(&codec_, i, number_of_streams, |
205 highest_resolution_stream, &stream_codec, | 208 highest_resolution_stream, &stream_codec, |
206 &send_stream); | 209 &send_stream); |
207 } | 210 } |
208 | 211 |
209 // TODO(ronghuawu): Remove once this is handled in VP8EncoderImpl. | 212 // TODO(ronghuawu): Remove once this is handled in VP8EncoderImpl. |
210 if (stream_codec.qpMax < kDefaultMinQp) { | 213 if (stream_codec.qpMax < kDefaultMinQp) { |
211 stream_codec.qpMax = kDefaultMaxQp; | 214 stream_codec.qpMax = kDefaultMaxQp; |
212 } | 215 } |
213 | 216 |
214 VideoEncoder* encoder = factory_->Create(); | 217 VideoEncoder* encoder = factory_->Create(); |
215 ret = encoder->InitEncode(&stream_codec, number_of_cores, max_payload_size); | 218 ret = encoder->InitEncode(&stream_codec, number_of_cores, max_payload_size); |
216 if (ret < 0) { | 219 if (ret < 0) { |
217 Release(); | 220 Release(); |
218 return ret; | 221 return ret; |
219 } | 222 } |
220 EncodedImageCallback* callback = new AdapterEncodedImageCallback(this, i); | 223 EncodedImageCallback* callback = new AdapterEncodedImageCallback(this, i); |
221 encoder->RegisterEncodeCompleteCallback(callback); | 224 encoder->RegisterEncodeCompleteCallback(callback); |
222 streaminfos_.push_back(StreamInfo(encoder, callback, stream_codec.width, | 225 streaminfos_.push_back(StreamInfo(encoder, callback, stream_codec.width, |
223 stream_codec.height, send_stream)); | 226 stream_codec.height, send_stream)); |
| 227 if (i != 0) |
| 228 implementation_name += ", "; |
| 229 implementation_name += streaminfos_[i].encoder->ImplementationName(); |
224 } | 230 } |
| 231 implementation_name_ = |
| 232 "SimulcastEncoderAdapter (" + implementation_name + ")"; |
225 return WEBRTC_VIDEO_CODEC_OK; | 233 return WEBRTC_VIDEO_CODEC_OK; |
226 } | 234 } |
227 | 235 |
228 int SimulcastEncoderAdapter::Encode( | 236 int SimulcastEncoderAdapter::Encode( |
229 const VideoFrame& input_image, | 237 const VideoFrame& input_image, |
230 const CodecSpecificInfo* codec_specific_info, | 238 const CodecSpecificInfo* codec_specific_info, |
231 const std::vector<FrameType>* frame_types) { | 239 const std::vector<FrameType>* frame_types) { |
232 if (!Initialized()) { | 240 if (!Initialized()) { |
233 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 241 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
234 } | 242 } |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 bool SimulcastEncoderAdapter::SupportsNativeHandle() const { | 495 bool SimulcastEncoderAdapter::SupportsNativeHandle() const { |
488 // We should not be calling this method before streaminfos_ are configured. | 496 // We should not be calling this method before streaminfos_ are configured. |
489 RTC_DCHECK(!streaminfos_.empty()); | 497 RTC_DCHECK(!streaminfos_.empty()); |
490 // TODO(pbos): Support textures when using more than one encoder. | 498 // TODO(pbos): Support textures when using more than one encoder. |
491 if (streaminfos_.size() != 1) | 499 if (streaminfos_.size() != 1) |
492 return false; | 500 return false; |
493 return streaminfos_[0].encoder->SupportsNativeHandle(); | 501 return streaminfos_[0].encoder->SupportsNativeHandle(); |
494 } | 502 } |
495 | 503 |
496 const char* SimulcastEncoderAdapter::ImplementationName() const { | 504 const char* SimulcastEncoderAdapter::ImplementationName() const { |
497 // We should not be calling this method before streaminfos_ are configured. | 505 return implementation_name_.c_str(); |
498 RTC_DCHECK(!streaminfos_.empty()); | |
499 // TODO(pbos): Support multiple implementation names for different encoders. | |
500 return streaminfos_[0].encoder->ImplementationName(); | |
501 } | 506 } |
502 | 507 |
503 } // namespace webrtc | 508 } // namespace webrtc |
OLD | NEW |