diff --git a/src/modules/video_coding/codecs/vp8/main/source/vp8.cc b/src/modules/video_coding/codecs/vp8/main/source/vp8.cc index fc5249b8a..9a0141762 100644 --- a/src/modules/video_coding/codecs/vp8/main/source/vp8.cc +++ b/src/modules/video_coding/codecs/vp8/main/source/vp8.cc @@ -324,24 +324,11 @@ int VP8Encoder::Encode(const RawImage& input_image, if (encoded_complete_callback_ == NULL) { return WEBRTC_VIDEO_CODEC_UNINITIALIZED; } - - // Check for change in frame size. - if (input_image._width != codec_.width || - input_image._height != codec_.height) { - codec_.width = input_image._width; - codec_.height = input_image._height; - - // Update encoder context for new frame size. - // Change of frame size will automatically trigger a key frame. - config_->g_w = codec_.width; - config_->g_h = codec_.height; - if (vpx_codec_enc_config_set(encoder_, config_)) { - return WEBRTC_VIDEO_CODEC_ERROR; - } - } - - vpx_img_wrap(raw_, IMG_FMT_I420, codec_.width, codec_.height, 1, - input_image._buffer); + // image in vpx_image_t format + raw_->planes[PLANE_Y] = input_image._buffer; + raw_->planes[PLANE_U] = &input_image._buffer[codec_.height * codec_.width]; + raw_->planes[PLANE_V] = + &input_image._buffer[codec_.height * codec_.width * 5 >> 2]; int flags = 0; #if WEBRTC_LIBVPX_VERSION >= 971 diff --git a/src/modules/video_coding/main/source/media_optimization.cc b/src/modules/video_coding/main/source/media_optimization.cc index 4053d8ded..e2c432980 100644 --- a/src/modules/video_coding/main/source/media_optimization.cc +++ b/src/modules/video_coding/main/source/media_optimization.cc @@ -24,8 +24,6 @@ _maxBitRate(0), _sendCodecType(kVideoCodecUnknown), _codecWidth(0), _codecHeight(0), -_initCodecWidth(0), -_initCodecHeight(0), _userFrameRate(0), _packetLossEnc(0), _fractionLost(0), @@ -66,7 +64,7 @@ WebRtc_Word32 VCMMediaOptimization::Reset() { memset(_incomingFrameTimes, -1, sizeof(_incomingFrameTimes)); - _incomingFrameRate = 0.0; + InputFrameRate(); // Resets _incomingFrameRate _frameDropper->Reset(); _lossProtLogic->Reset(_clock->MillisecondTimestamp()); _frameDropper->SetRates(0, 0); @@ -282,8 +280,6 @@ VCMMediaOptimization::SetEncodingData(VideoCodecType sendCodecType, _frameDropper->SetRates(static_cast(bitRate), static_cast(frameRate)); _userFrameRate = static_cast(frameRate); - _initCodecWidth = width; - _initCodecHeight = height; _codecWidth = width; _codecHeight = height; _numLayers = (numLayers <= 1) ? 1 : numLayers; // Can also be zero. @@ -579,51 +575,43 @@ VCMMediaOptimization::QMUpdate(VCMResolutionScale* qm) // Check for no change if (qm->spatialHeightFact == 1 && qm->spatialWidthFact == 1 && - qm->temporalFact == 1) { - return false; + qm->temporalFact == 1) + { + return false; } + // Content metrics hold native values + VideoContentMetrics* cm = _content->LongTermAvgData(); + // Temporal WebRtc_UWord32 frameRate = static_cast (_incomingFrameRate + 0.5f); // Check if go back up in temporal resolution - if (qm->temporalFact == 0) { - // Currently only allow for 1/2 frame rate reduction per action. - // TODO (marpan): allow for 2/3 reduction - frameRate = (WebRtc_UWord32) 2 * _incomingFrameRate; + if (qm->temporalFact == 0) + { + frameRate = (WebRtc_UWord32) 2 * _incomingFrameRate; } // go down in temporal resolution - else { - frameRate = (WebRtc_UWord32)(_incomingFrameRate / qm->temporalFact + 1); - } - // Reset _incomingFrameRate if temporal action was selected. - if (qm->temporalFact != 1) { - memset(_incomingFrameTimes, -1, sizeof(_incomingFrameTimes)); - _incomingFrameRate = frameRate; + else + { + frameRate = (WebRtc_UWord32)(_incomingFrameRate / qm->temporalFact + 1); } // Spatial - WebRtc_UWord32 width = _codecWidth; WebRtc_UWord32 height = _codecHeight; - // Check if go back up in spatial resolution, and update frame sizes. - // Currently only allow for 2x2 spatial down-sampling. - // TODO (marpan): allow for 1x2, 2x1, and 4/3x4/3 (or 3/2x3/2). - if (qm->spatialHeightFact == 0 && qm->spatialWidthFact == 0) { - width = _codecWidth * 2; - height = _codecHeight * 2; + WebRtc_UWord32 width = _codecWidth; + // Check if go back up in spatial resolution + if (qm->spatialHeightFact == 0 && qm->spatialWidthFact == 0) + { + height = cm->nativeHeight; + width = cm->nativeWidth; } - else { - width = _codecWidth / qm->spatialWidthFact; - height = _codecHeight / qm->spatialHeightFact; + else + { + height = _codecHeight / qm->spatialHeightFact; + width = _codecWidth / qm->spatialWidthFact; } - _codecWidth = width; - _codecHeight = height; - - // New frame sizes should never exceed the original sizes - // from SetEncodingData(). - assert(_codecWidth <= _initCodecWidth); - assert(_codecHeight <= _initCodecHeight); WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCoding, _id, "Quality Mode Update: W = %d, H = %d, FR = %f", @@ -635,6 +623,8 @@ VCMMediaOptimization::QMUpdate(VCMResolutionScale* qm) return true; } + + void VCMMediaOptimization::UpdateIncomingFrameRate() { @@ -681,6 +671,10 @@ VCMMediaOptimization::ProcessIncomingFrameRate(WebRtc_Word64 now) _incomingFrameRate = nrOfFrames * 1000.0f / static_cast(diff); } } + else + { + _incomingFrameRate = static_cast(nrOfFrames); + } } WebRtc_UWord32 diff --git a/src/modules/video_coding/main/source/media_optimization.h b/src/modules/video_coding/main/source/media_optimization.h index 14e5d1a2d..7d87a6d04 100644 --- a/src/modules/video_coding/main/source/media_optimization.h +++ b/src/modules/video_coding/main/source/media_optimization.h @@ -168,8 +168,6 @@ private: VideoCodecType _sendCodecType; WebRtc_UWord16 _codecWidth; WebRtc_UWord16 _codecHeight; - WebRtc_UWord16 _initCodecWidth; - WebRtc_UWord16 _initCodecHeight; float _userFrameRate; VCMFrameDropper* _frameDropper; diff --git a/src/video_engine/vie_encoder.cc b/src/video_engine/vie_encoder.cc index 646449755..c80b5be74 100644 --- a/src/video_engine/vie_encoder.cc +++ b/src/video_engine/vie_encoder.cc @@ -823,8 +823,26 @@ WebRtc_Word32 QMTestVideoSettingsCallback::SetVideoQMSettings( const WebRtc_UWord32 frame_rate, const WebRtc_UWord32 width, const WebRtc_UWord32 height) { - // Update VPM with encoder target resolution - return vpm_->SetTargetResolution(width, height, frame_rate); + WebRtc_Word32 ret_val = 0; + ret_val = vpm_->SetTargetResolution(width, height, frame_rate); + + if (!ret_val) { + // Get current settings. + VideoCodec current_codec; + vcm_->SendCodec(¤t_codec); + WebRtc_UWord32 current_bit_rate = vcm_->Bitrate(); + + // Set the new calues. + current_codec.height = static_cast(height); + current_codec.width = static_cast(width); + current_codec.maxFramerate = static_cast(frame_rate); + current_codec.startBitrate = current_bit_rate; + + // Re-register encoder with the updated settings. + ret_val = vcm_->RegisterSendCodec(¤t_codec, num_cores_, + max_payload_length_); + } + return ret_val; } void QMTestVideoSettingsCallback::SetMaxPayloadLength(