Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,27 @@ private Surface prepareVideoEncoder() {
// Create a MediaCodec encoder and configure it. Get a Surface we can use for recording into.
try {
mVideoEncoder = MediaCodec.createEncoderByType(videoMimeType);

int width = streamingParams.getResolution().getResolutionWidth();
int height = streamingParams.getResolution().getResolutionHeight();
int frameRate = streamingParams.getFrameRate();

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
boolean streamSupported = mVideoEncoder.getCodecInfo()
.getCapabilitiesForType(videoMimeType)
.getVideoCapabilities()
.areSizeAndRateSupported(width, height, frameRate);

if (!streamSupported) {
String errorString = "Video streaming " + width + " by " + height + " at "
+ frameRate + "fps is unsupported on this device";

DebugTool.logError(TAG, errorString);

return null;
}
}

mVideoEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
Surface surface = mVideoEncoder.createInputSurface(); //prepared

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,18 @@ public void onServiceStarted(SdlSession session, SessionType type, boolean isEnc
hapticManager = new HapticInterfaceManager(internalInterface);
}
checkState();
startEncoder();
stateMachine.transitionToState(StreamingStateMachine.STARTED);
hasStarted = true;
boolean encoderStarted = startEncoder();
if (encoderStarted) {
stateMachine.transitionToState(StreamingStateMachine.STARTED);
hasStarted = true;
} else {
DebugTool.logError(TAG, "Error starting video encoder");
stateMachine.transitionToState(StreamingStateMachine.ERROR);
withPendingRestart = false;
if (session != null) {
session.endService(SessionType.NAV);
}
}
}
}

Expand Down Expand Up @@ -473,7 +482,7 @@ protected void startStreaming(VideoStreamingParameters parameters, boolean encry
/**
* Initializes and starts the virtual display encoder and creates the remote display
*/
private void startEncoder() {
private boolean startEncoder() {
try {
if (remoteDisplay != null) {
remoteDisplay.resizeView(parameters.getResolution().getResolutionWidth(), parameters.getResolution().getResolutionHeight());
Expand All @@ -490,7 +499,9 @@ private void startEncoder() {
} catch (Exception e) {
stateMachine.transitionToState(StreamingStateMachine.ERROR);
e.printStackTrace();
return false;
}
return true;
}

/**
Expand Down