1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
23 This effect allows recording a video from the session.
27 - svn co svn://77.74.232.49/captury/trunk/capseo
28 - you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am
30 - the usual configure && make && make install procedure
31 (you may want to pass --enable-theora --with-accel=x86 [or amd64])
33 - svn co svn://77.74.232.49/captury/trunk/libcaptury
34 - you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am
36 - the usual configure && make && make install procedure
38 Video is saved to $HOME/kwin_video.cps, use
39 "cpsrecode -i kwin_video.cps -o - | mplayer -" to play,
40 use mencoder the same way to create a video.
44 #include "videorecord.h"
47 #include <kactioncollection.h>
52 #include <kio/netaccess.h>
53 #include <KConfigGroup>
54 #include <KGlobalSettings>
59 KWIN_EFFECT( videorecord
, VideoRecordEffect
)
61 VideoRecordEffect::VideoRecordEffect()
64 KActionCollection
* actionCollection
= new KActionCollection( this );
65 KAction
* a
= static_cast< KAction
* >( actionCollection
->addAction( "VideoRecord" ));
66 a
->setText( i18n("Toggle Video Recording" ));
67 a
->setGlobalShortcut( KShortcut( Qt::CTRL
+ Qt::META
+ Qt::Key_V
));
68 connect( a
, SIGNAL( triggered( bool )), this, SLOT( toggleRecording()));
69 area
= QRect( 0, 0, displayWidth(), displayHeight());
72 VideoRecordEffect::~VideoRecordEffect()
77 void VideoRecordEffect::paintScreen( int mask
, QRegion region
, ScreenPaintData
& data
)
79 effects
->paintScreen( mask
, region
, data
);
81 capture_region
= ( mask
& ( PAINT_WINDOW_TRANSFORMED
| PAINT_SCREEN_TRANSFORMED
))
82 ? QRect( 0, 0, displayWidth(), displayHeight()) : region
;
85 void VideoRecordEffect::postPaintScreen()
87 effects
->postPaintScreen();
91 if( CapturyProcessRegionStart( client
) == CAPTURY_SUCCESS
)
93 capture_region
&= QRect( 0, 0, displayWidth(), displayHeight()); // limit to screen
94 foreach( QRect r
, capture_region
.rects())
96 int gly
= displayHeight() - r
.y() - r
.height(); // opengl coords
97 CapturyProcessRegion( client
, r
.x(), gly
, r
.width(), r
.height());
99 CapturyProcessRegionCommit( client
);
102 CapturyProcessFrame( client
);
107 void VideoRecordEffect::startRecording()
111 bzero( &config
, sizeof( config
));
114 config
.width
= area
.width();
115 config
.height
= area
.height();
117 config
.fps
= 30; // TODO
118 config
.deviceType
= CAPTURY_DEVICE_GLX
; // TODO
119 config
.deviceHandle
= display();
120 config
.windowHandle
= rootWindow(); // TODO
121 config
.cursor
= true;
122 client
= CapturyOpen( &config
);
125 kDebug( 1212 ) << "Video recording init failed";
128 KConfigGroup conf
= EffectsHandler::effectConfig("VideoRecord");
129 QString videoPath
=conf
.readEntry( "videopath", KGlobalSettings::documentPath() );
130 QString
videoName(videoPath
+"/kwin_video1.cps" );
131 while(QFile::exists( videoName
)) {
132 autoincFilename( videoName
);
134 if( CapturySetOutputFileName( client
, QFile::encodeName( videoName
).constData() ) != CAPTURY_SUCCESS
)
136 kDebug( 1212 ) << "Video recording file open failed";
139 effects
->addRepaintFull(); // trigger reading initial screen contents into buffer
140 kDebug( 1212 ) << "Video recording start";
143 void VideoRecordEffect::autoincFilename(QString
& name
)
145 // If the name contains a number then increment it
146 QRegExp
numSearch( "(^|[^\\d])(\\d+)" ); // we want to match as far left as possible, and when the number is at the start of the name
147 // Does it have a number?
148 int start
= numSearch
.lastIndexIn( name
);
150 // It has a number, increment it
151 start
= numSearch
.pos( 2 ); // we are only interested in the second group
152 QString numAsStr
= numSearch
.capturedTexts()[ 2 ];
153 QString number
= QString::number( numAsStr
.toInt() + 1 );
154 number
= number
.rightJustified( numAsStr
.length(), '0' );
155 name
.replace( start
, number
.length(), number
);
158 void VideoRecordEffect::stopRecording()
162 kDebug( 1212 ) << "Video recording stop";
163 CapturyClose( client
);
167 void VideoRecordEffect::toggleRecording()
177 #include "videorecord.moc"