SDL2 and libvlc help?

This forum is about all development around libVLC.
kingwill101
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 00:18

SDL2 and libvlc help?

Postby kingwill101 » 11 Jan 2014 00:30

all day i have been trying to integrate libvlc into sdl but cant seem to get it right. my code compiles but on run it gives a segfault, any help would be appreciated.

//video.cpp

Code: Select all

#include "video.hpp" void *lock(void *data, void **p_pixels); void unlock(void *data, void *id, void *const *p_pixels); void display(void *data, void *id); Video::Video() { } Video::~Video(){ //cleanup time if(isPlaying == true){ this->stop(); } libvlc_media_player_release(mp); libvlc_release(inst); SDL_DestroyMutex(this->con->mutex); SDL_DestroyRenderer(con->renderer); } Video::Video(SDL_Renderer *r){ this->inst = libvlc_new(0, NULL); this->con->renderer = r; this->con->t = SDL_CreateTexture(this->con->renderer,SDL_PIXELFORMAT_BGR565,SDL_TEXTUREACCESS_STREAMING,400,400); this->con->mutex = SDL_CreateMutex(); libvlc_video_set_callbacks(mp, lock,unlock,display,&this->con); libvlc_video_set_format(mp, "RV16", 100, 100, 200); } void *lock(void *data, void **p_pixels) { Context *ctx = (Context*)data; int n; SDL_LockMutex(ctx->mutex); SDL_LockTexture(ctx->t,NULL,p_pixels, &ctx->n); //*p_pixels = ctx->surf->pixels; return NULL; /* picture identifier, not needed here */ } void unlock(void *data, void *id, void *const *p_pixels) { Context *ctx = (Context*)data; SDL_UnlockTexture(ctx->t); SDL_UnlockMutex(ctx->mutex); } void display(void *data, void *id) { /* VLC wants to display the video */ (void) data; } void Video::loadTrack(std::string path){ currentTrack = path; m = libvlc_media_new_path(inst, path.c_str()); mp = libvlc_media_player_new_from_media(m); libvlc_media_release(m); } void Video::pause(){ if(paused == false) { libvlc_media_player_set_pause(mp, 1); paused = true; }else if(paused == true){ libvlc_media_player_set_pause(mp, 0); paused = false; } } void Video::play(){ if (isPlaying == false){ libvlc_media_player_play(mp); isPlaying = true; } } std::string Video::current(){ return currentTrack; } void Video::stop(){ if(isPlaying == true){ libvlc_media_player_stop(mp); isPlaying = false; } }

Code: Select all

#ifndef VIDEO_H #define VIDEO_H #include <SDL2/SDL.h> #include <vlc/vlc.h> #include <string> struct Context { SDL_mutex *mutex; SDL_Renderer *renderer; SDL_Texture *t; int n; }; class Video { public: Video(); Video(SDL_Renderer *r); ~Video(); void play(); void pause(); void stop(); void loadTrack(std::string); std::string current(); //void lock(void *data, void **pixels); //void unlock(void *data, void *id, void *const *p_pixels); //void display(void *data, void *id); void init(); std::string currentTrack; private: bool isPlaying; // is the media player playing anything bool paused; // is the media player currently paused libvlc_instance_t *inst; //holds our libvlc instance libvlc_media_player_t *mp; //media player libvlc_media_t *m; // stores data for each media object SDL_Rect rect; SDL_Surface *screen; SDL_Renderer *renderrer; Context *con; }; #endif // VIDEO_H
thiis is where my debugger complains

Code: Select all

libvlc_video_set_callbacks(mp, lock,unlock,display,&this->con);

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: SDL2 and libvlc help?

Postby Jean-Baptiste Kempf » 11 Jan 2014 18:01

Please share the backtrace.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

kingwill101
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 00:18

Re: SDL2 and libvlc help?

Postby kingwill101 » 13 Jan 2014 16:21

Please share the backtrace.
as requested

Code: Select all

(gdb) bt #0 0x00007ffff6b05037 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff6b08698 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff6afde03 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #3 0x00007ffff6afdeb2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6 #4 0x00007ffff78d3add in __pthread_mutex_lock_full () from /lib/x86_64-linux-gnu/libpthread.so.0 #5 0x00007ffff6473d92 in var_SetChecked () from /usr/lib/libvlccore.so.5 #6 0x00007ffff76c3c58 in libvlc_video_set_callbacks () from /usr/lib/libvlc.so.5 #7 0x000000000040272c in Video::Video (this=0x1a10840, r=0x658af0) at ../kingeng/video.cpp:34 #8 0x0000000000401a3d in main () at ../kingeng/main.cpp:44 (gdb)
a little more info

Code: Select all

(gdb) run Starting program: /home/user/qtcreator-2.8.1/build-kingeng-Desktop-Debug/kingeng warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7ffff7fce700 (LWP 5611)] [New Thread 0x7ffff28fa700 (LWP 5616)] kingeng: pthread_mutex_lock.c:317: __pthread_mutex_lock_full: Assertion `(-(e)) != 3 || !robust' failed. Program received signal SIGABRT, Aborted. 0x00007ffff6b05037 in raise () from /lib/x86_64-linux-gnu/libc.so.6 (gdb)

kingwill101
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 00:18

Re: SDL2 and libvlc help?

Postby kingwill101 » 16 Jan 2014 16:42

anybody?

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: SDL2 and libvlc help?

Postby sherington » 16 Jan 2014 16:48

Doesn't your constructor reference mp when it is null?

You don't assign mp until you call loadTrack...

kingwill101
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 00:18

Re: SDL2 and libvlc help?

Postby kingwill101 » 16 Jan 2014 22:56

Doesn't your constructor reference mp when it is null?

You don't assign mp until you call loadTrack...
wow!! how could i not notice that..thanks in a million!!

so that seemed to have helped alot but now im getting another error and im not sure if it is related

Code: Select all

invalid and inefficient vfw-avi packed B frames detected

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: SDL2 and libvlc help?

Postby Jean-Baptiste Kempf » 17 Jan 2014 18:52

Unrelated and you should not worry.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

kingwill101
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 00:18

Re: SDL2 and libvlc help?

Postby kingwill101 » 20 Jan 2014 18:05

my videoes fail to play after that error so i guess i can worry now


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 18 guests