Code: Select all
m_vlcobj=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
Code: Select all
~"#0 0xb7fdd424 in __kernel_vsyscall ()\n"
>~"#1 0xb6dd01df in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64\n"
>~"#2 0xb6dd3825 in __GI_abort () at abort.c:91\n"
>~"#3 0xb6e0d39a in __libc_message (do_abort=2, fmt=0xb6f07aa8 \"*** glibc detected *** %s: %s: 0x%s ***\\n\") at ../sysdeps/unix/sysv/linux/libc_fatal.c:201\n"
>~"#4 0xb6e17ee2 in malloc_printerr (action=<optimized out>, str=<optimized out>, ptr=0xb74bee9c) at malloc.c:5018\n"
>~"#5 0xb6e1c56d in __GI___libc_realloc (oldmem=0xb74bee9c, bytes=32) at malloc.c:3021\n"
>~"#6 0xb70ffe67 in QListData::realloc(int) () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#7 0xb70fff4c in QListData::append(int) () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#8 0xb70fffd3 in QListData::append() () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#9 0xb70bb2c8 in ?? () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#10 0xb70b94fd in ?? () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#11 0xb70ba0d8 in ?? () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#12 0xb70ba8ec in qMessageFormatString(QtMsgType, QMessageLogContext const&, QString const&) () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#13 0xb70baa72 in ?? () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#14 0xb70b8227 in ?? () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#15 0xb70b8383 in ?? () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#16 0xb70b894f in QMessageLogger::fatal(char const*, ...) const () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#17 0xb72ae52f in QMetaType::registerNormalizedType(QByteArray const&, void (*)(void*), void* (*)(void const*), void (*)(void*), void* (*)(void*, void const*), int, QFlags<QMetaType::TypeFlag>, QMetaObject const*) () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#18 0xb72ae5e7 in QMetaType::registerType(char const*, void (*)(void*), void* (*)(void const*), void (*)(void*), void* (*)(void*, void const*), int, QFlags<QMetaType::TypeFlag>, QMetaObject const*) () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#19 0xb72ae6a7 in QMetaType::registerType(char const*, void (*)(void*), void* (*)(void const*)) () from /home/fardst/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
>~"#20 0xb0a9ba8e in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4\n"
>~"#21 0xb0899f40 in ?? () from /usr/lib/i386-linux-gnu/libQtGui.so.4\n"
>~"#22 0xb7feceab in call_init (env=0xbffff78c, argv=0xbffff784, argc=1, l=<optimized out>) at dl-init.c:85\n"
>~"#23 call_init (l=<optimized out>, argc=1, argv=0xbffff784, env=0xbffff78c) at dl-init.c:35\n"
>~"#24 0xb7fecf94 in _dl_init (main_map=<optimized out>, argc=1, argv=0xbffff784, env=0xbffff78c) at dl-init.c:134\n"
>~"#25 0xb7ff0fa6 in dl_open_worker (a=0xbfffeea0) at dl-open.c:549\n"
>~"#26 0xb7fecccf in _dl_catch_error (objname=0xbfffeec4, errstring=0xbfffeec8, mallocedp=0xbfffeecf, operate=0xb7ff0c40 <dl_open_worker>, args=0xbfffeea0) at dl-error.c:178\n"
>~"#27 0xb7ff07f4 in _dl_open (file=0x8378450 \"/usr/lib/vlc/plugins/gui/libqt4_plugin.so\", mode=-2147483647, caller_dlopen=0xb6d3d1a0, nsid=-2, argc=1, argv=0xbffff784, env=0xbffff78c) at dl-open.c:639\n"
>~"#28 0xb65e3be9 in dlopen_doit (a=0xbffff070) at dlopen.c:67\n"
>~"#29 0xb7fecccf in _dl_catch_error (objname=0x8055f7c, errstring=0x8055f80, mallocedp=0x8055f78, operate=0xb65e3b50 <dlopen_doit>, args=0xbffff070) at dl-error.c:178\n"
>~"#30 0xb65e433a in _dlerror_run (operate=0xb65e3b50 <dlopen_doit>, args=0xbffff070) at dlerror.c:164\n"
>~"#31 0xb65e3c97 in __dlopen (file=0x8378450 \"/usr/lib/vlc/plugins/gui/libqt4_plugin.so\", mode=1) at dlopen.c:88\n"
>~"#32 0xb6d3d1a0 in module_Load (p_this=0x829bf30, psz_file=0x8378450 \"/usr/lib/vlc/plugins/gui/libqt4_plugin.so\", p_handle=0xbffff0ec, lazy=true) at posix/plugin.c:62\n"
>~"#33 0xb6d1e931 in module_InitDynamic (obj=0x829bf30, path=0x8378450 \"/usr/lib/vlc/plugins/gui/libqt4_plugin.so\", fast=true) at modules/bank.c:536\n"
>~"#34 0xb6d1ec78 in AllocatePluginFile (st=0xbffff158, relpath=0x8376d68 \"gui/libqt4_plugin.so\", abspath=0x8378450 \"/usr/lib/vlc/plugins/gui/libqt4_plugin.so\", bank=0xbffff2f0) at modules/bank.c:479\n"
>~"#35 AllocatePluginDir (bank=0xbffff2f0, maxdepth=3, absdir=0x8376d48 \"/usr/lib/vlc/plugins/gui\", reldir=0x836d448 \"gui\") at modules/bank.c:440\n"
>~"#36 0xb6d1ebd3 in AllocatePluginDir (bank=0xbffff2f0, maxdepth=4, absdir=0x82ae8a8 \"/usr/lib/vlc/plugins\", reldir=0x0) at modules/bank.c:444\n"
>~"#37 0xb6d1ef54 in AllocatePluginPath (p_this=0x829bf30, path=0x82ae8a8 \"/usr/lib/vlc/plugins\", mode=CACHE_USE) at modules/bank.c:353\n"
>~"#38 0xb6d1f63a in AllocateAllPlugins (p_this=0x829bf30) at modules/bank.c:282\n"
>~"#39 module_LoadPlugins (obj=0x829bf30) at modules/bank.c:189\n"
>~"#40 0xb6c9aa93 in libvlc_InternalInit (p_libvlc=0x829bf30, i_argc=6, ppsz_argv=0xbffff570) at libvlc.c:247\n"
>~"#41 0xb7faa0cb in libvlc_new (argc=5, argv=0xbffff604) at core.c:59\n"
>~"#42 0x0804cc4b in Player::Player (this=0xbffff6a0) at ../libVlc/Player.cpp:71\n"
>~"#43 0x0804bfa8 in main (argc=1, argv=0xbffff784) at ../libVlc/main.cpp:8\n"
Code: Select all
#include "Player.h"
#include <QtXml/QDomDocument>
#include <QVBoxLayout>
#include <QPushButton>
#include <QSlider>
#include <QTimer>
#include <QFrame>
#include <QEvent>
#include <QMouseEvent>
#include <QApplication>
#include <QPainter>
#include <QMenuBar>
#include <QAction>
#include <QMainWindow>
#include <QFileDialog>
#include <QDebug>
#include <QFile>
#include <iostream>
#include <stdio.h>
const QEvent::Type VLC_EVENT_TYPE = (QEvent::Type)5001;
class QUpdatePosEvent:public QEvent
{
public:
QUpdatePosEvent(int newPos):QEvent(VLC_EVENT_TYPE){m_newPos = newPos;}
int m_newPos;
};
Player::Player()
: QWidget()
{
QMenuBar* menubar=new QMenuBar;
//preparation of the vlc command
const char * 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
};
m_video_wnd=new QFrame(this);
m_volume_level=new QSlider(Qt::Horizontal,this);
m_volume_level->setMaximum(100);
// Note: if you use streaming, there is no ability to use the position slider
m_video_position=new QSlider(Qt::Horizontal,this);
m_video_position->setMaximum(POSITION_RESOLUTION);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(menubar);
layout->addWidget(m_video_wnd);
layout->addWidget(m_video_position);
layout->addWidget(m_volume_level);
setLayout(layout);
QMenu *fileMenu = new QMenu("&File");
QAction *fileAction = new QAction("Open..", this);
fileAction->setShortcut(Qt::CTRL + Qt::Key_O);
fileMenu->addAction(fileAction);
fileMenu->addSeparator();
fileMenu->addAction("Close", QApplication::instance(), SLOT(quit()), Qt::CTRL + Qt::Key_X);
QMenu *aboutMenu = new QMenu("&About");
aboutMenu->addAction("About");
connect(fileAction, SIGNAL(triggered()), this, SLOT(menuOpen()));
menubar->addMenu(fileMenu);
menubar->addMenu(aboutMenu);
m_vlcobj=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
m_player = libvlc_media_player_new (m_vlcobj );
connect(m_video_position, SIGNAL(sliderMoved(int)), this, SLOT(changePosition(int)));
connect(m_volume_level, SIGNAL(sliderMoved(int)), this, SLOT(changeVolume(int)));
libvlc_event_manager_t * evtManager;
evtManager = libvlc_media_player_event_manager(m_player);
libvlc_event_attach(evtManager,
libvlc_MediaPlayerPositionChanged,
(libvlc_callback_t)onVlcEvent, this);
libvlc_event_attach(evtManager,libvlc_MediaPlayerEndReached,
(libvlc_callback_t)onVlcEvent,this);
libvlc_event_attach(evtManager,libvlc_MediaPlayerStopped,
(libvlc_callback_t)onVlcEvent,this);
#if defined(Q_OS_WIN)
libvlc_media_player_set_hwnd(m_player, m_video_wnd->winId() );
#else
libvlc_media_player_set_xwindow(m_player, (int)(m_video_wnd->winId()) );
#endif
menuOpen();
}
Player::~Player()
{
libvlc_media_player_stop (m_player);
libvlc_media_player_release (m_player);
libvlc_release (m_vlcobj);
}
int Player::createConfigFile(QString config_path)
{
if (QFile::exists(config_path)==false)
{
std::cout << __FUNCTION__ << " create sample configuration file " << (const char*)config_path.toLatin1()<<std::endl;
QFile file(config_path);
QDomDocument doc( "qtvlc" );
QDomElement root = doc.createElement( "qtvlc" );
doc.appendChild( root );
{
QDomElement tag = doc.createElement("aspect_ratio");
root.appendChild(tag);
QDomText t = doc.createTextNode("4:3");
tag.appendChild(t);
}
{
QDomElement tag = doc.createElement("crop_geometry");
root.appendChild(tag);
QDomText t = doc.createTextNode("512x384+64+48");
tag.appendChild(t);
}
if( !file.open( QIODevice::WriteOnly ) )
{
std::cout << __FUNCTION__ << " failed to save file " << (const char*)config_path.toLatin1()<<std::endl;
return __LINE__;
}
QTextStream ts( &file );
ts << doc.toString();
file.close();
}
return 0;
}
void Player::playFile(QString media_path)
{
m_media = libvlc_media_new_path (m_vlcobj, media_path.toUtf8());
libvlc_media_player_set_media (m_player, m_media);
QString config_path("qtvlc.xml");
createConfigFile(config_path);
QFile file(config_path);
QDomDocument doc;
QString errorStr;
int errorLine =0;
int errorCol=0;
if(!doc.setContent(&file,true,&errorStr,&errorLine,&errorCol))
{
std::cout<<__FUNCTION__ << " error "<<(const char*)errorStr.toLatin1()
<< " at line " << errorLine << " character " << errorCol
<<std::endl;
return;
}
{
QDomNodeList lst = doc.elementsByTagName("aspect_ratio");
if (lst.count()>0)
{
QDomNode node=lst.at(0);
QString text=node.toElement().text();
std::cout<<"node "<<(const char*)node.nodeName().toLatin1() << " is "
<< (const char*)text.toLatin1() << std::endl;
std::cout<<"set "<<(const char*)node.nodeName().toLatin1()<<std::endl;
libvlc_video_set_aspect_ratio(m_player, (const char*)text.toLatin1()); // 16:9
}
}
{
QDomNodeList lst = doc.elementsByTagName("crop_geometry");
if (lst.count()>0)
{
QDomNode node=lst.at(0);
QString text=node.toElement().text();
std::cout<<"node "<<(const char*)node.nodeName().toLatin1() << " is "
<< (const char*)text.toLatin1() << std::endl;
std::cout<<"set "<<(const char*)node.nodeName().toLatin1()<<std::endl;
libvlc_video_set_crop_geometry(m_player, (const char*)text.toLatin1()); // 512x384+64+48
}
}
libvlc_media_player_play (m_player );
}
void Player::changeVolume(int newVolume)
{
libvlc_audio_set_volume (m_player,newVolume );
}
void Player::changePosition(int newPosition)
{
libvlc_media_t *curMedia = libvlc_media_player_get_media (m_player);
if (curMedia == NULL)
return;
float pos=(float)(newPosition)/(float)POSITION_RESOLUTION;
libvlc_media_player_set_position (m_player, pos);
raise();
}
void Player::onVlcEvent( const libvlc_event_t * pEvt, void * pData )
{
std::cout << __FUNCTION__ << " event type " << pEvt->type << std::endl;
int siderPos = 0;
if(pEvt->type == libvlc_MediaPlayerPositionChanged)
{
if(pData)
{
Player* pp = (Player*)pData;
int64_t iLength=libvlc_media_player_get_length(pp->m_player);
int64_t iTime=libvlc_media_player_get_time(pp->m_player);
siderPos=iLength ? static_cast<int>((static_cast<double>(iTime)/static_cast<double>(iLength) * POSITION_RESOLUTION)) : 0;
}
}
if (pEvt->type == libvlc_MediaPlayerEndReached)
siderPos = POSITION_RESOLUTION;
QApplication::postEvent( (QWidget*)pData, new QUpdatePosEvent(siderPos));
}
void Player::customEvent( QEvent *e )
{
if (e->type() == VLC_EVENT_TYPE)
{
QUpdatePosEvent* posev = (QUpdatePosEvent*)e;
m_video_position->setValue(posev->m_newPos);
int volume=libvlc_audio_get_volume (m_player);
m_volume_level->setValue(volume);
}
}
void Player::mouseMoveEvent( QMouseEvent * event )
{
}
void Player::mousePressEvent( QMouseEvent * event )
{
m_mouse_pos = event->pos();
}
void Player::mouseReleaseEvent( QMouseEvent * event )
{
QPoint mouse_pos2 = event->pos();
QPoint mouse_pos1 = m_mouse_pos;
m_mouse_pos.setX(-1);
m_mouse_pos.setY(-1);
// libvlc_set_crop_geometry(mp, "512x384+64+48");
//option[0] = "--vout-filter";
//option[1] = "crop";
//option[2] = "--custom-crop-ratios=512x384+64+48,384x288+128+96,256x192+192+144,128x96+256+192,64x48+288+216";
// http://forum.videolan.org/viewtopic.php?f=32&t=88913
//libvlc_video_set_crop_geometry(m_player, "left+top+right+bottom");
}
void Player::paintEvent( QPaintEvent * event )
{
int margin = 10;
int topRectHeight = 50;
QPainter painter(this);
QColor color(10,150,100);
painter.setBrush(QBrush(color));
painter.drawRect(0,0,width(),height());
QRect topRect(margin,margin,width()-2*margin,topRectHeight);
painter.drawRect(topRect);
painter.drawText(width()/3,topRectHeight/2+margin,"test paintEvent");
QRect downRect(margin,topRectHeight+2*margin,width()-2*margin,
height()-topRectHeight-3*margin);
painter.drawRect(downRect);
}
void Player::menuOpen()
{
std::cout << __FUNCTION__ << std::endl;
QString file = QFileDialog::getOpenFileName(this, tr("Open video"),
"/d4/bin/m",
"Video (*.avi *.mp4 *.mpg)");
if (file.length())
{
playFile(file);
}
}
and the file header:
Code: Select all
#ifndef PLAYER_H
#define PLAYER_H
#include <vlc/vlc.h>
#include <QWidget>
class QVBoxLayout;
class QPushButton;
class QTimer;
class QFrame;
class QSlider;
class QMouseEvent;
#define POSITION_RESOLUTION 100
struct libvlc_event_t;
class Player : public QWidget/*QWidget*/
{
Q_OBJECT
QSlider *m_video_position;
QSlider *m_volume_level;
QFrame *m_video_wnd;
libvlc_instance_t *m_vlcobj;
libvlc_media_player_t *m_player;
libvlc_media_t *m_media;
QPoint m_mouse_pos;
public:
Player();
~Player();
static void onVlcEvent(const libvlc_event_t * pEvt, void * pData);
protected:
void mouseMoveEvent( QMouseEvent * event );
void mousePressEvent( QMouseEvent * event );
void mouseReleaseEvent( QMouseEvent * event );
void paintEvent( QPaintEvent * event );
public slots:
void playFile(QString file);
void changeVolume(int newVolume);
void changePosition(int newPosition);
void customEvent(QEvent *e);
void menuOpen();
private:
int createConfigFile(QString config_path);
};
#endif // PLAYER_H