Code: Select all
libvlc_video_set_format_callbacks
Code: Select all
struct ctx
{
unsigned char *pixeldata;
std::mutex imagemutex;
};
static void *lock(void *data, void **p_pixels)
{
struct ctx *ctx = reinterpret_cast<struct ctx *>(data);
ctx->imagemutex.lock();
*p_pixels = ctx->pixeldata;
return NULL;
}
static void unlock(void *data, void *id, void *const *p_pixels)
{
struct ctx *ctx = reinterpret_cast<struct ctx *>(data);
ctx->imagemutex.unlock();
assert(id == NULL);
}
unsigned setup(void **opaque, char *chroma, unsigned *width, unsigned *height, unsigned *pitches, unsigned *lines)
{
struct ctx *callback = reinterpret_cast<struct ctx *>(*opaque);
unsigned nWidth = (*width);
unsigned nHeight = (*height);
(*pitches) = nWidth * 3;
(*lines) = nHeight;
chroma = (char *)"RV24";
callback->pixeldata = new unsigned char[nWidth*nHeight*3];
return 1;
}
int main(int argc, char *argv[])
{
libvlc_instance_t *vlcInstance;
libvlc_media_player_t *_player;
libvlc_media_t *_media;
const char * const vlc_args[] = {
"-I", "dummy", // Don't use any interface
"--ignore-config", // Don't use VLC's config
"--extraintf=logger", // Log anything
"--verbose=2", // Be much more verbose then normal for debugging purpose
};
vlcInstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
_media = libvlc_media_new_location(vlcInstance , "rtsp://address");
_player = libvlc_media_player_new_from_media(_media);
struct ctx *callback = new struct ctx;
libvlc_video_set_callbacks(_player, lock, unlock, 0, callback);
libvlc_video_set_format_callbacks(_player, setup, 0);
libvlc_media_player_play(_player);
}
Code: Select all
libvlc_video_set_format_callbacks(_player, setup, 0);
Code: Select all
libvlc_video_set_format(_player, "RV24", 720, 404, 720 * 3);