Improve VLC error handling
This commit is contained in:
parent
ff35b01bac
commit
08cba25071
|
@ -53,7 +53,6 @@ VLCEngine::~VLCEngine() {
|
||||||
libvlc_media_player_stop(player_);
|
libvlc_media_player_stop(player_);
|
||||||
libvlc_media_player_release(player_);
|
libvlc_media_player_release(player_);
|
||||||
libvlc_release(instance_);
|
libvlc_release(instance_);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,17 +69,14 @@ bool VLCEngine::Init() {
|
||||||
// Create the VLC instance
|
// Create the VLC instance
|
||||||
instance_ = libvlc_new(sizeof(args) / sizeof(*args), args);
|
instance_ = libvlc_new(sizeof(args) / sizeof(*args), args);
|
||||||
if (!instance_) return false;
|
if (!instance_) return false;
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
// Create the media player
|
// Create the media player
|
||||||
player_ = libvlc_media_player_new(instance_);
|
player_ = libvlc_media_player_new(instance_);
|
||||||
if (!player_) return false;
|
if (!player_) return false;
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
// Add event handlers
|
// Add event handlers
|
||||||
libvlc_event_manager_t *player_em = libvlc_media_player_event_manager(player_);
|
libvlc_event_manager_t *player_em = libvlc_media_player_event_manager(player_);
|
||||||
if (!player_em) return false;
|
if (!player_em) return false;
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
AttachCallback(player_em, libvlc_MediaPlayerEncounteredError, StateChangedCallback);
|
AttachCallback(player_em, libvlc_MediaPlayerEncounteredError, StateChangedCallback);
|
||||||
AttachCallback(player_em, libvlc_MediaPlayerNothingSpecial, StateChangedCallback);
|
AttachCallback(player_em, libvlc_MediaPlayerNothingSpecial, StateChangedCallback);
|
||||||
|
@ -90,7 +86,6 @@ bool VLCEngine::Init() {
|
||||||
AttachCallback(player_em, libvlc_MediaPlayerPaused, StateChangedCallback);
|
AttachCallback(player_em, libvlc_MediaPlayerPaused, StateChangedCallback);
|
||||||
AttachCallback(player_em, libvlc_MediaPlayerStopped, StateChangedCallback);
|
AttachCallback(player_em, libvlc_MediaPlayerStopped, StateChangedCallback);
|
||||||
AttachCallback(player_em, libvlc_MediaPlayerEndReached, StateChangedCallback);
|
AttachCallback(player_em, libvlc_MediaPlayerEndReached, StateChangedCallback);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -144,7 +139,6 @@ void VLCEngine::Stop(bool stop_after) {
|
||||||
|
|
||||||
if (!Initialised()) return;
|
if (!Initialised()) return;
|
||||||
libvlc_media_player_stop(player_);
|
libvlc_media_player_stop(player_);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +146,6 @@ void VLCEngine::Pause() {
|
||||||
|
|
||||||
if (!Initialised()) return;
|
if (!Initialised()) return;
|
||||||
libvlc_media_player_pause(player_);
|
libvlc_media_player_pause(player_);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +153,6 @@ void VLCEngine::Unpause() {
|
||||||
|
|
||||||
if (!Initialised()) return;
|
if (!Initialised()) return;
|
||||||
libvlc_media_player_play(player_);
|
libvlc_media_player_play(player_);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,14 +168,12 @@ void VLCEngine::Seek(quint64 offset_nanosec) {
|
||||||
float pos = float(offset) / len;
|
float pos = float(offset) / len;
|
||||||
|
|
||||||
libvlc_media_player_set_position(player_, pos);
|
libvlc_media_player_set_position(player_, pos);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VLCEngine::SetVolumeSW(uint percent) {
|
void VLCEngine::SetVolumeSW(uint percent) {
|
||||||
if (!Initialised()) return;
|
if (!Initialised()) return;
|
||||||
libvlc_audio_set_volume(player_, percent);
|
libvlc_audio_set_volume(player_, percent);
|
||||||
HandleErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 VLCEngine::position_nanosec() const {
|
qint64 VLCEngine::position_nanosec() const {
|
||||||
|
@ -250,13 +240,9 @@ uint VLCEngine::position() const {
|
||||||
if (!Initialised()) return (0);
|
if (!Initialised()) return (0);
|
||||||
|
|
||||||
bool is_playing = libvlc_media_player_is_playing(player_);
|
bool is_playing = libvlc_media_player_is_playing(player_);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
if (!is_playing) return 0;
|
if (!is_playing) return 0;
|
||||||
|
|
||||||
float pos = libvlc_media_player_get_position(player_);
|
float pos = libvlc_media_player_get_position(player_);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
return (pos * length());
|
return (pos * length());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -266,30 +252,19 @@ uint VLCEngine::length() const {
|
||||||
if (!Initialised()) return(0);
|
if (!Initialised()) return(0);
|
||||||
|
|
||||||
bool is_playing = libvlc_media_player_is_playing(player_);
|
bool is_playing = libvlc_media_player_is_playing(player_);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
if (!is_playing) return 0;
|
if (!is_playing) return 0;
|
||||||
|
|
||||||
libvlc_time_t len = libvlc_media_player_get_length(player_);
|
libvlc_time_t len = libvlc_media_player_get_length(player_);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VLCEngine::CanDecode(const QUrl &url) {
|
bool VLCEngine::CanDecode(const QUrl &url) { return true; }
|
||||||
|
|
||||||
// TODO
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VLCEngine::HandleErrors() const {
|
|
||||||
}
|
|
||||||
|
|
||||||
void VLCEngine::AttachCallback(libvlc_event_manager_t *em, libvlc_event_type_t type, libvlc_callback_t callback) {
|
void VLCEngine::AttachCallback(libvlc_event_manager_t *em, libvlc_event_type_t type, libvlc_callback_t callback) {
|
||||||
|
|
||||||
libvlc_event_attach(em, type, callback, this);
|
libvlc_event_attach(em, type, callback, this);
|
||||||
HandleErrors();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,19 +274,29 @@ void VLCEngine::StateChangedCallback(const libvlc_event_t *e, void *data) {
|
||||||
|
|
||||||
switch (e->type) {
|
switch (e->type) {
|
||||||
case libvlc_MediaPlayerNothingSpecial:
|
case libvlc_MediaPlayerNothingSpecial:
|
||||||
|
break;
|
||||||
|
|
||||||
case libvlc_MediaPlayerStopped:
|
case libvlc_MediaPlayerStopped:
|
||||||
case libvlc_MediaPlayerEncounteredError:
|
|
||||||
engine->state_ = Engine::Empty;
|
engine->state_ = Engine::Empty;
|
||||||
|
emit engine->StateChanged(engine->state_);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case libvlc_MediaPlayerEncounteredError:
|
||||||
|
engine->state_ = Engine::Error;
|
||||||
|
emit engine->StateChanged(engine->state_);
|
||||||
|
emit engine->FatalError();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case libvlc_MediaPlayerOpening:
|
case libvlc_MediaPlayerOpening:
|
||||||
case libvlc_MediaPlayerBuffering:
|
case libvlc_MediaPlayerBuffering:
|
||||||
case libvlc_MediaPlayerPlaying:
|
case libvlc_MediaPlayerPlaying:
|
||||||
engine->state_ = Engine::Playing;
|
engine->state_ = Engine::Playing;
|
||||||
|
emit engine->StateChanged(engine->state_);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case libvlc_MediaPlayerPaused:
|
case libvlc_MediaPlayerPaused:
|
||||||
engine->state_ = Engine::Paused;
|
engine->state_ = Engine::Paused;
|
||||||
|
emit engine->StateChanged(engine->state_);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case libvlc_MediaPlayerEndReached:
|
case libvlc_MediaPlayerEndReached:
|
||||||
|
@ -320,8 +305,6 @@ void VLCEngine::StateChangedCallback(const libvlc_event_t *e, void *data) {
|
||||||
return; // Don't emit state changed here
|
return; // Don't emit state changed here
|
||||||
}
|
}
|
||||||
|
|
||||||
emit engine->StateChanged(engine->state_);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EngineBase::PluginDetailsList VLCEngine::GetPluginList() const {
|
EngineBase::PluginDetailsList VLCEngine::GetPluginList() const {
|
||||||
|
|
|
@ -75,7 +75,6 @@ class VLCEngine : public Engine::Base {
|
||||||
uint position() const;
|
uint position() const;
|
||||||
uint length() const;
|
uint length() const;
|
||||||
bool CanDecode(const QUrl &url);
|
bool CanDecode(const QUrl &url);
|
||||||
void HandleErrors() const;
|
|
||||||
void AttachCallback(libvlc_event_manager_t* em, libvlc_event_type_t type, libvlc_callback_t callback);
|
void AttachCallback(libvlc_event_manager_t* em, libvlc_event_type_t type, libvlc_callback_t callback);
|
||||||
static void StateChangedCallback(const libvlc_event_t* e, void* data);
|
static void StateChangedCallback(const libvlc_event_t* e, void* data);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue