Compare commits

..

2 Commits

3 changed files with 44 additions and 68 deletions

View File

@ -16,8 +16,9 @@ public:
virtual void seek(size_t position) = 0;
virtual size_t size() = 0;
virtual void close() = 0;
virtual void skip_id3_tag() {};
virtual bool usable() = 0;
virtual int peek(int offset) = 0;
void skip_id3_tag();
};
class SDDataSource : public DataSource {
@ -32,8 +33,8 @@ public:
void seek(size_t position);
size_t size();
void close();
void skip_id3_tag();
bool usable();
int peek(int offset=0);
};
class HTTPSDataSource : public DataSource {
@ -54,5 +55,4 @@ public:
void close();
bool usable();
int peek(int offset=0);
void skip_id3_tag();
};

View File

@ -11,21 +11,16 @@
[platformio]
default_envs = esp32
[extra]
lib_deps =
63 ; MFRC522
https://github.com/me-no-dev/ESPAsyncWebServer.git
ArduinoJSON
6691 ; TinyXML
[env:esp32]
[env]
platform = espressif32
board = esp-wrover-kit
framework = arduino
upload_speed = 512000
build_flags=!./build_version.sh
lib_deps = ${extra.lib_deps}
upload_port = /dev/cu.SLAB_USBtoUART
lib_deps =
63 ; MFRC522
https://github.com/me-no-dev/ESPAsyncWebServer.git
64 ; ArduinoJSON
6691 ; TinyXML
monitor_speed = 115200
board_build.embed_files =
src/webinterface/timezones.json.gz
@ -35,10 +30,8 @@ board_build.embed_files =
extra_scripts =
post:tools/post_build.py
[env:esp32]
build_flags=!./build_version.sh
upload_port = /dev/cu.SLAB_USBtoUART
[env:deploy]
platform = espressif32
board = esp-wrover-kit
framework = arduino
lib_deps = ${extra.lib_deps}
board_build.embed_txtfiles = src/index.html
board_build.partitions = partitions.csv

View File

@ -1,5 +1,29 @@
#include "data_sources.h"
void DataSource::skip_id3_tag() {
if (peek(0)=='I' && peek(1)=='D' && peek(2)=='3') {
DEBUG("ID3 tag found\n");
// Skip ID3 tag marker
read(); read(); read();
// Skip ID3 tag version
read(); read();
byte tags = read();
bool footer_present = tags & 0x10;
DEBUG("ID3 footer found: %d\n", footer_present);
uint32_t offset = 0;
for (byte i=0; i<4; i++) {
offset <<= 7;
offset |= (0x7F & read());
}
offset += 10;
if (footer_present) offset += 10;
DEBUG("ID3 tag length is %d bytes.\n", offset);
seek(offset);
} else {
DEBUG("No ID3 tag found\n");
}
}
////////////// SDDataSource //////////////
SDDataSource::SDDataSource(String file) { _file = SD.open(file, "r"); }
SDDataSource::~SDDataSource() { if (_file) _file.close(); }
@ -10,31 +34,14 @@ void SDDataSource::seek(size_t position) { _file.seek(position); }
size_t SDDataSource::size() { return _file.size(); }
void SDDataSource::close() { _file.close(); }
bool SDDataSource::usable() { return _file; }
void SDDataSource::skip_id3_tag() {
uint32_t original_position = _file.position();
uint32_t offset = 0;
if (_file.read()=='I' && _file.read()=='D' && _file.read()=='3') {
DEBUG("ID3 tag found\n");
// Skip ID3 tag version
_file.read(); _file.read();
byte tags = _file.read();
bool footer_present = tags & 0x10;
DEBUG("ID3 footer found: %d\n", footer_present);
for (byte i=0; i<4; i++) {
offset <<= 7;
offset |= (0x7F & _file.read());
int SDDataSource::peek(int offset) {
if (offset==0) return _file.peek();
size_t start_position = _file.position();
_file.seek(start_position + offset);
int result = _file.peek();
_file.seek(start_position);
return result;
}
offset += 10;
if (footer_present) offset += 10;
DEBUG("ID3 tag length is %d bytes.\n", offset);
_file.seek(offset);
} else {
DEBUG("No ID3 tag found\n");
_file.seek(original_position);
}
}
////////////// HTTPSDataSource //////////////
@ -62,27 +69,3 @@ void HTTPSDataSource::seek(size_t position) { _http->close(); delete _http; _ini
size_t HTTPSDataSource::size() { return _http->getSize(); }
void HTTPSDataSource::close() { _http->close(); }
int HTTPSDataSource::peek(int offset) { return _http->peek(offset); }
void HTTPSDataSource::skip_id3_tag() {
uint32_t offset = 0;
if (_http->peek(0)=='I' && _http->peek(1)=='D' && _http->peek(2)=='3') {
DEBUG("ID3 tag found\n");
// Skip ID3 tag marker
_http->read(); _http->read(); _http->read();
// Skip ID3 tag version
_http->read(); _http->read();
byte tags = _http->read();
bool footer_present = tags & 0x10;
DEBUG("ID3 footer found: %d\n", footer_present);
for (byte i=0; i<4; i++) {
offset <<= 7;
offset |= (0x7F & _http->read());
}
offset += 10;
if (footer_present) offset += 10;
DEBUG("ID3 tag length is %d bytes.\n", offset);
seek(offset);
} else {
DEBUG("No ID3 tag found\n");
}
}