mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-30 05:17:19 +00:00
refactor: remove old BambuPlayer-based media player from macOS
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// BambuPlayer.h
|
||||
// BambuPlayer
|
||||
//
|
||||
// Created by cmguo on 2021/12/6.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AVFoundation/AVSampleBufferDisplayLayer.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BambuPlayer : NSObject
|
||||
|
||||
+ (void) initialize;
|
||||
|
||||
- (instancetype) initWithDisplayLayer: (AVSampleBufferDisplayLayer*) layer;
|
||||
- (instancetype) initWithImageView: (NSView*) view;
|
||||
- (int) open: (char const *) url;
|
||||
- (NSSize) videoSize;
|
||||
- (int) play;
|
||||
- (void) stop;
|
||||
- (void) close;
|
||||
|
||||
- (void) setLogger: (void (*)(void const * context, int level, char const * msg)) logger withContext: (void const *) context;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -19,48 +19,6 @@ void wxMediaCtrl_OnSize(wxWindow * ctrl, wxSize const & videoSize, int width, in
|
||||
typedef struct _GstElement GstElement;
|
||||
#endif
|
||||
|
||||
#ifdef __WXMAC__
|
||||
|
||||
class wxMediaCtrl2 : public wxWindow
|
||||
{
|
||||
public:
|
||||
wxMediaCtrl2(wxWindow * parent);
|
||||
|
||||
~wxMediaCtrl2();
|
||||
|
||||
void Load(wxURI url);
|
||||
|
||||
void Play();
|
||||
|
||||
void Stop();
|
||||
|
||||
void SetIdleImage(wxString const & image);
|
||||
|
||||
wxMediaState GetState() const;
|
||||
|
||||
wxSize GetVideoSize() const;
|
||||
|
||||
int GetLastError() const { return m_error; }
|
||||
|
||||
static inline const wxMediaState MEDIASTATE_BUFFERING = static_cast<wxMediaState>(6);
|
||||
|
||||
protected:
|
||||
void DoSetSize(int x, int y, int width, int height, int sizeFlags) override;
|
||||
|
||||
static void bambu_log(void const *ctx, int level, char const *msg);
|
||||
|
||||
void NotifyStopped();
|
||||
|
||||
private:
|
||||
void create_player();
|
||||
void * m_player = nullptr;
|
||||
wxMediaState m_state = wxMEDIASTATE_STOPPED;
|
||||
int m_error = 0;
|
||||
wxSize m_video_size{16, 9};
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class wxMediaCtrl2 : public wxMediaCtrl
|
||||
{
|
||||
public:
|
||||
@@ -114,6 +72,4 @@ private:
|
||||
wxSize m_video_size{16, 9};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* wxMediaCtrl2_h */
|
||||
|
||||
@@ -1,181 +0,0 @@
|
||||
//
|
||||
// wxMediaCtrl2.m
|
||||
// OrcaSlicer
|
||||
//
|
||||
// Created by cmguo on 2021/12/7.
|
||||
//
|
||||
|
||||
#import "wxMediaCtrl2.h"
|
||||
#import "wx/mediactrl.h"
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "BambuPlayer/BambuPlayer.h"
|
||||
#import "../Utils/NetworkAgent.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
wxDEFINE_EVENT(EVT_MEDIA_CTRL_STAT, wxCommandEvent);
|
||||
|
||||
#define BAMBU_DYNAMIC
|
||||
|
||||
void wxMediaCtrl2::bambu_log(void const * ctx, int level, char const * msg)
|
||||
{
|
||||
if (level == 1) {
|
||||
wxString msg2(msg);
|
||||
if (msg2.EndsWith("]")) {
|
||||
int n = msg2.find_last_of('[');
|
||||
if (n != wxString::npos) {
|
||||
long val = 0;
|
||||
wxMediaCtrl2 * ctrl = (wxMediaCtrl2 *) ctx;
|
||||
if (msg2.SubString(n + 1, msg2.Length() - 2).ToLong(&val))
|
||||
ctrl->m_error = (int) val;
|
||||
}
|
||||
} else if (strstr(msg, "stat_log")) {
|
||||
wxMediaCtrl2 * ctrl = (wxMediaCtrl2 *) ctx;
|
||||
wxCommandEvent evt(EVT_MEDIA_CTRL_STAT);
|
||||
evt.SetEventObject(ctrl);
|
||||
evt.SetString(strchr(msg, ' ') + 1);
|
||||
wxPostEvent(ctrl, evt);
|
||||
}
|
||||
} else if (level < 0) {
|
||||
wxMediaCtrl2 * ctrl = (wxMediaCtrl2 *) ctx;
|
||||
ctrl->NotifyStopped();
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << msg;
|
||||
}
|
||||
|
||||
wxMediaCtrl2::wxMediaCtrl2(wxWindow * parent)
|
||||
: wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
|
||||
{
|
||||
NSView * imageView = (NSView *) GetHandle();
|
||||
imageView.layer = [[CALayer alloc] init];
|
||||
CGColorRef color = CGColorCreateGenericRGB(0, 0, 0, 1.0f);
|
||||
imageView.layer.backgroundColor = color;
|
||||
CGColorRelease(color);
|
||||
imageView.wantsLayer = YES;
|
||||
create_player();
|
||||
}
|
||||
|
||||
wxMediaCtrl2::~wxMediaCtrl2()
|
||||
{
|
||||
BambuPlayer * player = (BambuPlayer *) m_player;
|
||||
[player dealloc];
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::create_player()
|
||||
{
|
||||
auto module = Slic3r::NetworkAgent::get_bambu_source_entry();
|
||||
if (!module) {
|
||||
//not ready yet
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Network plugin not ready currently!";
|
||||
return;
|
||||
}
|
||||
Class cls = (__bridge Class) dlsym(module, "OBJC_CLASS_$_BambuPlayer");
|
||||
if (cls == nullptr) {
|
||||
m_error = -2;
|
||||
return;
|
||||
}
|
||||
NSView * imageView = (NSView *) GetHandle();
|
||||
BambuPlayer * player = [cls alloc];
|
||||
[player initWithImageView: imageView];
|
||||
[player setLogger: bambu_log withContext: this];
|
||||
m_player = player;
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Load(wxURI url)
|
||||
{
|
||||
if (!m_player) {
|
||||
create_player();
|
||||
if (!m_player) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": create_player failed currently!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BambuPlayer * player = (BambuPlayer *) m_player;
|
||||
if (player) {
|
||||
[player close];
|
||||
m_error = 0;
|
||||
m_error = [player open: url.BuildURI().ToUTF8()];
|
||||
}
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Play()
|
||||
{
|
||||
if (!m_player) {
|
||||
create_player();
|
||||
if (!m_player) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": create_player failed currently!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
[player2 play];
|
||||
if (m_state != wxMEDIASTATE_PLAYING) {
|
||||
m_state = wxMEDIASTATE_PLAYING;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::Stop()
|
||||
{
|
||||
if (!m_player) {
|
||||
create_player();
|
||||
if (!m_player) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": create_player failed currently!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
[player2 close];
|
||||
NotifyStopped();
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::SetIdleImage(wxString const &image)
|
||||
{
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::NotifyStopped()
|
||||
{
|
||||
if (m_state != wxMEDIASTATE_STOPPED) {
|
||||
m_state = wxMEDIASTATE_STOPPED;
|
||||
wxMediaEvent event(wxEVT_MEDIA_STATECHANGED);
|
||||
event.SetId(GetId());
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
}
|
||||
|
||||
wxMediaState wxMediaCtrl2::GetState() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
wxSize wxMediaCtrl2::GetVideoSize() const
|
||||
{
|
||||
BambuPlayer * player2 = (BambuPlayer *) m_player;
|
||||
if (player2) {
|
||||
NSSize size = [player2 videoSize];
|
||||
if (size.width > 0)
|
||||
const_cast<wxSize&>(m_video_size) = {(int) size.width, (int) size.height};
|
||||
return {(int) size.width, (int) size.height};
|
||||
} else {
|
||||
return {0, 0};
|
||||
}
|
||||
}
|
||||
|
||||
void wxMediaCtrl2::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||
{
|
||||
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
|
||||
if (sizeFlags & wxSIZE_USE_EXISTING) return;
|
||||
wxMediaCtrl_OnSize(this, m_video_size, width, height);
|
||||
}
|
||||
Reference in New Issue
Block a user