Reverting 1680: valgrind memory leak reported.

TBR=marpan
Review URL: https://webrtc-codereview.appspot.com/392011

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1686 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
marpan@webrtc.org 2012-02-14 22:37:10 +00:00
parent 738bcdc4ee
commit 79a99de8e4
4 changed files with 54 additions and 57 deletions

View File

@ -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

View File

@ -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<float>(bitRate),
static_cast<float>(frameRate));
_userFrameRate = static_cast<float>(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<WebRtc_UWord32>
(_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<float>(diff);
}
}
else
{
_incomingFrameRate = static_cast<float>(nrOfFrames);
}
}
WebRtc_UWord32

View File

@ -168,8 +168,6 @@ private:
VideoCodecType _sendCodecType;
WebRtc_UWord16 _codecWidth;
WebRtc_UWord16 _codecHeight;
WebRtc_UWord16 _initCodecWidth;
WebRtc_UWord16 _initCodecHeight;
float _userFrameRate;
VCMFrameDropper* _frameDropper;

View File

@ -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(&current_codec);
WebRtc_UWord32 current_bit_rate = vcm_->Bitrate();
// Set the new calues.
current_codec.height = static_cast<WebRtc_UWord16>(height);
current_codec.width = static_cast<WebRtc_UWord16>(width);
current_codec.maxFramerate = static_cast<WebRtc_UWord8>(frame_rate);
current_codec.startBitrate = current_bit_rate;
// Re-register encoder with the updated settings.
ret_val = vcm_->RegisterSendCodec(&current_codec, num_cores_,
max_payload_length_);
}
return ret_val;
}
void QMTestVideoSettingsCallback::SetMaxPayloadLength(