File: VideoDeviceWin32.cpp

package info (click to toggle)
camstream 0.27%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 12,368 kB
  • ctags: 5,393
  • sloc: cpp: 17,031; sh: 8,154; asm: 455; ansic: 440; makefile: 343
file content (641 lines) | stat: -rw-r--r-- 19,607 bytes parent folder | download | duplicates (2)
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

#include "ccvt.h"

#include "VideoCollector.h"
#include "VideoDeviceWin32.h"

/** 
  \param index The index of the video driver


*/
CVideoDeviceWin32::CVideoDeviceWin32(int index)
{
   char name[100], version[100];
   CAPDRIVERCAPS Capabilities;

qDebug(">> CVideoDeviceWin32::CVideoDeviceWin32(%d)", index);

   m_BMISize = 0;
   m_pBMIBuf = 0;
   m_pVideoInfo = 0;
   m_Palette = 0;

   m_CapIndex = index;
   capGetDriverDescription(m_CapIndex, name, sizeof(name), version, sizeof(version));
   name[99] = '\0';
   version[99] = '\0';
   m_NodeName = version;
   m_IntfName = name;

   // First create the capture window. Well, this is an invisible window
   // with no border, no attributes, no nuttin'.
   m_CapHandle = capCreateCaptureWindow((LPTSTR)TEXT("Capture Window"),
                                        0,
                                        0, 0, 160, 120,
                                        (HWND) 0, 0);

   if (!m_CapHandle) {
     qWarning("Could not create capturewindow handle.");
   }
   else {
     // Connect to capture device, get capabilities 
     if (!capDriverConnect(m_CapHandle, m_CapIndex)) {
       qWarning("Failed to connect to capDriver %d", m_CapIndex);
     } 
     else {
       if (!capDriverGetName(m_CapHandle, name, sizeof(name)))
         m_IntfName = "** error **";
       else
         m_IntfName = name;
       if (!capDriverGetVersion(m_CapHandle, version, sizeof(version)))
         m_NodeName = "** error **";
       else
         m_NodeName = version;

       if (!capDriverGetCaps(m_CapHandle, &Capabilities, sizeof(Capabilities)))
         qWarning("Could not get driver capabilities!");
       else {
         m_HasDisplayDialog = Capabilities.fHasDlgVideoDisplay;
         m_HasFormatDialog  = Capabilities.fHasDlgVideoFormat;
         m_HasSourceDialog  = Capabilities.fHasDlgVideoSource;
   
         qDebug("HasOverlay             %s", Capabilities.fHasOverlay              ? "yes" : "no");
         qDebug("HasDlgVideoSource      %s", Capabilities.fHasDlgVideoSource       ? "yes" : "no");
         qDebug("HasDlgVideoFormat      %s", Capabilities.fHasDlgVideoFormat       ? "yes" : "no");
         qDebug("HasDlgVideoDisplay     %s", Capabilities.fHasDlgVideoDisplay      ? "yes" : "no");
         qDebug("CaptureInitialized     %s", Capabilities.fCaptureInitialized      ? "yes" : "no");
         qDebug("DriverSuppliesPalettes %s", Capabilities.fDriverSuppliesPalettes  ? "yes" : "no");

         qDebug("VideoIn     = %d", Capabilities.hVideoIn);
         qDebug("VideoOut    = %d", Capabilities.hVideoOut);
         qDebug("VideoExtIn  = %d", Capabilities.hVideoExtIn);
         qDebug("VideoExtOut = %d", Capabilities.hVideoExtOut);
       }

       if (!capDriverDisconnect(m_CapHandle))
         qWarning("Could not disconnect from handle?");
       DestroyWindow(m_CapHandle);
       m_CapHandle = 0;
       m_Validated = true;
     }
   }
qDebug("<< CVideoDeviceWin32::CVideoDeviceWin32()");
}

CVideoDeviceWin32::~CVideoDeviceWin32()
{
   qDebug("CVideoDeviceWin32::~CVideoDeviceWin32(%d)", m_CapIndex);
}

// private

void CVideoDeviceWin32::CreateImagesRGB()
{
   unsigned int i;
qDebug("<> CVideoDeviceWin32::CreateImagesRGB()");
   m_RGB.resize(m_Buffers);
   for (i = 0; i < m_Buffers; i++) {
      m_RGB.insert(i, new QImage(m_ImageSize, 32));
   }
}

void CVideoDeviceWin32::DeleteImagesRGB()
{
qDebug("<> CVideoDeviceWin32::DeleteImagesRGB()");
   m_RGB.resize(0);
}

void CVideoDeviceWin32::CreateImagesYUV()
{
   QImage *img = 0;
   unsigned int i, j;
   QSize QuarterSize;

qDebug("<> CVideoDeviceWin32::CreateImagesYUV()");
   QuarterSize.setWidth(m_ImageSize.width() / 2);
   QuarterSize.setHeight(m_ImageSize.height() / 2);
   m_Y.resize(m_Buffers);
   m_U.resize(m_Buffers);
   m_V.resize(m_Buffers);
   for (i = 0; i < m_Buffers; i++) {
      img = new QImage(m_ImageSize, 8, 256);
      for (j = 0; j< 256; j++)
         img->setColor(j, m_GrayScale[j]);
      m_Y.insert(i, img);

      img = new QImage(QuarterSize, 8, 256);
      for (j = 0; j< 256; j++)
         img->setColor(j, m_GrayScale[j]);
      m_U.insert(i, img);

      img = new QImage(QuarterSize, 8, 256);
      for (j = 0; j< 256; j++)
         img->setColor(j, m_GrayScale[j]);
      m_V.insert(i, img);
   }
}

void CVideoDeviceWin32::DeleteImagesYUV()
{
qDebug("<> CVideoDeviceWin32::DeleteImagesYUV()");
   m_Y.resize(0);
   m_U.resize(0);
   m_V.resize(0);
}


bool CVideoDeviceWin32::TryPalette(Palettes pal)
{
   bool ret = false;

   switch(pal) {
     case palI420:
       m_pVideoInfo->bmiHeader.biSizeImage = (m_ImageSize.width() * m_ImageSize.height() * 3) / 2;
       m_pVideoInfo->bmiHeader.biPlanes = 1;
       m_pVideoInfo->bmiHeader.biBitCount = 12;
       m_pVideoInfo->bmiHeader.biCompression = palI420;
       ret = capSetVideoFormat(m_CapHandle, m_pVideoInfo, m_BMISize);
       break;
         
     case palRGB24:
       m_pVideoInfo->bmiHeader.biSizeImage = 0;
       m_pVideoInfo->bmiHeader.biPlanes = 1;
       m_pVideoInfo->bmiHeader.biBitCount = 24;
       m_pVideoInfo->bmiHeader.biCompression = BI_RGB;
       ret = capSetVideoFormat(m_CapHandle, m_pVideoInfo, m_BMISize);
       break;

     case palRGB32:
       m_pVideoInfo->bmiHeader.biSizeImage = 0;
       m_pVideoInfo->bmiHeader.biPlanes = 1;
       m_pVideoInfo->bmiHeader.biBitCount = 32;
       m_pVideoInfo->bmiHeader.biCompression = BI_RGB;
       ret = capSetVideoFormat(m_CapHandle, m_pVideoInfo, m_BMISize);
       break;
     
     default:
       qWarning("CVideoDeviceWin32::TryPalette() unkown palette %d requested.", pal);
       break;
   }
   if (ret)
     m_Palette = pal;
qDebug("TryPalette(%d) return %c", pal, ret ? 'T' : 'F');
   return ret;
}

void CVideoDeviceWin32::UpdateCaptureStatus()
{
   CAPSTATUS NewStatus;

   if (m_CapHandle == 0) {
     memset(&m_CaptureStatus, 0, sizeof(m_CaptureStatus));
     return;
   }
   if (!capGetStatus(m_CapHandle, &NewStatus, sizeof(NewStatus))) {
     qWarning("Failed to get CapStatus.");
     return;
   }
   // compare with old status, emit signals if parameters have changed

   m_CaptureStatus = NewStatus;
}


void CVideoDeviceWin32::DumpVideoFormat(const BITMAPINFO *info) const
{
   const BITMAPINFOHEADER *h0 = &info->bmiHeader; // <= NT 3.51 
   const BITMAPV4HEADER   *h4 = 0; // NT 4.0, Win95
#if (WINVER >= 0x500)
   const BITMAPV5HEADER   *h5 = 0; // Win98, >= NT 5.0
#endif
   qDebug("CVideoDeviceWin32::DumpVideoFormat()");
   qDebug("struct size         : %d", h0->biSize);
   qDebug("width               : %d", h0->biWidth);
   qDebug("height              : %d", h0->biHeight);
   qDebug("planes              : %d", h0->biPlanes);
   qDebug("bit count           : %d", h0->biBitCount);
   qDebug("compression         :x%x", h0->biCompression);
   qDebug("size image          : %d", h0->biSizeImage);
   qDebug("xpels per meter     : %d", h0->biXPelsPerMeter);
   qDebug("ypels per meter     : %d", h0->biYPelsPerMeter);
   qDebug("colors used         : %d", h0->biClrUsed);
   qDebug("colors important    : %d", h0->biClrImportant);
}

void CVideoDeviceWin32::DumpCaptureParms(const CAPTUREPARMS *cp) const
{
   qDebug("CVideoDeviceWin32::DumpCaptureParms()");
   qDebug("uSeconds per frame  : %ld" , cp->dwRequestMicroSecPerFrame);
   qDebug("User must hit OK?   : %c"  , cp->fMakeUserHitOKToCapture ? 'T' : 'F');
   qDebug("Percent drop error  : %d%%", cp->wPercentDropForError);
   qDebug("Yield?              : %c"  , cp->fYield ? 'T' : 'F');
   qDebug("Index size          : %ld" , cp->dwIndexSize);
   qDebug("Chunk Granularity   : %d"  , cp->wChunkGranularity);
   qDebug("Using DOS memory?   : %c"  , cp->fUsingDOSMemory ? 'T': 'F');
   qDebug("Buffers requested   : %d"  , cp->wNumVideoRequested);
   qDebug("Capture Audio?      : %c"  , cp->fCaptureAudio ? 'T' : 'F');
   qDebug("Audio buffers       : %d"  , cp->wNumAudioRequested);
   qDebug("Abort key           :x%x"  , cp->vKeyAbort);
   qDebug("Abort left mouse?   : %c"  , cp->fAbortLeftMouse ? 'T' : 'F');
   qDebug("Abort right mouse?  : %c"  , cp->fAbortRightMouse ? 'T' : 'F');
   qDebug("Limit enabled?      : %c"  , cp->fLimitEnabled ? 'T' : 'F');
   qDebug("Time limit          : %d"  , cp->wTimeLimit);
   qDebug("MCI Controlled?     : %c"  , cp->fMCIControl ? 'T' : 'F');
   qDebug("Step MCI device?    : %c"  , cp->fStepMCIDevice ? 'T' : 'F');
   qDebug("MCI start time      : %ld" , cp->dwMCIStartTime);
   qDebug("MCI stop time       : %ld" , cp->dwMCIStopTime);
   qDebug("Double resolution?  : %c"  , cp->fStepCaptureAt2x ? 'T' : 'F');
   qDebug("Average capture step: %d"  , cp->wStepCaptureAverageFrames);
   qDebug("Audio buffer size   : %ld" , cp->dwAudioBufferSize);
   qDebug("Disable write cache?: %c"  , cp->fDisableWriteCache ? 'T' : 'F');
   qDebug("Stream Master       : %d"  , cp->AVStreamMaster);
}

void CVideoDeviceWin32::DumpCaptureStatus(const CAPSTATUS *cs) const
{
   qDebug("CVideoDeviceWin32::DumpCaptureStatus(%p)", cs);
   if (cs == 0)
     cs = &m_CaptureStatus;
   qDebug("Image  width        : %d"  , cs->uiImageWidth);
   qDebug("Image height        : %d"  , cs->uiImageHeight);
   qDebug("Live window?        : %c"  , cs->fLiveWindow ? 'T' : 'F');
   qDebug("Overlay window?     : %c"  , cs->fOverlayWindow ? 'T' : 'F');
   qDebug("Scaled?             : %c"  , cs->fScale ? 'T' : 'F');
   qDebug("Scroll              : (%d,%d)", cs->ptScroll.x, cs->ptScroll.y);
   qDebug("Using def. palette? : %c"  , cs->fUsingDefaultPalette ? 'T' : 'F');
   qDebug("Audio hardware?     : %c"  , cs->fAudioHardware ? 'T' : 'F');
   qDebug("Capture file exists?: %c"  , cs->fCapFileExists ? 'T' : 'F');
   qDebug("Current video frame : %ld" , cs->dwCurrentVideoFrame);
   qDebug("Video frames dropped: %ld" , cs->dwCurrentVideoFramesDropped);
   qDebug("Current wave samples: %ld" , cs->dwCurrentWaveSamples);
   qDebug("Time elapsed (ms)   : %ld" , cs->dwCurrentTimeElapsedMS); 
   qDebug("Capturing now       : %c"  , cs->fCapturingNow ? 'T' : 'F');
   qDebug("# video buffers     : %d"  , cs->wNumVideoAllocated);
   qDebug("# audio buffers     : %d"  , cs->wNumAudioAllocated);
}

// private slots

// protected

bool CVideoDeviceWin32::Init()
{
   bool ret = false;

   qDebug(">> CVideoDeviceWin32::Init()");
   m_Palette = 0;
   // Open handle in an invisible window
   m_CapHandle = capCreateCaptureWindow((LPTSTR)TEXT("Capture Window"),
#if 1
                                        0,
                                        0, 0, 160, 120,
#else
                                        WS_BORDER | WS_VISIBLE,
                                        0, 0, 320, 240,
#endif
                                        (HWND) 0, 0);

   if (!m_CapHandle) {
     qWarning("Could not create capwindow handle.");
   }
   else {
     // Connect to capture device
     if (capDriverConnect(m_CapHandle, m_CapIndex)) {
       // Register; this will make sure we are being callbacked (if you will excuse the grammar...)
       CVideoCollector::Instance()->RegisterDevice(m_CapHandle, this);
       ret = true;

       // Get the size of the video format structure & allocate memory
       m_BMISize = capGetVideoFormatSize(m_CapHandle);
       ASSERT(m_BMISize > 0);
       m_pBMIBuf = new uchar[m_BMISize];
       m_pVideoInfo = (BITMAPINFO *)m_pBMIBuf;

       // Get the actual format structure; It contains width, height, and
       // 'compression' info
       if (capGetVideoFormat(m_CapHandle, m_pBMIBuf, m_BMISize)) {
         qDebug("Got VideoFormat, struct size = %d", m_BMISize);
         DumpVideoFormat(m_pVideoInfo);
       }
       else
         qDebug("capGetVideoFormat failed.");

       // Get initial capture status
       capGetStatus(m_CapHandle, &m_CaptureStatus, sizeof(m_CaptureStatus));
       m_ImageSize.setWidth(m_CaptureStatus.uiImageWidth);
       m_ImageSize.setHeight(m_CaptureStatus.uiImageHeight);
     }
     else {
       qWarning("Failed to connect to capDriver %d", m_CapIndex);
       DestroyWindow(m_CapHandle);
       m_CapHandle = 0;
     }
   }
   qDebug("<< CVideoDeviceWin32::Init()");
   return ret;
}

/** 
  \brief Make device inactive
  
  This function is called when the device is no longer in use;
  it unregisters the device (eliminating callback), and destroys the 
  capture handle
*/
void CVideoDeviceWin32::Exit()
{
   qDebug(">> CVideoDeviceWin32::Exit()");
   if (m_CapHandle != 0) {
     CVideoCollector::Instance()->UnregisterDevice(m_CapHandle);
     if (!capDriverDisconnect(m_CapHandle))
       qWarning("Could not disconnect from handle?");
     DestroyWindow(m_CapHandle);
   }
   m_CapHandle = 0;

   delete [] m_pBMIBuf;
   m_pBMIBuf = 0;
   m_pVideoInfo = 0;
   m_BMISize = 0;

   m_Palette = 0;
   m_ImageSize.setWidth(-1);
   m_ImageSize.setHeight(-1);
   qDebug("<< CVideoDeviceWin32::Exit()");
}



bool CVideoDeviceWin32::StartCapture()
{
   bool ret = true;
   CAPTUREPARMS CP;

   if (m_CapHandle == 0)
     return false;

   qDebug(">> CVideoDeviceWin32::StartCapture()");
   memset(&CP, 0, sizeof(CP));

#if 0
qDebug("enabling Preview");
   if (!capPreviewRate(m_CapHandle, 200)) //200 ms = 5 fps
     qWarning("Could nog set preview rate. Hmmm.");
   if (!capPreview(m_CapHandle, true)) {
     qWarning("Failed to setup Preview.");
     ret = false;
   }
#endif

   // set 'video' mode
qDebug("Setting video mode");
   m_pVideoInfo->bmiHeader.biWidth = m_ImageSize.width();
   m_pVideoInfo->bmiHeader.biHeight = m_ImageSize.height(); /* A negative height means the image is straight up. Somebody please shoot me... */

   /* When asked for both YUV and RGB images, we prefer YUV to RGB. */
   if (m_PalYUV > 0) {
     ret = TryPalette(palI420)  || 
           TryPalette(palRGB32) ||
           TryPalette(palRGB24);
   }
   else if (m_PalRGB > 0) {
     ret = TryPalette(palRGB32) ||
           TryPalette(palRGB24) ||
           TryPalette(palI420);
   }
   else {
     // should not happen...
     qWarning("StartCapture but no palette requested???");
     return false;
   }

   if (!ret) {
     qWarning("Could not set video format. Bugger.");
   }

   // Get capture setup
   if (!capCaptureGetSetup(m_CapHandle, &CP, sizeof(CP)))
     qWarning("capCaptureGetSetup() failed!");
DumpCaptureParms(&CP);

   m_Buffers = CP.wNumVideoRequested;
   if (m_RequestedBuffers > 0 && m_Buffers > m_RequestedBuffers)
     m_Buffers = m_RequestedBuffers;

   // Set capture parameters
#if 1
//   CP.dwRequestMicroSecPerFrame = 200000; // 200 ms = 5 fps
//   CP.fMakeUserHitOKToCapture = false;
//   CP.wPercentDropForError = 10; // 10% framedrop allowed
   CP.fYield = true; // when true, re-entrant. 
//   CP.dwIndexSize = 0; // use default
//   CP.wChunkGranularity = 0;
//   CP.wNumVideoRequested = m_RequestedBuffers; // 
   CP.fCaptureAudio = false; // for now
   CP.vKeyAbort = 0;
   CP.fAbortLeftMouse = false;
   CP.fAbortRightMouse = false;
   CP.fLimitEnabled = false; // endless streaming...
   CP.wTimeLimit = 0; // seconds
qDebug("calling capCaptureSetSetup");
   if (!capCaptureSetSetup(m_CapHandle, &CP, sizeof(CP)))
     qWarning("capCaptureSetSetup() failed!");
#endif

   /* now that we know what palette we are going to get from the cam,
      create the actual image buffers before we start capturing 
      (race conditions....)
    */
   if (m_PalRGB > 0)
     CreateImagesRGB();    
   if (m_PalYUV > 0)
     CreateImagesYUV();
   CreateVideoFrames();
#if 1
   // CaptureSequenceNoFile() will cause a video stream without writing it to a file.
qDebug("calling capCaptureSequenceNoFile");
   if (!capCaptureSequenceNoFile(m_CapHandle))
     qWarning("capCaptureSequenceNoFile() failed!");
#endif

   UpdateCaptureStatus();
DumpCaptureStatus();

   start();
   qDebug("<< CVideoDeviceWin32::StartCapture()");
   return ret;
}

void CVideoDeviceWin32::StopCapture()
{
   qDebug(">> CVideoDeviceWin32::StopCapture()");
   if (m_CapHandle != 0) {
     capPreview(m_CapHandle, false);
     capCaptureStop(m_CapHandle);

     /* Clean up image buffers */
     DeleteVideoFrames();
     if (m_PalRGB == 0)
       DeleteImagesRGB();
     if (m_PalYUV == 0)
       DeleteImagesYUV();

     UpdateCaptureStatus();
   }
   if (running())
     m_Capturing.wakeAll();
   while (running())
      {};
   qDebug("<< CVideoDeviceWin32::StopCapture()");
}


/* Does nothing, really */

void CVideoDeviceWin32::run()
{
   qDebug(">> CVideoDeviceWin32::run()");
   m_Capturing.wait();
   qDebug("<< CVideoDeviceWin32::run()");
}

// public

long CVideoDeviceWin32::GetDescriptor() const
{
   return (long)m_CapHandle;
}

void CVideoDeviceWin32::Mute(bool on) const
{
   /* do nothing */
}
  


/* Various callback functions */

bool CVideoDeviceWin32::CallbackControl(int id)
{
   switch(id) {
     case CONTROLCALLBACK_PREROLL:
       qDebug("CallbackControl: Get ready to roll!");
       break;
     case CONTROLCALLBACK_CAPTURING:
       //qDebug("CallbackControl: Capturing...");
       break;
     default:
       qDebug("CallbackControl: unknown code %d", id);
       break;
   }
//qDebug("CaptureCount = %d", GetCaptureCount());
   return (GetCaptureCount() > 0);
}

bool CVideoDeviceWin32::CallbackError(int id, const QString &text)
{
qDebug("CallbackError(%d, \"%s\")", id, (const char *)text);
   return true;
}

bool CVideoDeviceWin32::CallbackStatus(int id, const QString &text)
{
   switch(id)
   {
     case 0:             qDebug("CallbackStatus: Reset"); break;
     case 502:           qDebug("CallbackStatus: Capture prepare"); break;
     case IDS_CAP_BEGIN: qDebug("CallbackStatus: Capture starts"); ;
     case IDS_CAP_END:   qDebug("CallbackStatus: Capture ends"); break;
     default:            qDebug("CallbackStatus(%d, \"%s\")", id, (const char *)text); break;
   }
   UpdateCaptureStatus();
   DumpCaptureStatus();
   return true;
}

bool CVideoDeviceWin32::CallbackVideoStream(VIDEOHDR *vh)
{
   uchar *dst = 0;
   const QImage *img = 0;
   CVideoFrame *frame = 0;

   m_FrameCount++;
#if 0
   if ((m_FrameCount % 10) == 0)
   {
qDebug("CallbackVideoStream(buffer = %p, len = %d, used = %d, time = %d, user = %d, flags = %d",
       vh->lpData, 
       vh->dwBufferLength, vh->dwBytesUsed, vh->dwTimeCaptured,
       vh->dwUser, vh->dwFlags);
   }
#endif
   if (!m_CaptureStatus.fCapturingNow)
     return false;
   
   frame = GetFillFrame(); 
   if (frame == 0) {
     m_FrameDropped++;
     return true;
   }

   img = frame->GetRGB();
   if (img != 0) {
     dst = img->bits();
     if (dst != 0) {
       switch(m_Palette)
       {
         case palI420:
           ccvt_420p_bgr32(m_ImageSize.width(), m_ImageSize.height(), vh->lpData, dst);
           emit FrameReady();
           break;

         case palRGB24:
           /* Negative height means image is upside down. Somebody please 
              shoot the person who is responsible for this.... *sigh* 
            */
           ccvt_bgr24_bgr32(m_ImageSize.width(), -m_ImageSize.height(), vh->lpData, dst);
           break;
       }
     }
   }
   ReturnFillFrame();
   SendSignal(frame_ready);
   return true;
}

bool CVideoDeviceWin32::CallbackYield()
{
qDebug("CallbackYield()");
   return true;
}



// public slosts

void CVideoDeviceWin32::ShowDisplayDialog()
{
   if (m_CapHandle && m_HasDisplayDialog) {
     capDlgVideoDisplay(m_CapHandle);
     UpdateCaptureStatus();
   }
}

void CVideoDeviceWin32::ShowFormatDialog()
{
   if (m_CapHandle && m_HasFormatDialog) {
     capDlgVideoFormat(m_CapHandle);
     UpdateCaptureStatus();
   }
}

void CVideoDeviceWin32::ShowSourceDialog()
{
   if (m_CapHandle && m_HasSourceDialog) {
     capDlgVideoSource(m_CapHandle);
     UpdateCaptureStatus();
   }
}