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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
|
/*
videodevice.cpp - Kopete Video Device Low-level Support
Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com>
Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include <assert.h>
#include <cstdlib>
#include <cerrno>
#include <cstring>
#include <kdebug.h>
#include <tdelocale.h>
#include <tqdir.h>
#include "videodevice.h"
#include "videodevicepool.h"
#define CLEAR(x) memset (&(x), 0, sizeof (x))
namespace Kopete {
namespace AV {
VideoDevicePool *VideoDevicePool::s_self = NULL;
__u64 VideoDevicePool::m_clients = 0;
VideoDevicePool* VideoDevicePool::self()
{
kdDebug(14010) << "libkopete (avdevice): self() called" << endl;
if (s_self == NULL)
{
s_self = new VideoDevicePool;
if (s_self)
m_clients = 0;
}
kdDebug(14010) << "libkopete (avdevice): self() exited successfuly. m_clients = " << m_clients << endl;
return s_self;
}
VideoDevicePool::VideoDevicePool()
{
}
VideoDevicePool::~VideoDevicePool()
{
}
/*!
\fn VideoDevicePool::open()
*/
int VideoDevicePool::open()
{
/// @todo implement me
m_ready.lock();
if(!m_videodevice.size())
{
kdDebug(14010) << k_funcinfo << "open(): No devices found. Must scan for available devices." << m_current_device << endl;
scanDevices();
}
if(!m_videodevice.size())
{
kdDebug(14010) << k_funcinfo << "open(): No devices found. bailing out." << m_current_device << endl;
m_ready.unlock();
return EXIT_FAILURE;
}
if(m_current_device >= m_videodevice.size())
{
kdDebug(14010) << k_funcinfo << "open(): Device out of scope (" << m_current_device << "). Defaulting to the first one." << endl;
m_current_device = 0;
}
int isopen = m_videodevice[currentDevice()].open();
if ( isopen == EXIT_SUCCESS)
{
loadConfig(); // Temporary hack. The open() seems to clean the input parameters. Need to find a way to fix it.
}
m_clients++;
kdDebug(14010) << k_funcinfo << "Number of clients: " << m_clients << endl;
m_ready.unlock();
return isopen;
}
/*!
\fn VideoDevicePool::open(int device)
*/
int VideoDevicePool::open(unsigned int device)
{
/// @todo implement me
kdDebug(14010) << k_funcinfo << "open(" << device << ") called." << endl;
if(device >= m_videodevice.size())
{
kdDebug(14010) << k_funcinfo << "open(" << device <<"): Device does not exist." << endl;
return EXIT_FAILURE;
}
close();
kdDebug(14010) << k_funcinfo << "open(" << device << ") Setting m_current_Device to " << device << endl;
m_current_device = device;
saveConfig();
kdDebug(14010) << k_funcinfo << "open(" << device << ") Calling open()." << endl;
return open();
}
bool VideoDevicePool::isOpen()
{
return m_videodevice[currentDevice()].isOpen();
}
/*!
\fn VideoDevicePool::showDeviceCapabilities(int device)
*/
int VideoDevicePool::showDeviceCapabilities(unsigned int device)
{
return m_videodevice[device].showDeviceCapabilities();
}
int VideoDevicePool::width()
{
return m_videodevice[currentDevice()].width();
}
int VideoDevicePool::minWidth()
{
return m_videodevice[currentDevice()].minWidth();
}
int VideoDevicePool::maxWidth()
{
return m_videodevice[currentDevice()].maxWidth();
}
int VideoDevicePool::height()
{
return m_videodevice[currentDevice()].height();
}
int VideoDevicePool::minHeight()
{
return m_videodevice[currentDevice()].minHeight();
}
int VideoDevicePool::maxHeight()
{
return m_videodevice[currentDevice()].maxHeight();
}
int VideoDevicePool::setSize( int newwidth, int newheight)
{
if(m_videodevice.size())
return m_videodevice[currentDevice()].setSize(newwidth, newheight);
else
{
kdDebug(14010) << k_funcinfo << "VideoDevicePool::setSize() fallback for no device." << endl;
m_buffer.width=newwidth;
m_buffer.height=newheight;
m_buffer.pixelformat= PIXELFORMAT_RGB24;
m_buffer.data.resize(m_buffer.width*m_buffer.height*3);
kdDebug(14010) << k_funcinfo << "VideoDevicePool::setSize() buffer size: "<< m_buffer.data.size() << endl;
}
return EXIT_SUCCESS;
}
/*!
\fn VideoDevicePool::close()
*/
int VideoDevicePool::close()
{
/// @todo implement me
if(m_clients)
m_clients--;
if((currentDevice() < m_videodevice.size())&&(!m_clients))
return m_videodevice[currentDevice()].close();
if(m_clients)
kdDebug(14010) << k_funcinfo << "VideoDevicePool::close() The video device is still in use." << endl;
if(currentDevice() >= m_videodevice.size())
kdDebug(14010) << k_funcinfo << "VideoDevicePool::close() Current device out of range." << endl;
return EXIT_FAILURE;
}
/*!
\fn VideoDevicePool::startCapturing()
*/
int VideoDevicePool::startCapturing()
{
kdDebug(14010) << k_funcinfo << "startCapturing() called." << endl;
if(m_videodevice.size())
return m_videodevice[currentDevice()].startCapturing();
return EXIT_FAILURE;
}
/*!
\fn VideoDevicePool::stopCapturing()
*/
int VideoDevicePool::stopCapturing()
{
if(m_videodevice.size())
return m_videodevice[currentDevice()].stopCapturing();
return EXIT_FAILURE;
}
// Implementation of the methods that get / set input's adjustment parameters
/*!
\fn VideoDevicePool::getBrightness()
*/
float VideoDevicePool::getBrightness()
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].getBrightness();
else
return 0;
}
/*!
\fn VideoDevicePool::setBrightness(float brightness)
*/
float VideoDevicePool::setBrightness(float brightness)
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].setBrightness(brightness);
else
return 0;
}
/*!
\fn VideoDevicePool::getContrast()
*/
float VideoDevicePool::getContrast()
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].getContrast();
else
return 0;
}
/*!
\fn VideoDevicePool::setContrast(float contrast)
*/
float VideoDevicePool::setContrast(float contrast)
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].setContrast(contrast);
else
return 0;
}
/*!
\fn VideoDevicePool::getSaturation()
*/
float VideoDevicePool::getSaturation()
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].getSaturation();
else
return 0;
}
/*!
\fn VideoDevicePool::setSaturation(float saturation)
*/
float VideoDevicePool::setSaturation(float saturation)
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].setSaturation(saturation);
else
return 0;
}
/*!
\fn VideoDevicePool::getWhiteness()
*/
float VideoDevicePool::getWhiteness()
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].getWhiteness();
else
return 0;
}
/*!
\fn VideoDevicePool::setWhiteness(float whiteness)
*/
float VideoDevicePool::setWhiteness(float whiteness)
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].setWhiteness(whiteness);
else
return 0;
}
/*!
\fn VideoDevicePool::getHue()
*/
float VideoDevicePool::getHue()
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].getHue();
else
return 0;
}
/*!
\fn VideoDevicePool::setHue(float hue)
*/
float VideoDevicePool::setHue(float hue)
{
if (currentDevice() < m_videodevice.size() )
return m_videodevice[currentDevice()].setHue(hue);
else
return 0;
}
/*!
\fn VideoDevicePool::getAutoBrightnessContrast()
*/
bool VideoDevicePool::getAutoBrightnessContrast()
{
if(m_videodevice.size())
return m_videodevice[currentDevice()].getAutoBrightnessContrast();
return false;
}
/*!
\fn VideoDevicePool::setAutoBrightnessContrast(bool brightnesscontrast)
*/
bool VideoDevicePool::setAutoBrightnessContrast(bool brightnesscontrast)
{
kdDebug(14010) << k_funcinfo << "VideoDevicePool::setAutoBrightnessContrast(" << brightnesscontrast << ") called." << endl;
if(m_videodevice.size())
return m_videodevice[currentDevice()].setAutoBrightnessContrast(brightnesscontrast);
return false;
}
/*!
\fn VideoDevicePool::getAutoColorCorrection()
*/
bool VideoDevicePool::getAutoColorCorrection()
{
if(m_videodevice.size())
return m_videodevice[currentDevice()].getAutoColorCorrection();
return false;
}
/*!
\fn VideoDevicePool::setAutoColorCorrection(bool colorcorrection)
*/
bool VideoDevicePool::setAutoColorCorrection(bool colorcorrection)
{
kdDebug(14010) << k_funcinfo << "VideoDevicePool::setAutoColorCorrection(" << colorcorrection << ") called." << endl;
if(m_videodevice.size())
return m_videodevice[currentDevice()].setAutoColorCorrection(colorcorrection);
return false;
}
/*!
\fn VideoDevicePool::getIMageAsMirror()
*/
bool VideoDevicePool::getImageAsMirror()
{
if(m_videodevice.size())
return m_videodevice[currentDevice()].getImageAsMirror();
return false;
}
/*!
\fn VideoDevicePool::setImageAsMirror(bool imageasmirror)
*/
bool VideoDevicePool::setImageAsMirror(bool imageasmirror)
{
kdDebug(14010) << k_funcinfo << "VideoDevicePool::setImageAsMirror(" << imageasmirror << ") called." << endl;
if(m_videodevice.size())
return m_videodevice[currentDevice()].setImageAsMirror(imageasmirror);
return false;
}
/*!
\fn VideoDevicePool::getFrame()
*/
int VideoDevicePool::getFrame()
{
// kdDebug(14010) << k_funcinfo << "VideoDevicePool::getFrame() called." << endl;
if(m_videodevice.size())
return m_videodevice[currentDevice()].getFrame();
else
{
kdDebug(14010) << k_funcinfo << "VideoDevicePool::getFrame() fallback for no device." << endl;
for(unsigned int loop=0; loop < m_buffer.data.size(); loop+=3)
{
m_buffer.data[loop] = 255;
m_buffer.data[loop+1] = 0;
m_buffer.data[loop+2] = 0;
}
}
// kdDebug(14010) << k_funcinfo << "VideoDevicePool::getFrame() exited successfuly." << endl;
return EXIT_SUCCESS;
}
/*!
\fn VideoDevicePool::getTQImage(TQImage *qimage)
*/
int VideoDevicePool::getImage(TQImage *qimage)
{
// kdDebug(14010) << k_funcinfo << "VideoDevicePool::getImage() called." << endl;
if(m_videodevice.size())
return m_videodevice[currentDevice()].getImage(qimage);
else
{
kdDebug(14010) << k_funcinfo << "VideoDevicePool::getImage() fallback for no device." << endl;
qimage->create(m_buffer.width, m_buffer.height,32, TQImage::IgnoreEndian);
uchar *bits=qimage->bits();
switch(m_buffer.pixelformat)
{
case PIXELFORMAT_NONE : break;
case PIXELFORMAT_GREY : break;
case PIXELFORMAT_RGB332 : break;
case PIXELFORMAT_RGB555 : break;
case PIXELFORMAT_RGB555X: break;
case PIXELFORMAT_RGB565 : break;
case PIXELFORMAT_RGB565X: break;
case PIXELFORMAT_RGB24 :
{
kdDebug(14010) << k_funcinfo << "VideoDevicePool::getImage() fallback for no device - RGB24." << endl;
int step=0;
for(int loop=0;loop < qimage->numBytes();loop+=4)
{
bits[loop] = m_buffer.data[step];
bits[loop+1] = m_buffer.data[step+1];
bits[loop+2] = m_buffer.data[step+2];
bits[loop+3] = 255;
step+=3;
}
}
break;
case PIXELFORMAT_BGR24 : break;
{
int step=0;
for(int loop=0;loop < qimage->numBytes();loop+=4)
{
bits[loop] = m_buffer.data[step+2];
bits[loop+1] = m_buffer.data[step+1];
bits[loop+2] = m_buffer.data[step];
bits[loop+3] = 255;
step+=3;
}
}
break;
case PIXELFORMAT_RGB32 : memcpy(bits,&m_buffer.data[0], m_buffer.data.size());
break;
case PIXELFORMAT_BGR32 : break;
}
}
kdDebug(14010) << k_funcinfo << "VideoDevicePool::getImage() exited successfuly." << endl;
return EXIT_SUCCESS;
}
/*!
\fn Kopete::AV::VideoDevicePool::selectInput(int input)
*/
int VideoDevicePool::selectInput(int newinput)
{
kdDebug(14010) << k_funcinfo << "VideoDevicePool::selectInput(" << newinput << ") called." << endl;
if(m_videodevice.size())
return m_videodevice[currentDevice()].selectInput(newinput);
else
return 0;
}
/*!
\fn Kopete::AV::VideoDevicePool::setInputParameters()
*/
int VideoDevicePool::setInputParameters()
{
if(m_videodevice.size())
return m_videodevice[currentDevice()].setInputParameters();
else
return EXIT_FAILURE;
}
/*!
\fn Kopete::AV::VideoDevicePool::fillDeviceKComboBox(KComboBox *combobox)
*/
int VideoDevicePool::fillDeviceKComboBox(KComboBox *combobox)
{
/// @todo implement me
kdDebug(14010) << k_funcinfo << "fillInputKComboBox: Called." << endl;
combobox->clear();
if(m_videodevice.size())
{
for (unsigned int loop=0; loop < m_videodevice.size(); loop++)
{
combobox->insertItem(m_videodevice[loop].m_name);
kdDebug(14010) << k_funcinfo << "DeviceKCombobox: Added device " << loop << ": " << m_videodevice[loop].m_name << endl;
}
combobox->setCurrentItem(currentDevice());
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
/*!
\fn Kopete::AV::VideoDevicePool::fillInputKComboBox(KComboBox *combobox)
*/
int VideoDevicePool::fillInputKComboBox(KComboBox *combobox)
{
/// @todo implement me
kdDebug(14010) << k_funcinfo << "fillInputKComboBox: Called." << endl;
combobox->clear();
if(m_videodevice.size())
{
if(m_videodevice[currentDevice()].inputs()>0)
{
for (unsigned int loop=0; loop < m_videodevice[currentDevice()].inputs(); loop++)
{
combobox->insertItem(m_videodevice[currentDevice()].m_input[loop].name);
kdDebug(14010) << k_funcinfo << "InputKCombobox: Added input " << loop << ": " << m_videodevice[currentDevice()].m_input[loop].name << " (tuner: " << m_videodevice[currentDevice()].m_input[loop].hastuner << ")" << endl;
}
combobox->setCurrentItem(currentInput());
return EXIT_SUCCESS;
}
}
return EXIT_FAILURE;
}
/*!
\fn Kopete::AV::VideoDevicePool::fillStandardKComboBox(KComboBox *combobox)
*/
int VideoDevicePool::fillStandardKComboBox(KComboBox *combobox)
{
/// @todo implement me
kdDebug(14010) << k_funcinfo << "fillInputKComboBox: Called." << endl;
combobox->clear();
if(m_videodevice.size())
{
if(m_videodevice[currentDevice()].inputs()>0)
{
for (unsigned int loop=0; loop < 25; loop++)
{
if ( (m_videodevice[currentDevice()].m_input[currentInput()].m_standards) & (1 << loop) )
combobox->insertItem(m_videodevice[currentDevice()].signalStandardName( 1 << loop));
/*
case STANDARD_PAL_B1 : return V4L2_STD_PAL_B1; break;
case STANDARD_PAL_G : return V4L2_STD_PAL_G; break;
case STANDARD_PAL_H : return V4L2_STD_PAL_H; break;
case STANDARD_PAL_I : return V4L2_STD_PAL_I; break;
case STANDARD_PAL_D : return V4L2_STD_PAL_D; break;
case STANDARD_PAL_D1 : return V4L2_STD_PAL_D1; break;
case STANDARD_PAL_K : return V4L2_STD_PAL_K; break;
case STANDARD_PAL_M : return V4L2_STD_PAL_M; break;
case STANDARD_PAL_N : return V4L2_STD_PAL_N; break;
case STANDARD_PAL_Nc : return V4L2_STD_PAL_Nc; break;
case STANDARD_PAL_60 : return V4L2_STD_PAL_60; break;
case STANDARD_NTSC_M : return V4L2_STD_NTSC_M; break;
case STANDARD_NTSC_M_JP : return V4L2_STD_NTSC_M_JP; break;
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
case STANDARD_SECAM_B : return V4L2_STD_SECAM_B; break;
case STANDARD_SECAM_D : return V4L2_STD_SECAM_D; break;
case STANDARD_SECAM_G : return V4L2_STD_SECAM_G; break;
case STANDARD_SECAM_H : return V4L2_STD_SECAM_H; break;
case STANDARD_SECAM_K : return V4L2_STD_SECAM_K; break;
case STANDARD_SECAM_K1 : return V4L2_STD_SECAM_K1; break;
case STANDARD_SECAM_L : return V4L2_STD_SECAM_L; break;
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
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
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
case STANDARD_PAL_BG : return V4L2_STD_PAL_BG; break;
case STANDARD_PAL_DK : return V4L2_STD_PAL_DK; break;
case STANDARD_PAL : return V4L2_STD_PAL; break;
case STANDARD_NTSC : return V4L2_STD_NTSC; break;
case STANDARD_SECAM_DK : return V4L2_STD_SECAM_DK; break;
case STANDARD_SECAM : return V4L2_STD_SECAM; break;
case STANDARD_525_60 : return V4L2_STD_525_60; break;
case STANDARD_625_50 : return V4L2_STD_625_50; break;
case STANDARD_ALL : return V4L2_STD_ALL; break;
combobox->insertItem(m_videodevice[currentDevice()].m_input[loop].name);
kdDebug(14010) << k_funcinfo << "StandardKCombobox: Added input " << loop << ": " << m_videodevice[currentDevice()].m_input[loop].name << " (tuner: " << m_videodevice[currentDevice()].m_input[loop].hastuner << ")" << endl;*/
}
combobox->setCurrentItem(currentInput());
return EXIT_SUCCESS;
}
}
return EXIT_FAILURE;
}
/*!
\fn Kopete::AV::VideoDevicePool::scanDevices()
*/
int VideoDevicePool::scanDevices()
{
/// @todo implement me
kdDebug(14010) << k_funcinfo << "called" << endl;
#if defined(__linux__) && defined(ENABLE_AV)
TQDir videodevice_dir;
const TQString videodevice_dir_path=TQString::fromLocal8Bit("/dev/v4l/");
const TQString videodevice_dir_filter=TQString::fromLocal8Bit("video*");
VideoDevice videodevice;
m_videodevice.clear();
m_modelvector.clear();
videodevice_dir.setPath(videodevice_dir_path);
videodevice_dir.setNameFilter(videodevice_dir_filter);
videodevice_dir.setFilter( TQDir::System | TQDir::NoSymLinks | TQDir::Readable | TQDir::Writable );
videodevice_dir.setSorting( TQDir::Name );
kdDebug(14010) << k_funcinfo << "Looking for devices in " << videodevice_dir_path << endl;
const TQFileInfoList *list = videodevice_dir.entryInfoList();
if (!list)
{
kdDebug(14010) << k_funcinfo << "Found no suitable devices in " << videodevice_dir_path << endl;
TQDir videodevice_dir;
const TQString videodevice_dir_path=TQString::fromLocal8Bit("/dev/");
const TQString videodevice_dir_filter=TQString::fromLocal8Bit("video*");
VideoDevice videodevice;
videodevice_dir.setPath(videodevice_dir_path);
videodevice_dir.setNameFilter(videodevice_dir_filter);
videodevice_dir.setFilter( TQDir::System | TQDir::NoSymLinks | TQDir::Readable | TQDir::Writable );
videodevice_dir.setSorting( TQDir::Name );
kdDebug(14010) << k_funcinfo << "Looking for devices in " << videodevice_dir_path << endl;
const TQFileInfoList *list = videodevice_dir.entryInfoList();
if (!list)
{
kdDebug(14010) << k_funcinfo << "Found no suitable devices in " << videodevice_dir_path << endl;
return EXIT_FAILURE;
}
TQFileInfoListIterator fileiterator ( *list );
TQFileInfo *fileinfo;
kdDebug(14010) << k_funcinfo << "scanning devices in " << videodevice_dir_path << "..." << endl;
while ( (fileinfo = fileiterator.current()) != 0 )
{
videodevice.setFileName(fileinfo->absFilePath());
kdDebug(14010) << k_funcinfo << "Found device " << videodevice.full_filename << endl;
videodevice.open(); // It should be opened with O_NONBLOCK (it's a FIFO) but I dunno how to do it using TQFile
if(videodevice.isOpen())
{
kdDebug(14010) << k_funcinfo << "File " << videodevice.full_filename << " was opened successfuly" << endl;
// This must be changed to proper code to handle multiple devices of the same model. It currently simply add models without proper checking
videodevice.close();
videodevice.m_modelindex=m_modelvector.addModel (videodevice.m_model); // Adds device to the device list and sets model number
m_videodevice.push_back(videodevice);
}
++fileiterator;
}
m_current_device = 0;
loadConfig();
kdDebug(14010) << k_funcinfo << "exited successfuly" << endl;
return EXIT_SUCCESS;
}
TQFileInfoListIterator fileiterator ( *list );
TQFileInfo *fileinfo;
kdDebug(14010) << k_funcinfo << "scanning devices in " << videodevice_dir_path << "..." << endl;
while ( (fileinfo = fileiterator.current()) != 0 )
{
videodevice.setFileName(fileinfo->absFilePath());
kdDebug(14010) << k_funcinfo << "Found device " << videodevice.full_filename << endl;
videodevice.open(); // It should be opened with O_NONBLOCK (it's a FIFO) but I dunno how to do it using TQFile
if(videodevice.isOpen())
{
kdDebug(14010) << k_funcinfo << "File " << videodevice.full_filename << " was opened successfuly" << endl;
// This must be changed to proper code to handle multiple devices of the same model. It currently simply add models without proper checking
videodevice.close();
videodevice.m_modelindex=m_modelvector.addModel (videodevice.m_model); // Adds device to the device list and sets model number
m_videodevice.push_back(videodevice);
}
++fileiterator;
}
m_current_device = 0;
loadConfig();
#endif
kdDebug(14010) << k_funcinfo << "exited successfuly" << endl;
return EXIT_SUCCESS;
}
/*!
\fn Kopete::AV::VideoDevicePool::hasDevices()
*/
bool VideoDevicePool::hasDevices()
{
/// @todo implement me
if(m_videodevice.size())
return true;
return false;
}
/*!
\fn Kopete::AV::VideoDevicePool::size()
*/
size_t VideoDevicePool::size()
{
/// @todo implement me
return m_videodevice.size();
}
/*!
\fn Kopete::AV::VideoDevicePool::currentDevice()
*/
unsigned int VideoDevicePool::currentDevice()
{
/// @todo implement me
return m_current_device;
}
/*!
\fn Kopete::AV::VideoDevicePool::currentInput()
*/
int VideoDevicePool::currentInput()
{
/// @todo implement me
return m_videodevice[currentDevice()].currentInput();
}
/*!
\fn Kopete::AV::VideoDevicePool::currentInput()
*/
unsigned int VideoDevicePool::inputs()
{
/// @todo implement me
return m_videodevice[currentDevice()].inputs();
}
/*!
\fn Kopete::AV::VideoDevicePool::loadConfig()
*/
void VideoDevicePool::loadConfig()
{
/// @todo implement me
kdDebug(14010) << k_funcinfo << "called" << endl;
if((hasDevices())&&(m_clients==0))
{
TDEConfig *config = TDEGlobal::config();
config->setGroup("Video Device Settings");
const TQString currentdevice = config->readEntry("Current Device", TQString());
kdDebug(14010) << k_funcinfo << "Current device: " << currentdevice << endl;
// m_current_device = 0; // Must check this thing because of the fact that multiple loadConfig in other methodas can do bad things. Watch out!
VideoDeviceVector::iterator vditerator;
for( vditerator = m_videodevice.begin(); vditerator != m_videodevice.end(); ++vditerator )
{
const TQString modelindex = TQString::fromLocal8Bit ( "Model %1 Device %2") .arg ((*vditerator).m_name ) .arg ((*vditerator).m_modelindex);
if(modelindex == currentdevice)
{
m_current_device = vditerator - m_videodevice.begin();
// kdDebug(14010) << k_funcinfo << "This place will be used to set " << modelindex << " as the current device ( " << (vditerator - m_videodevice.begin()) << " )." << endl;
}
const TQString name = config->readEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Name") .arg ((*vditerator).m_name ) .arg ((*vditerator).m_modelindex)), (*vditerator).m_model);
const int currentinput = config->readNumEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Current input") .arg ((*vditerator).m_name ) .arg ((*vditerator).m_modelindex)), 0);
kdDebug(14010) << k_funcinfo << "Device name: " << name << endl;
kdDebug(14010) << k_funcinfo << "Device current input: " << currentinput << endl;
(*vditerator).selectInput(currentinput);
for (size_t input = 0 ; input < (*vditerator).m_input.size(); input++)
{
const float brightness = config->readDoubleNumEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Brightness").arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input)) , 0.5 );
const float contrast = config->readDoubleNumEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Contrast") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input)) , 0.5 );
const float saturation = config->readDoubleNumEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Saturation").arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input)) , 0.5 );
const float whiteness = config->readDoubleNumEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Whiteness") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input)) , 0.5 );
const float hue = config->readDoubleNumEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Hue") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input)) , 0.5 );
const bool autobrightnesscontrast = config->readBoolEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 AutoBrightnessContrast") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input)) , false );
const bool autocolorcorrection = config->readBoolEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 AutoColorCorrection") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input)) , false );
const bool imageasmirror = config->readBoolEntry((TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 mageAsMirror") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input)) , false );
(*vditerator).setBrightness(brightness);
(*vditerator).setContrast(contrast);
(*vditerator).setSaturation(saturation);
(*vditerator).setHue(hue);
(*vditerator).setAutoBrightnessContrast(autobrightnesscontrast);
(*vditerator).setAutoColorCorrection(autocolorcorrection);
(*vditerator).setImageAsMirror(imageasmirror);
kdDebug(14010) << k_funcinfo << "Brightness:" << brightness << endl;
kdDebug(14010) << k_funcinfo << "Contrast :" << contrast << endl;
kdDebug(14010) << k_funcinfo << "Saturation:" << saturation << endl;
kdDebug(14010) << k_funcinfo << "Whiteness :" << whiteness << endl;
kdDebug(14010) << k_funcinfo << "Hue :" << hue << endl;
kdDebug(14010) << k_funcinfo << "AutoBrightnessContrast:" << autobrightnesscontrast << endl;
kdDebug(14010) << k_funcinfo << "AutoColorCorrection :" << autocolorcorrection << endl;
kdDebug(14010) << k_funcinfo << "ImageAsMirror :" << imageasmirror << endl;
}
}
}
}
/*!
\fn Kopete::AV::VideoDevicePool::saveConfig()
*/
void VideoDevicePool::saveConfig()
{
/// @todo implement me
kdDebug(14010) << k_funcinfo << "called" << endl;
if(hasDevices())
{
TDEConfig *config = TDEGlobal::config();
config->setGroup("Video Device Settings");
/* if(m_modelvector.size())
{
VideoDeviceModelPool::m_devicemodel::iterator vmiterator;
for( vmiterator = m_modelvector.begin(); vmiterator != m_modelvector.end(); ++vmiterator )
{
kdDebug(14010) << "Device Model: " << (*vmiterator).model << endl;
kdDebug(14010) << "Device Count: " << (*vmiterator).count << endl;
}
}
*/
// Stores what is the current video device in use
const TQString currentdevice = TQString(TQString::fromLocal8Bit ( "Model %1 Device %2" )) .arg(m_videodevice[m_current_device].m_model) .arg(m_videodevice[m_current_device].m_modelindex);
config->writeEntry( "Current Device", currentdevice);
VideoDeviceVector::iterator vditerator;
for( vditerator = m_videodevice.begin(); vditerator != m_videodevice.end(); ++vditerator )
{
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Name:" << (*vditerator).m_name << endl;
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Current input:" << (*vditerator).currentInput() << endl;
// Stores current input for the given video device
const TQString name = TQString::fromLocal8Bit ( "Model %1 Device %2 Name") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex);
const TQString currentinput = TQString::fromLocal8Bit ( "Model %1 Device %2 Current input") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex);
config->writeEntry( name, (*vditerator).m_name);
config->writeEntry( currentinput, (*vditerator).currentInput());
for (size_t input = 0 ; input < (*vditerator).m_input.size(); input++)
{
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Input:" << input << ":Brightness: " << (*vditerator).m_input[input].getBrightness() << endl;
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Input:" << input << ":Contrast : " << (*vditerator).m_input[input].getContrast() << endl;
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Input:" << input << ":Saturation: " << (*vditerator).m_input[input].getSaturation() << endl;
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Input:" << input << ":Whiteness : " << (*vditerator).m_input[input].getWhiteness() << endl;
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Input:" << input << ":Hue : " << (*vditerator).m_input[input].getHue() << endl;
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Input:" << input << ":Automatic brightness / contrast: " << (*vditerator).m_input[input].getAutoBrightnessContrast() << endl;
kdDebug(14010) << "Model:" << (*vditerator).m_model << ":Index:" << (*vditerator).m_modelindex << ":Input:" << input << ":Automatic color correction : " << (*vditerator).m_input[input].getAutoColorCorrection() << endl;
// Stores configuration about each channel
const TQString brightness = TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Brightness") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input);
const TQString contrast = TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Contrast") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input);
const TQString saturation = TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Saturation") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input);
const TQString whiteness = TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Whiteness") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input);
const TQString hue = TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 Hue") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input);
const TQString autobrightnesscontrast = TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 AutoBrightnessContrast") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input);
const TQString autocolorcorrection = TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 AutoColorCorrection") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input);
const TQString imageasmirror = TQString::fromLocal8Bit ( "Model %1 Device %2 Input %3 ImageAsMirror") .arg ((*vditerator).m_model ) .arg ((*vditerator).m_modelindex) .arg (input);
config->writeEntry( brightness, (*vditerator).m_input[input].getBrightness());
config->writeEntry( contrast, (*vditerator).m_input[input].getContrast());
config->writeEntry( saturation, (*vditerator).m_input[input].getSaturation());
config->writeEntry( whiteness, (*vditerator).m_input[input].getWhiteness());
config->writeEntry( hue, (*vditerator).m_input[input].getHue());
config->writeEntry( autobrightnesscontrast, (*vditerator).m_input[input].getAutoBrightnessContrast());
config->writeEntry( autocolorcorrection, (*vditerator).m_input[input].getAutoColorCorrection());
config->writeEntry( imageasmirror, (*vditerator).m_input[input].getImageAsMirror());
}
}
config->sync();
kdDebug(14010) << endl;
}
}
}
}
|