Optimize decoder capability checking

This commit is contained in:
Cameron Gutman 2019-12-14 15:20:44 -08:00
parent af6b8c9b88
commit 88930a9de4
2 changed files with 27 additions and 26 deletions

View File

@ -267,21 +267,26 @@ bool Session::isHardwareDecodeAvailable(SDL_Window* window,
return ret; return ret;
} }
int Session::getDecoderCapabilities(SDL_Window* window, bool Session::populateDecoderProperties(SDL_Window* window)
StreamingPreferences::VideoDecoderSelection vds,
int videoFormat, int width, int height, int frameRate)
{ {
IVideoDecoder* decoder; IVideoDecoder* decoder;
if (!chooseDecoder(vds, window, videoFormat, width, height, frameRate, true, false, true, decoder)) { if (!chooseDecoder(m_Preferences->videoDecoderSelection,
window,
m_StreamConfig.enableHdr ? VIDEO_FORMAT_H265_MAIN10 :
(m_StreamConfig.supportsHevc ? VIDEO_FORMAT_H265 : VIDEO_FORMAT_H264),
m_StreamConfig.width,
m_StreamConfig.height,
m_StreamConfig.fps,
true, false, true, decoder)) {
return false; return false;
} }
int caps = decoder->getDecoderCapabilities(); m_VideoCallbacks.capabilities |= decoder->getDecoderCapabilities();
delete decoder; delete decoder;
return caps; return true;
} }
Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *preferences) Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *preferences)
@ -430,15 +435,6 @@ bool Session::initialize()
break; break;
} }
// Add the capability flags from the chosen decoder/renderer
// Requires m_StreamConfig.supportsHevc to be initialized
m_VideoCallbacks.capabilities |= getDecoderCapabilities(testWindow,
m_Preferences->videoDecoderSelection,
m_StreamConfig.supportsHevc ? VIDEO_FORMAT_H265 : VIDEO_FORMAT_H264,
m_StreamConfig.width,
m_StreamConfig.height,
m_StreamConfig.fps);
switch (m_Preferences->windowMode) switch (m_Preferences->windowMode)
{ {
default: default:
@ -454,6 +450,12 @@ bool Session::initialize()
// signals for them, if appropriate // signals for them, if appropriate
bool ret = validateLaunch(testWindow); bool ret = validateLaunch(testWindow);
if (ret) {
// Populate decoder-dependent properties.
// Must be done after validateLaunch() since m_StreamConfig is finalized.
ret = populateDecoderProperties(testWindow);
}
SDL_DestroyWindow(testWindow); SDL_DestroyWindow(testWindow);
if (!ret) { if (!ret) {
@ -500,13 +502,14 @@ bool Session::validateLaunch(SDL_Window* testWindow)
bool hevcForced = m_Preferences->videoCodecConfig == StreamingPreferences::VCC_FORCE_HEVC || bool hevcForced = m_Preferences->videoCodecConfig == StreamingPreferences::VCC_FORCE_HEVC ||
m_Preferences->videoCodecConfig == StreamingPreferences::VCC_FORCE_HEVC_HDR; m_Preferences->videoCodecConfig == StreamingPreferences::VCC_FORCE_HEVC_HDR;
if (!isHardwareDecodeAvailable(testWindow, if (m_Preferences->videoDecoderSelection == StreamingPreferences::VDS_AUTO && // Force hardware decoding checked below
m_Preferences->videoDecoderSelection, m_Preferences->videoCodecConfig != StreamingPreferences::VCC_AUTO && // Already checked in initialize()
VIDEO_FORMAT_H265, !isHardwareDecodeAvailable(testWindow,
m_StreamConfig.width, m_Preferences->videoDecoderSelection,
m_StreamConfig.height, VIDEO_FORMAT_H265,
m_StreamConfig.fps) && m_StreamConfig.width,
m_Preferences->videoDecoderSelection == StreamingPreferences::VDS_AUTO) { m_StreamConfig.height,
m_StreamConfig.fps)) {
if (hevcForced) { if (hevcForced) {
emitLaunchWarning("Using software decoding due to your selection to force HEVC without GPU support. This may cause poor streaming performance."); emitLaunchWarning("Using software decoding due to your selection to force HEVC without GPU support. This may cause poor streaming performance.");
} }
@ -592,6 +595,7 @@ bool Session::validateLaunch(SDL_Window* testWindow)
} }
if (m_Preferences->videoDecoderSelection == StreamingPreferences::VDS_FORCE_HARDWARE && if (m_Preferences->videoDecoderSelection == StreamingPreferences::VDS_FORCE_HARDWARE &&
!m_StreamConfig.enableHdr && // HEVC Main10 was already checked for hardware decode support above
!isHardwareDecodeAvailable(testWindow, !isHardwareDecodeAvailable(testWindow,
m_Preferences->videoDecoderSelection, m_Preferences->videoDecoderSelection,
m_StreamConfig.supportsHevc ? VIDEO_FORMAT_H265 : VIDEO_FORMAT_H264, m_StreamConfig.supportsHevc ? VIDEO_FORMAT_H265 : VIDEO_FORMAT_H264,

View File

@ -61,10 +61,7 @@ private:
void emitLaunchWarning(QString text); void emitLaunchWarning(QString text);
static bool populateDecoderProperties(SDL_Window* window);
int getDecoderCapabilities(SDL_Window* window,
StreamingPreferences::VideoDecoderSelection vds,
int videoFormat, int width, int height, int frameRate);
IAudioRenderer* createAudioRenderer(const POPUS_MULTISTREAM_CONFIGURATION opusConfig); IAudioRenderer* createAudioRenderer(const POPUS_MULTISTREAM_CONFIGURATION opusConfig);