Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/http_mjpeg_streamer/webcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ FMT:
go httpVideo(*addr, li)
}

timeout := uint32(5) //5 seconds
timeout := time.Second * 5
start := time.Now()
var fr time.Duration

Expand Down
14 changes: 9 additions & 5 deletions examples/stdout_streamer/stdout_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
// Example usage: go run stdout_streamer.go | vlc -
package main

import "github.com/blackjack/webcam"
import "os"
import "fmt"
import "sort"
import (
"fmt"
"os"
"sort"
"time"

"github.com/blackjack/webcam"
)

func readChoice(s string) int {
var i int
Expand Down Expand Up @@ -89,7 +93,7 @@ func main() {
panic(err.Error())
}

timeout := uint32(5) //5 seconds
timeout := time.Second * 5
for {
err = cam.WaitForFrame(timeout)

Expand Down
7 changes: 3 additions & 4 deletions v4l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webcam
import (
"bytes"
"encoding/binary"
"time"
"unsafe"

"github.com/blackjack/webcam/ioctl"
Expand Down Expand Up @@ -431,15 +432,13 @@ func stopStreaming(fd uintptr) (err error) {

}

func waitForFrame(fd uintptr, timeout uint32) (count int, err error) {
func waitForFrame(fd uintptr, timeout time.Duration) (count int, err error) {

for {
fds := &unix.FdSet{}
fds.Set(int(fd))

var oneSecInNsec int64 = 1e9
timeoutNsec := int64(timeout) * oneSecInNsec
nativeTimeVal := unix.NsecToTimeval(timeoutNsec)
nativeTimeVal := unix.NsecToTimeval(int64(timeout))
tv := &nativeTimeVal

count, err = unix.Select(int(fd+1), fds, nil, nil, tv)
Expand Down
8 changes: 5 additions & 3 deletions webcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package webcam

import (
"errors"
"golang.org/x/sys/unix"
"reflect"
"time"
"unsafe"

"golang.org/x/sys/unix"
)

// Webcam object
Expand Down Expand Up @@ -232,8 +234,8 @@ func (w *Webcam) ReleaseFrame(index uint32) error {
return mmapEnqueueBuffer(w.fd, index)
}

// Wait until frame could be read
func (w *Webcam) WaitForFrame(timeout uint32) error {
// WaitForFrame waits until frame could be read
func (w *Webcam) WaitForFrame(timeout time.Duration) error {

count, err := waitForFrame(w.fd, timeout)

Expand Down