Update v4l2 discovery
This commit is contained in:
+29
-19
@@ -44,32 +44,33 @@ func apiV4L2(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
formats, _ := dev.ListFormats()
|
formats, _ := dev.ListFormats()
|
||||||
for _, fourCC := range formats {
|
for _, fourCC := range formats {
|
||||||
source := &api.Source{}
|
name, ffmpeg := findFormat(fourCC)
|
||||||
|
source := &api.Source{Name: name}
|
||||||
|
|
||||||
for _, format := range device.Formats {
|
sizes, _ := dev.ListSizes(fourCC)
|
||||||
if format.FourCC == fourCC {
|
for _, wh := range sizes {
|
||||||
source.Name = format.Name
|
if source.Info != "" {
|
||||||
source.URL = "v4l2:device?video=" + path + "&input_format=" + format.FFmpeg + "&video_size="
|
source.Info += " "
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if source.Name != "" {
|
source.Info += fmt.Sprintf("%dx%d", wh[0], wh[1])
|
||||||
sizes, _ := dev.ListSizes(fourCC)
|
|
||||||
for _, wh := range sizes {
|
frameRates, _ := dev.ListFrameRates(fourCC, wh[0], wh[1])
|
||||||
size := fmt.Sprintf("%dx%d", wh[0], wh[1])
|
for _, fr := range frameRates {
|
||||||
if source.Info != "" {
|
source.Info += fmt.Sprintf("@%d", fr)
|
||||||
source.Info += " " + size
|
|
||||||
} else {
|
if source.URL == "" && ffmpeg != "" {
|
||||||
source.Info = size
|
source.URL = fmt.Sprintf(
|
||||||
source.URL += size
|
"v4l2:device?video=%s&input_format=%s&video_size=%dx%d&framerate=%d",
|
||||||
|
path, ffmpeg, wh[0], wh[1], fr,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
source.Name = string(binary.LittleEndian.AppendUint32(nil, fourCC))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sources = append(sources, source)
|
if source.Info != "" {
|
||||||
|
sources = append(sources, source)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = dev.Close()
|
_ = dev.Close()
|
||||||
@@ -77,3 +78,12 @@ func apiV4L2(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
api.ResponseSources(w, sources)
|
api.ResponseSources(w, sources)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findFormat(fourCC uint32) (name, ffmpeg string) {
|
||||||
|
for _, format := range device.Formats {
|
||||||
|
if format.FourCC == fourCC {
|
||||||
|
return format.Name, format.FFmpeg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(binary.LittleEndian.AppendUint32(nil, fourCC)), ""
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user