OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 | 53 |
54 VCMGenericEncoder::VCMGenericEncoder(VideoEncoder* encoder, | 54 VCMGenericEncoder::VCMGenericEncoder(VideoEncoder* encoder, |
55 VideoEncoderRateObserver* rate_observer, | 55 VideoEncoderRateObserver* rate_observer, |
56 bool internalSource) | 56 bool internalSource) |
57 : encoder_(encoder), | 57 : encoder_(encoder), |
58 rate_observer_(rate_observer), | 58 rate_observer_(rate_observer), |
59 vcm_encoded_frame_callback_(nullptr), | 59 vcm_encoded_frame_callback_(nullptr), |
60 bit_rate_(0), | 60 bit_rate_(0), |
61 frame_rate_(0), | 61 frame_rate_(0), |
62 internal_source_(internalSource), | 62 internal_source_(internalSource), |
63 rotation_(kVideoRotation_0) { | 63 rotation_(kVideoRotation_0), |
64 is_screenshare_(false) { | |
64 } | 65 } |
65 | 66 |
66 VCMGenericEncoder::~VCMGenericEncoder() | 67 VCMGenericEncoder::~VCMGenericEncoder() |
67 { | 68 { |
68 } | 69 } |
69 | 70 |
70 int32_t VCMGenericEncoder::Release() | 71 int32_t VCMGenericEncoder::Release() |
71 { | 72 { |
72 { | 73 { |
73 rtc::CritScope lock(&rates_lock_); | 74 rtc::CritScope lock(&rates_lock_); |
74 bit_rate_ = 0; | 75 bit_rate_ = 0; |
75 frame_rate_ = 0; | 76 frame_rate_ = 0; |
76 vcm_encoded_frame_callback_ = nullptr; | 77 vcm_encoded_frame_callback_ = nullptr; |
77 } | 78 } |
78 | 79 |
79 return encoder_->Release(); | 80 return encoder_->Release(); |
80 } | 81 } |
81 | 82 |
82 int32_t | 83 int32_t |
83 VCMGenericEncoder::InitEncode(const VideoCodec* settings, | 84 VCMGenericEncoder::InitEncode(const VideoCodec* settings, |
84 int32_t numberOfCores, | 85 int32_t numberOfCores, |
85 size_t maxPayloadSize) | 86 size_t maxPayloadSize) |
86 { | 87 { |
87 { | 88 { |
88 rtc::CritScope lock(&rates_lock_); | 89 rtc::CritScope lock(&rates_lock_); |
89 bit_rate_ = settings->startBitrate * 1000; | 90 bit_rate_ = settings->startBitrate * 1000; |
90 frame_rate_ = settings->maxFramerate; | 91 frame_rate_ = settings->maxFramerate; |
91 } | 92 } |
92 | 93 |
94 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing; | |
93 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) { | 95 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) { |
94 LOG(LS_ERROR) << "Failed to initialize the encoder associated with " | 96 LOG(LS_ERROR) << "Failed to initialize the encoder associated with " |
95 "payload name: " << settings->plName; | 97 "payload name: " << settings->plName; |
96 return -1; | 98 return -1; |
97 } | 99 } |
98 return 0; | 100 return 0; |
99 } | 101 } |
100 | 102 |
101 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame, | 103 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame, |
102 const CodecSpecificInfo* codecSpecificInfo, | 104 const CodecSpecificInfo* codecSpecificInfo, |
103 const std::vector<FrameType>& frameTypes) { | 105 const std::vector<FrameType>& frameTypes) { |
104 std::vector<VideoFrameType> video_frame_types(frameTypes.size(), | 106 std::vector<VideoFrameType> video_frame_types(frameTypes.size(), |
105 kDeltaFrame); | 107 kDeltaFrame); |
106 VCMEncodedFrame::ConvertFrameTypes(frameTypes, &video_frame_types); | 108 VCMEncodedFrame::ConvertFrameTypes(frameTypes, &video_frame_types); |
107 | 109 |
108 rotation_ = inputFrame.rotation(); | 110 rotation_ = inputFrame.rotation(); |
109 | 111 |
110 if (vcm_encoded_frame_callback_) { | 112 if (vcm_encoded_frame_callback_) { |
111 // Keep track of the current frame rotation and apply to the output of the | 113 // Keep track of the current frame rotation and apply to the output of the |
112 // encoder. There might not be exact as the encoder could have one frame | 114 // encoder. There might not be exact as the encoder could have one frame |
113 // delay but it should be close enough. | 115 // delay but it should be close enough. |
114 vcm_encoded_frame_callback_->SetRotation(rotation_); | 116 vcm_encoded_frame_callback_->SetRotation(rotation_); |
115 } | 117 } |
116 | 118 |
117 return encoder_->Encode(inputFrame, codecSpecificInfo, &video_frame_types); | 119 int32_t result = |
120 encoder_->Encode(inputFrame, codecSpecificInfo, &video_frame_types); | |
121 if (is_screenshare_ && result == WEBRTC_VIDEO_CODEC_OK && | |
stefan-webrtc
2015/06/18 09:39:02
This is really hard to understand. What Does it do
sprang_webrtc
2015/06/18 13:05:02
Yes, this was an ad-hoc way to discover that the e
stefan-webrtc
2015/06/23 14:28:32
I'm wondering if it would be better to have this l
sprang_webrtc
2015/06/23 15:07:30
It's more difficult since we don't know until afte
| |
122 vcm_encoded_frame_callback_ != nullptr && | |
123 !vcm_encoded_frame_callback_->GetAndResetFrameProduced()) { | |
124 result = | |
125 encoder_->Encode(inputFrame, codecSpecificInfo, &video_frame_types); | |
126 vcm_encoded_frame_callback_->GetAndResetFrameProduced(); | |
127 } | |
128 | |
129 return result; | |
118 } | 130 } |
119 | 131 |
120 int32_t | 132 int32_t |
121 VCMGenericEncoder::SetChannelParameters(int32_t packetLoss, int64_t rtt) | 133 VCMGenericEncoder::SetChannelParameters(int32_t packetLoss, int64_t rtt) |
122 { | 134 { |
123 return encoder_->SetChannelParameters(packetLoss, rtt); | 135 return encoder_->SetChannelParameters(packetLoss, rtt); |
124 } | 136 } |
125 | 137 |
126 int32_t | 138 int32_t |
127 VCMGenericEncoder::SetRates(uint32_t newBitRate, uint32_t frameRate) | 139 VCMGenericEncoder::SetRates(uint32_t newBitRate, uint32_t frameRate) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 /*************************** | 219 /*************************** |
208 * Callback Implementation | 220 * Callback Implementation |
209 ***************************/ | 221 ***************************/ |
210 VCMEncodedFrameCallback::VCMEncodedFrameCallback( | 222 VCMEncodedFrameCallback::VCMEncodedFrameCallback( |
211 EncodedImageCallback* post_encode_callback) | 223 EncodedImageCallback* post_encode_callback) |
212 : _sendCallback(), | 224 : _sendCallback(), |
213 _mediaOpt(NULL), | 225 _mediaOpt(NULL), |
214 _payloadType(0), | 226 _payloadType(0), |
215 _internalSource(false), | 227 _internalSource(false), |
216 _rotation(kVideoRotation_0), | 228 _rotation(kVideoRotation_0), |
217 post_encode_callback_(post_encode_callback) | 229 post_encode_callback_(post_encode_callback), |
230 frame_produced_(false) | |
218 #ifdef DEBUG_ENCODER_BIT_STREAM | 231 #ifdef DEBUG_ENCODER_BIT_STREAM |
219 , | 232 , |
220 _bitStreamAfterEncoder(NULL) | 233 _bitStreamAfterEncoder(NULL) |
221 #endif | 234 #endif |
222 { | 235 { |
223 #ifdef DEBUG_ENCODER_BIT_STREAM | 236 #ifdef DEBUG_ENCODER_BIT_STREAM |
224 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); | 237 _bitStreamAfterEncoder = fopen("encoderBitStream.bit", "wb"); |
225 #endif | 238 #endif |
226 } | 239 } |
227 | 240 |
(...skipping 10 matching lines...) Expand all Loading... | |
238 _sendCallback = transport; | 251 _sendCallback = transport; |
239 return VCM_OK; | 252 return VCM_OK; |
240 } | 253 } |
241 | 254 |
242 int32_t VCMEncodedFrameCallback::Encoded( | 255 int32_t VCMEncodedFrameCallback::Encoded( |
243 const EncodedImage& encodedImage, | 256 const EncodedImage& encodedImage, |
244 const CodecSpecificInfo* codecSpecificInfo, | 257 const CodecSpecificInfo* codecSpecificInfo, |
245 const RTPFragmentationHeader* fragmentationHeader) { | 258 const RTPFragmentationHeader* fragmentationHeader) { |
246 post_encode_callback_->Encoded(encodedImage, NULL, NULL); | 259 post_encode_callback_->Encoded(encodedImage, NULL, NULL); |
247 | 260 |
261 frame_produced_ = true; | |
262 | |
248 if (_sendCallback == NULL) { | 263 if (_sendCallback == NULL) { |
249 return VCM_UNINITIALIZED; | 264 return VCM_UNINITIALIZED; |
250 } | 265 } |
251 | 266 |
252 #ifdef DEBUG_ENCODER_BIT_STREAM | 267 #ifdef DEBUG_ENCODER_BIT_STREAM |
253 if (_bitStreamAfterEncoder != NULL) { | 268 if (_bitStreamAfterEncoder != NULL) { |
254 fwrite(encodedImage._buffer, 1, encodedImage._length, | 269 fwrite(encodedImage._buffer, 1, encodedImage._length, |
255 _bitStreamAfterEncoder); | 270 _bitStreamAfterEncoder); |
256 } | 271 } |
257 #endif | 272 #endif |
(...skipping 20 matching lines...) Expand all Loading... | |
278 return VCM_OK; | 293 return VCM_OK; |
279 } | 294 } |
280 | 295 |
281 void | 296 void |
282 VCMEncodedFrameCallback::SetMediaOpt( | 297 VCMEncodedFrameCallback::SetMediaOpt( |
283 media_optimization::MediaOptimization *mediaOpt) | 298 media_optimization::MediaOptimization *mediaOpt) |
284 { | 299 { |
285 _mediaOpt = mediaOpt; | 300 _mediaOpt = mediaOpt; |
286 } | 301 } |
287 | 302 |
303 bool VCMEncodedFrameCallback::GetAndResetFrameProduced() { | |
304 bool frame_produced = frame_produced_; | |
305 frame_produced_ = false; | |
306 return frame_produced; | |
307 } | |
308 | |
288 } // namespace webrtc | 309 } // namespace webrtc |
OLD | NEW |