Subsonic API: try to not transcode if the requested format/max bitrate is compatible with the actual file
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "MediaRetrieval.hpp"
|
||||
|
||||
#include "av/IAudioFile.hpp"
|
||||
#include "av/TranscodeParameters.hpp"
|
||||
#include "av/TranscodeResourceHandlerCreator.hpp"
|
||||
#include "av/Types.hpp"
|
||||
@@ -99,8 +100,23 @@ namespace API::Subsonic
|
||||
parameters.inputFileParameters.duration = track->getDuration();
|
||||
}
|
||||
|
||||
if (format != "raw") // raw => no transcode
|
||||
if (format == "raw") // raw => no transcode
|
||||
return parameters;
|
||||
|
||||
const auto audioFile{ Av::parseAudioFile(parameters.inputFileParameters.trackPath) };
|
||||
|
||||
// check if transcode is really needed or not
|
||||
// same format as requested, bitrate is lower than requested => no need to transcode
|
||||
if (const auto streamInfo{ audioFile->getBestStreamInfo() })
|
||||
{
|
||||
// assume reported codec is "mp3", "opus", "vorbis", etc.
|
||||
if (StringUtils::stringCaseInsensitiveEqual(streamInfo->codec, format) && (maxBitRate == 0 || (streamInfo->bitrate / 1000) <= maxBitRate))
|
||||
{
|
||||
LMS_LOG(API_SUBSONIC, DEBUG) << "stream parameters are compatible with actual file: no transcode";
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
const User::pointer user{ User::find(context.dbSession, context.userId) };
|
||||
if (!user)
|
||||
throw UserNotAuthorizedError{};
|
||||
@@ -117,8 +133,7 @@ namespace API::Subsonic
|
||||
|
||||
transcodeParameters.bitrate = user->getSubsonicDefaultTranscodeBitrate();
|
||||
if (maxBitRate != 0)
|
||||
transcodeParameters.bitrate = Utils::clamp(transcodeParameters.bitrate, std::size_t{ 48 }, maxBitRate);
|
||||
}
|
||||
transcodeParameters.bitrate = Utils::clamp(transcodeParameters.bitrate, std::size_t{ 48000 }, maxBitRate * 1000);
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user