Support using VP9 video codec in AppRTCDemo.

- Add peer connection Java API to initialize field trial string.
- Add setting option to select VP8 or Vp9 as default video codec.
- Minor code clean up and allowing 720p portrait encoding.

R=wzh@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/39899004

Cr-Commit-Position: refs/heads/master@{#8303}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8303 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
glaznev@webrtc.org
2015-02-09 23:25:58 +00:00
parent f7e6cfd3a0
commit 44ae4c8b07
12 changed files with 98 additions and 62 deletions

View File

@@ -34,7 +34,6 @@ import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.net.Uri;
import android.opengl.GLSurfaceView;
@@ -93,7 +92,8 @@ public class AppRTCDemoActivity extends Activity
private boolean activityRunning;
private int runTimeMs;
private int startBitrate;
private boolean hwCodec;
private String videoCodec;
private boolean hwCodecAcceleration;
private boolean iceConnected;
private boolean isError;
@@ -216,7 +216,13 @@ public class AppRTCDemoActivity extends Activity
ConnectActivity.EXTRA_CMDLINE, false);
runTimeMs = intent.getIntExtra(ConnectActivity.EXTRA_RUNTIME, 0);
startBitrate = intent.getIntExtra(ConnectActivity.EXTRA_BITRATE, 0);
hwCodec = intent.getBooleanExtra(ConnectActivity.EXTRA_HWCODEC, true);
if (intent.hasExtra(ConnectActivity.EXTRA_VIDEOCODEC)) {
videoCodec = intent.getStringExtra(ConnectActivity.EXTRA_VIDEOCODEC);
} else {
videoCodec = PeerConnectionClient.VIDEO_CODEC_VP8; // use VP8 by default.
}
hwCodecAcceleration = intent.getBooleanExtra(
ConnectActivity.EXTRA_HWCODEC, true);
if (url != null) {
if (loopback || (roomName != null && !roomName.equals(""))) {
@@ -269,14 +275,14 @@ public class AppRTCDemoActivity extends Activity
// Create peer connection factory when EGL context is ready.
private void createPeerConnectionFactory() {
final AppRTCDemoActivity thisCopy = this;
runOnUiThread(new Runnable() {
@Override
public void run() {
if (pc == null) {
pc = new PeerConnectionClient();
pc.createPeerConnectionFactory(
thisCopy, hwCodec, VideoRendererGui.getEGLContext(), thisCopy);
pc.createPeerConnectionFactory(AppRTCDemoActivity.this,
videoCodec, hwCodecAcceleration,
VideoRendererGui.getEGLContext(), AppRTCDemoActivity.this);
}
if (signalingParameters != null) {
Log.w(TAG, "EGL context is ready after room connection.");
@@ -499,11 +505,6 @@ public class AppRTCDemoActivity extends Activity
logAndToast("Creating peer connection...");
pc.createPeerConnection(
localRender, remoteRender, signalingParameters, startBitrate);
if (pc.isHDVideo()) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
// Schedule statistics display.
final Runnable repeatedStatsLogger = new Runnable() {
@@ -533,7 +534,8 @@ public class AppRTCDemoActivity extends Activity
}
}, null);
if (!success) {
Log.e(TAG, "getStats() return false!");
Log.w(TAG, "getStats() return false!");
videoView.postDelayed(runnableThis, 1000);
}
}
};

View File

@@ -67,6 +67,7 @@ public class ConnectActivity extends Activity {
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_BITRATE = "org.appspot.apprtc.BITRATE";
public static final String EXTRA_VIDEOCODEC = "org.appspot.apprtc.VIDEOCODEC";
public static final String EXTRA_HWCODEC = "org.appspot.apprtc.HWCODEC";
private static final String TAG = "ConnectActivity";
private static final int CONNECTION_REQUEST = 1;
@@ -83,7 +84,8 @@ public class ConnectActivity extends Activity {
private String keyprefFps;
private String keyprefBitrateType;
private String keyprefBitrateValue;
private String keyprefHwCodec;
private String keyprefVideoCodec;
private String keyprefHwCodecAcceleration;
private String keyprefCpuUsageDetection;
private String keyprefRoomServerUrl;
private String keyprefRoom;
@@ -102,7 +104,8 @@ public class ConnectActivity extends Activity {
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);
keyprefVideoCodec = getString(R.string.pref_videocodec_key);
keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key);
keyprefCpuUsageDetection = getString(R.string.pref_cpu_usage_detection_key);
keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key);
keyprefRoom = getString(R.string.pref_room_key);
@@ -256,8 +259,12 @@ public class ConnectActivity extends Activity {
getString(R.string.pref_room_server_url_default));
url = WebSocketRTCClient.getGAEConnectionUrl(url, roomName);
// Get default video codec.
String videoCodec = sharedPref.getString(keyprefVideoCodec,
getString(R.string.pref_videocodec_default));
// Check HW codec flag.
boolean hwCodec = sharedPref.getBoolean(keyprefHwCodec,
boolean hwCodec = sharedPref.getBoolean(keyprefHwCodecAcceleration,
Boolean.valueOf(getString(R.string.pref_hwcodec_default)));
// Add video resolution constraints.
@@ -345,6 +352,7 @@ public class ConnectActivity extends Activity {
intent.putExtra(EXTRA_CMDLINE, commandLineRun);
intent.putExtra(EXTRA_RUNTIME, runTimeMs);
intent.putExtra(EXTRA_BITRATE, startBitrate);
intent.putExtra(EXTRA_VIDEOCODEC, videoCodec);
intent.putExtra(EXTRA_HWCODEC, hwCodec);
startActivityForResult(intent, CONNECTION_REQUEST);
}

View File

@@ -37,7 +37,6 @@ import android.util.Log;
import org.webrtc.DataChannel;
import org.webrtc.IceCandidate;
import org.webrtc.MediaConstraints;
import org.webrtc.MediaConstraints.KeyValuePair;
import org.webrtc.MediaStream;
import org.webrtc.MediaStreamTrack;
import org.webrtc.PeerConnection;
@@ -64,6 +63,9 @@ import java.util.regex.Pattern;
public class PeerConnectionClient {
private static final String TAG = "PCRTCClient";
private static final boolean PREFER_ISAC = false;
public static final String VIDEO_CODEC_VP8 = "VP8";
public static final String VIDEO_CODEC_VP9 = "VP9";
private static final String FIELD_TRIAL_VP9 = "WebRTC-SupportVP9/Enabled/";
public static final String VIDEO_TRACK_ID = "ARDAMSv0";
public static final String AUDIO_TRACK_ID = "ARDAMSa0";
@@ -134,7 +136,8 @@ public class PeerConnectionClient {
public void createPeerConnectionFactory(
final Context context,
final boolean vp8HwAcceleration,
final String videoCodec,
final boolean videoCodecHwAcceleration,
final EGLContext renderEGLContext,
final PeerConnectionEvents events) {
this.events = events;
@@ -143,7 +146,7 @@ public class PeerConnectionClient {
@Override
public void run() {
createPeerConnectionFactoryInternal(
context, vp8HwAcceleration, renderEGLContext);
context, videoCodec, videoCodecHwAcceleration, renderEGLContext);
}
});
}
@@ -177,13 +180,19 @@ public class PeerConnectionClient {
private void createPeerConnectionFactoryInternal(
Context context,
boolean vp8HwAcceleration,
String videoCodec,
boolean videoCodecHwAcceleration,
EGLContext renderEGLContext) {
Log.d(TAG, "Create peer connection factory with EGLContext "
+ renderEGLContext);
isError = false;
if (videoCodec.equals(VIDEO_CODEC_VP9)) {
PeerConnectionFactory.initializeFieldTrials(FIELD_TRIAL_VP9);
} else {
PeerConnectionFactory.initializeFieldTrials(null);
}
if (!PeerConnectionFactory.initializeAndroidGlobals(
context, true, true, vp8HwAcceleration, renderEGLContext)) {
context, true, true, videoCodecHwAcceleration, renderEGLContext)) {
events.onPeerConnectionError("Failed to initializeAndroidGlobals");
}
factory = new PeerConnectionFactory();
@@ -252,35 +261,6 @@ public class PeerConnectionClient {
events.onPeerConnectionClosed();
}
public boolean isHDVideo() {
if (signalingParameters.videoConstraints == null) {
return false;
}
int minWidth = 0;
int minHeight = 0;
for (KeyValuePair keyValuePair :
signalingParameters.videoConstraints.mandatory) {
if (keyValuePair.getKey().equals("minWidth")) {
try {
minWidth = Integer.parseInt(keyValuePair.getValue());
} catch (NumberFormatException e) {
Log.e(TAG, "Can not parse video width from video constraints");
}
} else if (keyValuePair.getKey().equals("minHeight")) {
try {
minHeight = Integer.parseInt(keyValuePair.getValue());
} catch (NumberFormatException e) {
Log.e(TAG, "Can not parse video height from video constraints");
}
}
}
if (minWidth * minHeight >= 1280 * 720) {
return true;
} else {
return false;
}
}
public boolean getStats(StatsObserver observer, MediaStreamTrack track) {
if (pc != null && !isError) {
return pc.getStats(observer, track);

View File

@@ -56,7 +56,6 @@ public class RoomParametersFetcher {
private static final String TAG = "RoomRTCClient";
private final RoomParametersFetcherEvents events;
private final boolean loopback;
private final String registerUrl;
private AsyncHttpURLConnection httpConnection;
/**
@@ -79,7 +78,6 @@ public class RoomParametersFetcher {
final RoomParametersFetcherEvents events) {
Log.d(TAG, "Connecting to room: " + registerUrl);
this.loopback = loopback;
this.registerUrl = registerUrl;
this.events = events;
httpConnection = new AsyncHttpURLConnection("POST", registerUrl, null,

View File

@@ -43,9 +43,9 @@ public class SettingsActivity extends Activity
private String keyprefFps;
private String keyprefStartBitrateType;
private String keyprefStartBitrateValue;
private String keyPrefVideoCodec;
private String keyprefHwCodec;
private String keyprefCpuUsageDetection;
private String keyprefSignaling;
private String keyPrefRoomServerUrl;
@Override
@@ -55,6 +55,7 @@ public class SettingsActivity extends Activity
keyprefFps = getString(R.string.pref_fps_key);
keyprefStartBitrateType = getString(R.string.pref_startbitrate_key);
keyprefStartBitrateValue = getString(R.string.pref_startbitratevalue_key);
keyPrefVideoCodec = getString(R.string.pref_videocodec_key);
keyprefHwCodec = getString(R.string.pref_hwcodec_key);
keyprefCpuUsageDetection = getString(R.string.pref_cpu_usage_detection_key);
keyPrefRoomServerUrl = getString(R.string.pref_room_server_url_key);
@@ -76,12 +77,12 @@ public class SettingsActivity extends Activity
updateSummary(sharedPreferences, keyprefResolution);
updateSummary(sharedPreferences, keyprefFps);
updateSummary(sharedPreferences, keyprefStartBitrateType);
updateSummary(sharedPreferences, keyPrefRoomServerUrl);
updateSummaryBitrate(sharedPreferences, keyprefStartBitrateValue);
setBitrateEnable(sharedPreferences);
updateSummary(sharedPreferences, keyPrefVideoCodec);
updateSummaryB(sharedPreferences, keyprefHwCodec);
updateSummaryB(sharedPreferences, keyprefCpuUsageDetection);
updateSummaryB(sharedPreferences, keyprefSignaling);
updateSummary(sharedPreferences, keyPrefRoomServerUrl);
}
@Override
@@ -98,12 +99,13 @@ public class SettingsActivity extends Activity
if (key.equals(keyprefResolution)
|| key.equals(keyprefFps)
|| key.equals(keyprefStartBitrateType)
|| key.equals(keyPrefRoomServerUrl)) {
|| key.equals(keyPrefRoomServerUrl)
|| key.equals(keyPrefVideoCodec)) {
updateSummary(sharedPreferences, key);
} else if (key.equals(keyprefStartBitrateValue)) {
updateSummaryBitrate(sharedPreferences, key);
} else if (key.equals(keyprefCpuUsageDetection)
|| key.equals(keyprefHwCodec) || key.equals(keyprefSignaling)) {
|| key.equals(keyprefHwCodec)) {
updateSummaryB(sharedPreferences, key);
}
if (key.equals(keyprefStartBitrateType)) {