2019-11-20 04:04:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <SD.h>
|
|
|
|
#include "config.h"
|
2019-11-27 05:51:20 +00:00
|
|
|
#include "http_client_wrapper.h"
|
2019-11-20 04:04:27 +00:00
|
|
|
|
|
|
|
class DataSource {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
DataSource() {};
|
2019-11-20 05:13:15 +00:00
|
|
|
virtual ~DataSource() {};
|
2019-11-20 04:04:27 +00:00
|
|
|
virtual size_t read(uint8_t* buf, size_t len) = 0;
|
2019-11-27 05:51:20 +00:00
|
|
|
virtual int read() = 0;
|
2019-11-20 04:04:27 +00:00
|
|
|
virtual size_t position() = 0;
|
|
|
|
virtual void seek(size_t position) = 0;
|
|
|
|
virtual size_t size() = 0;
|
|
|
|
virtual void close() = 0;
|
2019-11-20 05:13:15 +00:00
|
|
|
virtual void skip_id3_tag() {};
|
|
|
|
virtual bool usable() = 0;
|
2019-11-20 04:04:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SDDataSource : public DataSource {
|
|
|
|
private:
|
|
|
|
File _file;
|
|
|
|
public:
|
|
|
|
SDDataSource(String file);
|
|
|
|
~SDDataSource();
|
|
|
|
size_t read(uint8_t* buf, size_t len);
|
2019-11-27 05:51:20 +00:00
|
|
|
int read();
|
2019-11-20 04:04:27 +00:00
|
|
|
size_t position();
|
|
|
|
void seek(size_t position);
|
|
|
|
size_t size();
|
|
|
|
void close();
|
|
|
|
void skip_id3_tag();
|
2019-11-20 05:13:15 +00:00
|
|
|
bool usable();
|
2019-11-20 04:04:27 +00:00
|
|
|
};
|
2019-11-20 05:13:15 +00:00
|
|
|
|
|
|
|
class HTTPSDataSource : public DataSource {
|
|
|
|
private:
|
|
|
|
WiFiClient* _stream = NULL;
|
2019-11-27 05:51:20 +00:00
|
|
|
HTTPClientWrapper* _http = NULL;
|
2019-11-20 05:13:15 +00:00
|
|
|
uint32_t _position;
|
2019-12-04 05:07:20 +00:00
|
|
|
String _url;
|
|
|
|
void _init(String url, uint32_t offset);
|
2019-11-20 05:13:15 +00:00
|
|
|
public:
|
|
|
|
HTTPSDataSource(String url, uint32_t offset=0);
|
|
|
|
~HTTPSDataSource();
|
|
|
|
size_t read(uint8_t* buf, size_t len);
|
2019-11-27 05:51:20 +00:00
|
|
|
int read();
|
2019-11-20 05:13:15 +00:00
|
|
|
size_t position();
|
|
|
|
void seek(size_t position);
|
|
|
|
size_t size();
|
|
|
|
void close();
|
|
|
|
bool usable();
|
2019-12-04 05:07:20 +00:00
|
|
|
int peek(int offset=0);
|
|
|
|
void skip_id3_tag();
|
2019-11-27 05:51:20 +00:00
|
|
|
};
|