mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +00:00
OK, now that there are clear repro steps, the crash on invalid metadata
should be fixed for reals.
This commit is contained in:
parent
a1591667f9
commit
2e00d0c536
@ -809,7 +809,10 @@ ITrack* PlaybackService::GetTrack(size_t index) {
|
||||
const size_t count = this->playlist.Count();
|
||||
|
||||
if (count && index < this->playlist.Count()) {
|
||||
return this->playlist.Get(index)->GetSdkValue();
|
||||
auto track = this->playlist.Get(index);
|
||||
if (track) {
|
||||
return track->GetSdkValue();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@ -1093,17 +1096,20 @@ ITransport::Gain PlaybackService::GainAtIndex(size_t index) {
|
||||
Mode mode = (Mode)playbackPrefs->GetInt(keys::ReplayGainMode.c_str(), (int) Mode::Disabled);
|
||||
|
||||
if (mode != Mode::Disabled && index < this->playlist.Count()) {
|
||||
int64_t id = this->playlist.Get(index)->GetId();
|
||||
auto query = std::make_shared<ReplayGainQuery>(id);
|
||||
if (this->library->Enqueue(query, ILibrary::QuerySynchronous)) {
|
||||
auto rg = query->GetResult();
|
||||
float gain = (mode == Mode::Album) ? rg->albumGain : rg->trackGain;
|
||||
float peak = (mode == Mode::Album) ? rg->albumPeak : rg->trackPeak;
|
||||
if (gain != 1.0f) {
|
||||
/* http://wiki.hydrogenaud.io/index.php?title=ReplayGain_2.0_specification#Reduced_gain */
|
||||
result.gain = powf(10.0f, (gain / 20.0f));
|
||||
result.peak = (1.0f / peak);
|
||||
result.peakValid = true;
|
||||
auto track = this->playlist.Get(index);
|
||||
if (track) {
|
||||
int64_t id = track->GetId();
|
||||
auto query = std::make_shared<ReplayGainQuery>(id);
|
||||
if (this->library->Enqueue(query, ILibrary::QuerySynchronous)) {
|
||||
auto rg = query->GetResult();
|
||||
float gain = (mode == Mode::Album) ? rg->albumGain : rg->trackGain;
|
||||
float peak = (mode == Mode::Album) ? rg->albumPeak : rg->trackPeak;
|
||||
if (gain != 1.0f) {
|
||||
/* http://wiki.hydrogenaud.io/index.php?title=ReplayGain_2.0_specification#Reduced_gain */
|
||||
result.gain = powf(10.0f, (gain / 20.0f));
|
||||
result.peak = (1.0f / peak);
|
||||
result.peakValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,11 +68,11 @@ static std::string GetPreferenceString(
|
||||
|
||||
template <typename MetadataT>
|
||||
static std::string GetMetadataString(
|
||||
MetadataT* metadata,
|
||||
const std::string& key,
|
||||
MetadataT* metadata,
|
||||
const std::string& key,
|
||||
const std::string& defaultValue = "missing metadata!")
|
||||
{
|
||||
if (!metadata) { defaultValue; }
|
||||
if (!metadata) { return defaultValue; }
|
||||
metadata->GetString(key.c_str(), threadLocalBuffer, sizeof(threadLocalBuffer));
|
||||
return std::string(threadLocalBuffer);
|
||||
}
|
||||
@ -89,7 +89,7 @@ static int64_t GetMetadataInt64(MetadataT* metadata, const std::string& key, int
|
||||
|
||||
static std::string GetValueString(
|
||||
musik::core::sdk::IValue* value,
|
||||
const std::string& defaultValue = "missing metadata!")
|
||||
const std::string& defaultValue = "missing metadata!")
|
||||
{
|
||||
if (!value) { return defaultValue; }
|
||||
value->GetValue(threadLocalBuffer, sizeof(threadLocalBuffer));
|
||||
|
@ -785,9 +785,15 @@ void WebSocketServer::RespondWithPlayQueueTracks(connection_hdl connection, json
|
||||
|
||||
for (int i = offset; i < to; i++) {
|
||||
ITrack* track = context.playback->GetTrack(i);
|
||||
if (idsOnly) { data.push_back(GetMetadataString(track, key::external_id)); }
|
||||
else { data.push_back(this->ReadTrackMetadata(track)); }
|
||||
track->Release();
|
||||
if (idsOnly) {
|
||||
data.push_back(GetMetadataString(track, key::external_id));
|
||||
}
|
||||
else {
|
||||
data.push_back(this->ReadTrackMetadata(track));
|
||||
}
|
||||
if (track) {
|
||||
track->Release();
|
||||
}
|
||||
}
|
||||
|
||||
editor->Release();
|
||||
@ -803,9 +809,15 @@ void WebSocketServer::RespondWithPlayQueueTracks(connection_hdl connection, json
|
||||
|
||||
for (int i = offset; i < to; i++) {
|
||||
ITrack* track = snapshot->GetTrack(i);
|
||||
if (idsOnly) { data.push_back(GetMetadataString(track, key::external_id)); }
|
||||
else { data.push_back(this->ReadTrackMetadata(track)); }
|
||||
track->Release();
|
||||
if (idsOnly) {
|
||||
data.push_back(GetMetadataString(track, key::external_id));
|
||||
}
|
||||
else {
|
||||
data.push_back(this->ReadTrackMetadata(track));
|
||||
}
|
||||
if (track) {
|
||||
track->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user