Changeset 8861 for trunk/MagicSoft/Cosy/videodev
- Timestamp:
- 02/12/08 16:01:56 (17 years ago)
- Location:
- trunk/MagicSoft/Cosy/videodev
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/videodev/MVideo.cc
r8859 r8861 45 45 #include <sys/ioctl.h> // ioctl 46 46 47 #include <TEnv.h> 47 48 #include <TString.h> 48 49 … … 50 51 #include "MLogManip.h" 51 52 53 #undef DEBUG 54 52 55 using namespace std; 53 56 54 57 //ClassImp(MVideo); 55 58 59 MVideoCtrl::MVideoCtrl(const v4l2_queryctrl &ctrl) 60 { 61 fId = ctrl.id; 62 fName = (const char*)ctrl.name; 63 fMinimum = ctrl.minimum; 64 fMaximum = ctrl.maximum; 65 fStep = ctrl.step; 66 fDefault = ctrl.default_value; 67 } 68 56 69 // ------------------------------------------------------------- 57 70 // … … 61 74 { 62 75 Reset(); 76 77 fControls.SetOwner(); 63 78 } 64 79 … … 72 87 memset(&fChannel, 0, sizeof(fChannel)); 73 88 memset(&fBuffer, 0, sizeof(fBuffer)); 89 memset(&fAbil, 0, sizeof(fAbil)); 74 90 75 91 fFileDesc = -1; 76 92 fMapBuffer = 0; 77 93 fChannel.channel = -1; 94 fAbil.tuner = -1; 95 96 fControls.Delete(); 78 97 } 79 98 … … 137 156 // ------------------------------------------------------------- 138 157 // 158 // Read the video standard 159 // 160 Bool_t MVideo::GetVideoStandard() 161 { 162 return Ioctl(VIDIOC_G_STD, &fVideoStandard)==-1; 163 } 164 165 // ------------------------------------------------------------- 166 // 167 // Read the abilities of the tuner 168 // 169 Bool_t MVideo::GetTunerAbilities() 170 { 171 fAbil.tuner = 0; // FIXME? 172 return Ioctl(VIDIOCGTUNER, &fAbil)!=-1; 173 } 174 175 // ------------------------------------------------------------- 176 // 177 // Enumerate (get) all controls from the device and store them 178 // as MVideoCtrl in fControls, starting with the id given as 179 // argument. 180 // 181 Bool_t MVideo::EnumerateControls(UInt_t id) 182 { 183 struct v4l2_queryctrl qctrl; 184 qctrl.id = id; 185 186 while (1) 187 { 188 if (Ioctl (VIDIOC_QUERYCTRL, &qctrl)==-1) 189 break; 190 191 if (qctrl.maximum<=qctrl.minimum) 192 continue; 193 194 fControls.Add(new MVideoCtrl(qctrl)); 195 196 qctrl.id++; 197 } 198 199 return kTRUE; 200 } 201 202 // ------------------------------------------------------------- 203 // 204 // Enumerate (get) all basic and private controls from the 205 // device and store them as MVideoCtrl in fControls. 206 // 207 Bool_t MVideo::EnumerateControls() 208 { 209 if (!EnumerateControls(V4L2_CID_BASE)) 210 return kFALSE; 211 if (!EnumerateControls(V4L2_CID_PRIVATE_BASE)) 212 return kFALSE; 213 214 return kTRUE; 215 } 216 217 // ------------------------------------------------------------- 218 // 219 // Reset a given control to it's default value as defined 220 // by the device. 221 // 222 Bool_t MVideo::ResetControl(MVideoCtrl &vctrl) const 223 { 224 return WriteControl(vctrl, vctrl.fDefault); 225 } 226 227 // ------------------------------------------------------------- 228 // 229 // Reset all enumereated device controls to their default. 230 // The default is defined by the device iteself. 231 // 232 Bool_t MVideo::ResetControls() const 233 { 234 Bool_t rc = kTRUE; 235 236 TIter Next(&fControls); 237 MVideoCtrl *ctrl = 0; 238 while ((ctrl=((MVideoCtrl*)Next()))) 239 if (!ResetControl(*ctrl)) 240 { 241 gLog << err << "ERROR - Could not reset " << ctrl->fName << "." << endl; 242 rc = kFALSE; 243 } 244 245 return rc; 246 } 247 248 // ------------------------------------------------------------- 249 // 250 // Read the value of the given control from the device 251 // and store it back into the given MVideoCtrl. 252 // 253 Bool_t MVideo::ReadControl(MVideoCtrl &vctrl) const 254 { 255 struct v4l2_control ctrl = { vctrl.fId, 0 }; 256 if (Ioctl(VIDIOC_G_CTRL, &ctrl)==-1) 257 return kFALSE; 258 259 vctrl.fValue = ctrl.value; 260 261 return kTRUE; 262 } 263 264 // ------------------------------------------------------------- 265 // 266 // Write the given value into the given control of the device. 267 // On success the value is stored in the given MVideoCtrl. 268 // 269 Bool_t MVideo::WriteControl(MVideoCtrl &vctrl, Int_t val) const 270 { 271 if (val<vctrl.fMinimum) 272 { 273 gLog << err << "ERROR - Value of " << val << " below minimum of " << vctrl.fMinimum << " for " << vctrl.fName << endl; 274 return kFALSE; 275 } 276 277 if (val>vctrl.fMaximum) 278 { 279 gLog << err << "ERROR - Value of " << val << " above maximum of " << vctrl.fMaximum << " for " << vctrl.fName << endl; 280 return kFALSE; 281 } 282 283 struct v4l2_control ctrl = { vctrl.fId, val }; 284 if (Ioctl(VIDIOC_S_CTRL, &ctrl)==-1) 285 return kFALSE; 286 287 vctrl.fValue = val; 288 289 return kTRUE; 290 } 291 292 // ------------------------------------------------------------- 293 // 294 // Set all controls from a TEnv. Note that all whitespaces 295 // and colons in the control names (as defined by the name of 296 // the MVideoCtrls stored in fControls) are replaced by 297 // underscores. 298 // 299 Bool_t MVideo::SetControls(TEnv &env) const 300 { 301 Bool_t rc = kTRUE; 302 303 TIter Next(&fControls); 304 TObject *o = 0; 305 while ((o=Next())) 306 { 307 if (!env.Defined(o->GetName())) 308 continue; 309 310 TString str = env.GetValue(o->GetName(), ""); 311 str = str.Strip(TString::kBoth); 312 str.ReplaceAll(" ", "_"); 313 str.ReplaceAll(":", "_"); 314 if (str.IsNull()) 315 continue; 316 317 MVideoCtrl &ctrl = *static_cast<MVideoCtrl*>(o); 318 319 const Int_t val = str=="default" || str=="def" ? 320 ctrl.fDefault : env.GetValue(o->GetName(), 0); 321 322 if (!WriteControl(ctrl, val)) 323 rc = kFALSE; 324 } 325 326 return rc; 327 } 328 329 330 // ------------------------------------------------------------- 331 // 139 332 // Open channel ch of the device 140 333 // … … 184 377 } 185 378 379 gLog << warn << "Setting video standard to PAL-N." << endl; 380 381 fVideoStandard = V4L2_STD_PAL_N; 382 if (Ioctl(VIDIOC_S_STD, &fVideoStandard)==-1) 383 { 384 gLog << err << "ERROR - Could not set video standard to PAL-N." << endl; 385 return kFALSE; 386 } 387 388 if (!EnumerateControls()) 389 { 390 gLog << err << "ERROR - Could not enumerate controls." << endl; 391 return kFALSE; 392 } 393 394 if (!ResetControls()) 395 { 396 gLog << err << "ERROR - Could not reset controls to default." << endl; 397 return kFALSE; 398 } 399 186 400 if (!GetCapabilities()) 187 401 { … … 198 412 return kFALSE; 199 413 } 200 414 /* 415 if (HasTuner()) 416 { 417 if (!GetTunerAbilities()) 418 { 419 gLog << err << "ERROR - Couldn't get tuner abilities." << endl; 420 return kFALSE; 421 } 422 } 423 */ 201 424 // get mmap grab buffer info 202 425 if (Ioctl(VIDIOCGMBUF, &fBuffer)==-1) … … 207 430 208 431 // map file (device) into memory 209 fMapBuffer = ( char*)mmap(0, fBuffer.size, PROT_READ|PROT_WRITE, MAP_SHARED, fFileDesc, 0);432 fMapBuffer = (unsigned char*)mmap(0, fBuffer.size, PROT_READ|PROT_WRITE, MAP_SHARED, fFileDesc, 0); 210 433 if (fMapBuffer == (void*)-1) 211 434 { … … 258 481 Bool_t MVideo::CaptureStart(unsigned int frame) const 259 482 { 483 frame %= fBuffer.frames; 484 260 485 struct video_mmap gb = 261 486 { 262 frame %fBuffer.frames,// frame487 frame, // frame 263 488 fCaps.maxheight, fCaps.maxwidth, // height, width 264 VIDEO_PALETTE_RGB24 489 VIDEO_PALETTE_RGB24 // palette 265 490 }; 491 492 #ifdef DEBUG 493 gLog << dbg << "CapturStart(" << frame << ")" << endl; 494 #endif 266 495 267 496 // … … 273 502 // if (errno == EAGAIN) 274 503 gLog << err; 275 gLog << "ERROR - Couldn't start capturing frame " << frame << " - unable to sync." << endl;504 gLog << "ERROR - Couldn't start capturing frame " << frame << "." << endl; 276 505 gLog << " Maybe your card doesn't support VIDEO_PALETTE_RGB24." << endl; 277 506 … … 283 512 // Wait until hardware has finished capture into framebuffer frame 284 513 // 285 Int_t MVideo::CaptureWait(unsigned int frame, char **ptr) const514 Int_t MVideo::CaptureWait(unsigned int frame, unsigned char **ptr) const 286 515 { 287 516 frame %= fBuffer.frames; 288 517 289 *ptr = NULL; 518 if (ptr) 519 *ptr = NULL; 290 520 291 521 const int SYNC_TIMEOUT = 1; 522 523 #ifdef DEBUG 524 gLog << dbg << "CaptureWait(" << frame << ")" << endl; 525 #endif 292 526 293 527 alarm(SYNC_TIMEOUT); … … 302 536 if (rc==-1) 303 537 { 304 gLog << err << "ERROR - Waiting for captured frame failed." << endl; 305 return kFALSE; 306 } 307 308 *ptr = fMapBuffer+fBuffer.offsets[frame]; 538 gLog << err << "ERROR - Waiting for " << frame << " frame failed." << endl; 539 return kFALSE; 540 } 541 542 if (ptr) 543 *ptr = fMapBuffer+fBuffer.offsets[frame]; 309 544 310 545 return kTRUE; … … 315 550 // Change the channel of a priviously opened device 316 551 // 317 Bool_t MVideo::SetChannel(Int_t chan)552 Int_t MVideo::SetChannel(Int_t chan) 318 553 { 319 554 if (fChannel.channel==chan) 320 return k TRUE;555 return kSKIP; 321 556 322 557 if (chan<0 || chan>=fCaps.channels) … … 360 595 // ------------------------------------------------------------- 361 596 // 597 // Has a tuner 598 // 599 Bool_t MVideo::HasTuner() const 600 { 601 return fCaps.type&VID_TYPE_TUNER; 602 } 603 604 // ------------------------------------------------------------- 605 // 362 606 // Returns the number of frame buffers which can be used 363 607 // … … 394 638 if (CanCapture()) 395 639 rc += " capture"; 396 if ( type&VID_TYPE_TUNER)640 if (HasTuner()) 397 641 rc += " tuner"; 398 642 if (type&VID_TYPE_TELETEXT) … … 415 659 } 416 660 661 TString MVideo::GetTunerFlags(Int_t flags) const 662 { 663 TString rc; 664 if (flags&VIDEO_TUNER_PAL) 665 rc += " PAL"; 666 if (flags&VIDEO_TUNER_NTSC) 667 rc += " NTSC"; 668 if (flags&VIDEO_TUNER_SECAM) 669 rc += " SECAM"; 670 if (flags&VIDEO_TUNER_LOW) 671 rc += " kHz"; 672 if (flags&VIDEO_TUNER_NORM) 673 rc += " CanSetNorm"; 674 if (flags&VIDEO_TUNER_STEREO_ON) 675 rc += " StereoOn"; 676 return rc; 677 } 678 679 TString MVideo::GetTunerMode(Int_t mode) const 680 { 681 switch (mode) 682 { 683 case VIDEO_MODE_PAL: 684 return "PAL"; 685 case VIDEO_MODE_NTSC: 686 return "NTSC"; 687 case VIDEO_MODE_SECAM: 688 return "SECAM"; 689 case VIDEO_MODE_AUTO: 690 return "AUTO"; 691 } 692 return "undefined"; 693 } 694 417 695 // ------------------------------------------------------------- 418 696 // … … 426 704 if (flags&VIDEO_VC_AUDIO) 427 705 rc += " audio"; 706 // if (flags&VIDEO_VC_NORM) 707 // rc += " normsetting"; 428 708 return rc; 429 709 } … … 438 718 return "TV"; 439 719 if (type&VIDEO_TYPE_CAMERA) 440 return " camera";720 return "Camera"; 441 721 return "unknown"; 442 722 } … … 448 728 TString MVideo::GetPalette(Int_t pal) const 449 729 { 450 if (pal&VIDEO_PALETTE_GREY) 451 return "Linear intensity grey scale"; 452 if (pal&VIDEO_PALETTE_HI240) 453 return "BT848 8-bit color cube"; 454 if (pal&VIDEO_PALETTE_RGB565) 455 return "RGB565 packed into 16-bit words"; 456 if (pal&VIDEO_PALETTE_RGB555) 457 return "RGB555 packed into 16-bit words, top bit undefined"; 458 if (pal&VIDEO_PALETTE_RGB24) 459 return "RGB888 packed into 24-bit words"; 460 if (pal&VIDEO_PALETTE_RGB32) 461 return "RGB888 packed into the low three bytes of 32-bit words. Top bits undefined."; 462 if (pal&VIDEO_PALETTE_YUV422) 463 return "Video style YUV422 - 8-bit packed, 4-bit Y, 2-bits U, 2-bits V"; 464 if (pal&VIDEO_PALETTE_YUYV) 465 return "YUYV"; 466 if (pal&VIDEO_PALETTE_UYVY) 467 return "UYVY"; 468 if (pal&VIDEO_PALETTE_YUV420) 469 return "YUV420"; 470 if (pal&VIDEO_PALETTE_YUV411) 471 return "YUV411"; 472 if (pal&VIDEO_PALETTE_RAW) 473 return "Raw capture (Bt848)"; 474 if (pal&VIDEO_PALETTE_YUV422P) 475 return "YUV 4:2:2 planar"; 476 if (pal&VIDEO_PALETTE_YUV411P) 477 return "YUV 4:1:1 planar"; 478 730 switch (pal) 731 { 732 case VIDEO_PALETTE_GREY: 733 return "VIDEO_PALETTE_GREY: Linear intensity grey scale"; 734 case VIDEO_PALETTE_HI240: 735 return "VIDEO_PALETTE_HI240: BT848 8-bit color cube"; 736 case VIDEO_PALETTE_RGB565: 737 return "VIDEO_PALETTE_RGB565: RGB565 packed into 16-bit words"; 738 case VIDEO_PALETTE_RGB555: 739 return "VIDEO_PALETTE_RGB555: RGB555 packed into 16-bit words, top bit undefined"; 740 case VIDEO_PALETTE_RGB24: 741 return "VIDEO_PALETTE_RGB24: RGB888 packed into 24-bit words"; 742 case VIDEO_PALETTE_RGB32: 743 return "VIDEO_PALETTE_RGB32: RGB888 packed into the low three bytes of 32-bit words. Top bits undefined."; 744 case VIDEO_PALETTE_YUV422: 745 return "VIDEO_PALETTE_YUV422: Video style YUV422 - 8-bit packed, 4-bit Y, 2-bits U, 2-bits V"; 746 case VIDEO_PALETTE_YUYV: 747 return "VIDEO_PALETTE_YUYV: YUYV"; 748 case VIDEO_PALETTE_UYVY: 749 return "VIDEO_PALETTE_UYVY: UYVY"; 750 case VIDEO_PALETTE_YUV420: 751 return "VIDEO_PALETTE_YUV420: YUV420"; 752 case VIDEO_PALETTE_YUV411: 753 return "VIDEO_PALETTE_YUV411: YUV411"; 754 case VIDEO_PALETTE_RAW: 755 return "VIDEO_PALETTE_RAW: Raw capture (Bt848)"; 756 case VIDEO_PALETTE_YUV422P: 757 return "VIDEO_PALETTE_YUV422P: YUV 4:2:2 planar"; 758 case VIDEO_PALETTE_YUV411P: 759 return "VIDEO_PALETTE_YUV411P: YUV 4:1:1 planar"; 760 } 479 761 return "unknown"; 480 762 } … … 505 787 { 506 788 gLog << " - Channel: " << fChannel.channel << " (" << fChannel.name << ")" << endl; 507 gLog << " - IsA: " << GetChannelType(fChannel.type) << " with " << GetChannelFlags(fChannel.flags) << endl;789 gLog << " - IsA: " << GetChannelType(fChannel.type) << " with " << GetChannelFlags(fChannel.flags) << " (" << fChannel.flags << ")" << endl; 508 790 //if (fChannel.flags&VIDEO_VC_NORM) 509 791 gLog << " - Norm: " << fChannel.norm << endl; 510 792 gLog << endl; 511 793 } 794 795 if (fAbil.tuner>=0) 796 { 797 gLog << " - Tuner: " << fAbil.tuner << endl; 798 gLog << " - Name: " << fAbil.name << endl; 799 gLog << " - Tuner Range: " << fAbil.rangelow << " - " << fAbil.rangehigh << endl; 800 gLog << " - Tuner flags: " << GetTunerFlags(fAbil.flags) << " (" << fAbil.flags << ")" << endl; 801 gLog << " - Tuner mode: " << GetTunerMode(fAbil.mode) << " (" << fAbil.mode << ")" <<endl; 802 gLog << " - Signal Strength: " << fAbil.signal << endl; 803 } 804 512 805 gLog << " - Brightness: " << fProp.brightness << endl; 513 806 gLog << " - Hue: " << fProp.hue << endl; … … 524 817 gLog << " 0x" << fBuffer.offsets[i]; 525 818 gLog << dec << endl; 819 820 gLog << "Controls:" << endl; 821 fControls.Print(); 526 822 } 527 823 -
trunk/MagicSoft/Cosy/videodev/MVideo.h
r8845 r8861 8 8 #ifndef __CINT__ 9 9 #ifndef __LINUX_VIDEODEV_H 10 #include "videodev.h" // video4linux 10 #include <linux/videodev.h> // video4linux 11 #endif 12 #ifndef __LINUX_VIDEODEV2_H 13 #include <linux/videodev2.h> // video4linux2 11 14 #endif 12 15 #endif 16 17 struct v4l2_queryctrl; 18 class TEnv; 19 20 class MVideoCtrl : public TObject 21 { 22 friend class MVideo; 23 private: 24 UInt_t fId; 25 //enum v4l2_ctrl_type type; 26 TString fName; 27 Int_t fMinimum; 28 Int_t fMaximum; 29 Int_t fStep; 30 Int_t fDefault; 31 UInt_t fFlags; 32 33 UInt_t fValue; 34 35 public: 36 MVideoCtrl(const v4l2_queryctrl &ctrl); 37 const char *GetName() const { return fName; } 38 const char *GetTitle() const { return Form("Range=[%d;%d] Step=%d Def=%d", fMinimum, fMaximum, fStep, fDefault); } 39 40 //ClassDef(MVideoCtrl, 0) // Helper class to enumare device controls 41 }; 13 42 14 43 class MVideo … … 19 48 int fFileDesc; // File descriptor 20 49 21 char *fMapBuffer;50 unsigned char *fMapBuffer; 22 51 23 52 protected: … … 26 55 struct video_mbuf fBuffer; // Buffer information 27 56 struct video_picture fProp; // Picture properties 57 struct video_tuner fAbil; // Tuner abilities 58 59 ULong64_t fVideoStandard; 60 61 TList fControls; 28 62 29 63 private: … … 32 66 void Reset(); 33 67 68 Bool_t EnumerateControls(UInt_t id); 69 Bool_t EnumerateControls(); 34 70 Bool_t GetCapabilities(); 35 71 Bool_t GetProperties(); 72 Bool_t GetTunerAbilities(); 73 Bool_t GetVideoStandard(); 36 74 Bool_t Init(Int_t channel); 37 75 … … 40 78 TString GetChannelFlags(Int_t flags) const; 41 79 TString GetChannelType(Int_t type) const; 80 TString GetTunerFlags(Int_t type) const; 81 TString GetTunerMode(Int_t type) const; 42 82 TString GetPalette(Int_t pal) const; 43 83 … … 49 89 Bool_t IsOpen() const { return fFileDesc>0 && fMapBuffer; } 50 90 Bool_t CanCapture() const; 91 Bool_t HasTuner() const; 51 92 Int_t GetNumBuffers() const; 52 93 … … 58 99 Int_t Close(); 59 100 60 Bool_t SetChannel(Int_t chan); 101 Int_t SetChannel(Int_t chan); 102 Bool_t ReadControl(MVideoCtrl &vctrl) const; 103 Bool_t WriteControl(MVideoCtrl &vctrl, Int_t val) const; 104 Bool_t SetControls(TEnv &env) const; 105 Bool_t ResetControl(MVideoCtrl &vctrl) const; 106 Bool_t ResetControls() const; 61 107 62 108 // Image capture 63 109 Bool_t CaptureStart(unsigned int frame) const; 64 Int_t CaptureWait(unsigned int frame, char **ptr) const;110 Int_t CaptureWait(unsigned int frame, unsigned char **ptr=0) const; 65 111 66 112 // Support
Note:
See TracChangeset
for help on using the changeset viewer.