Skip to content

Commit c163c17

Browse files
authored
Improve handling of unsupported resolutions (#1804)
* 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 * Add missing spaces to if statements
1 parent 1abdbf8 commit c163c17

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

android/sdl_android/src/main/java/com/smartdevicelink/encoder/VirtualDisplayEncoder.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,27 @@ private Surface prepareVideoEncoder() {
480480
// Create a MediaCodec encoder and configure it. Get a Surface we can use for recording into.
481481
try {
482482
mVideoEncoder = MediaCodec.createEncoderByType(videoMimeType);
483+
484+
int width = streamingParams.getResolution().getResolutionWidth();
485+
int height = streamingParams.getResolution().getResolutionHeight();
486+
int frameRate = streamingParams.getFrameRate();
487+
488+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
489+
boolean streamSupported = mVideoEncoder.getCodecInfo()
490+
.getCapabilitiesForType(videoMimeType)
491+
.getVideoCapabilities()
492+
.areSizeAndRateSupported(width, height, frameRate);
493+
494+
if (!streamSupported) {
495+
String errorString = "Video streaming " + width + " by " + height + " at "
496+
+ frameRate + "fps is unsupported on this device";
497+
498+
DebugTool.logError(TAG, errorString);
499+
500+
return null;
501+
}
502+
}
503+
483504
mVideoEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
484505
Surface surface = mVideoEncoder.createInputSurface(); //prepared
485506

android/sdl_android/src/main/java/com/smartdevicelink/managers/video/VideoStreamManager.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,18 @@ public void onServiceStarted(SdlSession session, SessionType type, boolean isEnc
144144
hapticManager = new HapticInterfaceManager(internalInterface);
145145
}
146146
checkState();
147-
startEncoder();
148-
stateMachine.transitionToState(StreamingStateMachine.STARTED);
149-
hasStarted = true;
147+
boolean encoderStarted = startEncoder();
148+
if (encoderStarted) {
149+
stateMachine.transitionToState(StreamingStateMachine.STARTED);
150+
hasStarted = true;
151+
} else {
152+
DebugTool.logError(TAG, "Error starting video encoder");
153+
stateMachine.transitionToState(StreamingStateMachine.ERROR);
154+
withPendingRestart = false;
155+
if (session != null) {
156+
session.endService(SessionType.NAV);
157+
}
158+
}
150159
}
151160
}
152161

@@ -473,7 +482,7 @@ protected void startStreaming(VideoStreamingParameters parameters, boolean encry
473482
/**
474483
* Initializes and starts the virtual display encoder and creates the remote display
475484
*/
476-
private void startEncoder() {
485+
private boolean startEncoder() {
477486
try {
478487
if (remoteDisplay != null) {
479488
remoteDisplay.resizeView(parameters.getResolution().getResolutionWidth(), parameters.getResolution().getResolutionHeight());
@@ -490,7 +499,9 @@ private void startEncoder() {
490499
} catch (Exception e) {
491500
stateMachine.transitionToState(StreamingStateMachine.ERROR);
492501
e.printStackTrace();
502+
return false;
493503
}
504+
return true;
494505
}
495506

496507
/**

0 commit comments

Comments
 (0)