-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Playlist improvements #269
Draft
laszloh
wants to merge
8
commits into
biologist79:dev
Choose a base branch
from
laszloh:feature/playlist_improvements
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d39fe3a
Add Playlist class and implementations
laszloh 43f6296
Rework fileValid to check for lower case
laszloh 6806501
Work on the queue side of the playlist
laszloh 57d031c
remove playlist cache support
laszloh b8796e2
Remove mock server test files
laszloh f43e0b0
Add test files for webstream and file playlist
laszloh 67f90a7
Apply automatic code formatting after rebase
laszloh 2e810d2
Secure gPlayProperties more with the lock_guard
laszloh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
#pragma once | ||
|
||
#include "cpp.h" | ||
|
||
#include <WString.h> | ||
#include <algorithm> | ||
#include <string.h> | ||
|
||
using sortFunc = int (*)(const void *, const void *); | ||
|
||
class Playlist { | ||
public: | ||
Playlist() { } | ||
virtual ~Playlist() { } | ||
|
||
virtual size_t size() const = 0; | ||
|
||
virtual bool isValid() const = 0; | ||
|
||
virtual const String getAbsolutePath(size_t idx) const = 0; | ||
|
||
virtual const String getFilename(size_t idx) const = 0; | ||
|
||
static int alphabeticSort(const void *x, const void *y) { | ||
const char *a = static_cast<const char *>(x); | ||
const char *b = static_cast<const char *>(y); | ||
|
||
return strcmp(a, b); | ||
} | ||
|
||
virtual void sort(sortFunc func = alphabeticSort) { } | ||
|
||
virtual void randomize() { } | ||
|
||
// Check if file-type is correct | ||
static bool fileValid(const String _fileItem) { | ||
constexpr size_t maxExtLen = strlen(*std::max_element(audioFileSufix.begin(), audioFileSufix.end(), [](const char *a, const char *b) { | ||
return strlen(a) < strlen(b); | ||
})); | ||
|
||
if (!_fileItem) { | ||
return false; | ||
} | ||
|
||
// check for http address | ||
if (_fileItem.startsWith("http://") || _fileItem.startsWith("https://")) { | ||
return true; | ||
} | ||
|
||
// Ignore hidden files starting with a '.' | ||
// lastIndex is -1 if '/' is not found --> first index will be 0 | ||
int fileNameIndex = _fileItem.lastIndexOf('/') + 1; | ||
if (_fileItem[fileNameIndex] == '.') { | ||
return false; | ||
} | ||
|
||
String extBuf; | ||
const size_t extStart = _fileItem.lastIndexOf('.'); | ||
const size_t extLen = _fileItem.length() - extStart; | ||
if (extLen > maxExtLen) { | ||
// we either did not find a . or extension was too long | ||
return false; | ||
} | ||
extBuf = _fileItem.substring(extStart); | ||
extBuf.toLowerCase(); | ||
|
||
for (const auto e : audioFileSufix) { | ||
if (extBuf.equals(e)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
protected: | ||
template <typename T> | ||
class PsramAllocator { | ||
public: | ||
typedef T value_type; | ||
typedef value_type *pointer; | ||
typedef const value_type *const_pointer; | ||
typedef value_type &reference; | ||
typedef const value_type &const_reference; | ||
typedef std::size_t size_type; | ||
typedef std::ptrdiff_t difference_type; | ||
|
||
public: | ||
template <typename U> | ||
struct rebind { | ||
typedef PsramAllocator<U> other; | ||
}; | ||
|
||
public: | ||
inline explicit PsramAllocator() { } | ||
inline ~PsramAllocator() { } | ||
inline PsramAllocator(PsramAllocator const &) { } | ||
template <typename U> | ||
inline explicit PsramAllocator(PsramAllocator<U> const &) { } | ||
|
||
// address | ||
inline pointer address(reference r) { return &r; } | ||
|
||
inline const_pointer address(const_reference r) { return &r; } | ||
|
||
// memory allocation | ||
inline pointer allocate(size_type cnt, typename std::allocator<void>::const_pointer = 0) { | ||
T *ptr = nullptr; | ||
if (psramFound()) { | ||
ptr = (T *) ps_malloc(cnt * sizeof(T)); | ||
} else { | ||
ptr = (T *) malloc(cnt * sizeof(T)); | ||
} | ||
return ptr; | ||
} | ||
|
||
inline void deallocate(pointer p, size_type cnt) { | ||
free(p); | ||
} | ||
|
||
// size | ||
inline size_type max_size() const { | ||
return std::numeric_limits<size_type>::max() / sizeof(T); | ||
} | ||
|
||
// construction/destruction | ||
inline void construct(pointer p, const T &t) { | ||
new (p) T(t); | ||
} | ||
|
||
inline void destroy(pointer p) { | ||
p->~T(); | ||
} | ||
|
||
inline bool operator==(PsramAllocator const &a) { return this == &a; } | ||
inline bool operator!=(PsramAllocator const &a) { return !operator==(a); } | ||
}; | ||
|
||
using pstring = std::basic_string<char, std::char_traits<char>, PsramAllocator<char>>; | ||
|
||
virtual void destroy() { } | ||
|
||
// clang-format off | ||
static constexpr auto audioFileSufix = std::to_array<const char*>({ | ||
".mp3", | ||
".aac", | ||
".m4a", | ||
".wav", | ||
".flac", | ||
".aac", | ||
// playlists | ||
".m3u", | ||
".m3u8", | ||
".pls", | ||
".asx" | ||
}); | ||
// clang-format on | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is obsolete, we are on Arduino >=2