40 #include <sys/types.h> 47 #include <sys/ioctl.h> 53 #include "MLogManip.h" 64 fName = (
const char*)ctrl.name;
65 fMinimum = ctrl.minimum;
66 fMaximum = ctrl.maximum;
68 fDefault = ctrl.default_value;
112 gLog << err <<
"ERROR - Ioctl: Device " <<
fPath <<
" not open." << endl;
119 const int rc = ioctl(
fFileDesc, req, opt);
126 if (!allowirq && errno==EAGAIN)
129 cout <<
"errno="<< errno << endl;
133 if (errno==4 || errno==16)
135 if (!allowirq && errno==4)
138 gLog << err <<
"ERROR - MVideo::Ioctl 0x" << hex << req <<
": errno=" << dec << errno <<
" - ";
139 gLog << strerror(errno) <<
" (rc=" << rc <<
")" << endl;
146 gLog << err <<
"ERROR - MVideo::Ioctl 0x" << hex << req <<
": errno=" << dec << errno <<
" - ";
147 gLog << strerror(errno) <<
" (rc=" << rc <<
")" << endl;
199 struct v4l2_queryctrl qctrl;
200 memset(&qctrl, 0,
sizeof(qctrl));
205 if (
Ioctl(VIDIOC_QUERYCTRL, &qctrl,
true,
true)==-1)
208 if (qctrl.maximum<=qctrl.minimum)
258 gLog << err <<
"ERROR - Could not reset " << ctrl->
fName <<
"." << endl;
272 struct v4l2_control ctrl = { vctrl.
fId, 0 };
273 if (
Ioctl(VIDIOC_G_CTRL, &ctrl)==-1)
276 vctrl.
fValue = ctrl.value;
290 gLog << err <<
"ERROR - Value of " << val <<
" below minimum of " << vctrl.
fMinimum <<
" for " << vctrl.
fName << endl;
296 gLog << err <<
"ERROR - Value of " << val <<
" above maximum of " << vctrl.
fMaximum <<
" for " << vctrl.
fName << endl;
300 struct v4l2_control ctrl = { vctrl.
fId, val };
301 if (
Ioctl(VIDIOC_S_CTRL, &ctrl)==-1)
324 if (!env.Defined(o->GetName()))
327 TString
str = env.GetValue(o->GetName(),
"");
328 str = str.Strip(TString::kBoth);
329 str.ReplaceAll(
" ",
"_");
330 str.ReplaceAll(
":",
"_");
336 const Int_t val = str==
"default" || str==
"def" ?
337 ctrl.
fDefault : env.GetValue(o->GetName(), 0);
354 const int rc =
Ioctl(request, &input);
360 vec.push_back(input);
369 for (vector<v4l2_input>::const_iterator it=
fInputs.begin(); it!=
fInputs.end(); it++)
371 gLog <<
"Input #" << it->index << endl;
372 gLog <<
" - " << it->name << endl;
373 gLog <<
" - " << (it->type==V4L2_INPUT_TYPE_CAMERA?
"Camera":
"Tuner") << endl;
374 gLog <<
" - TV Standard: " << hex << it->std << dec << endl;
376 gLog <<
" - Status: 0x" << hex << it->status;
377 if (it->status&V4L2_IN_ST_NO_POWER)
379 if (it->status&V4L2_IN_ST_NO_SIGNAL)
381 if (it->status&V4L2_IN_ST_NO_COLOR)
383 if (it->status&V4L2_IN_ST_NO_H_LOCK)
385 if (it->status&V4L2_IN_ST_COLOR_KILL)
386 gLog <<
" ColorKill";
475 gLog <<
"Index #" << it->index << endl;
476 gLog <<
" - TV Standard: " << it->name << hex <<
"(" << it->id <<
")" << dec << endl;
477 gLog <<
" - FPS: " << it->frameperiod.numerator <<
"/" << it->frameperiod.denominator << endl;
478 gLog <<
" - Lines: " << it->framelines << endl;
488 const Bool_t rc =
Init(ch);
504 gLog << warn <<
"WARNING - Device " <<
fPath <<
" already open." << endl;
508 gLog << all <<
"Opening " <<
fPath <<
"... " << flush;
518 gLog << err <<
"ERROR: " << strerror(errno) << endl;
525 if (fcntl(
fFileDesc, F_SETFD, FD_CLOEXEC)<0)
527 gLog << err <<
"ERROR - Call to fnctl (F_SETFD, FD_CLOEXEC) failed." << endl;
550 if (
Ioctl(VIDIOC_S_INPUT, &index)==-1)
552 gLog << err <<
"ERROR - Could not set input." << endl;
557 if (
Ioctl(VIDIOC_G_INPUT, &index))
559 gLog << err <<
"ERROR - Could not get input." << endl;
564 memset(&input, 0,
sizeof (input));
566 if (
Ioctl(VIDIOC_ENUMINPUT, &input))
568 gLog << err <<
"ERROR - Could enum input." << endl;
571 gLog <<
"*** Input: " << input.name <<
" (" << input.index <<
")" << endl;
574 if (
Ioctl (VIDIOC_S_STD, &st))
576 gLog << err <<
"ERROR - Could not set standard." << endl;
581 if (
Ioctl(VIDIOC_QUERYCAP, &cap))
583 gLog << err <<
"ERROR - Could not get capabilities." << endl;
587 if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
589 gLog << err <<
"ERROR - No capture capabaility." << endl;
593 v4l2_cropcap cropcap;
594 cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
596 if (
Ioctl(VIDIOC_CROPCAP, &cropcap)==-1)
601 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
602 crop.c = cropcap.defrect;
604 if (
Ioctl(VIDIOC_S_CROP, &crop))
606 gLog << err <<
"Could not reset cropping." << endl;
611 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
612 fmt.fmt.pix.width = 768;
613 fmt.fmt.pix.height = 576;
614 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
616 if (
Ioctl(VIDIOC_S_FMT, &fmt)==-1)
618 gLog << err <<
"ERROR - Could not set format." << endl;
625 v4l2_requestbuffers reqbuf;
626 memset (&reqbuf, 0,
sizeof (reqbuf));
628 reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
629 reqbuf.memory = V4L2_MEMORY_MMAP;
632 if (
Ioctl(VIDIOC_REQBUFS, &reqbuf)==-1)
634 gLog << err <<
"ERROR - Couldn't setup frame buffers." << endl;
638 gLog << all <<
"Allocated " << reqbuf.count <<
" frame buffers." << endl;
640 for (
unsigned int i=0;
i<reqbuf.count;
i++)
643 memset (&buffer, 0,
sizeof (buffer));
645 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
646 buffer.memory = V4L2_MEMORY_MMAP;
649 if (
Ioctl(VIDIOC_QUERYBUF, &buffer))
651 gLog << err <<
"ERROR - Request of frame buffer " <<
i <<
" failed." << endl;
655 void *ptr = mmap(NULL, buffer.length,
656 PROT_READ | PROT_WRITE,
660 if (MAP_FAILED == ptr)
663 gLog << err <<
"ERROR - Could not allocate shared memory." << endl;
671 fBuffers.push_back(make_pair(buffer, ptr));
679 v4l2_buf_type
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
680 if (
Ioctl(VIDIOC_STREAMON, &type)==-1)
682 gLog << err <<
"ERROR - Couldn't start capturing." << endl;
686 cout <<
"*** Stream on" << endl;
713 gLog << err <<
"ERROR!" << endl;
718 gLog <<
"done." << endl;
721 for (vector<pair<v4l2_buffer,void*> >::iterator it=
fBuffers.begin(); it!=
fBuffers.end(); it++)
723 munmap(it->second, it->first.length);
744 gLog << err <<
"ERROR - Couldn't buffer " << frame <<
"." << endl;
796 const Int_t rc =
Ioctl(VIDIOC_DQBUF, const_cast<v4l2_buffer*>(&
fBuffers[frame].
first),
false);
806 gLog << err <<
"ERROR - Waiting for " << frame <<
" frame failed." << endl;
811 *ptr =
static_cast<unsigned char*
>(
fBuffers[frame].second);
829 gLog << err <<
"ERROR - Set channel " << chan <<
" out of range." << endl;
837 gLog << err <<
"ERROR - Couldn't switch to channel " << chan <<
"." << endl;
838 gLog <<
" You might need a bttv version > 0.5.13" << endl;
845 gLog << err <<
"ERROR - Getting information for channel " << chan <<
" failed." << endl;
851 gLog << all <<
"Switched to channel " << chan << endl;
927 rc +=
" subcapature";
971 TString rc =
"video";
1003 return "VIDEO_PALETTE_GREY: Linear intensity grey scale";
1005 return "VIDEO_PALETTE_HI240: BT848 8-bit color cube";
1007 return "VIDEO_PALETTE_RGB565: RGB565 packed into 16-bit words";
1009 return "VIDEO_PALETTE_RGB555: RGB555 packed into 16-bit words, top bit undefined";
1011 return "VIDEO_PALETTE_RGB24: RGB888 packed into 24-bit words";
1013 return "VIDEO_PALETTE_RGB32: RGB888 packed into the low three bytes of 32-bit words. Top bits undefined.";
1015 return "VIDEO_PALETTE_YUV422: Video style YUV422 - 8-bit packed, 4-bit Y, 2-bits U, 2-bits V";
1017 return "VIDEO_PALETTE_YUYV: YUYV";
1019 return "VIDEO_PALETTE_UYVY: UYVY";
1021 return "VIDEO_PALETTE_YUV420: YUV420";
1023 return "VIDEO_PALETTE_YUV411: YUV411";
1025 return "VIDEO_PALETTE_RAW: Raw capture (Bt848)";
1027 return "VIDEO_PALETTE_YUV422P: YUV 4:2:2 planar";
1029 return "VIDEO_PALETTE_YUV411P: YUV 4:1:1 planar";
1052 gLog <<
" - Size: ";
1090 gLog << inf2 <<
"Controls:" << endl;
#define VIDEO_PALETTE_YUYV
#define VIDEO_PALETTE_UYVY
struct video_picture fProp
#define VID_TYPE_SUBCAPTURE
Bool_t ResetControl(MVideoCtrl &vctrl) const
#define VIDEO_PALETTE_YUV420
#define VIDEO_PALETTE_RAW
std::vector< v4l2_standard > fStandards
#define VIDEO_PALETTE_HI240
void PrintStandards() const
int Ioctl(int req, void *opt, bool allowirq=true, bool force=false) const
#define VID_TYPE_TELETEXT
#define VIDEO_PALETTE_YUV422P
Bool_t Open(Int_t channel=0)
int64_t first
Size of this column in the tile.
struct video_capability fCaps
#define VID_TYPE_FRAMERAM
#define VID_TYPE_CHROMAKEY
Bool_t ResetControls() const
TString GetDevType(int type) const
TString GetPalette(Int_t pal) const
Bool_t GetTunerAbilities()
#define VIDEO_TUNER_STEREO_ON
TString GetTunerMode(Int_t type) const
#define VID_TYPE_CLIPPING
Int_t CaptureWait(unsigned int frame, unsigned char **ptr=0) const
TString GetChannelFlags(Int_t flags) const
Bool_t EnumerateControls()
Bool_t GetVideoStandard()
Int_t GetNumBuffers() const
#define VID_TYPE_MONOCHROME
Bool_t CanCapture() const
TString GetTunerFlags(Int_t type) const
struct video_channel fChannel
Bool_t CaptureStart(unsigned int frame) const
Bool_t Enumerate(std::vector< S > &s, int request)
#define VIDEO_PALETTE_RGB24
#define VIDEO_PALETTE_GREY
#define VIDEO_PALETTE_YUV411P
Int_t SetChannel(Int_t chan)
Bool_t ReadControl(MVideoCtrl &vctrl) const
Bool_t WriteControl(MVideoCtrl &vctrl, Int_t val) const
std::vector< std::pair< v4l2_buffer, void * > > fBuffers
#define VIDEO_PALETTE_RGB32
#define VIDEO_PALETTE_RGB555
unsigned char * fMapBuffer
#define VIDEO_TYPE_CAMERA
MVideoCtrl(const v4l2_queryctrl &ctrl)
#define VIDEO_PALETTE_YUV422
Bool_t SetControls(TEnv &env) const
#define VIDEO_PALETTE_RGB565
#define VIDEO_TUNER_SECAM
std::vector< v4l2_input > fInputs
TString GetChannelType(Int_t type) const
Bool_t Init(Int_t channel)
#define VIDEO_PALETTE_YUV411
MVideo(const char *path="/dev/video0")