WIP: Lots of streaming stuff

This commit is contained in:
2019-11-27 06:51:20 +01:00
parent 710b8a2cdc
commit 6f8683ba9d
11 changed files with 551 additions and 78 deletions

View File

@ -3,7 +3,7 @@
#include <Arduino.h>
#include <SD.h>
#include "config.h"
#include <HTTPClient.h>
#include "http_client_wrapper.h"
class DataSource {
private:
@ -11,7 +11,7 @@ public:
DataSource() {};
virtual ~DataSource() {};
virtual size_t read(uint8_t* buf, size_t len) = 0;
virtual uint8_t read() = 0;
virtual int read() = 0;
virtual size_t position() = 0;
virtual void seek(size_t position) = 0;
virtual size_t size() = 0;
@ -27,7 +27,7 @@ public:
SDDataSource(String file);
~SDDataSource();
size_t read(uint8_t* buf, size_t len);
uint8_t read();
int read();
size_t position();
void seek(size_t position);
size_t size();
@ -39,17 +39,16 @@ public:
class HTTPSDataSource : public DataSource {
private:
WiFiClient* _stream = NULL;
HTTPClient* _http = NULL;
uint32_t _length;
HTTPClientWrapper* _http = NULL;
uint32_t _position;
public:
HTTPSDataSource(String url, uint32_t offset=0);
~HTTPSDataSource();
size_t read(uint8_t* buf, size_t len);
uint8_t read();
int read();
size_t position();
void seek(size_t position);
size_t size();
void close();
bool usable();
};
};

View File

@ -0,0 +1,37 @@
#pragma once
#include <HTTPClient.h>
#include "config.h"
class HTTPClientWrapper {
private:
HTTPClient* _http;
uint8_t* _buffer;
uint16_t _buffer_size;
uint16_t _buffer_length;
uint16_t _buffer_position;
uint32_t _chunk_length;
bool _connected = false;
String _content_type;
uint32_t _length;
bool _request(String method, String url, uint32_t offset=0, uint8_t redirection_count=0);
WiFiClient* _stream;
bool _is_chunked;
void _read_next_chunk_header(bool first);
uint16_t _fill_buffer();
public:
HTTPClientWrapper();
~HTTPClientWrapper();
bool get(String url, uint32_t offset=0, uint8_t redirection_count=0);
bool head(String url, uint32_t offset=0, uint8_t redirection_count=0);
String getContentType();
String getString();
int read();
uint32_t read(uint8_t* dst, uint32_t len);
void close();
uint32_t getSize();
String readUntil(String sep);
String readLine();
};

View File

@ -2,6 +2,14 @@
#include <Arduino.h>
#include <vector>
#include <ArduinoJson.h>
#include "http_client_wrapper.h"
struct PlaylistEntry {
String filename;
String title;
bool operator<(PlaylistEntry p) { return title < p.title; }
};
class Playlist {
private:
@ -9,10 +17,17 @@ private:
uint32_t _current_track = 0;
bool _started = false;
bool _shuffled = false;
std::vector<String> _files;
std::vector<PlaylistEntry> _files;
void _add_path(String path);
void _examine_http_url(String url);
void _parse_rss(HTTPClientWrapper* http);
void _parse_m3u(HTTPClientWrapper* http);
void _parse_pls(HTTPClientWrapper* http);
public:
Playlist(String path, bool is_url=false);
String title;
Playlist(String path);
void start();
uint16_t get_file_count();
bool has_track_next();
bool has_track_prev();
bool track_next();