Added theme support for disabling audio playback for each defined video.

This commit is contained in:
Leon Styhre 2022-02-19 21:45:31 +01:00
parent 29514d4db9
commit f803e23fd2
4 changed files with 42 additions and 33 deletions

View file

@ -111,6 +111,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"defaultImage", PATH}, {"defaultImage", PATH},
{"imageType", STRING}, {"imageType", STRING},
{"gameselector", STRING}, {"gameselector", STRING},
{"audio", BOOLEAN},
{"interpolation", STRING}, {"interpolation", STRING},
{"pillarboxes", BOOLEAN}, {"pillarboxes", BOOLEAN},
{"scanlines", BOOLEAN}, {"scanlines", BOOLEAN},

View file

@ -32,6 +32,7 @@ VideoComponent::VideoComponent()
, mMediaViewerMode {false} , mMediaViewerMode {false}
, mScreensaverMode {false} , mScreensaverMode {false}
, mTargetIsMax {false} , mTargetIsMax {false}
, mPlayAudio {true}
, mDrawPillarboxes {true} , mDrawPillarboxes {true}
, mRenderScanlines {false} , mRenderScanlines {false}
, mLegacyTheme {false} , mLegacyTheme {false}
@ -132,6 +133,9 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mVideoAreaPos = elem->get<glm::vec2>("pos") * scale; mVideoAreaPos = elem->get<glm::vec2>("pos") * scale;
} }
if (elem->has("audio"))
mPlayAudio = elem->get<bool>("audio");
if (elem->has("interpolation")) { if (elem->has("interpolation")) {
const std::string interpolation {elem->get<std::string>("interpolation")}; const std::string interpolation {elem->get<std::string>("interpolation")};
if (interpolation == "linear") { if (interpolation == "linear") {

View file

@ -121,6 +121,7 @@ protected:
bool mMediaViewerMode; bool mMediaViewerMode;
bool mScreensaverMode; bool mScreensaverMode;
bool mTargetIsMax; bool mTargetIsMax;
bool mPlayAudio;
bool mDrawPillarboxes; bool mDrawPillarboxes;
bool mRenderScanlines; bool mRenderScanlines;
bool mLegacyTheme; bool mLegacyTheme;

View file

@ -1351,47 +1351,50 @@ void VideoFFmpegComponent::startVideoStream()
} }
// Audio stream setup, optional as some videos do not have any audio tracks. // Audio stream setup, optional as some videos do not have any audio tracks.
// Audio can also be disabled per video via the theme configuration.
mAudioStreamIndex = if (mPlayAudio) {
av_find_best_stream(mFormatContext, AVMEDIA_TYPE_AUDIO, -1, -1, nullptr, 0); mAudioStreamIndex =
av_find_best_stream(mFormatContext, AVMEDIA_TYPE_AUDIO, -1, -1, nullptr, 0);
if (mAudioStreamIndex < 0) { if (mAudioStreamIndex < 0) {
LOG(LogDebug) << "VideoFFmpegComponent::startVideoStream(): " LOG(LogDebug) << "VideoFFmpegComponent::startVideoStream(): "
"File does not seem to contain any audio streams"; "File does not seem to contain any audio streams";
}
if (mAudioStreamIndex >= 0) {
mAudioStream = mFormatContext->streams[mAudioStreamIndex];
mAudioCodec =
const_cast<AVCodec*>(avcodec_find_decoder(mAudioStream->codecpar->codec_id));
if (!mAudioCodec) {
LOG(LogError) << "Couldn't find a suitable audio codec for file \"" << mVideoPath
<< "\"";
return;
} }
mAudioCodecContext = avcodec_alloc_context3(mAudioCodec); if (mAudioStreamIndex >= 0) {
mAudioStream = mFormatContext->streams[mAudioStreamIndex];
mAudioCodec =
const_cast<AVCodec*>(avcodec_find_decoder(mAudioStream->codecpar->codec_id));
if (mAudioCodec->capabilities & AV_CODEC_CAP_TRUNCATED) if (!mAudioCodec) {
mAudioCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED; LOG(LogError) << "Couldn't find a suitable audio codec for file \""
<< mVideoPath << "\"";
return;
}
// Some formats want separate stream headers. mAudioCodecContext = avcodec_alloc_context3(mAudioCodec);
if (mAudioCodecContext->flags & AVFMT_GLOBALHEADER)
mAudioCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
if (avcodec_parameters_to_context(mAudioCodecContext, mAudioStream->codecpar)) { if (mAudioCodec->capabilities & AV_CODEC_CAP_TRUNCATED)
LOG(LogError) << "VideoFFmpegComponent::startVideoStream(): " mAudioCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
"Couldn't fill the audio codec context parameters for file \""
<< mVideoPath << "\"";
return;
}
if (avcodec_open2(mAudioCodecContext, mAudioCodec, nullptr)) { // Some formats want separate stream headers.
LOG(LogError) << "VideoFFmpegComponent::startVideoStream(): " if (mAudioCodecContext->flags & AVFMT_GLOBALHEADER)
"Couldn't initialize the audio codec context for file \"" mAudioCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
<< mVideoPath << "\"";
return; if (avcodec_parameters_to_context(mAudioCodecContext, mAudioStream->codecpar)) {
LOG(LogError) << "VideoFFmpegComponent::startVideoStream(): "
"Couldn't fill the audio codec context parameters for file \""
<< mVideoPath << "\"";
return;
}
if (avcodec_open2(mAudioCodecContext, mAudioCodec, nullptr)) {
LOG(LogError) << "VideoFFmpegComponent::startVideoStream(): "
"Couldn't initialize the audio codec context for file \""
<< mVideoPath << "\"";
return;
}
} }
} }