Add VideoRecordEffect for saving video captures.

Requires external lib to compile, see the videorecord.cpp .


svn path=/branches/work/kwin_composite/; revision=636625
This commit is contained in:
Luboš Luňák 2007-02-23 16:20:22 +00:00
parent faa99fd5a7
commit 0498cd7785
6 changed files with 217 additions and 0 deletions

View file

@ -14,6 +14,15 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/effects
)
include(UsePkgConfig)
PKGCONFIG(libcaptury CAPTURY_INCLUDES CAPTURY_LINK_DIR CAPTURY_LDFLAGS CAPTURY_CFLAGS)
if( CAPTURY_LDFLAGS )
SET( CAPTURY_FOUND TRUE )
endif( CAPTURY_LDFLAGS )
macro_bool_to_01( CAPTURY_FOUND HAVE_CAPTURY )
configure_file(config-kwin.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kwin.h )
include_directories(${CMAKE_CURRENT_BINARY_DIR})
########### next target ###############
@ -70,6 +79,13 @@ set(kwin_KDEINIT_SRCS
effects/desktopchangeslide.cpp
)
if( CAPTURY_FOUND )
set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS}
effects/videorecord.cpp
)
include_directories(${CAPTURY_INCLUDES})
endif( CAPTURY_FOUND )
if(HAVE_OPENGL)
set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS}
effects/wavywindows.cpp
@ -104,6 +120,10 @@ endif (X11_Xrender_FOUND)
if (X11_Xfixes_FOUND)
target_link_libraries(kdeinit_kwin ${X11_Xfixes_LIB})
endif (X11_Xfixes_FOUND)
if( HAVE_CAPTURY )
target_link_libraries(kdeinit_kwin ${CAPTURY_LDFLAGS})
endif( HAVE_CAPTURY )
install(TARGETS kdeinit_kwin DESTINATION ${LIB_INSTALL_DIR} )

2
config-kwin.h.cmake Normal file
View file

@ -0,0 +1,2 @@
/* Define if you have libcaptury */
#cmakedefine HAVE_CAPTURY 1

View file

@ -28,6 +28,9 @@ License. See the file "COPYING" for the exact licensing terms.
#include "effects/shakymove.h"
#include "effects/shiftworkspaceup.h"
#include "effects/showfps.h"
#ifdef HAVE_CAPTURY
#include "effects/videorecord.h"
#endif
#ifdef HAVE_OPENGL
#include "effects/wavywindows.h"
#endif
@ -128,6 +131,9 @@ EffectsHandler::EffectsHandler()
return;
KWinInternal::effects = this;
#ifdef HAVE_CAPTURY
registerEffect("VideoRecord", new GenericEffectFactory<VideoRecordEffect>);
#endif
registerEffect("ShowFps", new GenericEffectFactory<ShowFpsEffect>);
registerEffect("Zoom", new GenericEffectFactory<ZoomEffect>);
registerEffect("PresentWindows", new GenericEffectFactory<PresentWindowsEffect>);

143
effects/videorecord.cpp Normal file
View file

@ -0,0 +1,143 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
/*
This effect allows recording a video from the session.
Requires libcaptury:
- svn co svn://battousai.mylair.de/capseo/trunk
- 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])
- svn co svn://battousai.mylair.de/captury/trunk/libcaptury
- you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am
- ./autogen.sh
- the usual configure && make && make install procedure
Video is saved to /tmp/kwin_video.cps, use
"cpsrecode -i kwin_video.cps -o - | mplayer -" to play,
use mencoder the same way to create a video.
*/
#include <config.h>
#include "videorecord.h"
#include <kaction.h>
#include <kactioncollection.h>
#include <klocale.h>
#include <workspace.h>
#include <GL/gl.h>
namespace KWinInternal
{
VideoRecordEffect::VideoRecordEffect()
: 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::Key_F11 ));
connect( a, SIGNAL( triggered( bool )), this, SLOT( toggleRecording()));
area = QRect( 0, 0, displayWidth(), displayHeight());
}
VideoRecordEffect::~VideoRecordEffect()
{
stopRecording();
}
void VideoRecordEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
{
effects->paintScreen( mask, region, data );
if( client != NULL )
capture_region = region;
}
void VideoRecordEffect::postPaintScreen()
{
effects->postPaintScreen();
if( client != NULL )
{
#if 1
if( CapturyProcessRegionStart( client ) == CAPTURY_SUCCESS )
{
foreach( QRect r, capture_region.rects())
{
int gly = displayHeight() - r.y() - r.height(); // opengl coords
CapturyProcessRegion( client, r.x(), gly, r.width(), r.height());
}
CapturyProcessRegionCommit( client );
}
#else
CapturyProcessFrame( client );
#endif
}
}
void VideoRecordEffect::startRecording()
{
if( client != NULL )
stopRecording();
bzero( &config, sizeof( config ));
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;
client = CapturyOpen( &config );
if( client == NULL )
{
kDebug( 1212 ) << "Video recording init failed" << endl;
return;
}
// TODO
if( CapturySetOutputFileName( client, "/tmp/kwin_video.cps" ) != CAPTURY_SUCCESS )
{
kDebug( 1212 ) << "Video recording file open failed" << endl;
return;
}
workspace()->addRepaintFull(); // trigger reading initial screen contents into buffer
kDebug( 1212 ) << "Video recording start" << endl;
}
void VideoRecordEffect::stopRecording()
{
if( client == NULL )
return;
kDebug( 1212 ) << "Video recording stop" << endl;
CapturyClose( client );
client = NULL;
}
void VideoRecordEffect::toggleRecording()
{
if( client == NULL )
startRecording();
else
stopRecording();
}
} // namespace
#include "videorecord.moc"

45
effects/videorecord.h Normal file
View file

@ -0,0 +1,45 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
// TODO MIT or some other licence, perhaps move to some lib
#ifndef KWIN_VIDEO_H
#define KWIN_VIDEO_H
#include <effects.h>
#include <captury/captury.h>
namespace KWinInternal
{
class VideoRecordEffect
: public QObject, public Effect
{
Q_OBJECT
public:
VideoRecordEffect();
virtual ~VideoRecordEffect();
virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
virtual void postPaintScreen();
private slots:
void toggleRecording();
private:
void startRecording();
void stopRecording();
captury_config_t config;
captury_t* client;
QRect area;
QRegion capture_region;
};
} // namespace
#endif

View file

@ -14,6 +14,7 @@ License. See the file "COPYING" for the exact licensing terms.
#include <config.h>
#include <config-X11.h>
#include <config-kwin.h>
#include <X11/Xlib.h>