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 <iostream>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#ifdef WIN32 #ifdef WIN32
#define DLLEXPORT __declspec(dllexport) #define DLLEXPORT __declspec(dllexport)
@ -83,4 +86,24 @@ static inline bool parseExternalId(const std::string& externalId, std::string& f
static inline std::string createExternalId(const std::string& fn, int track) { static inline std::string createExternalId(const std::string& fn, int track) {
return "gme://" + std::to_string(track) + "/" + fn; 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; extern IEnvironment* environment;
bool GmeDataStream::Open(const char *uri, unsigned int options) { bool GmeDataStream::Open(const char *uri, unsigned int options) {
std::string fn; if (parseExternalId(uri, this->filename, this->trackNumber)) {
if (parseExternalId(uri, fn, this->trackNumber)) {
if (environment) { if (environment) {
this->stream = environment->GetDataStream(fn.c_str()); this->stream = environment->GetDataStream(this->filename.c_str());
if (this->stream) { if (this->stream) {
return true; return true;
} }

View File

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

View File

@ -39,8 +39,9 @@
static const int BUFFER_SAMPLE_COUNT = 2048; static const int BUFFER_SAMPLE_COUNT = 2048;
static const int CHANNELS = 2; static const int CHANNELS = 2;
static const int SAMPLE_RATE = 44100; static const int SAMPLE_RATE = 44100;
static const int SAMPLES_PER_MS = SAMPLE_RATE / 1000; static const int SAMPLES_PER_MS = (SAMPLE_RATE * CHANNELS) / 1000;
static const int FADE_LENGTH_MS = 2000; 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; static const float F_SHRT_MAX = (float) SHRT_MAX;
GmeDecoder::GmeDecoder() { GmeDecoder::GmeDecoder() {
@ -64,6 +65,11 @@ bool GmeDecoder::Open(musik::core::sdk::IDataStream *stream) {
if (!gme_open_data(data, length, &this->gme, SAMPLE_RATE)) { if (!gme_open_data(data, length, &this->gme, SAMPLE_RATE)) {
int trackNum = this->stream->GetTrackNumber(); 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 = bool error =
!!gme_track_info(this->gme, &this->info, trackNum) || !!gme_track_info(this->gme, &this->info, trackNum) ||
!!gme_start_track(this->gme, trackNum); !!gme_start_track(this->gme, trackNum);
@ -75,7 +81,7 @@ bool GmeDecoder::Open(musik::core::sdk::IDataStream *stream) {
this->info = nullptr; this->info = nullptr;
} }
else { 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 <set>
#include <map> #include <map>
#include <gme.h> #include <gme.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
using namespace musik::core::sdk; 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( static void updateMetadata(
const std::string& fn, const std::string& fn,
IIndexerSource* source, IIndexerSource* source,
IIndexerWriter* indexer) IIndexerWriter* indexer)
{ {
gme_t* data = nullptr; 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) { if (err) {
std::cerr << "error opening file: " << err << "\n"; std::cerr << "error opening file: " << err << "\n";
} }
else { else {
// std::string m3u = getM3uFor(fn); std::string m3u = getM3uFor(fn);
// if (m3u.size()) { if (m3u.size()) {
// err = gme_load_m3u(data, m3u.c_str()); err = gme_load_m3u(data, m3u.c_str());
// if (err) { if (err) {
// std::cerr << "m3u found, but load failed: " << err << "\n"; std::cerr << "m3u found, but load failed: " << err << "\n";
// } }
// } }
for (int i = 0; i < gme_track_count(data); i++) { for (int i = 0; i < gme_track_count(data); i++) {
gme_info_t* info = nullptr; gme_info_t* info = nullptr;

View File

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