Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add patch #11

Closed
YouROK opened this issue Jun 27, 2017 · 3 comments
Closed

Add patch #11

YouROK opened this issue Jun 27, 2017 · 3 comments

Comments

@YouROK
Copy link

YouROK commented Jun 27, 2017

Please add patch, I add some ioctls functions, get/set controls

@YouROK
Copy link
Author

YouROK commented Jun 27, 2017

@YouROK
Copy link
Author

YouROK commented Jun 27, 2017

From f5e157e649e2353b86e5161b0c7526eab8c61d85 Mon Sep 17 00:00:00 2001
From: YouROK
Date: Tue, 27 Jun 2017 21:38:10 +0300
Subject: [PATCH] add ioctl funcs


v4l2.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
webcam.go | 8 ++++++++
2 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/v4l2.go b/v4l2.go
index 3770550..244d969 100644
--- a/v4l2.go
+++ b/v4l2.go
@@ -23,14 +23,23 @@ const (
V4L2_FRMSIZE_TYPE_STEPWISE uint32 = 3
)

+const (

  • V4L2_CID_BASE uint32 = 0x00980900
  • V4L2_CID_AUTO_WHITE_BALANCE uint32 = V4L2_CID_BASE + 12
  • V4L2_CID_PRIVATE_BASE uint32 = 0x08000000
    +)

var (

  • VIDIOC_QUERYCAP = ioctl.IoR(uintptr('V'), 0, unsafe.Sizeof(v4l2_capability{}))
  • VIDIOC_ENUM_FMT = ioctl.IoRW(uintptr('V'), 2, unsafe.Sizeof(v4l2_fmtdesc{}))
  • VIDIOC_S_FMT = ioctl.IoRW(uintptr('V'), 5, unsafe.Sizeof(v4l2_format{}))
  • VIDIOC_REQBUFS = ioctl.IoRW(uintptr('V'), 8, unsafe.Sizeof(v4l2_requestbuffers{}))
  • VIDIOC_QUERYBUF = ioctl.IoRW(uintptr('V'), 9, unsafe.Sizeof(v4l2_buffer{}))
  • VIDIOC_QBUF = ioctl.IoRW(uintptr('V'), 15, unsafe.Sizeof(v4l2_buffer{}))
  • VIDIOC_DQBUF = ioctl.IoRW(uintptr('V'), 17, unsafe.Sizeof(v4l2_buffer{}))
  • VIDIOC_QUERYCAP = ioctl.IoR(uintptr('V'), 0, unsafe.Sizeof(v4l2_capability{}))
  • VIDIOC_ENUM_FMT = ioctl.IoRW(uintptr('V'), 2, unsafe.Sizeof(v4l2_fmtdesc{}))
  • VIDIOC_S_FMT = ioctl.IoRW(uintptr('V'), 5, unsafe.Sizeof(v4l2_format{}))
  • VIDIOC_REQBUFS = ioctl.IoRW(uintptr('V'), 8, unsafe.Sizeof(v4l2_requestbuffers{}))
  • VIDIOC_QUERYBUF = ioctl.IoRW(uintptr('V'), 9, unsafe.Sizeof(v4l2_buffer{}))
  • VIDIOC_QBUF = ioctl.IoRW(uintptr('V'), 15, unsafe.Sizeof(v4l2_buffer{}))
  • VIDIOC_DQBUF = ioctl.IoRW(uintptr('V'), 17, unsafe.Sizeof(v4l2_buffer{}))
  • VIDIOC_S_CTRL = ioctl.IoRW(uintptr('V'), 28, unsafe.Sizeof(v4l2_control{}))
  • VIDIOC_QUERYCTRL = ioctl.IoRW(uintptr('V'), 36, unsafe.Sizeof(v4l2_queryctrl{}))
  • //sizeof int32
    VIDIOC_STREAMON = ioctl.IoW(uintptr('V'), 18, 4)
    VIDIOC_ENUM_FRAMESIZES = ioctl.IoRW(uintptr('V'), 74, unsafe.Sizeof(v4l2_frmsizeenum{}))
    @@ -138,6 +147,50 @@ type v4l2_timecode struct {
    userbits [4]uint8
    }

+type v4l2_queryctrl struct {

  • id uint32
  • _type uint32
  • name [32]uint8
  • minimum int32
  • maximum int32
  • step int32
  • default_value int32
  • flags uint32
  • reserved [2]uint32
    +}

+type v4l2_control struct {

  • id uint32
  • value int32
    +}

+func setControl(fd uintptr, id uint32, val int32) error {

  • ctrl := &v4l2_control{}
  • ctrl.id = id
  • ctrl.value = val
  • return ioctl.Ioctl(fd, VIDIOC_S_CTRL, uintptr(unsafe.Pointer(ctrl)))
    +}

+func getControls(fd uintptr) map[uint32]string {

  • query := &v4l2_queryctrl{}
  • var controls map[uint32]string
  • var err error
  • for query.id = V4L2_CID_BASE; err == nil; query.id++ {
  •   err = ioctl.Ioctl(fd, VIDIOC_QUERYCTRL, uintptr(unsafe.Pointer(query)))
    
  •   if err == nil {
    
  •   	controls[query.id] = CToGoString(query.name[:])
    
  •   }
    
  • }
  • err = nil
  • for query.id = V4L2_CID_PRIVATE_BASE; err == nil; query.id++ {
  •   err = ioctl.Ioctl(fd, VIDIOC_QUERYCTRL, uintptr(unsafe.Pointer(query)))
    
  •   if err == nil {
    
  •   	controls[query.id] = CToGoString(query.name[:])
    
  •   }
    
  • }
  • return controls
    +}

func checkCapabilities(fd uintptr) (supportsVideoCapture bool, supportsVideoStreaming bool, err error) {

caps := &v4l2_capability{}

diff --git a/webcam.go b/webcam.go
index f992c42..a2a89d8 100644
--- a/webcam.go
+++ b/webcam.go
@@ -116,6 +116,14 @@ func (w *Webcam) SetImageFormat(f PixelFormat, width, height uint32) (PixelForma
}
}

+func (w *Webcam) SetAutoWhiteBalance(val bool) error {

  • v := int32(0)
  • if val {
  •   v = 1
    
  • }
  • return setControl(w.fd, V4L2_CID_AUTO_WHITE_BALANCE, v)
    +}

// Start streaming process
func (w *Webcam) StartStreaming() error {

--
2.11.0

@blackjack
Copy link
Owner

Done. Thanks for your effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants