2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This effect allows recording a video from the session.
|
2008-02-04 12:06:13 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
Requires libcaptury:
|
2008-02-04 12:06:13 +00:00
|
|
|
|
2008-03-27 15:41:59 +00:00
|
|
|
- git clone git://gitorious.org/capseo/mainline.git capseo
|
2007-04-29 17:35:43 +00:00
|
|
|
- you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am
|
|
|
|
- ./autogen.sh
|
|
|
|
- the usual configure && make && make install procedure
|
|
|
|
(you may want to pass --enable-theora --with-accel=x86 [or amd64])
|
|
|
|
|
2008-03-27 15:41:59 +00:00
|
|
|
- git clone git://gitorious.org/libcaptury/mainline.git libcaptury
|
2007-04-29 17:35:43 +00:00
|
|
|
- you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am
|
|
|
|
- ./autogen.sh
|
|
|
|
- the usual configure && make && make install procedure
|
2008-02-04 12:06:13 +00:00
|
|
|
|
2007-08-31 13:06:40 +00:00
|
|
|
Video is saved to $HOME/kwin_video.cps, use
|
2007-04-29 17:35:43 +00:00
|
|
|
"cpsrecode -i kwin_video.cps -o - | mplayer -" to play,
|
2008-03-27 15:41:59 +00:00
|
|
|
to create a video use "cpsrecode -c theora -i kwin_video.cps -o screen.ogg"
|
|
|
|
or use mencoder in a similar way as mplayer.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "videorecord.h"
|
|
|
|
|
|
|
|
#include <kaction.h>
|
|
|
|
#include <kactioncollection.h>
|
2007-10-06 02:11:47 +00:00
|
|
|
#include <kdebug.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <klocale.h>
|
2007-08-31 15:10:25 +00:00
|
|
|
#include <qdir.h>
|
|
|
|
#include <qfile.h>
|
2008-02-04 12:06:13 +00:00
|
|
|
#include <kio/netaccess.h>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KGlobalSettings>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-05-28 08:43:54 +00:00
|
|
|
#include <strings.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(videorecord, VideoRecordEffect)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
VideoRecordEffect::VideoRecordEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
: client(NULL)
|
|
|
|
{
|
|
|
|
KActionCollection* actionCollection = new KActionCollection(this);
|
|
|
|
KAction* a = static_cast< KAction* >(actionCollection->addAction("VideoRecord"));
|
|
|
|
a->setText(i18n("Toggle Video Recording"));
|
|
|
|
a->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::META + Qt::Key_V));
|
|
|
|
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleRecording()));
|
|
|
|
area = QRect(0, 0, displayWidth(), displayHeight());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
VideoRecordEffect::~VideoRecordEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
stopRecording();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void VideoRecordEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
|
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
if (client != NULL)
|
|
|
|
capture_region = (mask & (PAINT_WINDOW_TRANSFORMED | PAINT_SCREEN_TRANSFORMED))
|
|
|
|
? QRect(0, 0, displayWidth(), displayHeight()) : region;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void VideoRecordEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (client != NULL) {
|
2007-04-29 17:35:43 +00:00
|
|
|
#if 1
|
2011-01-30 14:34:42 +00:00
|
|
|
if (CapturyProcessRegionStart(client) == CAPTURY_SUCCESS) {
|
|
|
|
capture_region &= QRect(0, 0, displayWidth(), displayHeight()); // limit to screen
|
|
|
|
foreach (const QRect & r, capture_region.rects()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
int gly = displayHeight() - r.y() - r.height(); // opengl coords
|
2011-01-30 14:34:42 +00:00
|
|
|
CapturyProcessRegion(client, r.x(), gly, r.width(), r.height());
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
CapturyProcessRegionCommit(client);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
#else
|
2011-01-30 14:34:42 +00:00
|
|
|
CapturyProcessFrame(client);
|
2007-04-29 17:35:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void VideoRecordEffect::startRecording()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (client != NULL)
|
2007-04-29 17:35:43 +00:00
|
|
|
stopRecording();
|
2011-01-30 14:34:42 +00:00
|
|
|
bzero(&config, sizeof(config));
|
2007-04-29 17:35:43 +00:00
|
|
|
config.x = area.x();
|
|
|
|
config.y = area.y();
|
|
|
|
config.width = area.width();
|
|
|
|
config.height = area.height();
|
|
|
|
config.scale = 0;
|
|
|
|
config.fps = 30; // TODO
|
|
|
|
config.deviceType = CAPTURY_DEVICE_GLX; // TODO
|
|
|
|
config.deviceHandle = display();
|
|
|
|
config.windowHandle = rootWindow(); // TODO
|
|
|
|
config.cursor = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
client = CapturyOpen(&config);
|
|
|
|
if (client == NULL) {
|
|
|
|
kDebug(1212) << "Video recording init failed";
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-04 12:06:13 +00:00
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig("VideoRecord");
|
2011-01-30 14:34:42 +00:00
|
|
|
QString videoPath = conf.readEntry("videopath", KGlobalSettings::documentPath());
|
|
|
|
QString videoName(videoPath + "/kwin_video1.cps");
|
|
|
|
while (QFile::exists(videoName)) {
|
|
|
|
autoincFilename(videoName);
|
2008-02-04 12:06:13 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (CapturySetOutputFileName(client, QFile::encodeName(videoName).constData()) != CAPTURY_SUCCESS) {
|
|
|
|
kDebug(1212) << "Video recording file open failed";
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull(); // trigger reading initial screen contents into buffer
|
|
|
|
kDebug(1212) << "Video recording start";
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-02-04 12:06:13 +00:00
|
|
|
void VideoRecordEffect::autoincFilename(QString & name)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
// If the name contains a number then increment it
|
|
|
|
QRegExp numSearch("(^|[^\\d])(\\d+)"); // we want to match as far left as possible, and when the number is at the start of the name
|
|
|
|
// Does it have a number?
|
|
|
|
int start = numSearch.lastIndexIn(name);
|
|
|
|
if (start != -1) {
|
|
|
|
// It has a number, increment it
|
|
|
|
start = numSearch.pos(2); // we are only interested in the second group
|
|
|
|
QString numAsStr = numSearch.capturedTexts()[ 2 ];
|
|
|
|
QString number = QString::number(numAsStr.toInt() + 1);
|
|
|
|
number = number.rightJustified(numAsStr.length(), '0');
|
|
|
|
name.replace(start, number.length(), number);
|
2008-02-04 12:06:13 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
void VideoRecordEffect::stopRecording()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (client == NULL)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
kDebug(1212) << "Video recording stop";
|
|
|
|
CapturyClose(client);
|
2007-04-29 17:35:43 +00:00
|
|
|
client = NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void VideoRecordEffect::toggleRecording()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (client == NULL)
|
2007-04-29 17:35:43 +00:00
|
|
|
startRecording();
|
|
|
|
else
|
|
|
|
stopRecording();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "videorecord.moc"
|