LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-29-2008, 05:32 PM   #1
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 788

Rep: Reputation: 40
Running mplayer *within* an app with kdevelop (not in separate window)


I want to have mplayer running in a small part of my application, in something like a frame in my main window. This must be possible to do as things like kmplayer do it.

What I'm doing is streaming in MPEGs over USB and recording them to hard drive. I would like to have a small mplayer window above the record/stop buttons and next to the filename selector.

Anyone know how to do this?
 
Old 05-29-2008, 07:02 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
You can look at the ffmpeg library, that's what MPlayer uses for most of that kind of stuff. If you are using SDL, check out smpeg, it's a layer on top of ffmpeg that makes some things easier.
 
Old 05-29-2008, 07:12 PM   #3
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 788

Original Poster
Rep: Reputation: 40
I suspect I didn't explain that very well!

I have a program I have written with a window - the main window on boot - and it has things like a record button, a stop button, a file selector and a menu to do things like bring up a dialogue box to alter the Hauppaugge's settings.

Now, above the record and stop buttons, I would like to have mplayer running, anchored to the spot, so if I minimise my program, because mplayer is running within it, mplayer is no longer visible either.

I can run mplayer, but it just comes up as a separate window altogether. I would like to do something like put a frame down and have mplayer anchored within that frame.

Hope that makes more sense, not the easiest thing to explain!
 
Old 05-30-2008, 06:15 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 77
It seems what you want is a generic XEmbed interface. What you use specifically depends on your toolkit.

Depending on whether your application uses Qt, kdelibs, or gtk+, you will want to use QX11EmbedWidget, QXEmbed, or GtkPlug respectively.
 
Old 05-30-2008, 06:26 PM   #5
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
Iam not sure how XEmbed works, so I may just be repeating things, but you can pass mplayer a X window id to use, assuming of course you can get a X window id from QT (I don't know how that works either), mplayer will happily then use that window.
 
Old 05-30-2008, 11:43 PM   #6
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 77
Quote:
Originally Posted by SciYro View Post
Iam not sure how XEmbed works, so I may just be repeating things, but you can pass mplayer a X window id to use, assuming of course you can get a X window id from QT (I don't know how that works either), mplayer will happily then use that window.
That’s exactly what I meant. Here is a sample implementation in Qt:
Code:
#include <QApplication>
#include <QProcess>
#include <QString>
#include <QStringList>
#include <QX11EmbedContainer>

int main(int argc, char *argv[]) {
	QApplication app(argc, argv);

	QX11EmbedContainer frame;
	
	QProcess mplayer;
	mplayer.start("/usr/bin/mplayer", QStringList("-wid")
	              << QString::number(frame.winId())
	              << "http://blip.tv/file/get/Lc-BdaleGarbee394.OGG");

	frame.resize(1280,720);
	frame.show();
     
	return app.exec();
}
Of course there is currently only one widget (frame), but it may be made the child of container widget which contains menu bars, etc.

Similarly (for applications which do not permit specification of window id), you can swallow up already running windows if their id is known.
 
Old 05-31-2008, 04:48 AM   #7
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 788

Original Poster
Rep: Reputation: 40
That looks perfect, thanks very much!
 
Old 05-31-2008, 06:36 AM   #8
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 788

Original Poster
Rep: Reputation: 40
Hmmm, well none of those seem to be an object within KDevelop, sadly.

The syntax for KDevelop is different for the headers, for example:

#include <qprocess.h>

I have to confess I don't understand what KDevelop have done to the Qt stuff to make these differences. I suppose there might be a way to import the objects in to KDevelop but that's beyond my knowledge at the moment. I'm still at the bottom of a large learning curve!

Edit: Found the KDevelop equivalent and installed it (doesn't come as default). Once I've sussed the proper syntax will post it.

Last edited by DiBosco; 05-31-2008 at 09:36 AM.
 
Old 05-31-2008, 11:00 AM   #9
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 788

Original Poster
Rep: Reputation: 40
I'm going round in circles here trying to work out this syntax!

I can almost get it to compile, but am getting this error:

/home/nyname/Software/KDE/pvrusb2/src/record.cpp:64: undefined reference to `QtXEmbedContainer::QtXEmbedContainer(QWidget*, char const*)'


I downloaded qtxembed-1.3-free and followed the install instructions, putting this header in my .cpp file:

#include </home/nyname/Installs/qtxembed-1.3-free/src/qtxembed.h>

The thing is, this line is falling over with that initial error above:

QtXEmbedContainer *mpframe = new QtXEmbedContainer(this,"mpf");

Now, when I install other things, the above line is the syntax for all other types of installed objects, so I guess the syntax is right.

I am therefore wondering whether there's a proper way to install new objects in to KDevelop. I've been searching Google and the KDevelop forums for hours with no joy!

I have managed to (I think) work out the KDevelop equivalent syntax for the other stuff and this is the only remaining error.
 
Old 05-31-2008, 04:31 PM   #10
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 77
I cannot help specifically with your kdevelop problems, since I am quite unfamiliar with the IDE. I was under the impression that kdevelop lets you use whatever toolkit you wish.

The example I gave works with Qt4 (specifically, I tested it on version 4.3.4). There are slight syntactic differences in Qt3 (in addition you will need the qtxembed-1.3-free addon for Qt3 as you have found out.

My advice is to stick with Qt4 for any new projects. Here’s how I would compile the program above (without kdevelop).
  1. Download and install the Qt4 libraries and headers (and build utilities).
  2. Copy the text from my post to a source file (name it something like wrapper.cc) in an empty directory.
  3. In a terminal in the same directory of the file, type
    Code:
    $ qmake -project -o wrapper.pro
    $ qmake
    $ make
    $ ./wrapper
If the above works, you at least know that you have all the correct dependencies working and installed. If not, you’ll have to troubleshoot some more. In particular, make sure that the qmake being used is from Qt4 and not from Qt3.

Now, you can worry about trying to get kdevelop to understand it.

Also, if you prefer to use kdelibs, you would want to use the class QXEmbed (but I am not really sure, since I am unfamiliar with kdelibs, especially kde4).
 
Old 05-31-2008, 04:33 PM   #11
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 77
Also, you may want to check out the source for kmplayer and smplayer which do things similar to what you want.
 
Old 05-31-2008, 09:23 PM   #12
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 788

Original Poster
Rep: Reputation: 40
Thanks, Osor, I'll play some more. I was under the misapprehension that Qt4 was for KDE4, which thinking about it, when it's a cross platform system is silly.

I did download the kmplayer source and couldn't understand it! This is all new to me.
 
Old 06-07-2008, 12:20 PM   #13
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 788

Original Poster
Rep: Reputation: 40
Thumbs up

Well, the Qt4 version works a treat, but I don't think it's practical to write it in Qt4 at the moment.

No matter how much playing I do with QXEmbed it just refuses to work.

This code compiles:

QXEmbed *eframe = new QXEmbed(this);
eframe->setGeometry(0,0,1280,720);
eframe->show();
QProcess *mp = new QProcess(eframe);



mp->setArguments("konsole");
mp->addArgument(QString("-wid ") + QString::number(eframe->winId()));
qWarning("The eframe winID is " + QString::number(eframe->winId()));

if (!mp->start())
{
textLabel1->setText("The application has not started");
}
eframe->setProtocol(QXEmbed::XEMBED);

eframe->embed(mp->processIdentifier());
qWarning("The embeded ID is " + QString::number(eframe->embeddedWinId()));



However, it just will not run the external app at all. It looks like what is needed, but doesn't work and the finally qwarning returns zero which indicates that no window has been embedded.

It might be that this line:

eframe->embed(mp->processIdentifier());

Really needs a winID, but I can't work out how that's done.

One thing that is evident is that the frame is being created because it overwrites a button that is on my form! It's just that the external app isn't getting embedded within the app.

If I take away the line:

mp->addArgument(QString("-wid ") + QString::number(eframe->winId()));

Then console is launched in its own window. Seem to be close, but it's got to the stage where I want to throw the computer out of the window!
 
Old 06-07-2008, 09:20 PM   #14
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 77
There are a few things going on. There are two ways to use a generic XEmbed container:
  1. Act as a “socket” for any new window which wants to use it. This means that you start the desired subprocess and somehow communicate to it the window id into which it should embed itself. This is the method I used in my post above—the “-wid” argument (which is specific to mplayer, btw) communicates to mplayer where it should embed itself.
  2. Swallow up an external window.
I read up a bit on QXEmbed, and there are a few limitations. The widget will not honor the first usage except by Qt applications, and even then, only when called in a specific manner. This means that what I showed before will not work with mplayer. You can (ostensibly) get this functionality to work with konsole, but I did not explore this further.

Unfortunately, the “swallowing” method (the only one available to you for mplayer) does not integrate seamlessly between container and window. Whereas in the previous Qt4 program, when you resized the QX11EmbedContainer widget, the mplayer window inside was automatically resized, you get no such functionality with the swallowing method. There are other things which you

Another thing is you will want some way of figuring out the window id of the window you want to swallow (you are correct that the argument to QXEmbed::embed() should be a window ID, not a PID). Doing this is hackish at best (and you will need to use Xlib from within your program).

To get around these limitations, here is what the kmplayer people do (I think):
  1. Create a plain, black-filled window of desired size using the Xlib function XCreateSimpleWindow().
  2. Since you know the WID of that plain window, swallow it up using embed().
  3. When running mplayer, use the -wid argument, but pass the WID of the plain window which is already embedded.
  4. When processing resize events (and such), relay the events to the mplayer window.
So basically, you will need to jump through hoops to use QXEmbed. Perhaps you should have tried to get qtxembed-1.3-free to work after all.
 
Old 01-20-2011, 06:50 AM   #15
schooner
LQ Newbie
 
Registered: Jan 2011
Posts: 1

Rep: Reputation: 0
MPlayer within another app

Hi,

Came across this whilst researching doing the same.

To assist anyone on the same quest, this is a snippet from my code which embeds a container widget in an otherwise blank frame and plays mplayer within it.
The app is one which controls and displays the output from a WAN camera at a remote location. The only software it came with was Windoze only.

cheers

void LinkCamDlg::PlayStream() //slot which plays URL after the info gathering has finished
{
bool ok;

if (errorProcess)
{
emit playdone();
return;
}

int w = movieWidth.toInt( &ok );
int h = movieHeight.toInt( &ok );
QString otherOptions = "";

if (movieAspect!="0")
otherOptions = "-aspect " + movieAspect + " ";

QRect screen = QApplication::desktop()->screenGeometry();

otherOptions += "-monitoraspect " + QString::number(screen.width()) + ":" + QString::number(screen.height()) + " ";

playSettings(); // enable buttons

// Crude but effective - add the values of the combined margins to width and top margin plus controls to height
// and the viewFrame will automatically be sized correctly
// NB This works exactly for -vo vx switch but if -vo x11 used need to allow extra margin of approx 20 even though the
// picture has a black border top and bottom, or it will not display

resize(QSize(w + 18, h + 197).expandedTo(minimumSizeHint()));

container = new QX11EmbedContainer(viewFrame);
container->resize(viewFrame->width(),viewFrame->height());
mp = new QProcess(container);
connect(mp, SIGNAL(readyReadStandardOutput()),this, SLOT(readPlayOutput())); // only used for debug in this app
connect(mp, SIGNAL(finished(int)),this, SLOT(endPlayProcess(int)));

// It is impossible to display 320 x 240 properly with the -vo x11 switch
// This has the side effect that can only take snapshots in 640x480

if(w < 640)
{
command = "-vo xv -wid " + QString::number(container->winId()) + " -zoom -vf scale=" + String::number(w)
+ ":" + QString::number(h) + " -slave " + URL;
pb_Snapshot->setEnabled(false);
}
else
{
command = "-vo x11 -wid " + QString::number(container->winId()) + " -zoom -vf scale=" + QString::number(w)
+ ":" + QString::number(h) + " -slave " + URL;
}



mp->start("mplayer " + command);
// This is crucial, for some reason it worked previously without explicitly pushing 'container' to the top
// but it didn't when I came back to it a couple of years later
container->show();

// send command string to stderr
qDebug() << command.toLatin1().data();
qDebug() << otherOptions.toLatin1().data();

// Using QUrl works and just entering the data didn't.
// Don't know why
QUrl url(INSERT URL HERE);
http = new QHttp(this);
connect(http, SIGNAL(requestFinished(int, bool)),this, SLOT(OnRequestFinished(int, bool)));

http->setHost(url.host(), url.port() != -1 ? url.port() : 80);
if (!url.userName().isEmpty())
http->setUser(url.userName(), url.password());

httpGetId = http->get(url.path());

}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mplayer window postion save vs mplayer plugin window matters Slackware 0 03-28-2008 09:36 PM
Running script in separate shell window louisgag Linux - Newbie 2 06-15-2005 06:11 PM
probs with compiling kdevelop app joeman3429 Programming 1 08-27-2004 08:41 PM
Can't start *.doc on separate window satimis Red Hat 0 07-01-2004 10:56 AM
enable separate terminal for application i/o in KDevelop mrosati Linux - Software 0 04-21-2004 10:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration