27 VideoPlayer(
const int32_t argc = 0,
const char *
const* argv =
nullptr)
29 vlc = libvlc_new(argc, argv);
42 bool loadMediaFromFile(
const char* path)
44 media = libvlc_media_new_path(vlc, path);
48 fprintf(stderr,
"unable to create media %s", path);
52 return loadMedia(media);
55 bool loadMediaFromUrl(
const char* url)
57 media = libvlc_media_new_location(vlc, url);
61 fprintf(stderr,
"unable to create media %s", url);
65 return loadMedia(media);
68 bool loadMedia(libvlc_media_t* media)
70 media_player = libvlc_media_player_new_from_media(media);
72 if (media_player == NULL)
74 fprintf(stderr,
"unable to create media player");
75 libvlc_media_release(media);
79 buffer.resize(width*height*3);
80 libvlc_video_set_callbacks(media_player, lock_callback, unlock_callback,
nullptr,
this);
81 libvlc_video_set_format(media_player,
"RV24", width, height, width*3);
83 libvlc_media_player_pause(media_player);
90 libvlc_media_player_play(media_player);
95 libvlc_media_player_pause(media_player);
100 return libvlc_media_player_is_playing(media_player);
108 libvlc_media_player_set_position(media_player, position);
116 return libvlc_media_player_get_position(media_player);
123 libvlc_media_player_stop(media_player);
124 libvlc_media_player_release(media_player);
125 media_player =
nullptr;
130 libvlc_media_release(media);
136 static void* lock_callback(
void *
object,
void **planes)
138 VideoPlayer* video_player =
static_cast<VideoPlayer*
>(object);
140 video_player->mutex.lock();
141 planes[0] =
static_cast<void*
>(video_player->buffer.data());
147 static void unlock_callback(
void *
object,
void* ,
void *
const * )
150 video_player->need_frame_update =
true;
152 video_player->mutex.unlock();
155 bool need_frame_update =
false;
159 uint32_t width = 800, height = 600;
162 std::vector<std::byte> buffer;
165 libvlc_instance_t* vlc =
nullptr;
168 libvlc_media_player_t* media_player =
nullptr;
171 libvlc_media_t* media =
nullptr;