Add start bitrate and vp8 hw acceleration option to
Android AppRTCDemo. - Add an option to set VP8 encoder start bitrate usig x-google-start-bitrate line in remote SDP. - Allow to enabled/disable VP8 hw decoder and encoder acceleration using appRTC settings. BUG=4046 R=jiayl@webrtc.org Review URL: https://webrtc-codereview.appspot.com/32539004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7775 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
32ec0dd032
commit
dea5173edf
@ -36,7 +36,7 @@ public class PeerConnectionAndroidTest extends ActivityTestCase {
|
|||||||
protected void setUp() {
|
protected void setUp() {
|
||||||
assertTrue(PeerConnectionFactory.initializeAndroidGlobals(
|
assertTrue(PeerConnectionFactory.initializeAndroidGlobals(
|
||||||
getInstrumentation().getContext(), true,
|
getInstrumentation().getContext(), true,
|
||||||
true, null));
|
true, true, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompleteSession() throws Exception {
|
public void testCompleteSession() throws Exception {
|
||||||
|
@ -163,6 +163,7 @@ static pthread_key_t g_jni_ptr;
|
|||||||
#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
|
#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
|
||||||
// Set in PeerConnectionFactory_initializeAndroidGlobals().
|
// Set in PeerConnectionFactory_initializeAndroidGlobals().
|
||||||
static bool factory_static_initialized = false;
|
static bool factory_static_initialized = false;
|
||||||
|
static bool vp8_hw_acceleration_enabled = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -2814,9 +2815,10 @@ JOW(jlong, PeerConnectionFactory_nativeCreateObserver)(
|
|||||||
JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)(
|
JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)(
|
||||||
JNIEnv* jni, jclass, jobject context,
|
JNIEnv* jni, jclass, jobject context,
|
||||||
jboolean initialize_audio, jboolean initialize_video,
|
jboolean initialize_audio, jboolean initialize_video,
|
||||||
jobject render_egl_context) {
|
jboolean vp8_hw_acceleration, jobject render_egl_context) {
|
||||||
CHECK(g_jvm) << "JNI_OnLoad failed to run?";
|
CHECK(g_jvm) << "JNI_OnLoad failed to run?";
|
||||||
bool failure = false;
|
bool failure = false;
|
||||||
|
vp8_hw_acceleration_enabled = vp8_hw_acceleration;
|
||||||
if (!factory_static_initialized) {
|
if (!factory_static_initialized) {
|
||||||
if (initialize_video) {
|
if (initialize_video) {
|
||||||
failure |= webrtc::SetCaptureAndroidVM(g_jvm, context);
|
failure |= webrtc::SetCaptureAndroidVM(g_jvm, context);
|
||||||
@ -2876,8 +2878,10 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
|
|||||||
scoped_ptr<cricket::WebRtcVideoEncoderFactory> encoder_factory;
|
scoped_ptr<cricket::WebRtcVideoEncoderFactory> encoder_factory;
|
||||||
scoped_ptr<cricket::WebRtcVideoDecoderFactory> decoder_factory;
|
scoped_ptr<cricket::WebRtcVideoDecoderFactory> decoder_factory;
|
||||||
#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
|
#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
|
||||||
encoder_factory.reset(new MediaCodecVideoEncoderFactory());
|
if (vp8_hw_acceleration_enabled) {
|
||||||
decoder_factory.reset(new MediaCodecVideoDecoderFactory());
|
encoder_factory.reset(new MediaCodecVideoEncoderFactory());
|
||||||
|
decoder_factory.reset(new MediaCodecVideoDecoderFactory());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
|
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
|
||||||
webrtc::CreatePeerConnectionFactory(worker_thread,
|
webrtc::CreatePeerConnectionFactory(worker_thread,
|
||||||
|
@ -51,7 +51,7 @@ public class PeerConnectionFactory {
|
|||||||
// decoding thread.
|
// decoding thread.
|
||||||
public static native boolean initializeAndroidGlobals(
|
public static native boolean initializeAndroidGlobals(
|
||||||
Object context, boolean initializeAudio, boolean initializeVideo,
|
Object context, boolean initializeAudio, boolean initializeVideo,
|
||||||
Object renderEGLContext);
|
boolean vp8HwAcceleration, Object renderEGLContext);
|
||||||
|
|
||||||
public PeerConnectionFactory() {
|
public PeerConnectionFactory() {
|
||||||
nativeFactory = nativeCreatePeerConnectionFactory();
|
nativeFactory = nativeCreatePeerConnectionFactory();
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="#800000FF"
|
android:textColor="#C000FF00"
|
||||||
android:textSize="12dp"
|
android:textSize="12dp"
|
||||||
android:layout_margin="8dp"/>
|
android:layout_margin="8dp"/>
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -19,4 +19,10 @@
|
|||||||
<item>30 fps</item>
|
<item>30 fps</item>
|
||||||
<item>15 fps</item>
|
<item>15 fps</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="startBitrate">
|
||||||
|
<item>Default</item>
|
||||||
|
<item>Manual</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -41,6 +41,24 @@
|
|||||||
<string name="pref_cpu_usage_detection_title">CPU overuse detection.</string>
|
<string name="pref_cpu_usage_detection_title">CPU overuse detection.</string>
|
||||||
<string name="pref_cpu_usage_detection_dlg">Adapt transmission to CPU status.</string>
|
<string name="pref_cpu_usage_detection_dlg">Adapt transmission to CPU status.</string>
|
||||||
<string name="pref_cpu_usage_detection_default">true</string>
|
<string name="pref_cpu_usage_detection_default">true</string>
|
||||||
<string name="pref_cpu_usage_detection_on">Enabled</string>
|
|
||||||
<string name="pref_cpu_usage_detection_off">Disabled</string>
|
<string name="pref_startbitrate_key">startbitrate_preference</string>
|
||||||
|
<string name="pref_startbitrate_title">Start bitrate setting.</string>
|
||||||
|
<string name="pref_startbitrate_dlg">Start bitrate setting.</string>
|
||||||
|
<string name="pref_startbitrate_default">Default</string>
|
||||||
|
|
||||||
|
<string name="pref_startbitratevalue_key">startbitratevalue_preference</string>
|
||||||
|
<string name="pref_startbitratevalue_title">Video encoder start bitrate.</string>
|
||||||
|
<string name="pref_startbitratevalue_dlg">Enter video encoder start bitrate in kbps.</string>
|
||||||
|
<string name="pref_startbitratevalue_default">1000</string>
|
||||||
|
|
||||||
|
<string name="pref_hwcodec_key">hwcodec_preference</string>
|
||||||
|
<string name="pref_hwcodec_title">VP8 hardware acceleration.</string>
|
||||||
|
<string name="pref_hwcodec_dlg">Use VP8 VP8 hardware accelerated codec (if available).</string>
|
||||||
|
<string name="pref_hwcodec_default">true</string>
|
||||||
|
|
||||||
|
<string name="pref_value_enabled">Enabled</string>
|
||||||
|
<string name="pref_value_disabled">Disabled</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
android:dialogTitle="@string/pref_resolution_dlg"
|
android:dialogTitle="@string/pref_resolution_dlg"
|
||||||
android:entries="@array/videoResolutions"
|
android:entries="@array/videoResolutions"
|
||||||
android:entryValues="@array/videoResolutionsValues" />
|
android:entryValues="@array/videoResolutionsValues" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="@string/pref_fps_key"
|
android:key="@string/pref_fps_key"
|
||||||
android:title="@string/pref_fps_title"
|
android:title="@string/pref_fps_title"
|
||||||
@ -14,10 +15,33 @@
|
|||||||
android:dialogTitle="@string/pref_fps_dlg"
|
android:dialogTitle="@string/pref_fps_dlg"
|
||||||
android:entries="@array/cameraFps"
|
android:entries="@array/cameraFps"
|
||||||
android:entryValues="@array/cameraFps" />
|
android:entryValues="@array/cameraFps" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="@string/pref_startbitrate_key"
|
||||||
|
android:title="@string/pref_startbitrate_title"
|
||||||
|
android:defaultValue="@string/pref_startbitrate_default"
|
||||||
|
android:dialogTitle="@string/pref_startbitrate_dlg"
|
||||||
|
android:entries="@array/startBitrate"
|
||||||
|
android:entryValues="@array/startBitrate" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:key="@string/pref_startbitratevalue_key"
|
||||||
|
android:title="@string/pref_startbitratevalue_title"
|
||||||
|
android:inputType="number"
|
||||||
|
android:defaultValue="@string/pref_startbitratevalue_default"
|
||||||
|
android:dialogTitle="@string/pref_startbitratevalue_dlg" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="@string/pref_hwcodec_key"
|
||||||
|
android:title="@string/pref_hwcodec_title"
|
||||||
|
android:dialogTitle="@string/pref_hwcodec_dlg"
|
||||||
|
android:defaultValue="@string/pref_hwcodec_default" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="@string/pref_cpu_usage_detection_key"
|
android:key="@string/pref_cpu_usage_detection_key"
|
||||||
android:title="@string/pref_cpu_usage_detection_title"
|
android:title="@string/pref_cpu_usage_detection_title"
|
||||||
android:dialogTitle="@string/pref_cpu_usage_detection_dlg"
|
android:dialogTitle="@string/pref_cpu_usage_detection_dlg"
|
||||||
android:defaultValue="@string/pref_cpu_usage_detection_default" />
|
android:defaultValue="@string/pref_cpu_usage_detection_default" />
|
||||||
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@ -91,6 +91,8 @@ public class AppRTCDemoActivity extends Activity
|
|||||||
private ImageButton videoScalingButton;
|
private ImageButton videoScalingButton;
|
||||||
private boolean commandLineRun;
|
private boolean commandLineRun;
|
||||||
private int runTimeMs;
|
private int runTimeMs;
|
||||||
|
private int startBitrate;
|
||||||
|
private boolean hwCodec;
|
||||||
private boolean iceConnected;
|
private boolean iceConnected;
|
||||||
private boolean isError;
|
private boolean isError;
|
||||||
|
|
||||||
@ -208,8 +210,10 @@ public class AppRTCDemoActivity extends Activity
|
|||||||
ConnectActivity.EXTRA_LOOPBACK, false);
|
ConnectActivity.EXTRA_LOOPBACK, false);
|
||||||
commandLineRun = intent.getBooleanExtra(
|
commandLineRun = intent.getBooleanExtra(
|
||||||
ConnectActivity.EXTRA_CMDLINE, false);
|
ConnectActivity.EXTRA_CMDLINE, false);
|
||||||
runTimeMs = intent.getIntExtra(
|
runTimeMs = intent.getIntExtra(ConnectActivity.EXTRA_RUNTIME, 0);
|
||||||
ConnectActivity.EXTRA_RUNTIME, 0);
|
startBitrate = intent.getIntExtra(ConnectActivity.EXTRA_BITRATE, 0);
|
||||||
|
hwCodec = intent.getBooleanExtra(ConnectActivity.EXTRA_HWCODEC, true);
|
||||||
|
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
String room = url.getQueryParameter("r");
|
String room = url.getQueryParameter("r");
|
||||||
if (loopback || (room != null && !room.equals(""))) {
|
if (loopback || (room != null && !room.equals(""))) {
|
||||||
@ -452,11 +456,11 @@ public class AppRTCDemoActivity extends Activity
|
|||||||
}
|
}
|
||||||
signalingParameters = params;
|
signalingParameters = params;
|
||||||
abortUnless(PeerConnectionFactory.initializeAndroidGlobals(
|
abortUnless(PeerConnectionFactory.initializeAndroidGlobals(
|
||||||
this, true, true, VideoRendererGui.getEGLContext()),
|
this, true, true, hwCodec, VideoRendererGui.getEGLContext()),
|
||||||
"Failed to initializeAndroidGlobals");
|
"Failed to initializeAndroidGlobals");
|
||||||
logAndToast("Creating peer connection...");
|
logAndToast("Creating peer connection...");
|
||||||
pc = new PeerConnectionClient(
|
pc = new PeerConnectionClient( this, localRender, remoteRender,
|
||||||
this, localRender, remoteRender, signalingParameters, this);
|
signalingParameters, this, startBitrate);
|
||||||
if (pc.isHDVideo()) {
|
if (pc.isHDVideo()) {
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,6 +65,8 @@ public class ConnectActivity extends Activity {
|
|||||||
public static final String EXTRA_LOOPBACK = "org.appspot.apprtc.LOOPBACK";
|
public static final String EXTRA_LOOPBACK = "org.appspot.apprtc.LOOPBACK";
|
||||||
public static final String EXTRA_CMDLINE = "org.appspot.apprtc.CMDLINE";
|
public static final String EXTRA_CMDLINE = "org.appspot.apprtc.CMDLINE";
|
||||||
public static final String EXTRA_RUNTIME = "org.appspot.apprtc.RUNTIME";
|
public static final String EXTRA_RUNTIME = "org.appspot.apprtc.RUNTIME";
|
||||||
|
public static final String EXTRA_BITRATE = "org.appspot.apprtc.BITRATE";
|
||||||
|
public static final String EXTRA_HWCODEC = "org.appspot.apprtc.HWCODEC";
|
||||||
private static final String TAG = "ConnectActivity";
|
private static final String TAG = "ConnectActivity";
|
||||||
private final boolean USE_WEBSOCKETS = false;
|
private final boolean USE_WEBSOCKETS = false;
|
||||||
private final String APPRTC_SERVER = "https://apprtc.appspot.com";
|
private final String APPRTC_SERVER = "https://apprtc.appspot.com";
|
||||||
@ -80,6 +82,9 @@ public class ConnectActivity extends Activity {
|
|||||||
private SharedPreferences sharedPref;
|
private SharedPreferences sharedPref;
|
||||||
private String keyprefResolution;
|
private String keyprefResolution;
|
||||||
private String keyprefFps;
|
private String keyprefFps;
|
||||||
|
private String keyprefBitrateType;
|
||||||
|
private String keyprefBitrateValue;
|
||||||
|
private String keyprefHwCodec;
|
||||||
private String keyprefCpuUsageDetection;
|
private String keyprefCpuUsageDetection;
|
||||||
private String keyprefRoom;
|
private String keyprefRoom;
|
||||||
private String keyprefRoomList;
|
private String keyprefRoomList;
|
||||||
@ -97,6 +102,9 @@ public class ConnectActivity extends Activity {
|
|||||||
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
keyprefResolution = getString(R.string.pref_resolution_key);
|
keyprefResolution = getString(R.string.pref_resolution_key);
|
||||||
keyprefFps = getString(R.string.pref_fps_key);
|
keyprefFps = getString(R.string.pref_fps_key);
|
||||||
|
keyprefBitrateType = getString(R.string.pref_startbitrate_key);
|
||||||
|
keyprefBitrateValue = getString(R.string.pref_startbitratevalue_key);
|
||||||
|
keyprefHwCodec = getString(R.string.pref_hwcodec_key);
|
||||||
keyprefCpuUsageDetection = getString(R.string.pref_cpu_usage_detection_key);
|
keyprefCpuUsageDetection = getString(R.string.pref_cpu_usage_detection_key);
|
||||||
keyprefRoom = getString(R.string.pref_room_key);
|
keyprefRoom = getString(R.string.pref_room_key);
|
||||||
keyprefRoomList = getString(R.string.pref_room_list_key);
|
keyprefRoomList = getString(R.string.pref_room_list_key);
|
||||||
@ -142,7 +150,7 @@ public class ConnectActivity extends Activity {
|
|||||||
if (loopback && !url.contains("debug=loopback")) {
|
if (loopback && !url.contains("debug=loopback")) {
|
||||||
url += "/?debug=loopback";
|
url += "/?debug=loopback";
|
||||||
}
|
}
|
||||||
connectToRoom(url, loopback);
|
connectToRoom(url, loopback, 0, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,9 +242,12 @@ public class ConnectActivity extends Activity {
|
|||||||
}
|
}
|
||||||
url += "/?r=" + roomName;
|
url += "/?r=" + roomName;
|
||||||
}
|
}
|
||||||
|
// Check HW codec flag.
|
||||||
|
boolean hwCodec = sharedPref.getBoolean(keyprefHwCodec,
|
||||||
|
Boolean.valueOf(getString(R.string.pref_hwcodec_default)));
|
||||||
|
// Add video resolution constraints.
|
||||||
String parametersResolution = null;
|
String parametersResolution = null;
|
||||||
String parametersFps = null;
|
String parametersFps = null;
|
||||||
// Add video resolution constraints.
|
|
||||||
String resolution = sharedPref.getString(keyprefResolution,
|
String resolution = sharedPref.getString(keyprefResolution,
|
||||||
getString(R.string.pref_resolution_default));
|
getString(R.string.pref_resolution_default));
|
||||||
String[] dimensions = resolution.split("[ x]+");
|
String[] dimensions = resolution.split("[ x]+");
|
||||||
@ -280,10 +291,20 @@ public class ConnectActivity extends Activity {
|
|||||||
url += parametersFps;
|
url += parametersFps;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (MediaCodecVideoEncoder.isPlatformSupported()) {
|
if (hwCodec && MediaCodecVideoEncoder.isPlatformSupported()) {
|
||||||
url += "&hd=true";
|
url += "&hd=true";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Get start bitrate.
|
||||||
|
int startBitrate = 0;
|
||||||
|
String bitrateTypeDefault = getString(R.string.pref_startbitrate_default);
|
||||||
|
String bitrateType = sharedPref.getString(
|
||||||
|
keyprefBitrateType, bitrateTypeDefault);
|
||||||
|
if (!bitrateType.equals(bitrateTypeDefault)) {
|
||||||
|
String bitrateValue = sharedPref.getString(keyprefBitrateValue,
|
||||||
|
getString(R.string.pref_startbitratevalue_default));
|
||||||
|
startBitrate = Integer.parseInt(bitrateValue);
|
||||||
|
}
|
||||||
// Test if CpuOveruseDetection should be disabled. By default is on.
|
// Test if CpuOveruseDetection should be disabled. By default is on.
|
||||||
boolean cpuOveruseDetection = sharedPref.getBoolean(
|
boolean cpuOveruseDetection = sharedPref.getBoolean(
|
||||||
keyprefCpuUsageDetection,
|
keyprefCpuUsageDetection,
|
||||||
@ -293,11 +314,12 @@ public class ConnectActivity extends Activity {
|
|||||||
url += "&googCpuOveruseDetection=false";
|
url += "&googCpuOveruseDetection=false";
|
||||||
}
|
}
|
||||||
// TODO(kjellander): Add support for custom parameters to the URL.
|
// TODO(kjellander): Add support for custom parameters to the URL.
|
||||||
connectToRoom(url, loopback);
|
connectToRoom(url, loopback, startBitrate, hwCodec);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void connectToRoom(String roomUrl, boolean loopback) {
|
private void connectToRoom(
|
||||||
|
String roomUrl, boolean loopback, int startBitrate, boolean hwCodec) {
|
||||||
if (validateUrl(roomUrl)) {
|
if (validateUrl(roomUrl)) {
|
||||||
Uri url = Uri.parse(roomUrl);
|
Uri url = Uri.parse(roomUrl);
|
||||||
Intent intent = new Intent(this, AppRTCDemoActivity.class);
|
Intent intent = new Intent(this, AppRTCDemoActivity.class);
|
||||||
@ -305,6 +327,8 @@ public class ConnectActivity extends Activity {
|
|||||||
intent.putExtra(EXTRA_LOOPBACK, loopback);
|
intent.putExtra(EXTRA_LOOPBACK, loopback);
|
||||||
intent.putExtra(EXTRA_CMDLINE, commandLineRun);
|
intent.putExtra(EXTRA_CMDLINE, commandLineRun);
|
||||||
intent.putExtra(EXTRA_RUNTIME, runTimeMs);
|
intent.putExtra(EXTRA_RUNTIME, runTimeMs);
|
||||||
|
intent.putExtra(EXTRA_BITRATE, startBitrate);
|
||||||
|
intent.putExtra(EXTRA_HWCODEC, hwCodec);
|
||||||
startActivityForResult(intent, CONNECTION_REQUEST);
|
startActivityForResult(intent, CONNECTION_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@ public class PeerConnectionClient {
|
|||||||
private MediaConstraints sdpMediaConstraints;
|
private MediaConstraints sdpMediaConstraints;
|
||||||
private MediaConstraints videoConstraints;
|
private MediaConstraints videoConstraints;
|
||||||
private PeerConnectionEvents events;
|
private PeerConnectionEvents events;
|
||||||
|
private int startBitrate;
|
||||||
private boolean isInitiator;
|
private boolean isInitiator;
|
||||||
private boolean useFrontFacingCamera = true;
|
private boolean useFrontFacingCamera = true;
|
||||||
private SessionDescription localSdp = null; // either offer or answer SDP
|
private SessionDescription localSdp = null; // either offer or answer SDP
|
||||||
@ -83,11 +84,13 @@ public class PeerConnectionClient {
|
|||||||
VideoRenderer.Callbacks localRender,
|
VideoRenderer.Callbacks localRender,
|
||||||
VideoRenderer.Callbacks remoteRender,
|
VideoRenderer.Callbacks remoteRender,
|
||||||
SignalingParameters signalingParameters,
|
SignalingParameters signalingParameters,
|
||||||
PeerConnectionEvents events) {
|
PeerConnectionEvents events,
|
||||||
|
int startBitrate) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.localRender = localRender;
|
this.localRender = localRender;
|
||||||
this.remoteRender = remoteRender;
|
this.remoteRender = remoteRender;
|
||||||
this.events = events;
|
this.events = events;
|
||||||
|
this.startBitrate = startBitrate;
|
||||||
isInitiator = signalingParameters.initiator;
|
isInitiator = signalingParameters.initiator;
|
||||||
queuedRemoteCandidates = new LinkedList<IceCandidate>();
|
queuedRemoteCandidates = new LinkedList<IceCandidate>();
|
||||||
|
|
||||||
@ -200,10 +203,14 @@ public class PeerConnectionClient {
|
|||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (pc != null) {
|
if (pc != null) {
|
||||||
SessionDescription sdpISAC = new SessionDescription(
|
String sdpDescription = preferISAC(sdp.description);
|
||||||
sdp.type, preferISAC(sdp.description));
|
if (startBitrate > 0) {
|
||||||
Log.d(TAG, "Set remote SDP");
|
sdpDescription = setStartBitrate(sdpDescription, startBitrate);
|
||||||
pc.setRemoteDescription(sdpObserver, sdpISAC);
|
}
|
||||||
|
Log.d(TAG, "Set remote SDP.");
|
||||||
|
SessionDescription sdpRemote = new SessionDescription(
|
||||||
|
sdp.type, sdpDescription);
|
||||||
|
pc.setRemoteDescription(sdpObserver, sdpRemote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -335,6 +342,39 @@ public class PeerConnectionClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String setStartBitrate(
|
||||||
|
String sdpDescription, int bitrateKbps) {
|
||||||
|
String[] lines = sdpDescription.split("\r\n");
|
||||||
|
int lineIndex = -1;
|
||||||
|
String vp8RtpMap = null;
|
||||||
|
Pattern vp8Pattern =
|
||||||
|
Pattern.compile("^a=rtpmap:(\\d+) VP8/90000[\r]?$");
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
Matcher vp8Matcher = vp8Pattern.matcher(lines[i]);
|
||||||
|
if (vp8Matcher.matches()) {
|
||||||
|
vp8RtpMap = vp8Matcher.group(1);
|
||||||
|
lineIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vp8RtpMap == null) {
|
||||||
|
Log.e(TAG, "No rtpmap for VP8 codec");
|
||||||
|
return sdpDescription;
|
||||||
|
}
|
||||||
|
Log.d(TAG, "Found rtpmap " + vp8RtpMap + " at " + lines[lineIndex]);
|
||||||
|
StringBuilder newSdpDescription = new StringBuilder();
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
newSdpDescription.append(lines[i]).append("\r\n");
|
||||||
|
if (i == lineIndex) {
|
||||||
|
String bitrateSet = "a=fmtp:" + vp8RtpMap +
|
||||||
|
" x-google-start-bitrate=" + bitrateKbps;
|
||||||
|
Log.d(TAG, "Add remote SDP line: " + bitrateSet);
|
||||||
|
newSdpDescription.append(bitrateSet).append("\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newSdpDescription.toString();
|
||||||
|
}
|
||||||
|
|
||||||
// Mangle SDP to prefer ISAC/16000 over any other audio codec.
|
// Mangle SDP to prefer ISAC/16000 over any other audio codec.
|
||||||
private static String preferISAC(String sdpDescription) {
|
private static String preferISAC(String sdpDescription) {
|
||||||
String[] lines = sdpDescription.split("\r\n");
|
String[] lines = sdpDescription.split("\r\n");
|
||||||
|
@ -38,6 +38,9 @@ public class SettingsActivity extends Activity
|
|||||||
private SettingsFragment settingsFragment;
|
private SettingsFragment settingsFragment;
|
||||||
private String keyprefResolution;
|
private String keyprefResolution;
|
||||||
private String keyprefFps;
|
private String keyprefFps;
|
||||||
|
private String keyprefStartBitrateType;
|
||||||
|
private String keyprefStartBitrateValue;
|
||||||
|
private String keyprefHwCodec;
|
||||||
private String keyprefCpuUsageDetection;
|
private String keyprefCpuUsageDetection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -45,6 +48,9 @@ public class SettingsActivity extends Activity
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
keyprefResolution = getString(R.string.pref_resolution_key);
|
keyprefResolution = getString(R.string.pref_resolution_key);
|
||||||
keyprefFps = getString(R.string.pref_fps_key);
|
keyprefFps = getString(R.string.pref_fps_key);
|
||||||
|
keyprefStartBitrateType = getString(R.string.pref_startbitrate_key);
|
||||||
|
keyprefStartBitrateValue = getString(R.string.pref_startbitratevalue_key);
|
||||||
|
keyprefHwCodec = getString(R.string.pref_hwcodec_key);
|
||||||
keyprefCpuUsageDetection = getString(R.string.pref_cpu_usage_detection_key);
|
keyprefCpuUsageDetection = getString(R.string.pref_cpu_usage_detection_key);
|
||||||
|
|
||||||
// Display the fragment as the main content.
|
// Display the fragment as the main content.
|
||||||
@ -63,6 +69,10 @@ public class SettingsActivity extends Activity
|
|||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
updateSummary(sharedPreferences, keyprefResolution);
|
updateSummary(sharedPreferences, keyprefResolution);
|
||||||
updateSummary(sharedPreferences, keyprefFps);
|
updateSummary(sharedPreferences, keyprefFps);
|
||||||
|
updateSummary(sharedPreferences, keyprefStartBitrateType);
|
||||||
|
updateSummaryBitrate(sharedPreferences, keyprefStartBitrateValue);
|
||||||
|
setBitrateEnable(sharedPreferences);
|
||||||
|
updateSummaryB(sharedPreferences, keyprefHwCodec);
|
||||||
updateSummaryB(sharedPreferences, keyprefCpuUsageDetection);
|
updateSummaryB(sharedPreferences, keyprefCpuUsageDetection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +87,18 @@ public class SettingsActivity extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||||
String key) {
|
String key) {
|
||||||
if (key.equals(keyprefResolution) || key.equals(keyprefFps)) {
|
if (key.equals(keyprefResolution) || key.equals(keyprefFps) ||
|
||||||
|
key.equals(keyprefStartBitrateType)) {
|
||||||
updateSummary(sharedPreferences, key);
|
updateSummary(sharedPreferences, key);
|
||||||
} else if (key.equals(keyprefCpuUsageDetection)) {
|
} else if (key.equals(keyprefStartBitrateValue)) {
|
||||||
|
updateSummaryBitrate(sharedPreferences, key);
|
||||||
|
} else if (key.equals(keyprefCpuUsageDetection) ||
|
||||||
|
key.equals(keyprefHwCodec)) {
|
||||||
updateSummaryB(sharedPreferences, key);
|
updateSummaryB(sharedPreferences, key);
|
||||||
}
|
}
|
||||||
|
if (key.equals(keyprefStartBitrateType)) {
|
||||||
|
setBitrateEnable(sharedPreferences);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSummary(SharedPreferences sharedPreferences, String key) {
|
private void updateSummary(SharedPreferences sharedPreferences, String key) {
|
||||||
@ -90,11 +107,30 @@ public class SettingsActivity extends Activity
|
|||||||
updatedPref.setSummary(sharedPreferences.getString(key, ""));
|
updatedPref.setSummary(sharedPreferences.getString(key, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSummaryBitrate(
|
||||||
|
SharedPreferences sharedPreferences, String key) {
|
||||||
|
Preference updatedPref = settingsFragment.findPreference(key);
|
||||||
|
updatedPref.setSummary(sharedPreferences.getString(key, "") + " kbps");
|
||||||
|
}
|
||||||
|
|
||||||
private void updateSummaryB(SharedPreferences sharedPreferences, String key) {
|
private void updateSummaryB(SharedPreferences sharedPreferences, String key) {
|
||||||
Preference updatedPref = settingsFragment.findPreference(key);
|
Preference updatedPref = settingsFragment.findPreference(key);
|
||||||
updatedPref.setSummary(sharedPreferences.getBoolean(key, true)
|
updatedPref.setSummary(sharedPreferences.getBoolean(key, true)
|
||||||
? getString(R.string.pref_cpu_usage_detection_on)
|
? getString(R.string.pref_value_enabled)
|
||||||
: getString(R.string.pref_cpu_usage_detection_off));
|
: getString(R.string.pref_value_disabled));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBitrateEnable(SharedPreferences sharedPreferences) {
|
||||||
|
Preference bitratePreferenceValue =
|
||||||
|
settingsFragment.findPreference(keyprefStartBitrateValue);
|
||||||
|
String bitrateTypeDefault = getString(R.string.pref_startbitrate_default);
|
||||||
|
String bitrateType = sharedPreferences.getString(
|
||||||
|
keyprefStartBitrateType, bitrateTypeDefault);
|
||||||
|
if (bitrateType.equals(bitrateTypeDefault)) {
|
||||||
|
bitratePreferenceValue.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
bitratePreferenceValue.setEnabled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user