I try to develop an application aroud libvlc to display webcam Stream. I use Qt to insert the Stream in a widget. I use callcack function to get the image pointor.
Here is my code:
Code: Select all
// IMPORT DES LIBRARIES Qt
#include <QVBoxLayout>
#include <QPushButton>
#include <QSlider>
#include <QTimer>
#include <QFrame>
#include <QDir>
#include <QDate>
#include <QAction>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsProxyWidget>
#include <QLabel>
#include <QTime>
// IMPORT DES LIBRARIES Qwt
// IMPORT DES LIBRARIES perso
#include <player.h>
#include <frame.h>
// IMPORT de la LIBRAIRIE qextserial
#include <iostream>
#include <stdio.h>
using namespace std;
Player::Player(QWidget *Parent)
: QWidget(Parent)
{
PlayerTime = 0; // Pointer dans le vide
_videoWidget =new QWidget(this);
_videoWidget->setStyleSheet("background-color:black;");
// view->setScene(scene);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(_videoWidget);
// layout->addWidget(view);
setLayout(layout);
/* Load the VLC engine */
inst = libvlc_new(0, NULL);
}
//desctructor
Player::~Player()
{
// delete _videoWidget;
//cout << "Suppression Player" << endl;
// libvlc_media_player_stop (mp);
/* Free the media_player */
// libvlc_media_player_release (mp);
// libvlc_release (inst);
//cout << "Suppression Player fin" << endl;
}
//////////////////////////////////////////////////////
/*
Nom: SetSetting
Paremètres entrées: void
Paremètres sorties: void
Description : Application des options
*/
//////////////////////////////////////////////////////
void Player::SetSetting()
{
}
void display(void *opaque, void *picture)
{
cout << "je passe la" << endl;
}
void *lock(void *data, void **p_pixels)
{
cout << "je passe li" << endl;
// struct ctx *ctx = data;
// SDL_LockMutex(ctx->mutex);
// SDL_LockSurface(ctx->surf);
// *p_pixels = ctx->surf->pixels;
return NULL; /* picture identifier, not needed here */
}
void unlock(void *data, void *id, void *const *p_pixels)
{
cout << "je passe lo" << endl;
// struct ctx *ctx = data;
// /* VLC just rendered the video, but we can also render stuff */
// uint16_t *pixels = *p_pixels;
// int x, y;
// for(y = 10; y < 40; y++)
// for(x = 10; x < 40; x++)
// if(x < 13 || y < 13 || x > 36 || y > 36)
// pixels[y * VIDEOWIDTH + x] = 0xffff;
// else
// pixels[y * VIDEOWIDTH + x] = 0x0;
// SDL_UnlockSurface(ctx->surf);
// SDL_UnlockMutex(ctx->mutex);
// assert(id == NULL); /* picture identifier, not needed here */
}
void Player::playFile()
{
m = libvlc_media_new_path(inst, "dshow://");
libvlc_media_add_option(m,":dshow-vdev="); //USB2.0 Grabber
libvlc_media_add_option(m,":dshow-adev=none"); //USB2.0 Grabber
/* Create a media player playing environement */
mp = libvlc_media_player_new_from_media (m);
libvlc_video_set_callbacks(mp,
lock,
unlock,
display,
(void *)this);
libvlc_media_player_set_hwnd(mp,_videoWidget->winId()); // for vlc 1.0
// libvlc_media_player_set_xwindow(mp,(uint32_t)this->winId());
/* play the media_player */
libvlc_media_player_play(mp);
// _videoWidget->move(-20,0);
MyPlayerStat = Play;
}
void Player::updateInterface()
{
}
void Player::AskRecord()
{
emit AskRecordSignal();
}
void Player::libvlc_media_player_record_start(QString Path)
{
if(MyPlayerStat != Record)
{
libvlc_media_player_stop (mp);
/* Free the media_player */
libvlc_media_player_release (mp);
// libvlc_release (inst);
m = libvlc_media_new_path(inst,"dshow://");
libvlc_media_add_option(m,":dshow-vdev="); //USB2.0 Grabber
libvlc_media_add_option(m,":dshow-adev=none"); //USB2.0 Grabber
QDate D = QDate::currentDate();
QTime time = QTime::currentTime();
QString timeString = time.toString();
QStringList Stmp = timeString.split(":");
QString Sout ="";
for(int i=0 ; i<Stmp.size() ; i++)
{
Sout += Stmp[i]+"_";
}
QString S;
S = QString::number(D.day()) + "_" + QString::number(D.month())+ "_" + QString::number(D.year())+ "_" + Sout + "video.asf" ;
QString Option = ":sout=#transcode{vcodec=WMV2,vb=800,scale=1,acodec=wma,ab=128,channels=2}:duplicate{dst=display,dst=std{access=file,mux=asf,dst="+Path+"\\"+S+"}}";
// QString Option = ":sout=#transcode{vcodec=WMV2,vb=800,scale=1,acodec=wma,ab=128,channels=2}:duplicate{dst=display,dst=std{access=file,mux=asf,dst=C:/Users/xavier/Desktop/tt44443.asf}}";
//cout << "options : " << Option.toStdString() << " et " << endl;
libvlc_media_add_option(m, Option.toStdString().data());
/* Create a media player playing environement */
mp = libvlc_media_player_new_from_media (m);
/* No need to keep the media now */
// libvlc_media_release (m);
libvlc_media_player_set_hwnd(mp, _videoWidget->winId()); // for vlc 1.0
/* play the media_player */
libvlc_media_player_play(mp);
inst = libvlc_new (0, NULL);
//demarrage du timer
IDTimer = startTimer(1000);
MyPlayerStat = Record;
if(PlayerTime == 0)
PlayerTime = new QTime();
else
{
delete PlayerTime;
PlayerTime = new QTime();
}
PlayerTime->start();
}
}
//////////////////////////////////////////////////////
/*
Nom: libvlc_media_player_record_stop
Paremètres entrées: void
Paremètres sorties: void
Description : Arret de l'affichage du flux video
*/
//////////////////////////////////////////////////////
void Player::libvlc_media_player_record_stop()
{
// Arret du timer
// Remise à zero de l'affichage
emit ValueRecordTime(" ");
if(MyPlayerStat != Play)
{
killTimer(IDTimer);
libvlc_media_player_stop(mp);
playFile();
}
}
//////////////////////////////////////////////////////
/*
Nom: libvlc_media_player_record_play
Paremètres entrées: void
Paremètres sorties: void
Description : Lancer l'affichage du flux video
*/
//////////////////////////////////////////////////////
void Player::libvlc_media_player_record_play()
{
if(MyPlayerStat != Record)
libvlc_media_player_play(mp);
}
//////////////////////////////////////////////////////
/*
Nom: ProcessFrame
Paremètres entrées: Frame
Paremètres sorties: void
Description : Traitement de la trame du RS232
*/
//////////////////////////////////////////////////////
void Player::ProcessFrame(Frame F)
{
}
//////////////////////////////////////////////////////
/*
Nom: timeConversion
Paremètres entrées: int msecs
Paremètres sorties: void
Description :
*/
//////////////////////////////////////////////////////
QString Player::timeConversion(int msecs)
{
QString formattedTime;
int hours = msecs/(1000*60*60);
int minutes = (msecs-(hours*1000*60*60))/(1000*60);
int seconds = (msecs-(minutes*1000*60)-(hours*1000*60*60))/1000;
// int milliseconds = msecs-(seconds*1000)-(minutes*1000*60)-(hours*1000*60*60);
formattedTime.append(QString("%1").arg(hours, 2, 10, QLatin1Char('0')) + ":" +
QString( "%1" ).arg(minutes, 2, 10, QLatin1Char('0')) + ":" +
QString( "%1" ).arg(seconds, 2, 10, QLatin1Char('0')));
return formattedTime;
}
//////////////////////////////////////////////////////
/*
Nom: timerEvent
Paremètres entrées: QTimerEvent* event
Paremètres sorties: void
Description : Timer permettant de gerer l'affichage
dans le label d'enregsitrement.
*/
//////////////////////////////////////////////////////
void Player::timerEvent(QTimerEvent* event)
{
if(MyPlayerStat == Record)
emit ValueRecordTime(" Rec: "+timeConversion(PlayerTime->elapsed()));
}
Why this happens? The error happens when I had that line for the callback functions: libvlc_video_set_callbacks(mp, lock, unlock, display,(void *)this);
Thank you in advance.