25 VideoPlayer(
const int argc = 0,
const char *
const* argv =
nullptr)
27 vlc = libvlc_new(argc, argv);
40 bool loadMediaFromFile(
const char* path)
42 media = libvlc_media_new_path(vlc, path);
46 fprintf(stderr,
"unable to create media %s", path);
50 return loadMedia(media);
53 bool loadMediaFromUrl(
const char* url)
55 media = libvlc_media_new_location(vlc, url);
59 fprintf(stderr,
"unable to create media %s", url);
63 return loadMedia(media);
66 bool loadMedia(libvlc_media_t* media)
68 media_player = libvlc_media_player_new_from_media(media);
70 if (media_player == NULL)
72 fprintf(stderr,
"unable to create media player");
73 libvlc_media_release(media);
77 buffer.resize(width*height*3);
78 libvlc_video_set_callbacks(media_player, lock_callback, unlock_callback,
nullptr,
this);
79 libvlc_video_set_format(media_player,
"RV24", width, height, width*3);
81 libvlc_media_player_pause(media_player);
88 libvlc_media_player_play(media_player);
93 libvlc_media_player_pause(media_player);
98 return libvlc_media_player_is_playing(media_player);
106 libvlc_media_player_set_position(media_player, position);
114 return libvlc_media_player_get_position(media_player);
121 libvlc_media_player_stop(media_player);
122 libvlc_media_player_release(media_player);
123 media_player =
nullptr;
128 libvlc_media_release(media);
134 static void* lock_callback(
void *
object,
void **planes)
136 VideoPlayer* video_player =
static_cast<VideoPlayer*
>(object);
138 video_player->mutex.lock();
139 planes[0] =
static_cast<void*
>(video_player->buffer.data());
145 static void unlock_callback(
void *
object,
void *picture,
void *
const *planes)
148 video_player->need_frame_update =
true;
150 video_player->mutex.unlock();
153 bool need_frame_update =
false;
157 uint32_t width = 800, height = 600;
160 std::vector<std::byte> buffer;
163 libvlc_instance_t* vlc =
nullptr;
166 libvlc_media_player_t* media_player =
nullptr;
169 libvlc_media_t* media =
nullptr;