Fix framerate based bitrate adjuster.
Fixes target bitrate calculation for framerate based adjuster. Adds new API to bitrate adjuster - getCodecConfigFramerate() - that returns the FPS that should be passed to MediaCodec on initialization. Bug: b/73741487, cl/186656928 Change-Id: Ia4a5e99d302de67fbee0c132ab8e9392bc205b44 Reviewed-on: https://webrtc-review.googlesource.com/65162 Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22716}
This commit is contained in:
committed by
Commit Bot
parent
8730135f26
commit
0bdb5dd0a9
@ -32,7 +32,7 @@ class BaseBitrateAdjuster implements BitrateAdjuster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAdjustedFramerate() {
|
public int getCodecConfigFramerate() {
|
||||||
return targetFps;
|
return targetFps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,6 @@ interface BitrateAdjuster {
|
|||||||
/** Gets the current bitrate. */
|
/** Gets the current bitrate. */
|
||||||
int getAdjustedBitrateBps();
|
int getAdjustedBitrateBps();
|
||||||
|
|
||||||
/** Gets the current framerate. */
|
/** Gets the framerate for initial codec configuration. */
|
||||||
int getAdjustedFramerate();
|
int getCodecConfigFramerate();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,10 +86,13 @@ class DynamicBitrateAdjuster extends BaseBitrateAdjuster {
|
|||||||
timeSinceLastAdjustmentMs = 0;
|
timeSinceLastAdjustmentMs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double getBitrateAdjustmentScale() {
|
||||||
|
return Math.pow(BITRATE_ADJUSTMENT_MAX_SCALE,
|
||||||
|
(double) bitrateAdjustmentScaleExp / BITRATE_ADJUSTMENT_STEPS);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAdjustedBitrateBps() {
|
public int getAdjustedBitrateBps() {
|
||||||
return (int) (targetBitrateBps
|
return (int) (targetBitrateBps * getBitrateAdjustmentScale());
|
||||||
* Math.pow(BITRATE_ADJUSTMENT_MAX_SCALE,
|
|
||||||
(double) bitrateAdjustmentScaleExp / BITRATE_ADJUSTMENT_STEPS));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,11 @@ class FramerateBitrateAdjuster extends BaseBitrateAdjuster {
|
|||||||
}
|
}
|
||||||
super.setTargets(targetBitrateBps, targetFps);
|
super.setTargets(targetBitrateBps, targetFps);
|
||||||
|
|
||||||
this.targetBitrateBps *= INITIAL_FPS / this.targetFps;
|
this.targetBitrateBps = this.targetBitrateBps * INITIAL_FPS / this.targetFps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCodecConfigFramerate() {
|
||||||
|
return INITIAL_FPS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import android.media.MediaCodecInfo;
|
|||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -26,6 +25,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.BlockingDeque;
|
import java.util.concurrent.BlockingDeque;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.webrtc.ThreadUtils.ThreadChecker;
|
import org.webrtc.ThreadUtils.ThreadChecker;
|
||||||
|
|
||||||
/** Android hardware video encoder. */
|
/** Android hardware video encoder. */
|
||||||
@ -186,7 +186,7 @@ class HardwareVideoEncoder implements VideoEncoder {
|
|||||||
format.setInteger(MediaFormat.KEY_BIT_RATE, adjustedBitrate);
|
format.setInteger(MediaFormat.KEY_BIT_RATE, adjustedBitrate);
|
||||||
format.setInteger(KEY_BITRATE_MODE, VIDEO_ControlRateConstant);
|
format.setInteger(KEY_BITRATE_MODE, VIDEO_ControlRateConstant);
|
||||||
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
|
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
|
||||||
format.setInteger(MediaFormat.KEY_FRAME_RATE, bitrateAdjuster.getAdjustedFramerate());
|
format.setInteger(MediaFormat.KEY_FRAME_RATE, bitrateAdjuster.getCodecConfigFramerate());
|
||||||
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, keyFrameIntervalSec);
|
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, keyFrameIntervalSec);
|
||||||
if (codecType == VideoCodecType.H264) {
|
if (codecType == VideoCodecType.H264) {
|
||||||
String profileLevelId = params.get(VideoCodecInfo.H264_FMTP_PROFILE_LEVEL_ID);
|
String profileLevelId = params.get(VideoCodecInfo.H264_FMTP_PROFILE_LEVEL_ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user