I think I'm getting the hang of it, render to textures always baffles me though. I understand it would be more efficient with 4.0 but last time I checked, webm was not stable so I might give it another try eventually.
As previously suggested, here is the new addition:
Code: Select all
void ZVideoLanMovie::UnlockMutexEvent(const VLC_Event *in_events, void *in_opaque)
{
std::condition_variable *l_cv = static_cast<std::condition_variable *>(in_opaque);
l_cv->notify_one();
}
Bool ZVideoLanMovie::MediaParse(libvlc_media_t *in_media, const libvlc_media_parse_flag_t &in_flags)
{
std::mutex l_mutex;
std::condition_variable l_cv;
std::unique_lock<std::mutex> l_lock(l_mutex);
libvlc_event_attach(m_MediaEventManager, libvlc_MediaParsedChanged, UnlockMutexEvent, &l_cv);
Int l_return = libvlc_media_parse_with_options(in_media, in_flags, 0);
l_cv.wait(l_lock);
libvlc_event_detach(m_MediaEventManager, libvlc_MediaParsedChanged, UnlockMutexEvent, &l_cv);
return l_return == 0;
}
Bool ZVideoLanMovie::Read(const Char *in_path)
{
Close();
m_Player = libvlc_media_player_new(m_VLC);
ZenValidateReturn(m_Player, false);
SetPlayerEvents(&ZVideoLanMovie::CallbackEvent, this);
libvlc_media_parse_flag_t l_flags;
if (ZStr::StartsWith(in_path, "http"))
{
m_Media = libvlc_media_new_location(m_VLC, in_path);
ZenValidateReturn(m_Media, false);
SetMediaEvents(&ZVideoLanMovie::CallbackEvent, this);
l_flags = libvlc_media_parse_network;
}
else
{
m_Media = libvlc_media_new_path(m_VLC, ZAgnostic::SlashesToBackSlashes(in_path));
ZenValidateReturn(m_Media, false);
SetMediaEvents(&ZVideoLanMovie::CallbackEvent, this);
libvlc_media_player_set_media(m_Player, m_Media);
l_flags = libvlc_media_parse_local;
}
if (MediaParse(m_Media, l_flags) == false)
{
ZenError("%s parsing options.", in_path);
}
return true;
}
void ZVideoLanMovie::CallbackEvent(const VLC_Event *in_events, void *in_opaque)
{
ZVideoLanMovie *l_video = static_cast<ZVideoLanMovie *>(in_opaque);
switch (in_events->type)
{
case libvlc_MediaSubItemAdded:
{
ZenStatus("ZVideoLanMovie::libvlc_MediaSubItemAdded");
l_video->m_Media = in_events->u.media_subitem_added.new_child;
libvlc_media_player_set_media(l_video->m_Player, l_video->m_Media);
break;
}
case libvlc_MediaPlayerVout:
{
Int l_count = in_events->u.media_player_vout.new_count;
if (l_count > 0)
{
ZenStatus("ZVideoLanMovie::libvlc_MediaPlayerVout : %d", l_count);
l_video->OnPlaybackReadyEvent();
}
break;
}
};
}
Up until now, I'm still looking for a call back that says: "everything is ready" to setup UI to video size and length. libvlc_MediaPlayerVout seems to be the closest cue but the problem I'm having is that youtube lua script is still processing while libvlc_MediaPlayerVout fires and render to texture sometimes works, sometimes it doesn't.
I'm wondering if anyone could see what am I missing?