mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 20:47:08 +03:00
new cspot/bell
This commit is contained in:
@@ -1,47 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic> // for atomic
|
||||
#include <cstdint> // for uint8_t, int64_t
|
||||
#include <ctime> // for size_t, time
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <mutex> // for mutex
|
||||
#include <string_view> // for string_view
|
||||
#include <vector> // for vector
|
||||
#include <atomic> // for atomic
|
||||
#include <cstdint> // for uint8_t, int64_t
|
||||
#include <ctime> // for size_t, time
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr, unique_ptr
|
||||
#include <mutex> // for mutex
|
||||
#include <string_view> // for string_view
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "BellTask.h" // for Task
|
||||
#include "CDNTrackStream.h" // for CDNTrackStream, CDNTrackStream::TrackInfo
|
||||
#include "BellTask.h" // for Task
|
||||
#include "CDNAudioFile.h"
|
||||
#include "TrackQueue.h"
|
||||
|
||||
namespace bell {
|
||||
class WrappedSemaphore;
|
||||
} // namespace bell
|
||||
|
||||
#ifdef BELL_VORBIS_FLOAT
|
||||
#include "vorbis/vorbisfile.h"
|
||||
#else
|
||||
#include "ivorbisfile.h" // for OggVorbis_File, ov_callbacks
|
||||
#include "ivorbisfile.h" // for OggVorbis_File, ov_callbacks
|
||||
#endif
|
||||
|
||||
namespace cspot {
|
||||
class TrackProvider;
|
||||
class TrackQueue;
|
||||
struct Context;
|
||||
struct TrackReference;
|
||||
|
||||
class TrackPlayer : bell::Task {
|
||||
public:
|
||||
typedef std::function<void()> TrackLoadedCallback;
|
||||
typedef std::function<size_t(uint8_t*, size_t, std::string_view, size_t)> DataCallback;
|
||||
// Callback types
|
||||
typedef std::function<void(std::shared_ptr<QueuedTrack>)> TrackLoadedCallback;
|
||||
typedef std::function<size_t(uint8_t*, size_t, std::string_view)> DataCallback;
|
||||
typedef std::function<void()> EOFCallback;
|
||||
typedef std::function<bool()> isAiringCallback;
|
||||
|
||||
TrackPlayer(std::shared_ptr<cspot::Context> ctx, isAiringCallback, EOFCallback, TrackLoadedCallback);
|
||||
TrackPlayer(std::shared_ptr<cspot::Context> ctx,
|
||||
std::shared_ptr<cspot::TrackQueue> trackQueue,
|
||||
EOFCallback eofCallback, TrackLoadedCallback loadedCallback);
|
||||
~TrackPlayer();
|
||||
|
||||
void loadTrackFromRef(TrackReference& ref, size_t playbackMs, bool startAutomatically);
|
||||
|
||||
void loadTrackFromRef(TrackReference& ref, size_t playbackMs,
|
||||
bool startAutomatically);
|
||||
void setDataCallback(DataCallback callback);
|
||||
|
||||
CDNTrackStream::TrackInfo getCurrentTrackInfo();
|
||||
|
||||
// CDNTrackStream::TrackInfo getCurrentTrackInfo();
|
||||
void seekMs(size_t ms);
|
||||
void stopTrack();
|
||||
void resetState();
|
||||
|
||||
// Vorbis codec callbacks
|
||||
size_t _vorbisRead(void* ptr, size_t size, size_t nmemb);
|
||||
@@ -49,35 +56,39 @@ class TrackPlayer : bell::Task {
|
||||
int _vorbisSeek(int64_t offset, int whence);
|
||||
long _vorbisTell();
|
||||
|
||||
void destroy();
|
||||
void stop();
|
||||
void start();
|
||||
|
||||
private:
|
||||
std::shared_ptr<cspot::Context> ctx;
|
||||
std::shared_ptr<cspot::TrackProvider> trackProvider;
|
||||
std::shared_ptr<cspot::CDNTrackStream> currentTrackStream;
|
||||
size_t sequence = std::time(nullptr);
|
||||
std::shared_ptr<cspot::TrackQueue> trackQueue;
|
||||
std::shared_ptr<cspot::CDNAudioFile> currentTrackStream;
|
||||
|
||||
std::unique_ptr<bell::WrappedSemaphore> playbackSemaphore;
|
||||
|
||||
TrackLoadedCallback trackLoaded;
|
||||
DataCallback dataCallback = nullptr;
|
||||
EOFCallback eofCallback;
|
||||
isAiringCallback isAiring;
|
||||
|
||||
// Playback control
|
||||
std::atomic<bool> currentSongPlaying;
|
||||
std::mutex playbackMutex;
|
||||
std::mutex seekMutex;
|
||||
|
||||
std::mutex dataOutMutex;
|
||||
|
||||
// Vorbis related
|
||||
OggVorbis_File vorbisFile;
|
||||
ov_callbacks vorbisCallbacks;
|
||||
int currentSection;
|
||||
|
||||
std::vector<uint8_t> pcmBuffer = std::vector<uint8_t>(1024);
|
||||
|
||||
size_t playbackPosition = 0;
|
||||
bool autoStart = false;
|
||||
std::atomic<bool> isRunning = true;
|
||||
|
||||
std::atomic<bool> isRunning = false;
|
||||
std::atomic<bool> pendingReset = false;
|
||||
std::atomic<bool> inFuture = false;
|
||||
std::atomic<size_t> pendingSeekPositionMs = 0;
|
||||
|
||||
std::mutex runningMutex;
|
||||
|
||||
void runTask() override;
|
||||
|
||||
Reference in New Issue
Block a user