summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/yahoo/yahoowebcam.cpp
blob: e5acd815330d76088bfb3913fda642521301d022 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
    yahoowebcam.cpp - Send webcam images

    Copyright (c) 2005 by André Duffec <andre.duffeck@kdemail.net>

    *************************************************************************
    *                                                                       *
    * 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.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <kdebug.h>
#include <tdeprocess.h>
#include <tdetempfile.h>
#include <tqtimer.h>

#include "client.h"
#include "yahoowebcam.h"
#include "yahooaccount.h"
#include "yahoowebcamdialog.h"
#include "avdevice/videodevicepool.h"


YahooWebcam::YahooWebcam( YahooAccount *account ) : TQObject( 0, "yahoo_webcam" )
{
	kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl;
	theAccount = account;
	theDialog = 0L;
	origImg = new KTempFile();
	convertedImg = new KTempFile();
	m_img = new TQImage();

	m_sendTimer = new TQTimer( this );
	connect( m_sendTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(sendImage()) );	

	m_updateTimer = new TQTimer( this );
	connect( m_updateTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(updateImage()) );	

	theDialog = new YahooWebcamDialog( "YahooWebcam" );
	connect( theDialog, TQ_SIGNAL(closingWebcamDialog()), this, TQ_SLOT(webcamDialogClosing()) );

	m_devicePool = Kopete::AV::VideoDevicePool::self();
	m_devicePool->open();
	m_devicePool->setSize(320, 240);
	m_devicePool->startCapturing();
	m_updateTimer->start( 250 );
}

YahooWebcam::~YahooWebcam()
{
	TQFile::remove( origImg->name() );
	TQFile::remove( convertedImg->name() );
	delete origImg;
	delete convertedImg;
	delete m_img;
}

void YahooWebcam::stopTransmission()
{
	m_sendTimer->stop();
}

void YahooWebcam::startTransmission()
{
	m_sendTimer->start( 1000 );
}

void YahooWebcam::webcamDialogClosing()
{
	m_sendTimer->stop();
	theDialog->delayedDestruct();
	emit webcamClosing();
	m_devicePool->stopCapturing(); 
	m_devicePool->close();
}

void YahooWebcam::updateImage()
{
	m_devicePool->getFrame();
	m_devicePool->getImage(m_img);
	theDialog->newImage( *m_img );
}

void YahooWebcam::sendImage()
{
	kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl;

	m_devicePool->getFrame();
	m_devicePool->getImage(m_img);
	
	origImg->close();
	convertedImg->close();
	
	m_img->save( origImg->name(), "JPEG");
	
	TDEProcess p;
	p << "jasper";
	p << "--input" << origImg->name() << "--output" << convertedImg->name() << "--output-format" << "jpc" << "-O" <<"cblkwidth=64\ncblkheight=64\nnumrlvls=4\nrate=0.0165\nprcheight=128\nprcwidth=2048\nmode=real";
	
	
	p.start( TDEProcess::Block );
	if( p.exitStatus() != 0 )
	{
		kdDebug(YAHOO_GEN_DEBUG) << " jasper exited with status " << p.exitStatus() << endl;
	}
	else
	{
		TQFile file( convertedImg->name() );
		if( file.open( IO_ReadOnly ) )
		{
			TQByteArray ar = file.readAll();
			theAccount->yahooSession()->sendWebcamImage( ar );
		}
		else
			kdDebug(YAHOO_GEN_DEBUG) << "Error opening the converted webcam image." << endl;
	}
}

void YahooWebcam::addViewer( const TQString &viewer )
{
	m_viewer.push_back( viewer );
	if( theDialog )
		theDialog->setViewer( m_viewer );
}

void YahooWebcam::removeViewer( const TQString &viewer )
{
	m_viewer.remove( viewer );
	if( theDialog )
		theDialog->setViewer( m_viewer );
}

#include "yahoowebcam.moc"