OK, now that there are clear repro steps, the crash on invalid metadata

should be fixed for reals.
This commit is contained in:
casey langen 2018-08-12 22:37:14 -07:00
parent a1591667f9
commit 2e00d0c536
3 changed files with 40 additions and 22 deletions

View File

@ -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;
}
}
}
}

View File

@ -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));

View File

@ -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();
}
}
}
}