111 lines
2.1 KiB
C++
111 lines
2.1 KiB
C++
#ifndef ECLIPT_LINUX_PLAYER_H
|
|
#define ECLIPT_LINUX_PLAYER_H
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <atomic>
|
|
#include <thread>
|
|
#include <condition_variable>
|
|
#include <vector>
|
|
|
|
namespace eclipt {
|
|
class EcliptPlayer;
|
|
struct VideoFrame;
|
|
struct AudioFrame;
|
|
}
|
|
|
|
namespace eclipt {
|
|
namespace platform {
|
|
namespace linux {
|
|
|
|
enum class DisplayBackend {
|
|
SDL2,
|
|
DRM,
|
|
X11,
|
|
Wayland
|
|
};
|
|
|
|
struct LinuxDisplayConfig {
|
|
DisplayBackend backend = DisplayBackend::SDL2;
|
|
int window_width = 1280;
|
|
int window_height = 720;
|
|
bool fullscreen = false;
|
|
bool vsync = true;
|
|
std::string title = "Eclipt";
|
|
};
|
|
|
|
struct LinuxAudioConfig {
|
|
int sample_rate = 48000;
|
|
int channels = 2;
|
|
int buffer_size = 1024;
|
|
};
|
|
|
|
class LinuxTexture {
|
|
public:
|
|
virtual ~LinuxTexture() = default;
|
|
virtual bool update(const eclipt::VideoFrame& frame) = 0;
|
|
virtual int getWidth() const = 0;
|
|
virtual int getHeight() const = 0;
|
|
};
|
|
|
|
class LinuxPlayer {
|
|
public:
|
|
LinuxPlayer();
|
|
~LinuxPlayer();
|
|
|
|
bool initialize(const LinuxDisplayConfig& display, const LinuxAudioConfig& audio);
|
|
void shutdown();
|
|
|
|
bool open(const std::string& url);
|
|
void close();
|
|
|
|
bool play();
|
|
bool pause();
|
|
bool stop();
|
|
|
|
bool seek(int64_t position_ms);
|
|
|
|
int getState() const;
|
|
|
|
void setVolume(float volume);
|
|
float getVolume() const;
|
|
|
|
void render();
|
|
|
|
using EventCallback = std::function<void(const void* event)>;
|
|
void setEventCallback(EventCallback callback);
|
|
|
|
eclipt::EcliptPlayer* getCorePlayer();
|
|
|
|
private:
|
|
std::unique_ptr<eclipt::EcliptPlayer> core_player_;
|
|
|
|
LinuxDisplayConfig display_config_;
|
|
LinuxAudioConfig audio_config_;
|
|
|
|
bool initialized_ = false;
|
|
bool running_ = false;
|
|
|
|
std::thread render_thread_;
|
|
std::mutex render_mutex_;
|
|
std::condition_variable render_cv_;
|
|
|
|
EventCallback event_callback_;
|
|
|
|
std::vector<eclipt::VideoFrame> frame_queue_;
|
|
std::mutex frame_mutex_;
|
|
std::condition_variable frame_cv_;
|
|
|
|
void onVideoFrame(eclipt::VideoFrame&& frame);
|
|
void onAudioFrame(eclipt::AudioFrame&& frame);
|
|
void renderLoop();
|
|
};
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|