Improved stability, but there seem to be bugs with m3u files. Will

probably add an option to disable them by default.
This commit is contained in:
Casey Langen 2019-01-03 23:57:40 -08:00
parent fd69636743
commit 62d35e709a
6 changed files with 46 additions and 38 deletions

View File

@ -39,6 +39,9 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
@ -84,3 +87,23 @@ static inline bool parseExternalId(const std::string& externalId, std::string& f
static inline std::string createExternalId(const std::string& fn, int track) {
return "gme://" + std::to_string(track) + "/" + fn;
}
static std::string getM3uFor(const std::string& fn) {
size_t lastDot = fn.find_last_of(".");
if (lastDot != std::string::npos) {
std::string m3u = fn.substr(0, lastDot) + ".m3u";
if (access(m3u.c_str(), R_OK) != -1) {
return m3u;
}
}
return "";
}
static bool exists(const std::string& externalId) {
std::string fn;
int trackNum;
if (!parseExternalId(externalId, fn, trackNum)) {
return false;
}
return access(fn.c_str(), R_OK) != -1;
}

View File

@ -41,10 +41,9 @@ using namespace musik::core::sdk;
extern IEnvironment* environment;
bool GmeDataStream::Open(const char *uri, unsigned int options) {
std::string fn;
if (parseExternalId(uri, fn, this->trackNumber)) {
if (parseExternalId(uri, this->filename, this->trackNumber)) {
if (environment) {
this->stream = environment->GetDataStream(fn.c_str());
this->stream = environment->GetDataStream(this->filename.c_str());
if (this->stream) {
return true;
}

View File

@ -56,8 +56,10 @@ class GmeDataStream: public musik::core::sdk::IDataStream {
virtual bool CanPrefetch() override;
int GetTrackNumber() { return this->trackNumber; }
std::string GetFilename() { return this->filename; }
private:
int trackNumber { 0 };
std::string filename;
musik::core::sdk::IDataStream* stream { nullptr };
};

View File

@ -39,8 +39,9 @@
static const int BUFFER_SAMPLE_COUNT = 2048;
static const int CHANNELS = 2;
static const int SAMPLE_RATE = 44100;
static const int SAMPLES_PER_MS = SAMPLE_RATE / 1000;
static const int FADE_LENGTH_MS = 2000;
static const int SAMPLES_PER_MS = (SAMPLE_RATE * CHANNELS) / 1000;
static const int FADE_LENGTH_MS = 2500;
static const int MAXIMUM_DURATION_MS = 150000; /* 2.5 mins */
static const float F_SHRT_MAX = (float) SHRT_MAX;
GmeDecoder::GmeDecoder() {
@ -64,6 +65,11 @@ bool GmeDecoder::Open(musik::core::sdk::IDataStream *stream) {
if (!gme_open_data(data, length, &this->gme, SAMPLE_RATE)) {
int trackNum = this->stream->GetTrackNumber();
std::string m3u = getM3uFor(this->stream->GetFilename());
if (m3u.size()) {
gme_load_m3u(this->gme, m3u.c_str());
}
bool error =
!!gme_track_info(this->gme, &this->info, trackNum) ||
!!gme_start_track(this->gme, trackNum);
@ -75,7 +81,7 @@ bool GmeDecoder::Open(musik::core::sdk::IDataStream *stream) {
this->info = nullptr;
}
else {
gme_set_fade(this->gme, this->info->play_length - FADE_LENGTH_MS, FADE_LENGTH_MS);
gme_set_fade(this->gme, MAXIMUM_DURATION_MS - FADE_LENGTH_MS, FADE_LENGTH_MS);
}
}
}

View File

@ -39,50 +39,27 @@
#include <set>
#include <map>
#include <gme.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
using namespace musik::core::sdk;
static std::string getM3uFor(const std::string& fn) {
size_t lastDot = fn.find_last_of(".");
if (lastDot != std::string::npos) {
std::string m3u = fn.substr(0, lastDot) + ".m3u";
if (access(m3u.c_str(), R_OK) != -1) {
return m3u;
}
}
return "";
}
static bool exists(const std::string& externalId) {
std::string fn;
int trackNum;
if (!parseExternalId(externalId, fn, trackNum)) {
return false;
}
return access(fn.c_str(), R_OK) != -1;
}
static void updateMetadata(
const std::string& fn,
IIndexerSource* source,
IIndexerWriter* indexer)
{
gme_t* data = nullptr;
gme_err_t err = gme_open_file(fn.c_str(), &data, 44100);
gme_err_t err = gme_open_file(fn.c_str(), &data, gme_info_only);
if (err) {
std::cerr << "error opening file: " << err << "\n";
}
else {
// std::string m3u = getM3uFor(fn);
// if (m3u.size()) {
// err = gme_load_m3u(data, m3u.c_str());
// if (err) {
// std::cerr << "m3u found, but load failed: " << err << "\n";
// }
// }
std::string m3u = getM3uFor(fn);
if (m3u.size()) {
err = gme_load_m3u(data, m3u.c_str());
if (err) {
std::cerr << "m3u found, but load failed: " << err << "\n";
}
}
for (int i = 0; i < gme_track_count(data); i++) {
gme_info_t* info = nullptr;

View File

@ -38,6 +38,7 @@
#include <core/sdk/IIndexerSource.h>
#include <functional>
#include <set>
#include <map>
class GmeIndexerSource: public musik::core::sdk::IIndexerSource {
public: