The code:
Code: Select all
libvlc::libvlc()
{
initVLC();
// Create a new media from the Media Resource Locator
m_vlcMedia = libvlc_media_new( m_vlcInstance, "rtsp://192.168.0.9", &m_ex );
libvlc_media_add_option(m_vlcMedia,":rtsp-caching=50", NULL);
// We now need a struct for storing the video buffer
// and a mutex to protect it.
// The structure will be given as an arguments for the
// lock/unlock callbacks.
struct ctx* context;
// Allocating the space for the structure
context = ( struct ctx* )malloc( sizeof( *context ) );
// Allocating the video buffer
context->pixels = ( uchar* )malloc( ( sizeof( *( context->pixels ) ) * VIDEO_WIDTH * VIDEO_HEIGHT ) * 4 );
// Allocating the mutex
context->mutex = new QMutex();
context->mainWindow = this;
// Creating some char[] to store the media options
char clock[64], cunlock[64], cdata[64];
char width[32], height[32], chroma[32], pitch[32];
// Preparing the options for the media
// The clock and cunlock contain a pointer to the associated
// static method (note the use of %lld).
//
// In that specific case we can't use Qt:
// The sprintf method of the QString does not support
// length modifiers (like %lld).
sprintf( clock, ":vmem-lock=%lld", (long long int)(intptr_t)lock );
sprintf( cunlock, ":vmem-unlock=%lld", (long long int)(intptr_t)unlock );
sprintf( cdata, ":vmem-data=%lld", (long long int)(intptr_t)context );
sprintf( width, ":vmem-width=%i", VIDEO_WIDTH );
sprintf( height, ":vmem-height=%i", VIDEO_HEIGHT );
sprintf( chroma, ":vmem-chroma=%s", "RV32" );
sprintf( pitch, ":vmem-pitch=%i", VIDEO_WIDTH * 4 );
// List of options
// This part can be easily replaced by a QStringList
// instead of a C array.
char const* media_options[] =
{
":vout=vmem",
width, height,
chroma, pitch,
clock, cunlock,
cdata
};
int media_options_size = sizeof( media_options )
/ sizeof( *media_options );
// Adding each option from the array to the media
for ( int i = 0; i < media_options_size; ++i )
{
libvlc_media_add_option( m_vlcMedia, media_options[i], &m_ex );
}
[color=#FF0000]
libvlc_media_track_info_t *tracks;
libvlc_media_get_tracks_info(m_vlcMedia, &tracks);[/color]
// Put the media into the mediaplayer
libvlc_media_player_set_media( m_vlcMediaplayer, m_vlcMedia, &m_ex );
// Finally, start the playback.
libvlc_media_player_play( m_vlcMediaplayer, &m_ex );
}
void libvlc::initVLC()
{
// List of parameters used to initialize libvlc.
// These arguments are same as those you can pass
// the the VLC command line.
char const* vlc_argv[] =
{
"--verbose", "3",
// Edit this line if libvlc can't locate your plugins directory
//"--plugin-path", "/path/to/vlc",
};
int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
// Initialize the libvlc exception mechanism
libvlc_exception_init( &m_ex );
// Create a libvlc instance
m_vlcInstance = libvlc_new( vlc_argc, vlc_argv, &m_ex );
// This for catching and printing exceptions
// raised by libvlc
// Create the mediaplayer used to play a media
m_vlcMediaplayer = libvlc_media_player_new( m_vlcInstance, &m_ex );
// Re-checking for exceptions
cvNamedWindow("win", CV_WINDOW_AUTOSIZE);
// We're done with the initialization!
}
g++ output :
At first:
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../qtsdk-2010.04/qt/mkspecs/linux-g++ -I../libvlc -I../../qtsdk-2010.04/qt/include/QtCore -I../../qtsdk-2010.04/qt/include/QtGui -I../../qtsdk-2010.04/qt/include -I../libvlc -I. -I. -o libvlc.o ../libvlc/libvlc.cpp
../libvlc/libvlc.cpp: In constructor ‘libvlc::libvlc()’:
../libvlc/libvlc.cpp:70: error: ‘libvlc_media_track_info_t’ was not declared in this scope
../libvlc/libvlc.cpp:70: error: ‘tracks’ was not declared in this scope
../libvlc/libvlc.cpp:71: error: ‘libvlc_media_get_tracks_info’ was not declared in this scope
make: *** [libvlc.o] Erreur 1
And after declared function:
g++ -Wl,-rpath,/home/sevil/qtsdk-2010.04/qt/lib -o libvlc libvlc.o main.o moc_libvlc.o -L/home/sevil/qtsdk-2010.04/qt/lib -lvlc -lcv -lcvaux -lhighgui -lQtGui -L/home/sevil/qtsdk-2010.04/qt/lib -L/usr/X11R6/lib -lQtCore -lpthread
libvlc.o: In function `libvlc':
../libvlc/libvlc.cpp:77: undefined reference to `libvlc_media_get_tracks_info(libvlc_media_t*, libvlc_media_track_info_t**)'
../libvlc/libvlc.cpp:77: undefined reference to `libvlc_media_get_tracks_info(libvlc_media_t*, libvlc_media_track_info_t**)'
collect2: ld returned 1 exit status
make: *** [libvlc] Erreur 1