getting something out of buffer
gir:field to get stuff out of structs but getting 'data still doesn't work null in length
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
(in-package :capturing-frames)
|
||||
(gir:require-namespace "GLib")
|
||||
(defvar *gstreamer* (gir:require-namespace "Gst"))
|
||||
(defvar *gstapp* (gir:require-namespace "GstApp"))
|
||||
|
||||
(defun cast-with-videobox (&optional stream-num)
|
||||
(gir:invoke (*gstreamer* 'init) '())
|
||||
@@ -20,7 +21,8 @@
|
||||
(queue1 (gir:invoke (*gstreamer* "ElementFactory" 'make) "queue" "queue1"))
|
||||
(queue2 (gir:invoke (*gstreamer* "ElementFactory" 'make) "queue" "queue2"))
|
||||
(sink (gir:invoke (*gstreamer* "ElementFactory" 'make) "autovideosink" "sink"))
|
||||
(appsink (gir:invoke (*gstreamer* "ElementFactory" 'make) "appsink" "appsink")))
|
||||
(appsink (gir:invoke (*gstreamer* "ElementFactory" 'make) "appsink" "appsink"))
|
||||
)
|
||||
(when stream-num
|
||||
;; Set pipewiresrc properties, such as the path
|
||||
(setf (gir:property source 'path) (format nil "~A" stream-num)))
|
||||
@@ -47,31 +49,51 @@
|
||||
(gir:property appsink "drop") t)
|
||||
|
||||
(gir:invoke (pipeline 'set-state) (gir:nget *gstreamer* "State" :playing))
|
||||
|
||||
|
||||
;; Example: Move the video 10 pixels down and 20 pixels to the right
|
||||
pipeline))
|
||||
(values pipeline appsink)))
|
||||
|
||||
(defun process-frame (sample)
|
||||
(format t ">>> got to process sample with ~A~%" sample)
|
||||
(let* ((buffer (gir:invoke (sample 'get-buffer)))
|
||||
(info (gir:invoke (buffer 'get-memory) 0))
|
||||
(map-info (gir:invoke (info 'map) (gir:nget *gstreamer* "MapFlags" :read)))
|
||||
(data (gir:property map-info 'data))
|
||||
(size (gir:property map-info 'size)))
|
||||
;; Process the frame data here
|
||||
(format t "Received frame of size ~A bytes~%" size)
|
||||
;; Example: Calculate average brightness
|
||||
(let ((sum 0))
|
||||
(dotimes (i size)
|
||||
(incf sum (aref data i)))
|
||||
(format t "Average brightness: ~A~%" (/ sum size)))
|
||||
;; Unmap the memory when done
|
||||
(gir:invoke (info 'unmap) map-info)))
|
||||
(info (gir:invoke (sample 'get-info)))
|
||||
(caps (gir:invoke (sample 'get-caps)))
|
||||
(caps-struct (gir:invoke (caps 'get-structure) 0))
|
||||
(width (gir:invoke ((gir:invoke (caps-struct 'get-value) "width") 'get-int)))
|
||||
(height (gir:invoke ((gir:invoke (caps-struct 'get-value) "height") 'get-int))))
|
||||
(multiple-value-bind (found map-info) (gir:invoke (buffer 'map) (gir:nget *gstreamer* "MapFlags" :read))
|
||||
(format t ">>>> the buffer has offset ~A~%" (gir:field buffer 'offset))
|
||||
(format t ">>>> what's in struct? ~A~%" (gir:invoke (caps-struct 'to-string)))
|
||||
(format t ">>>> the fields are width ~A, height ~A~%" width height)
|
||||
(format t ">>>> and map result are ~A and ~A~%" found map-info)
|
||||
(when found
|
||||
(let ((data (gir:field map-info 'data))
|
||||
(size (gir:field map-info 'size)))
|
||||
(format t ">>>> and struct info? ~A~%" map-info)
|
||||
; (format t ">>>> and data has size ~A and buf ~A~%" size (or data "empty data"))
|
||||
)))
|
||||
;; Unmap the memory when done
|
||||
;; (gir:invoke (info 'unmap) map-info)
|
||||
))
|
||||
|
||||
(defun start-processing (appsink)
|
||||
(gir:connect appsink "new-sample"
|
||||
(lambda (appsink)
|
||||
(let ((sample (gir:invoke (appsink 'pull-sample))))
|
||||
(format t ">> got printed object ~A~%" appsink)
|
||||
(format t ">> got printed class ~A~%" (gir:gir-class-of appsink))
|
||||
(format t ">> trying to get method on sink ~A~%" (gir:nget appsink 'pull-sample))
|
||||
(let ((sample (gir:invoke (appsink 'pull-sample))))
|
||||
(when sample
|
||||
(process-frame sample)
|
||||
(gir:invoke (sample 'unref))))
|
||||
(process-frame sample)))
|
||||
|
||||
|
||||
(gir:nget *gstreamer* "FlowReturn" :ok))))
|
||||
|
||||
(defun try-run ()
|
||||
(multiple-value-bind (pipeline appsink) (cast-with-videobox)
|
||||
(format t "got appsink ~A" appsink)
|
||||
(start-processing appsink)
|
||||
(loop
|
||||
(sleep 1))))
|
||||
|
||||
;(try-run)
|
||||
|
||||
Reference in New Issue
Block a user