Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Improve handling of unsupported resolutions
Adds a check in VirtualDisplayEncoder for unsupported resolutions that makes the virtual display encoder fail to start, prints a more helpful error message, and propagates an exception to the video stream manager
Changes in VideoStreamManager now kill the video stream service when the encoder fails to start, allowing for subsequent streams to start after an encoder error
  • Loading branch information
noah-livio committed Apr 5, 2022
commit 5d5d08215df8bf8eb7621fd6ae60f7752c644457
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