~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvilib/ext/avdevice/videodevicepool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <cerrno>
24
24
#include <cstring>
25
25
 
26
 
#include <kdebug.h>
27
 
#include <klocale.h>
28
 
#include <kglobal.h>
29
 
#include <kconfig.h>
30
 
#include <kconfiggroup.h>
31
 
#include <qdir.h>
32
 
#include <solid/device.h>
33
 
#include <solid/devicenotifier.h>
34
 
#include <solid/deviceinterface.h>
35
 
#include <solid/video.h>
36
 
 
 
26
#include <QDir>
 
27
#include <QDebug>
37
28
 
38
29
#include "videodevice.h"
39
30
#include "videodevicepool.h"
40
31
 
 
32
#ifdef COMPILE_KDE_SUPPORT
 
33
        #include <klocale.h>
 
34
        #include <kglobal.h>
 
35
        #include <kconfig.h>
 
36
        #include <kconfiggroup.h>
 
37
        #include <solid/devicenotifier.h>
 
38
        #include <solid/deviceinterface.h>
 
39
        #include <solid/video.h>
 
40
#endif
 
41
 
41
42
#define CLEAR(x) memset (&(x), 0, sizeof (x))
42
43
 
43
44
namespace Kopete {
61
62
}
62
63
 
63
64
VideoDevicePool::VideoDevicePool()
64
 
: m_current_device(0)
 
65
: m_current_device(-1)
65
66
{
 
67
#ifdef COMPILE_KDE_SUPPORT
66
68
        connect( Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(const QString&)), SLOT(deviceAdded(const QString &)) );
67
69
        connect( Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(const QString&)), SLOT(deviceRemoved(const QString &)) );
 
70
        /* NOTE: No locking needed as long as we don't connect with Qt::ConnectionType = Qt::DirectConnection
 
71
                 while the signals are emitted by other threads
 
72
         */
 
73
        foreach( Solid::Device device, Solid::Device::listFromType(Solid::DeviceInterface::Video, QString()) )
 
74
                registerDevice( device );
 
75
#endif
68
76
}
69
77
 
70
78
 
71
79
VideoDevicePool::~VideoDevicePool()
72
80
{
 
81
        foreach ( VideoDevice* vd, m_videodevices )
 
82
                delete vd;
73
83
}
74
84
 
75
85
 
80
90
 */
81
91
int VideoDevicePool::open(int device)
82
92
{
83
 
    /// @todo implement me
84
93
        qDebug() << "called with device" << device;
85
 
        m_ready.lock();
86
 
        if (!m_videodevice.size())
87
 
        {
88
 
                qDebug() << "open(): No devices found. Must scan for available devices." << m_current_device;
89
 
                scanDevices();
90
 
        }
91
 
        if (!m_videodevice.size() || (device >= m_videodevice.size()))
92
 
        {
93
 
                qDebug() << "open(): Device not found. bailing out." << m_current_device;
94
 
                m_ready.unlock();
 
94
        if (!m_videodevices.size() || (device >= m_videodevices.size()))
 
95
        {
 
96
                qDebug() << "Device not found.";
95
97
                return EXIT_FAILURE;
96
98
        }
97
 
        int current_device = m_current_device;
98
99
        if (device < 0)
99
100
        {
100
 
                qDebug() << "Trying to load saved device (using default device if not available)";
101
 
                loadSelectedDevice();   // Set m_current_device to saved device (if device available)
 
101
                qDebug() << "Trying to load saved device.";
 
102
                device = getSavedDevice();
 
103
                if (device < 0)
 
104
                {
 
105
                        if (m_current_device < 0)
 
106
                                device = 0;
 
107
                        else
 
108
                                device = m_current_device;
 
109
                        qDebug() << "Saved device is not available, using default device:" << device;
 
110
                }
102
111
        }
103
 
        else
104
 
                m_current_device = device;
105
112
        int isopen = EXIT_FAILURE;
106
 
        if ((m_current_device != current_device) || !isOpen())
 
113
        if ((device != m_current_device) || !isOpen())
107
114
        {
108
115
                if (isOpen())
109
116
                {
110
 
                        if (EXIT_SUCCESS == m_videodevice[current_device].close())
 
117
                        if (EXIT_SUCCESS == m_videodevices[m_current_device]->close())
111
118
                                m_clients--;
112
119
                        else
113
 
                        {
114
 
                                m_ready.unlock();
115
120
                                return EXIT_FAILURE;
116
 
                        }
117
121
                }
118
 
                isopen = m_videodevice[m_current_device].open();
 
122
                isopen = m_videodevices[device]->open();
119
123
                if (isopen == EXIT_SUCCESS)
120
124
                {
 
125
                        m_current_device = device;
121
126
                        loadDeviceConfig(); // Load and apply device parameters
122
127
                        m_clients++;
123
128
                }
128
133
                m_clients++;
129
134
        }
130
135
        qDebug() << "Number of clients: " << m_clients;
131
 
        m_ready.unlock();
132
136
        return isopen;
133
137
}
134
138
 
135
139
bool VideoDevicePool::isOpen()
136
140
{
137
 
        return m_videodevice[currentDevice()].isOpen();
 
141
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
142
                return m_videodevices[m_current_device]->isOpen();
 
143
        else
 
144
                return false;
138
145
}
139
146
 
140
147
/*!
141
148
    \fn VideoDevicePool::showDeviceCapabilities(int device)
142
149
 */
143
 
int VideoDevicePool::showDeviceCapabilities(unsigned int device)
 
150
int VideoDevicePool::showDeviceCapabilities(int device)
144
151
{
145
 
        return m_videodevice[device].showDeviceCapabilities();
 
152
        if (device < 0)
 
153
                device = m_current_device;
 
154
        if ((device >= 0) && (device < m_videodevices.size()))
 
155
                return m_videodevices[device]->showDeviceCapabilities();
 
156
        else
 
157
                return EXIT_FAILURE;
146
158
}
147
159
 
148
160
int VideoDevicePool::width()
149
161
{
150
 
        return m_videodevice[currentDevice()].width();
 
162
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
163
                return m_videodevices[m_current_device]->width();
 
164
        else
 
165
                return 0;
151
166
}
152
167
 
153
168
int VideoDevicePool::minWidth()
154
169
{
155
 
        return m_videodevice[currentDevice()].minWidth();
 
170
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
171
                return m_videodevices[m_current_device]->minWidth();
 
172
        else
 
173
                return 0;
156
174
}
157
175
 
158
176
int VideoDevicePool::maxWidth()
159
177
{
160
 
        return m_videodevice[currentDevice()].maxWidth();
 
178
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
179
                return m_videodevices[m_current_device]->maxWidth();
 
180
        else
 
181
                return 0;
161
182
}
162
183
 
163
184
int VideoDevicePool::height()
164
185
{
165
 
        return m_videodevice[currentDevice()].height();
 
186
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
187
                return m_videodevices[m_current_device]->height();
 
188
        else
 
189
                return 0;
166
190
}
167
191
 
168
192
int VideoDevicePool::minHeight()
169
193
{
170
 
        return m_videodevice[currentDevice()].minHeight();
 
194
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
195
                return m_videodevices[m_current_device]->minHeight();
 
196
        else
 
197
                return 0;
171
198
}
172
199
 
173
200
int VideoDevicePool::maxHeight()
174
201
{
175
 
        return m_videodevice[currentDevice()].maxHeight();
 
202
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
203
                return m_videodevices[m_current_device]->maxHeight();
 
204
        else
 
205
                return 0;
176
206
}
177
207
 
178
208
int VideoDevicePool::setSize( int newwidth, int newheight)
179
209
{
180
 
        if(m_videodevice.size())
181
 
                return m_videodevice[currentDevice()].setSize(newwidth, newheight);
 
210
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
211
                return m_videodevices[m_current_device]->setSize(newwidth, newheight);
182
212
        else
183
213
        {
184
214
                qDebug() << "VideoDevicePool::setSize() fallback for no device.";
199
229
int VideoDevicePool::close()
200
230
{
201
231
        int ret = EXIT_FAILURE;
202
 
        if (m_current_device >= m_videodevice.size())
 
232
        if ((m_current_device < 0) || (m_current_device >= m_videodevices.size()))
203
233
        {
204
234
                qDebug() << "Current device out of range.";
205
235
        }
215
245
        }
216
246
        else
217
247
        {
218
 
                ret = m_videodevice[m_current_device].close();
 
248
                ret = m_videodevices[m_current_device]->close();
219
249
                if (EXIT_SUCCESS == ret)
220
250
                        m_clients--;
221
251
        }
228
258
int VideoDevicePool::startCapturing()
229
259
{
230
260
        qDebug() << "startCapturing() called.";
231
 
        if(m_videodevice.size())
232
 
                return m_videodevice[currentDevice()].startCapturing();
233
 
        return EXIT_FAILURE;
 
261
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
262
                return m_videodevices[m_current_device]->startCapturing();
 
263
        else
 
264
                return EXIT_FAILURE;
234
265
}
235
266
 
236
267
 
239
270
 */
240
271
int VideoDevicePool::stopCapturing()
241
272
{
242
 
        if(m_videodevice.size())
243
 
                return m_videodevice[currentDevice()].stopCapturing();
244
 
        return EXIT_FAILURE;
 
273
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
274
                return m_videodevices[m_current_device]->stopCapturing();
 
275
        else
 
276
                return EXIT_FAILURE;
245
277
}
246
278
 
247
279
 
254
286
 */
255
287
QList<NumericVideoControl> VideoDevicePool::getSupportedNumericControls()
256
288
{
257
 
        if (currentDevice() < m_videodevice.size() )
258
 
                return m_videodevice[currentDevice()].getSupportedNumericControls();
 
289
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
290
                return m_videodevices[m_current_device]->getSupportedNumericControls();
259
291
        else
260
292
                return QList<NumericVideoControl>();
261
293
}
267
299
 */
268
300
QList<BooleanVideoControl> VideoDevicePool::getSupportedBooleanControls()
269
301
{
270
 
        if (currentDevice() < m_videodevice.size() )
271
 
                return m_videodevice[currentDevice()].getSupportedBooleanControls();
 
302
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
303
                return m_videodevices[m_current_device]->getSupportedBooleanControls();
272
304
        else
273
305
                return QList<BooleanVideoControl>();
274
306
}
280
312
 */
281
313
QList<MenuVideoControl> VideoDevicePool::getSupportedMenuControls()
282
314
{
283
 
        if (currentDevice() < m_videodevice.size() )
284
 
                return m_videodevice[currentDevice()].getSupportedMenuControls();
 
315
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
316
                return m_videodevices[m_current_device]->getSupportedMenuControls();
285
317
        else
286
318
                return QList<MenuVideoControl>();
287
319
}
293
325
 */
294
326
QList<ActionVideoControl> VideoDevicePool::getSupportedActionControls()
295
327
{
296
 
        if (currentDevice() < m_videodevice.size() )
297
 
                return m_videodevice[currentDevice()].getSupportedActionControls();
 
328
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
329
                return m_videodevices[m_current_device]->getSupportedActionControls();
298
330
        else
299
331
                return QList<ActionVideoControl>();
300
332
}
310
342
 */
311
343
int VideoDevicePool::getControlValue(quint32 ctrl_id, qint32 * value)
312
344
{
313
 
        if (currentDevice() < m_videodevice.size() )
314
 
                return m_videodevice[currentDevice()].getControlValue(ctrl_id, value);
 
345
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
346
                return m_videodevices[m_current_device]->getControlValue(ctrl_id, value);
315
347
        else
316
348
                return EXIT_FAILURE;
317
349
}
328
360
 */
329
361
int VideoDevicePool::setControlValue(quint32 ctrl_id, qint32 value)
330
362
{
331
 
        if (currentDevice() < m_videodevice.size() )
332
 
                return m_videodevice[currentDevice()].setControlValue(ctrl_id, value);
 
363
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
364
                return m_videodevices[m_current_device]->setControlValue(ctrl_id, value);
333
365
        else
334
366
                return EXIT_FAILURE;
335
367
}
341
373
int VideoDevicePool::getFrame()
342
374
{
343
375
//      qDebug() << "VideoDevicePool::getFrame() called.";
344
 
        if(m_videodevice.size())
345
 
                return m_videodevice[currentDevice()].getFrame();
 
376
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
377
                return m_videodevices[m_current_device]->getFrame();
346
378
        else
347
 
        {
348
 
                qDebug() << "VideoDevicePool::getFrame() fallback for no device.";
349
 
                for(int loop=0; loop < m_buffer.data.size(); loop+=3)
350
 
                {
351
 
                        m_buffer.data[loop]   = 255;
352
 
                        m_buffer.data[loop+1] = 0;
353
 
                        m_buffer.data[loop+2] = 0;
354
 
                }
355
 
        }
356
 
        qDebug() << "VideoDevicePool::getFrame() exited successfuly.";
357
 
 
358
 
        return EXIT_SUCCESS;
 
379
                return EXIT_FAILURE;
359
380
}
360
381
 
361
382
/*!
364
385
int VideoDevicePool::getImage(QImage *qimage)
365
386
{
366
387
//      qDebug() << "VideoDevicePool::getImage() called.";
367
 
        if(m_videodevice.size())
368
 
                return m_videodevice[currentDevice()].getImage(qimage);
 
388
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
389
                return m_videodevices[m_current_device]->getImage(qimage);
369
390
        else
370
 
        {
371
 
                qDebug() << "VideoDevicePool::getImage() fallback for no device.";
372
 
 
373
 
                // do NOT delete qimage here, as it is received as a parameter
374
 
                if (qimage->width() != width() || qimage->height() != height())
375
 
                        *qimage = QImage(width(), height(), QImage::Format_RGB32);
376
 
 
377
 
                uchar *bits=qimage->bits();
378
 
                switch(m_buffer.pixelformat)
379
 
                {
380
 
                        case PIXELFORMAT_NONE   : break;
381
 
                        case PIXELFORMAT_GREY   : break;
382
 
                        case PIXELFORMAT_RGB332 : break;
383
 
                        case PIXELFORMAT_RGB555 : break;
384
 
                        case PIXELFORMAT_RGB555X: break;
385
 
                        case PIXELFORMAT_RGB565 : break;
386
 
                        case PIXELFORMAT_RGB565X: break;
387
 
                        case PIXELFORMAT_RGB24  :
388
 
                                {
389
 
                                        qDebug() << "VideoDevicePool::getImage() fallback for no device - RGB24.";
390
 
                                        int step=0;
391
 
                                        for(int loop=0;loop < qimage->numBytes();loop+=4)
392
 
                                        {
393
 
                                                bits[loop]   = m_buffer.data[step];
394
 
                                                bits[loop+1] = m_buffer.data[step+1];
395
 
                                                bits[loop+2] = m_buffer.data[step+2];
396
 
                                                bits[loop+3] = 255;
397
 
                                                step+=3;
398
 
                                        }
399
 
                                }
400
 
                                break;
401
 
                        case PIXELFORMAT_BGR24  : break;
402
 
                                {
403
 
                                        int step=0;
404
 
                                        for(int loop=0;loop < qimage->numBytes();loop+=4)
405
 
                                        {
406
 
                                                bits[loop]   = m_buffer.data[step+2];
407
 
                                                bits[loop+1] = m_buffer.data[step+1];
408
 
                                                bits[loop+2] = m_buffer.data[step];
409
 
                                                bits[loop+3] = 255;
410
 
                                                step+=3;
411
 
                                        }
412
 
                                }
413
 
                                break;
414
 
                        case PIXELFORMAT_RGB32  : memcpy(bits,&m_buffer.data[0], m_buffer.data.size());
415
 
                                break;
416
 
                        case PIXELFORMAT_BGR32  : break;
417
 
                        case PIXELFORMAT_YUYV   : break;
418
 
                        case PIXELFORMAT_UYVY   : break;
419
 
                        case PIXELFORMAT_YUV420P: break;
420
 
                        case PIXELFORMAT_YUV422P: break;
421
 
                        default: break;
422
 
                }
423
 
        }
424
 
        qDebug() << "VideoDevicePool::getImage() exited successfuly.";
425
 
        return EXIT_SUCCESS;
 
391
                return EXIT_FAILURE;
426
392
}
427
393
 
428
394
/*!
431
397
int VideoDevicePool::selectInput(int newinput)
432
398
{
433
399
        qDebug() << "VideoDevicePool::selectInput(" << newinput << ") called.";
434
 
        if(m_videodevice.size())
435
 
                return m_videodevice[currentDevice()].selectInput(newinput);
 
400
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
401
                return m_videodevices[m_current_device]->selectInput(newinput);
436
402
        else
437
 
                return 0;
 
403
                return EXIT_FAILURE;
438
404
}
439
405
 
440
406
/*!
441
407
    \fn Kopete::AV::VideoDevicePool::fillDeviceQComboBox(QComboBox *combobox)
442
408
 */
443
 
int VideoDevicePool::fillDeviceQComboBox(QComboBox *combobox)
 
409
void VideoDevicePool::fillDeviceQComboBox(QComboBox *combobox)
444
410
{
445
 
    /// @todo implement me
446
411
        qDebug() << "Called.";
447
 
// check if QComboBox is a valid pointer.
448
 
        if (combobox != NULL)
 
412
        if (combobox == NULL)
 
413
                return;
 
414
        combobox->clear();
 
415
        if (m_videodevices.size())
449
416
        {
450
 
                combobox->clear();
451
 
                qDebug() << "Combobox cleaned.";
452
 
                if(m_videodevice.size())
 
417
                for (int loop = 0; loop < m_videodevices.size(); loop++)
453
418
                {
454
 
                        for (int loop=0; loop < m_videodevice.size(); loop++)
455
 
                        {
456
 
                                combobox->addItem(m_videodevice[loop].m_name);
457
 
                                qDebug() << "Added device " << loop << ": " << m_videodevice[loop].m_name;
458
 
                        }
459
 
                        combobox->setCurrentIndex(currentDevice());
460
 
                        combobox->setEnabled(true);
461
 
                        return EXIT_SUCCESS;
 
419
                        combobox->addItem(m_videodevices[loop]->m_name);
 
420
                        qDebug() << "Added device" << loop << ":  " << m_videodevices[loop]->m_name;
462
421
                }
463
 
                combobox->setEnabled(false);
 
422
                combobox->setCurrentIndex(m_current_device);
464
423
        }
465
 
        return EXIT_FAILURE;
 
424
        combobox->setEnabled(m_videodevices.size());
466
425
}
467
426
 
468
427
/*!
469
428
    \fn Kopete::AV::VideoDevicePool::fillInputQComboBox(QComboBox *combobox)
470
429
 */
471
 
int VideoDevicePool::fillInputQComboBox(QComboBox *combobox)
 
430
void VideoDevicePool::fillInputQComboBox(QComboBox *combobox)
472
431
{
473
 
    /// @todo implement me
474
432
        qDebug() << "Called.";
475
 
        if (combobox != NULL)
 
433
        if (combobox == NULL)
 
434
                return;
 
435
        combobox->clear();
 
436
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
476
437
        {
477
 
                combobox->clear();
478
 
                if ( !m_videodevice.isEmpty() && (currentDevice()>=0) && currentDevice() < m_videodevice.size() )
 
438
                if (m_videodevices[m_current_device]->inputs() > 0)
479
439
                {
480
 
                        if(m_videodevice[currentDevice()].inputs()>0)
 
440
                        for (int loop = 0; loop < m_videodevices[m_current_device]->inputs(); loop++)
481
441
                        {
482
 
                                for (int loop=0; loop < m_videodevice[currentDevice()].inputs(); loop++)
483
 
                                {
484
 
                                        combobox->addItem(m_videodevice[currentDevice()].m_input[loop].name);
485
 
                                        qDebug() << "Added input " << loop << ": " << m_videodevice[currentDevice()].m_input[loop].name << " (tuner: " << m_videodevice[currentDevice()].m_input[loop].hastuner << ")";
486
 
                                }
487
 
                                combobox->setCurrentIndex(currentInput());
488
 
                                combobox->setEnabled(true);
489
 
                                return EXIT_SUCCESS;
 
442
                                combobox->addItem(m_videodevices[m_current_device]->m_input[loop].name);
 
443
                                qDebug() << "Added input" << loop << ":  " << m_videodevices[m_current_device]->m_input[loop].name
 
444
                                         << " (tuner: " << m_videodevices[m_current_device]->m_input[loop].hastuner << ")";
490
445
                        }
 
446
                        combobox->setCurrentIndex(m_videodevices[m_current_device]->currentInput());
491
447
                }
492
 
                combobox->setEnabled(false);
493
448
        }
494
 
        return EXIT_FAILURE;
 
449
        combobox->setEnabled(combobox->count());
495
450
}
496
451
 
497
452
/*!
498
453
    \fn Kopete::AV::VideoDevicePool::fillStandardQComboBox(QComboBox *combobox)
499
454
 */
500
 
int VideoDevicePool::fillStandardQComboBox(QComboBox *combobox)
 
455
void VideoDevicePool::fillStandardQComboBox(QComboBox *combobox)
501
456
{
502
 
    /// @todo implement me
503
457
        qDebug() << "Called.";
504
 
        if (combobox != NULL)
 
458
        if (combobox == NULL)
 
459
                return;
 
460
        combobox->clear();
 
461
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
505
462
        {
506
 
                combobox->clear();
507
 
                if ( !m_videodevice.isEmpty() && currentDevice() < m_videodevice.size() )
 
463
                if (m_videodevices[m_current_device]->inputs() > 0)
508
464
                {
509
 
                        if(m_videodevice[currentDevice()].inputs()>0)
 
465
                        for (unsigned int loop = 0; loop < 25; loop++)
510
466
                        {
511
 
                                for (unsigned int loop=0; loop < 25; loop++)
 
467
                                if (m_videodevices[m_current_device]->m_input[currentInput()].m_standards & (1 << loop))
512
468
                                {
513
 
                                        if ( (m_videodevice[currentDevice()].m_input[currentInput()].m_standards) & (1 << loop) )
514
 
                                                combobox->addItem(m_videodevice[currentDevice()].signalStandardName( 1 << loop));
515
 
/*
516
 
                                case STANDARD_PAL_B1    : return V4L2_STD_PAL_B1;       break;
517
 
                                case STANDARD_PAL_G     : return V4L2_STD_PAL_G;        break;
518
 
                                case STANDARD_PAL_H     : return V4L2_STD_PAL_H;        break;
519
 
                                case STANDARD_PAL_I     : return V4L2_STD_PAL_I;        break;
520
 
                                case STANDARD_PAL_D     : return V4L2_STD_PAL_D;        break;
521
 
                                case STANDARD_PAL_D1    : return V4L2_STD_PAL_D1;       break;
522
 
                                case STANDARD_PAL_K     : return V4L2_STD_PAL_K;        break;
523
 
                                case STANDARD_PAL_M     : return V4L2_STD_PAL_M;        break;
524
 
                                case STANDARD_PAL_N     : return V4L2_STD_PAL_N;        break;
525
 
                                case STANDARD_PAL_Nc    : return V4L2_STD_PAL_Nc;       break;
526
 
                                case STANDARD_PAL_60    : return V4L2_STD_PAL_60;       break;
527
 
                                case STANDARD_NTSC_M    : return V4L2_STD_NTSC_M;       break;
528
 
                                case STANDARD_NTSC_M_JP : return V4L2_STD_NTSC_M_JP;    break;
529
 
                                case STANDARD_NTSC_443  : return V4L2_STD_NTSC;         break; // Using workaround value because my videodev2.h header seems to not include this standard in struct __u64 v4l2_std_id
530
 
                                case STANDARD_SECAM_B   : return V4L2_STD_SECAM_B;      break;
531
 
                                case STANDARD_SECAM_D   : return V4L2_STD_SECAM_D;      break;
532
 
                                case STANDARD_SECAM_G   : return V4L2_STD_SECAM_G;      break;
533
 
                                case STANDARD_SECAM_H   : return V4L2_STD_SECAM_H;      break;
534
 
                                case STANDARD_SECAM_K   : return V4L2_STD_SECAM_K;      break;
535
 
                                case STANDARD_SECAM_K1  : return V4L2_STD_SECAM_K1;     break;
536
 
                                case STANDARD_SECAM_L   : return V4L2_STD_SECAM_L;      break;
537
 
                                case STANDARD_SECAM_LC  : return V4L2_STD_SECAM;        break; // Using workaround value because my videodev2.h header seems to not include this standard in struct __u64 v4l2_std_id
538
 
                                case STANDARD_ATSC_8_VSB        : return V4L2_STD_ATSC_8_VSB;   break; // ATSC/HDTV Standard officially not supported by V4L2 but exists in videodev2.h
539
 
                                case STANDARD_ATSC_16_VSB       : return V4L2_STD_ATSC_16_VSB;  break; // ATSC/HDTV Standard officially not supported by V4L2 but exists in videodev2.h
540
 
                                case STANDARD_PAL_BG    : return V4L2_STD_PAL_BG;       break;
541
 
                                case STANDARD_PAL_DK    : return V4L2_STD_PAL_DK;       break;
542
 
                                case STANDARD_PAL       : return V4L2_STD_PAL;          break;
543
 
                                case STANDARD_NTSC      : return V4L2_STD_NTSC;         break;
544
 
                                case STANDARD_SECAM_DK  : return V4L2_STD_SECAM_DK;     break;
545
 
                                case STANDARD_SECAM     : return V4L2_STD_SECAM;        break;
546
 
                                case STANDARD_525_60    : return V4L2_STD_525_60;       break;
547
 
                                case STANDARD_625_50    : return V4L2_STD_625_50;       break;
548
 
                                case STANDARD_ALL       : return V4L2_STD_ALL;          break;
549
 
 
550
 
                                combobox->insertItem(m_videodevice[currentDevice()].m_input[loop].name);
551
 
                                qDebug() << "StandardQComboBox: Added input " << loop << ": " << m_videodevice[currentDevice()].m_input[loop].name << " (tuner: " << m_videodevice[currentDevice()].m_input[loop].hastuner << ")";*/
 
469
                                        combobox->addItem(m_videodevices[m_current_device]->signalStandardName(1 << loop));
 
470
                                        qDebug() << "Added signal standard" << loop << ":  " << m_videodevices[m_current_device]->signalStandardName(1 << loop);
552
471
                                }
553
 
                                combobox->setCurrentIndex(0);   // FIXME: set to actual signal standard
554
 
                                combobox->setEnabled(combobox->count());
555
 
                                return EXIT_SUCCESS;
 
472
                                  
556
473
                        }
557
 
                }
558
 
                combobox->setEnabled(false);
559
 
        }
560
 
        return EXIT_FAILURE;
561
 
}
562
 
 
563
 
/*!
564
 
    \fn Kopete::AV::VideoDevicePool::scanDevices()
565
 
 */
566
 
int VideoDevicePool::scanDevices()
567
 
{
568
 
    /// @todo implement me
569
 
 
570
 
        if (m_videodevice.isEmpty()) {
571
 
                qDebug() << "called";
572
 
#ifndef COMPILE_DISABLE_AVDEVICE
573
 
                foreach (Solid::Device device,
574
 
                                Solid::Device::listFromType(Solid::DeviceInterface::Video, QString())) {
575
 
                        registerDevice( device );
576
 
                }
577
 
 
578
 
#endif
579
 
                qDebug() << "exited successfuly";
580
 
        } else {
581
 
                qDebug() << "Not scanning: initial device list already loaded";
582
 
        }
583
 
        return EXIT_SUCCESS;
584
 
}
585
 
 
586
 
void VideoDevicePool::registerDevice( Solid::Device & device )
587
 
{
588
 
        qDebug() << "New video device at " << device.udi();
 
474
                        combobox->setCurrentIndex(0);   // FIXME: set to actual signal standard
 
475
                }  
 
476
        }
 
477
        combobox->setEnabled(combobox->count());
 
478
}
 
479
#ifdef COMPILE_KDE_SUPPORT
 
480
bool VideoDevicePool::registerDevice( Solid::Device & device )
 
481
{
 
482
        qDebug() << "called, UDI is:\n   " << device.udi();
589
483
        const Solid::Device * vendorDevice = &device;
590
 
        while ( vendorDevice->isValid() && vendorDevice->vendor().isEmpty() )
591
 
        {
592
 
                vendorDevice = new Solid::Device( vendorDevice->parentUdi() );
593
 
        }
594
 
        if ( vendorDevice->isValid() )
595
 
        {
596
 
                qDebug() << "vendor: " << vendorDevice->vendor() << ", product: " << vendorDevice->product();
597
 
        }
598
 
        Solid::Video * solidVideoDevice = device.as<Solid::Video>();
599
 
        if ( solidVideoDevice ) {
600
 
                QStringList protocols = solidVideoDevice->supportedProtocols();
601
 
                if ( protocols.contains( "video4linux" ) )
 
484
        while (vendorDevice->isValid() && vendorDevice->vendor().isEmpty())
 
485
                vendorDevice = new Solid::Device(vendorDevice->parentUdi());
 
486
        /* NOTE: The device we register has usually an empty vendor string and a less meaningfull product string.
 
487
           So we go up to the first parent device that has a non-empty vendor string,
 
488
           because we find the expected strings describing the device there.
 
489
         */
 
490
        if (vendorDevice->isValid())
 
491
                qDebug() << "vendor:" << vendorDevice->vendor() << ", product:" << vendorDevice->product();
 
492
        else
 
493
                qDebug() << "vendor:" << device.vendor() << ", product:" << device.product();
 
494
 
 
495
        if (device.isValid())
 
496
        {
 
497
                Solid::Video * solidVideoDevice = device.as<Solid::Video>();
 
498
                if (solidVideoDevice)
602
499
                {
603
 
                        QStringList drivers = solidVideoDevice->supportedDrivers( "video4linux" );
604
 
                        if ( drivers.contains( "video4linux" ) )
 
500
                        QStringList protocols = solidVideoDevice->supportedProtocols();
 
501
                        if (protocols.contains("video4linux"))
605
502
                        {
606
 
                                qDebug() << "V4L device path is" << solidVideoDevice->driverHandle( "video4linux" ).toString();
607
 
                                VideoDevice videodevice;
608
 
                                videodevice.setUdi( device.udi() );
609
 
                                videodevice.setFileName(solidVideoDevice->driverHandle( "video4linux" ).toString());
610
 
                                qDebug() << "Found device " << videodevice.fileName();
611
 
                                videodevice.open();
612
 
                                if(videodevice.isOpen())
 
503
                                QStringList drivers = solidVideoDevice->supportedDrivers("video4linux");
 
504
                                if (drivers.contains("video4linux"))
613
505
                                {
614
 
                                        qDebug() << "File " << videodevice.fileName() << " was opened successfuly";
615
 
                                        videodevice.close();
616
 
                                        m_videodevice.push_back(videodevice);
 
506
                                        VideoDevice* videodevice = new VideoDevice;
 
507
                                        videodevice->setUdi( device.udi() );
 
508
                                        videodevice->setFileName(solidVideoDevice->driverHandle("video4linux").toString());
 
509
                                        qDebug() << "V4L device path is" << solidVideoDevice->driverHandle("video4linux").toString();
 
510
                                        if (EXIT_SUCCESS == videodevice->open())
 
511
                                        {
 
512
                                                bool cap = videodevice->canCapture();
 
513
                                                videodevice->close();
 
514
                                                if (cap)
 
515
                                                {
 
516
                                                        if (m_videodevices.size() == 0)
 
517
                                                                m_current_device = 0;
 
518
                                                        m_videodevices.push_back(videodevice);
 
519
                                                        qDebug() << "Device is a valid video device, adding it to video device pool.";
 
520
                                                        return true;
 
521
                                                }
 
522
                                                else
 
523
                                                        qDebug() << "Device does not support capturing.";
 
524
                                        }
 
525
                                        else
 
526
                                                qDebug() << "Device could not be opened.";
 
527
                                        delete videodevice;
617
528
                                }
618
529
                        }
619
530
                }
 
531
                else
 
532
                        qDebug() << "Device is not a video device.";
620
533
        }
621
 
}
622
 
 
623
 
/*!
624
 
    \fn Kopete::AV::VideoDevicePool::hasDevices()
625
 
 */
626
 
bool VideoDevicePool::hasDevices()
627
 
{
628
 
    /// @todo implement me
629
 
        if(m_videodevice.size())
630
 
                return true;
 
534
        else
 
535
                qDebug() << "Not a valid Solid device: device is not available in the system.";
631
536
        return false;
632
537
}
633
 
 
 
538
#endif
634
539
/*!
635
540
    \fn Kopete::AV::VideoDevicePool::size()
636
541
 */
637
542
int VideoDevicePool::size()
638
543
{
639
544
    /// @todo implement me
640
 
        return m_videodevice.size();
 
545
        return m_videodevices.size();
641
546
}
642
547
 
643
548
/*!
654
559
 */
655
560
QString VideoDevicePool::currentDeviceUdi()
656
561
{
657
 
        if (m_videodevice.size() && (m_current_device >= 0))
658
 
                return m_videodevice[m_current_device].udi();
 
562
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
563
                return m_videodevices[m_current_device]->udi();
659
564
        else
660
565
                return QString();
661
566
}
666
571
int VideoDevicePool::currentInput()
667
572
{
668
573
    /// @todo implement me
669
 
        return m_videodevice[currentDevice()].currentInput();
 
574
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
575
                return m_videodevices[m_current_device]->currentInput();
 
576
        else
 
577
                return -1;
670
578
}
671
579
 
672
580
/*!
675
583
int VideoDevicePool::inputs()
676
584
{
677
585
    /// @todo implement me
678
 
        return m_videodevice[currentDevice()].inputs();
 
586
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
 
587
                return m_videodevices[m_current_device]->inputs();
 
588
        else
 
589
                return 0;
679
590
}
680
591
 
681
592
/*!
682
 
    \fn void Kopete::AV::VideoDevicePool::loadSelectedDevice()
683
 
    \brief Loads and selects the saved device
 
593
    \fn int Kopete::AV::VideoDevicePool::getSavedDevice()
 
594
    \brief Returns the index of the saved device
684
595
 */
685
 
void VideoDevicePool::loadSelectedDevice()
 
596
int VideoDevicePool::getSavedDevice()
686
597
{
 
598
#ifdef COMPILE_KDE_SUPPORT
687
599
        qDebug() << "called";
688
 
        if (hasDevices())
 
600
        if (m_videodevices.size())
689
601
        {
690
602
                KConfigGroup config(KGlobal::config(), "Video Device Settings");
691
603
                QString currentdevice = config.readEntry("Current Device", QString());
693
605
                if (!currentdevice.isEmpty())
694
606
                {
695
607
                        qDebug() << "Saved device:" << currentdevice;
696
 
                        VideoDeviceVector::iterator vditerator;
697
 
                        for( vditerator = m_videodevice.begin(); vditerator != m_videodevice.end(); ++vditerator )
 
608
                        QVector<VideoDevice*>::iterator vditerator;
 
609
                        for( vditerator = m_videodevices.begin(); vditerator != m_videodevices.end(); ++vditerator )
698
610
                        {
699
 
                                if ((*vditerator).udi() == currentdevice)
 
611
                                if ((*vditerator)->udi() == currentdevice)
700
612
                                {
701
 
                                        m_current_device = std::distance (m_videodevice.begin(), vditerator);
702
 
                                        qDebug() << "Saved device is available, setting device-index to" << m_current_device;
703
 
                                        return;
 
613
                                        int devIndex = std::distance (m_videodevices.begin(), vditerator);
 
614
                                        qDebug() << "Saved device is available, device index is" << devIndex;
 
615
                                        return devIndex;
704
616
                                }
705
617
                        }
706
618
                        qDebug() << "Saved device is not available.";
708
620
                else
709
621
                        qDebug() << "No device saved.";
710
622
        }
 
623
#endif
 
624
        return -1;
711
625
}
712
626
 
713
627
/*!
718
632
 */
719
633
void VideoDevicePool::loadDeviceConfig()
720
634
{
 
635
#ifdef COMPILE_KDE_SUPPORT
721
636
        qDebug() << "called";
722
 
        if (hasDevices())
 
637
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
723
638
        {
724
639
                KConfigGroup config(KGlobal::config(), "Video Device Settings");
725
640
                // Load input and apply
726
 
                const QString key_currentinput = QString::fromLocal8Bit( "Device %1 Current Input" ).arg( m_videodevice[m_current_device].udi() );
 
641
                const QString key_currentinput = QString::fromLocal8Bit( "Device %1 Current Input" ).arg( m_videodevices[m_current_device]->udi() );
727
642
                const int currentinput = config.readEntry(key_currentinput, 0);
728
643
                qDebug() << "Setting input to" << currentinput;
729
 
                if (currentinput != m_videodevice[m_current_device].currentInput())
730
 
                        m_videodevice[m_current_device].selectInput(currentinput);
 
644
                if (currentinput != m_videodevices[m_current_device]->currentInput())
 
645
                        m_videodevices[m_current_device]->selectInput(currentinput);
731
646
                // Load video-controls and apply
732
647
                quint32 ctrl_id;
733
648
                qint32 ctrl_value;
734
649
                QString ctrl_key;
735
650
                bool ok = false;
736
 
                const QString key_control_start = QString::fromLocal8Bit( "Device %1 Input %2 Control " ).arg( m_videodevice[m_current_device].udi() ,  m_videodevice[m_current_device].currentInput() );
 
651
                const QString key_control_start = QString::fromLocal8Bit( "Device %1 Input %2 Control " ).arg( m_videodevices[m_current_device]->udi() ).arg( m_videodevices[m_current_device]->currentInput() );
737
652
                QStringList ctrl_keys = config.keyList().filter(key_control_start);
738
653
                qDebug() << "Found" << ctrl_keys.size() << "saved values for video-controls";
739
654
                foreach (ctrl_key, ctrl_keys)
750
665
                                if (ok && !tmpstr.isEmpty())
751
666
                                {
752
667
                                        qDebug() << "Setting control" << ctrl_id << "to value" << ctrl_value;
753
 
                                        m_videodevice[m_current_device].setControlValue(ctrl_id, ctrl_value);
 
668
                                        m_videodevices[m_current_device]->setControlValue(ctrl_id, ctrl_value);
754
669
                                }
755
670
                                else
756
671
                                        qDebug() << "Saved value for control" << ctrl_id << "is invalid:" << tmpstr;
760
675
                }
761
676
        }
762
677
        /* TODO: load and apply signal standard */
 
678
#endif
763
679
}
764
680
 
765
681
/*!
770
686
 */
771
687
void VideoDevicePool::saveCurrentDeviceConfig()
772
688
{
 
689
#ifdef COMPILE_KDE_SUPPORT
773
690
        qDebug() << "called";
774
 
        if (hasDevices())
 
691
        if ((m_current_device >= 0) && (m_current_device < m_videodevices.size()))
775
692
        {
776
693
                KConfigGroup config(KGlobal::config(), "Video Device Settings");
777
694
                // Save current device:
778
 
                qDebug() << "Current device:" << m_videodevice[m_current_device].udi();
779
 
                config.writeEntry( "Current Device", m_videodevice[m_current_device].udi() );
 
695
                qDebug() << "Current device:" << m_videodevices[m_current_device]->udi();
 
696
                config.writeEntry( "Current Device", m_videodevices[m_current_device]->udi() );
780
697
                // Save current device name (for debugging only):
781
 
                qDebug() << "Current device name:" << m_videodevice[m_current_device].m_name;
782
 
                const QString name = QString::fromLocal8Bit( "Device %1 Name" ).arg( m_videodevice[m_current_device].udi() );
783
 
                config.writeEntry( name, m_videodevice[m_current_device].m_name );
 
698
                qDebug() << "Current device name:" << m_videodevices[m_current_device]->m_name;
 
699
                const QString name = QString::fromLocal8Bit( "Device %1 Name" ).arg( m_videodevices[m_current_device]->udi() );
 
700
                config.writeEntry( name, m_videodevices[m_current_device]->m_name );
784
701
                // Open device if closed:
785
702
                bool wasClosed = false;
786
 
                if (!m_videodevice[m_current_device].isOpen())
 
703
                if (!m_videodevices[m_current_device]->isOpen())
787
704
                {
788
705
                        qDebug() << "Device is currently closed, will be opened.";
789
706
                        wasClosed = true;
790
 
                        if (EXIT_SUCCESS != m_videodevice[m_current_device].open())
 
707
                        if (EXIT_SUCCESS != m_videodevices[m_current_device]->open())
791
708
                        {
792
709
                                qDebug() << "Failed to open the device. Saving aborted.";
793
710
                                config.sync();
795
712
                        }
796
713
                }
797
714
                // Save current input:
798
 
                qDebug() << "Current input:" << m_videodevice[m_current_device].currentInput();
799
 
                const QString key_currentinput = QString::fromLocal8Bit( "Device %1 Current Input" ).arg( m_videodevice[m_current_device].udi() );
800
 
                config.writeEntry( key_currentinput, m_videodevice[m_current_device].currentInput() );
 
715
                qDebug() << "Current input:" << m_videodevices[m_current_device]->currentInput();
 
716
                const QString key_currentinput = QString::fromLocal8Bit( "Device %1 Current Input" ).arg( m_videodevices[m_current_device]->udi() );
 
717
                config.writeEntry( key_currentinput, m_videodevices[m_current_device]->currentInput() );
801
718
                // --- Save values of the controls ---:
802
719
                qint32 ctrl_value;
803
 
                const QString key_control_start = QString::fromLocal8Bit( "Device %1 Input %2 Control " ).arg( m_videodevice[m_current_device].udi() ,  m_videodevice[m_current_device].currentInput() );
 
720
                const QString key_control_start = QString::fromLocal8Bit( "Device %1 Input %2 Control " ).arg( m_videodevices[m_current_device]->udi() ).arg( m_videodevices[m_current_device]->currentInput() );
804
721
                // Save values of the numeric controls:
805
 
                QList<NumericVideoControl> numCtrls = m_videodevice[m_current_device].getSupportedNumericControls();
 
722
                QList<NumericVideoControl> numCtrls = m_videodevices[m_current_device]->getSupportedNumericControls();
806
723
                NumericVideoControl numCtrl;
807
724
                foreach (numCtrl, numCtrls)
808
725
                {
809
 
                        if (EXIT_SUCCESS == m_videodevice[m_current_device].getControlValue(numCtrl.id, &ctrl_value))
 
726
                        if (EXIT_SUCCESS == m_videodevices[m_current_device]->getControlValue(numCtrl.id, &ctrl_value))
810
727
                        {
811
728
                                qDebug() << "Numeric control:" << numCtrl.id << "value" << ctrl_value;
812
729
                                config.writeEntry( key_control_start + QString::number(numCtrl.id), ctrl_value );
815
732
                                qDebug() << "Error: couldn't get current value for numeric control" << numCtrl.id;
816
733
                }
817
734
                // Save values of the boolean controls:
818
 
                QList<BooleanVideoControl> boolCtrls = m_videodevice[m_current_device].getSupportedBooleanControls();
 
735
                QList<BooleanVideoControl> boolCtrls = m_videodevices[m_current_device]->getSupportedBooleanControls();
819
736
                BooleanVideoControl boolCtrl;
820
737
                foreach (boolCtrl, boolCtrls)
821
738
                {
822
 
                        if (EXIT_SUCCESS == m_videodevice[m_current_device].getControlValue(boolCtrl.id, &ctrl_value))
 
739
                        if (EXIT_SUCCESS == m_videodevices[m_current_device]->getControlValue(boolCtrl.id, &ctrl_value))
823
740
                        {
824
741
                                qDebug() << "Boolean control:" << boolCtrl.id << "value" << ctrl_value;
825
742
                                config.writeEntry( key_control_start + QString::number(boolCtrl.id), ctrl_value );
828
745
                                qDebug() << "Error: couldn't get current value for boolean control" << numCtrl.id;
829
746
                }
830
747
                // Save values of the menu controls:
831
 
                QList<MenuVideoControl> menuCtrls = m_videodevice[m_current_device].getSupportedMenuControls();
 
748
                QList<MenuVideoControl> menuCtrls = m_videodevices[m_current_device]->getSupportedMenuControls();
832
749
                MenuVideoControl menuCtrl;
833
750
                foreach (menuCtrl, menuCtrls)
834
751
                {
835
 
                        if (EXIT_SUCCESS == m_videodevice[m_current_device].getControlValue(menuCtrl.id, &ctrl_value))
 
752
                        if (EXIT_SUCCESS == m_videodevices[m_current_device]->getControlValue(menuCtrl.id, &ctrl_value))
836
753
                        {
837
754
                                qDebug() << "Menu-control:" << menuCtrl.id << "value" << ctrl_value;
838
755
                                config.writeEntry( key_control_start + QString::number(menuCtrl.id), ctrl_value );
844
761
                // Close device again (if it was closed before):
845
762
                if (wasClosed)
846
763
                {
847
 
                        if (EXIT_SUCCESS == m_videodevice[m_current_device].close())
 
764
                        if (EXIT_SUCCESS == m_videodevices[m_current_device]->close())
848
765
                                qDebug() << "Device successfully closed.";
849
766
                        else
850
767
                                qDebug() << "Error: failed to close the device.";
852
769
                config.sync();
853
770
        }
854
771
        /* TODO: save signal standard */
 
772
#endif
855
773
}
856
774
 
857
775
void VideoDevicePool::deviceAdded( const QString & udi )
858
776
{
859
 
        qDebug() << "("<< udi << ") called";
 
777
        qDebug() << "called with UDI" << udi;
 
778
#ifdef COMPILE_KDE_SUPPORT
860
779
        Solid::Device dev( udi );
861
780
        if ( dev.is<Solid::Video>() )
862
781
        {
863
 
                registerDevice( dev );
864
 
                emit deviceRegistered( udi );
 
782
                qDebug() << "Device is a video device, trying to register it.";
 
783
                if ( registerDevice( dev ) )
 
784
                        emit deviceRegistered( udi );
865
785
        }
 
786
        else
 
787
                qDebug() << "Device is not a video device";
 
788
#endif
866
789
}
867
 
 
868
790
void VideoDevicePool::deviceRemoved( const QString & udi )
869
791
{
870
 
        qDebug() << "("<< udi << ") called";
 
792
        qDebug() << "called with UDI" << udi;
871
793
        int i = 0;
872
 
        m_ready.lock();
873
 
        foreach ( VideoDevice vd, m_videodevice )
 
794
        foreach ( VideoDevice* vd, m_videodevices )
874
795
        {
875
 
                if ( vd.udi() == udi )
 
796
                if ( vd->udi() == udi )
876
797
                {
877
 
                        qDebug() << "Video device '" << udi << "' has been removed!";
878
 
                        // not sure if this is safe but at this point the device node is gone already anyway
879
 
                        m_videodevice.remove( i );
 
798
                        qDebug() << "Video device with UDI" << udi << "has been removed!";
 
799
                        delete m_videodevices[i]; // NOTE: device is closed in destructor
 
800
                        m_videodevices.remove( i );
880
801
                        if (m_current_device == i)
881
802
                        {
882
 
                                m_current_device = 0;
 
803
                                if (m_videodevices.size())
 
804
                                        m_current_device = 0;
 
805
                                else
 
806
                                        m_current_device = -1;
883
807
                                m_clients = 0;
884
808
                        }
885
809
                        else if (m_current_device > i)
886
810
                        {
887
811
                                m_current_device--;
888
812
                        }
889
 
                        m_ready.unlock();
890
813
                        emit deviceUnregistered( udi );
891
 
                        /* NOTE: do not emit deviceUnregistered( udi ) with mutex locked ! => potential deadlock ! */
892
814
                        return;
893
815
                }
894
816
                else
895
 
                {
896
817
                        i++;
897
 
                }
898
818
        }
899
 
        m_ready.unlock();
900
819
}
901
820
 
902
821
} // namespace AV