init
This commit is contained in:
110
platform/linux/include/eclipt-linux/EcliptLinux.h
Normal file
110
platform/linux/include/eclipt-linux/EcliptLinux.h
Normal file
@@ -0,0 +1,110 @@
|
||||
#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
|
||||
145
platform/linux/src/EcliptLinux.cpp
Normal file
145
platform/linux/src/EcliptLinux.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "../include/eclipt-linux/EcliptLinux.h"
|
||||
#include "../../../libEcliptPlayer/include/eclipt/EcliptPlayer.h"
|
||||
#include "../../../libEcliptPlayer/include/eclipt/Frame.h"
|
||||
#include "../../../libEcliptPlayer/include/eclipt/Config.h"
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
|
||||
namespace eclipt {
|
||||
namespace platform {
|
||||
namespace linux {
|
||||
|
||||
LinuxPlayer::LinuxPlayer() = default;
|
||||
|
||||
LinuxPlayer::~LinuxPlayer() {
|
||||
shutdown();
|
||||
}
|
||||
|
||||
bool LinuxPlayer::initialize(const LinuxDisplayConfig& display, const LinuxAudioConfig& audio) {
|
||||
display_config_ = display;
|
||||
audio_config_ = audio;
|
||||
|
||||
core_player_ = std::make_unique<eclipt::EcliptPlayer>();
|
||||
|
||||
core_player_->setVideoCallback([this](VideoFrame&& frame) {
|
||||
onVideoFrame(std::move(frame));
|
||||
});
|
||||
|
||||
core_player_->setAudioCallback([this](AudioFrame&& frame) {
|
||||
onAudioFrame(std::move(frame));
|
||||
});
|
||||
|
||||
initialized_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LinuxPlayer::shutdown() {
|
||||
running_ = false;
|
||||
|
||||
if (render_thread_.joinable()) {
|
||||
render_cv_.notify_all();
|
||||
render_thread_.join();
|
||||
}
|
||||
|
||||
if (core_player_) {
|
||||
core_player_->close();
|
||||
}
|
||||
|
||||
initialized_ = false;
|
||||
}
|
||||
|
||||
bool LinuxPlayer::open(const std::string& url) {
|
||||
if (!core_player_) return false;
|
||||
return core_player_->open(url);
|
||||
}
|
||||
|
||||
void LinuxPlayer::close() {
|
||||
if (core_player_) {
|
||||
core_player_->close();
|
||||
}
|
||||
}
|
||||
|
||||
bool LinuxPlayer::play() {
|
||||
if (!core_player_) return false;
|
||||
running_ = true;
|
||||
render_thread_ = std::thread([this]() { renderLoop(); });
|
||||
return core_player_->play();
|
||||
}
|
||||
|
||||
bool LinuxPlayer::pause() {
|
||||
if (!core_player_) return false;
|
||||
return core_player_->pause();
|
||||
}
|
||||
|
||||
bool LinuxPlayer::stop() {
|
||||
running_ = false;
|
||||
if (core_player_) {
|
||||
core_player_->stop();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LinuxPlayer::seek(int64_t position_ms) {
|
||||
if (!core_player_) return false;
|
||||
return core_player_->seek(position_ms, eclipt::SeekDirection::Absolute);
|
||||
}
|
||||
|
||||
int LinuxPlayer::getState() const {
|
||||
if (!core_player_) return 0;
|
||||
return static_cast<int>(core_player_->getState());
|
||||
}
|
||||
|
||||
void LinuxPlayer::setVolume(float volume) {
|
||||
if (core_player_) {
|
||||
core_player_->setVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
float LinuxPlayer::getVolume() const {
|
||||
if (!core_player_) return 0.0f;
|
||||
return core_player_->getVolume();
|
||||
}
|
||||
|
||||
void LinuxPlayer::render() {
|
||||
if (!running_) return;
|
||||
|
||||
VideoFrame frame;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(frame_mutex_);
|
||||
if (!frame_queue_.empty()) {
|
||||
frame = std::move(frame_queue_.front());
|
||||
frame_queue_.erase(frame_queue_.begin());
|
||||
}
|
||||
}
|
||||
|
||||
if (frame.isValid()) {
|
||||
// Render frame using the configured display backend
|
||||
}
|
||||
}
|
||||
|
||||
void LinuxPlayer::setEventCallback(EventCallback callback) {
|
||||
event_callback_ = std::move(callback);
|
||||
}
|
||||
|
||||
void LinuxPlayer::onVideoFrame(VideoFrame&& frame) {
|
||||
std::lock_guard<std::mutex> lock(frame_mutex_);
|
||||
if (frame_queue_.size() < 3) {
|
||||
frame_queue_.push_back(std::move(frame));
|
||||
frame_cv_.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
void LinuxPlayer::onAudioFrame(AudioFrame&& frame) {
|
||||
// Handle audio frame
|
||||
}
|
||||
|
||||
void LinuxPlayer::renderLoop() {
|
||||
while (running_) {
|
||||
render();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(16));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
44
platform/linux/src/main.cpp
Normal file
44
platform/linux/src/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "eclipt-linux/EcliptLinux.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace eclipt::platform::linux;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <url>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
LinuxDisplayConfig display;
|
||||
display.title = "Eclipt IPTV Player";
|
||||
display.window_width = 1280;
|
||||
display.window_height = 720;
|
||||
|
||||
LinuxAudioConfig audio;
|
||||
|
||||
LinuxPlayer player;
|
||||
|
||||
if (!player.initialize(display, audio)) {
|
||||
std::cerr << "Failed to initialize player" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!player.open(argv[1])) {
|
||||
std::cerr << "Failed to open: " << argv[1] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!player.play()) {
|
||||
std::cerr << "Failed to start playback" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Playing: " << argv[1] << std::endl;
|
||||
std::cout << "Press Enter to stop..." << std::endl;
|
||||
std::cin.get();
|
||||
|
||||
player.stop();
|
||||
player.shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user