Programming/golang2023. 3. 28. 10:36

웹소켓을 통해 데이터를 JSON으로 변환해서 보내니 웹서버에 부하가 걸리는 것 같아서

binary 데이터 그대로~ 보내고 웹에서 binary를 처리하도록 하려고 찾아보는 중

 

서버 사이드(golang)

for {
    messageType, p, err := conn.ReadMessage()
    if err != nil {
        log.Println(err)
        return
    }
    if err := conn.WriteMessage(messageType, p); err != nil {
        log.Println(err)
        return
    }
}
In above snippet of code, p is a []byte and messageType is an int with value websocket.BinaryMessage or websocket.TextMessage.

[링크 : https://pkg.go.dev/github.com/gorilla/websocket#section-readme]

[링크 : https://kiwitrip.tistory.com/5]

 

클라이언트 사이드(웹 브라우저)

webSocket.onmessage = function (message) {
    var blob = message.data;
    var fileReader = new FileReader();
    fileReader.onload = function (event) {
        var arrayBuffer = event.target.result;
        var dataview = new DataView(arrayBuffer);
        var answer = dataview.getFloat64(0);
        alert("Server> : " + answer);
    };
    fileReader.readAsArrayBuffer(blob);
};

[링크 : http://www.gisdeveloper.co.kr/?p=5594]

 

+

23.04.04

var wsHost = "http://my-sites-url.com/path/to/echo-web-socket-handler";
var ws = new WebSocket(wsHost);
var buffer = new ArrayBuffer(5); // 5 byte buffer
var bufferView = new DataView(buffer);

bufferView.setFloat32(0, Math.PI);
bufferView.setUint8(4, 127);

ws.binaryType = 'arraybuffer';

ws.onmessage = function(message) {
    var view = new DataView(message.data);
    console.log('Uint8:', view.getUint8(4), 'Float32:', view.getFloat32(0))
};

ws.onopen = function() {
    ws.send(buffer);
};

[링크 : https://riptutorial.com/javascript/example/6661/working-with-binary-messages]

'Programming > golang' 카테고리의 다른 글

go 포맷터  (0) 2023.05.11
golang echo directory listing  (0) 2023.05.08
golang 크로스 컴파일 GOARM GOARCH  (0) 2023.02.03
golang map 에 데이터 추가하기  (0) 2023.01.13
golang reflect  (0) 2023.01.03
Posted by 구차니
Linux2023. 3. 27. 14:12

전혀 연관없는 곳에서 발견

bash에서 tab 누르면 어떤 명령어는 하위 명령어에 대해서 자동 완성이 지원되는데

아래 경로의 completions 라는 경로에 파일명을 따라서 수행된다.

/usr/share/bash-completion

 

[링크 : https://github.com/Xilinx/gstreamer/blob/master/data/bash-completion/completions/gst-launch-1.0]

[링크 : https://kubernetes.io/ko/docs/tasks/tools/included/optional-kubectl-configs-bash-linux/]

'Linux' 카테고리의 다른 글

sysfs ethernet link status  (0) 2023.05.17
리눅스 커맨드 라인에서 몇줄씩 건너뛰고 출력하기  (0) 2023.03.30
리눅스 키보드로 강제 종료하기  (0) 2023.03.10
shopt nohup  (0) 2023.01.27
리눅스 배터리 wear level  (0) 2023.01.04
Posted by 구차니

되는데 엄청 느리다.

아마 async 옵션을 안줘서 그런거 같은데..

 

아무튼 gstaremer의 파이프를 구성하는데 ximagesink가 비디오를 출력하기 위한 마지막 sink 니까

파이프 구성없이 v4l2src를 실행하고 jpegdec 한다음(MJPG 웹캠이라) mix 라는 이름을 가지고 있던 videomixer 에게 던지면 끝

$ gst-launch-1.0 v4l2src ! jpegdec ! videomixer name=mix ! videoconvert ! ximagesink v4l2src device=/dev/video2 ! jpegdec ! mix.

'프로그램 사용 > gstreamer' 카테고리의 다른 글

gstremaer videobox + videomixer  (0) 2023.04.10
gst-inspector.c  (0) 2023.04.06
gstreamer videomixer ... 2?  (0) 2023.03.27
gstreamer pad - sink 와 src  (0) 2023.03.27
gstreamer cheat sheet - tee, queue  (0) 2023.03.22
Posted by 구차니

chatGPT 님께 물어보니 tee나 queue 대신 videomixer를 알려주시는데

videomixer의 경우 특이하게(?) sink_%u 라고 여러개의 sink를 받을 수 있는 엘리먼트이다.

Pad Templates
sink_%u
video/x-raw:
         format: { AYUV, BGRA, ARGB, RGBA, ABGR, Y444, Y42B, YUY2, UYVY, YVYU, I420, YV12, NV12, NV21, Y41B, RGB, BGR, xRGB, xBGR, RGBx, BGRx }
          width: [ 1, 2147483647 ]
         height: [ 1, 2147483647 ]
      framerate: [ 0/1, 2147483647/1 ]
Presence – request

Direction – sink

Object type – GstPad

src
video/x-raw:
         format: { AYUV, BGRA, ARGB, RGBA, ABGR, Y444, Y42B, YUY2, UYVY, YVYU, I420, YV12, NV12, NV21, Y41B, RGB, BGR, xRGB, xBGR, RGBx, BGRx }
          width: [ 1, 2147483647 ]
         height: [ 1, 2147483647 ]
      framerate: [ 0/1, 2147483647/1 ]
Presence – always

Direction – src

Object type – GstPad

[링크 : https://gstreamer.freedesktop.org/documentation/videomixer/index.html?gi-language=c]

 

그럴싸 하게 주는데 막상 실행하면 에러 -_-

$ gst-launch-1.0 \
v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480 ! videorate ! videoconvert ! videocrop top=0 left=0 right=640 bottom=480 ! \
videomixer name=mix \
sink_0::xpos=0 sink_0::ypos=0 sink_0::alpha=0 \
v4l2src device=/dev/video1 ! video/x-raw,width=640,height=480 ! videorate ! videoconvert ! videocrop top=0 left=0 right=640 bottom=480 ! \
sink_1::xpos=640 sink_1::ypos=0 sink_1::alpha=0 \
! videoconvert ! autovideosink

(gst-launch-1.0:11399): GStreamer-CRITICAL **: 12:04:11.113: gst_element_link_pads_filtered: assertion 'GST_IS_BIN (parent)' failed
WARNING: erroneous pipeline: syntax error

'프로그램 사용 > gstreamer' 카테고리의 다른 글

gst-inspector.c  (0) 2023.04.06
gstreamer videomixer 반쪽 성공  (0) 2023.03.27
gstreamer pad - sink 와 src  (0) 2023.03.27
gstreamer cheat sheet - tee, queue  (0) 2023.03.22
gstreamer를 이용하여 uvc 웹캠 (mjpg) 보기  (0) 2023.03.22
Posted by 구차니

pad는 입/출력을 모두 의미할 수 있고(PCB의 IC의 발이 pad 니까..)

pad의 종류에 sink와 src가 있는데

sink는 예상과는 다르게 입력이다. src가 해당 엘리먼트의 출력..(어떤 놈이 이렇게 이름을 이따구로 정해놓은거냐 -_-)

 

[링크 : https://gstreamer.freedesktop.org/documentation/application-development/basics/pads.html?gi-language=c]

 

+

pad에 src만 있는 녀석을 소스

sink / src가 있는 녀석을 필터

sink 만 있는 녀석을 sink 라고 표현하는 듯

[링크 : https://gstreamer.freedesktop.org/documentation/application-development/basics/elements.html?gi-language=c]

[링크 : https://gstreamer.freedesktop.org/documentation/tutorials/basic/dynamic-pipelines.html?gi-language=c]

 

가장 만만(?)한 v4l 웹캠 입력을 예를 들어 보면 아래와 같은 파이프가 구성되는데

v4l2src 가 jpegdec를 거쳐 xvimagesink로 전달된다.

$ gst-launch-1.0 v4l2src ! jpegdec ! xvimagesink

 

v4l2src는 sink가 없는 엘리먼트인데 이걸 머라고 불러야 하나?

아무튼 src의 image/jpeg로 뱉어주면(아마 자동으로 서로 사용가능한 포맷을 맞추는 느낌?)

src
image/jpeg:
video/mpeg:
    mpegversion: 4
   systemstream: false
video/mpeg:
    mpegversion: { (int)1, (int)2 }
video/mpegts:
   systemstream: true
video/x-bayer:
         format: { bggr, gbrg, grbg, rggb }
          width: [ 1, 32768 ]
         height: [ 1, 32768 ]
      framerate: [ 0/1, 2147483647/1 ]
video/x-dv:
   systemstream: true
video/x-fwht:
video/x-h263:
        variant: itu
video/x-h264:
  stream-format: { (string)byte-stream, (string)avc }
      alignment: au
video/x-h265:
  stream-format: byte-stream
      alignment: au
video/x-pwc1:
          width: [ 1, 32768 ]
         height: [ 1, 32768 ]
      framerate: [ 0/1, 2147483647/1 ]
video/x-pwc2:
          width: [ 1, 32768 ]
         height: [ 1, 32768 ]
      framerate: [ 0/1, 2147483647/1 ]
video/x-raw:
         format: { RGB16, BGR, RGB, ABGR, xBGR, RGBA, RGBx, GRAY8, GRAY16_LE, GRAY16_BE, YVU9, YV12, YUY2, YVYU, UYVY, Y42B, Y41B, YUV9, NV12_64Z32, NV12_8L128, NV12_10BE_8L128, NV24, NV12_16L32S, NV61, NV16, NV21, NV12, I420, ARGB, xRGB, BGRA, BGRx, BGR15, RGB15 }
          width: [ 1, 32768 ]
         height: [ 1, 32768 ]
      framerate: [ 0/1, 2147483647/1 ]
video/x-sonix:
          width: [ 1, 32768 ]
         height: [ 1, 32768 ]
      framerate: [ 0/1, 2147483647/1 ]
video/x-vp8:
video/x-vp9:
video/x-wmv:
     wmvversion: 3
         format: WVC1

video/x-raw(format:Interlaced):
         format: { RGB16, BGR, RGB, ABGR, xBGR, RGBA, RGBx, GRAY8, GRAY16_LE, GRAY16_BE, YVU9, YV12, YUY2, YVYU, UYVY, Y42B, Y41B, YUV9, NV12_64Z32, NV12_8L128, NV12_10BE_8L128, NV24, NV12_16L32S, NV61, NV16, NV21, NV12, I420, ARGB, xRGB, BGRA, BGRx, BGR15, RGB15 }
          width: [ 1, 32768 ]
         height: [ 1, 32768 ]
      framerate: [ 0/1, 2147483647/1 ]
 interlace-mode: alternate
Presence – always

Direction – src

Object type – GstPad

[링크 : https://gstreamer.freedesktop.org/documentation/video4linux2/v4l2src.html?gi-language=c]

 

jpegdec 에서는 image/jpeg로 받아 video/x-raw로 변환해서 출력하고

Pad Templates
sink
image/jpeg:
Presence – always

Direction – sink

Object type – GstPad

src
video/x-raw:
         format: { I420, RGB, BGR, RGBx, xRGB, BGRx, xBGR, GRAY8 }
          width: [ 1, 2147483647 ]
         height: [ 1, 2147483647 ]
      framerate: [ 0/1, 2147483647/1 ]
Presence – always

Direction – src

Object type – GstPad

[링크 : https://gstreamer.freedesktop.org/documentation/jpeg/jpegdec.html?gi-language=c]

 

xvimagesink는 video/x-raw로 받아서 화면으로 출력한다.

Pad Templates
sink
video/x-raw:
      framerate: [ 0/1, 2147483647/1 ]
          width: [ 1, 2147483647 ]
         height: [ 1, 2147483647 ]
Presence – always

Direction – sink

Object type – GstPad

[링크 : https://gstreamer.freedesktop.org/documentation/xvimagesink/index.html]

'프로그램 사용 > gstreamer' 카테고리의 다른 글

gstreamer videomixer 반쪽 성공  (0) 2023.03.27
gstreamer videomixer ... 2?  (0) 2023.03.27
gstreamer cheat sheet - tee, queue  (0) 2023.03.22
gstreamer를 이용하여 uvc 웹캠 (mjpg) 보기  (0) 2023.03.22
gstream videomixer  (0) 2023.02.17
Posted by 구차니

어우 요즘 낮잠이 너무 늘었어..

'개소리 왈왈 > 직딩의 비애' 카테고리의 다른 글

대략 빡침  (0) 2023.04.13
외근 야근  (0) 2023.04.03
외근 외근.야근  (0) 2023.03.21
언제나 피곤  (0) 2023.03.12
피곤  (0) 2023.03.11
Posted by 구차니

난 미숙하니 세금 안내도 되나?

 

[링크 :https://v.daum.net/v/20230324161743197]

 

'개소리 왈왈 > 정치관련 신세한탄' 카테고리의 다른 글

만우절  (0) 2023.04.01
탄핵으로도 부족한 만행  (0) 2023.03.30
3.1절  (0) 2023.03.01
외근이.잦아..  (0) 2023.02.28
이명박 특사..?  (0) 2023.01.25
Posted by 구차니

Hamming 적용(끝부분으로 갈수록 0에 가깝게 억제) -> 손실 발생 -> 겹침(overlap) 적용 -> 손실 최소화

[링크 : https://m.blog.naver.com/ksunghwank/140119596852]

 

앞뒤에 0으로 된 신호가 있다고 간주하도록 신호의 앞 뒤를 0으로 눌러서 하면

유한시간 간격으로 좁힌다 라고 하는데 discrete 이기 때문인가?

[링크 : https://medialink.tistory.com/135]

 

특별한 이유가 없다면 Hanning 윈도우 적용하는 것이 좋다라..

Rectangluar는 가장 높은 주파수 분해능을 제공

Hamming, Hanning은 연속적인 파형 분석에 주로 사용됨

[링크 : https://m.blog.naver.com/lecroykorea/221549211257]

 

 

아무튼.. 요약하자면 입력받은 데이터를 그대로 때려박아도(rectangular) 상관없지만

분석 유형에 따라 Hanning등을 적용하는 것이 더 나을 수도 있다. 정도인가?

 

+

오버랩 블록의 몇 %를 다음 블록에서 다시 사용

그렇다면 전체 분석되는 주파수 범위가 늘어날 것 같은데, 시간 해상도를 높이는데 사용된다고 한다.

어떻게 보면.. Moving average 처럼 주파수를 옆으로 shift 해가면서 분석되서 나오는 주파수도 넓히고

새로운 주파수가 아닌 과거 주파수를 포함하긴 하지만 더 짧은 시간 주기로 결과를 낼 수 있는

반대로 생각하면 연산량에 더 많아지는 결과를 얻을 수 있게 될 듯?

[링크 : https://m.blog.naver.com/suya309/221467948212]

 

 

+

2023.03.30

[링크 : https://sanghyu.tistory.com/38]

[링크 : https://paeton.tistory.com/entry/Window-Function을-쓰는-이유

 

[링크 : https://dsp.stackexchange.com/questions/13856/filter-size-vs-fft-size-and-overlap-add]

[링크 : https://commons.wikimedia.org/wiki/File:FFT_size_vs_filter_length_for_Overlap-add_convolution.svg]

[링크 : https://dsp.stackexchange.com/questions/47448/window-periodoverlap-and-fft]

 

[링크 : https://www.katjaas.nl/FFTwindow/FFTwindow.html]

'프로그램 사용 > fft, fftw' 카테고리의 다른 글

spectrogram  (0) 2023.03.29
fft 분석 패러미터  (0) 2023.03.29
cabs()  (0) 2023.02.15
FFT 분석 기법  (0) 2023.02.07
fft window 함수  (0) 2022.11.16
Posted by 구차니
embeded/i.mx 8m plus2023. 3. 23. 10:46

크아.. 볼게 너무 많아 ㅠㅠ

그런데 openAMP가 나오는게 먼가.. 쎄~~~하다 -_-

 

linux / cortex-A / rpmsg <-> rtos or baremetal / cortex-M / rpmsg-lite

 

성능 향상은 openAMP와는 넘사벽일 수도 있는 설정이 존재하고

Core A와 Core B 이기종(heterogeneous) 장치간의 통신을 지원한다.

[링크 : https://github.com/nxp-mcuxpresso/rpmsg-lite]

'embeded > i.mx 8m plus' 카테고리의 다른 글

nxp i.mx8mp win iot part 2  (0) 2023.05.26
nxp i.mx8mp win iot  (0) 2023.05.26
i.mx8m plus cortex-m7 part.2  (0) 2023.02.23
i.mx8m plus cortex-m7  (0) 2023.02.23
i.mx8m plus win iot 실행  (0) 2023.02.23
Posted by 구차니

원본 설명.. tee는 그나마 알아듣겠는데

tee
Split data to multiple pads. Branching the data flow is useful when e.g. capturing a video where the video is shown on the screen and also encoded and written to a file. Another example is playing music and hooking up a visualisation module.

One needs to use separate queue elements (or a multiqueue) in each branch to provide separate threads for each branch. Otherwise a blocked dataflow in one branch would stall the other branches.

Example launch line
 gst-launch-1.0 filesrc location=song.ogg ! decodebin ! tee name=t ! queue ! audioconvert ! audioresample ! autoaudiosink t. ! queue ! audioconvert ! goom ! videoconvert ! autovideosink

Play song.ogg audio file which must be in the current working directory and render visualisations using the goom element (this can be easier done using the playbin element, this is just an example pipeline).

[링크 : https://gstreamer.freedesktop.org/documentation/coreelements/tee.html?gi-language=c]

 

queue는 도대체 어떻게 해석을 해야하냐..

queue
Data is queued until one of the limits specified by the , and/or properties has been reached. Any attempt to push more buffers into the queue will block the pushing thread until more space becomes available.

The queue will create a new thread on the source pad to decouple the processing on sink and source pad.

You can query how many buffers are queued by reading the property. You can track changes by connecting to the notify::current-level-buffers signal (which like all signals will be emitted from the streaming thread). The same applies to the and properties.

The default queue size limits are 200 buffers, 10MB of data, or one second worth of data, whichever is reached first.

As said earlier, the queue blocks by default when one of the specified maximums (bytes, time, buffers) has been reached. You can set the property to specify that instead of blocking it should leak (drop) new or old buffers.

The signal is emitted when the queue has less data than the specified minimum thresholds require (by default: when the queue is empty). The signal is emitted when the queue is filled up. Both signals are emitted from the context of the streaming thread.

[링크 : https://gstreamer.freedesktop.org/documentation/coreelements/queue.html?gi-language=c]

 

 

마태복음님 만세!

얼마나 직관적인가!!

Multiple outputs (tee)
This page describes the tee element, which allows audio & video streams to be sent to more than one place.

[링크 : https://github.com/matthew1000/gstreamer-cheat-sheet/blob/master/tee.md]

 

queue는 쓰레드 경계로 쓰거나 버퍼(속도가 다를 경우 완충을 위한)로 사용된다.

Queues
A queue can appear almost anywhere in a GStreamer pipeline. Like most elements, it has an input (sink) and output (src). It has two uses:

As a thread boundary - i.e. The elements after a queue will run in a different thread to those before it
As a buffer, for when different parts of the pipeline may move at different speeds.

[링크 : https://github.com/matthew1000/gstreamer-cheat-sheet/blob/master/queues.md]

 

 

+

$ gst-launch-1.0 videotestsrc ! videoconvert ! tee name=t ! queue ! autovideosink t. ! queue ! autovideosink
$ gst-launch-1.0 videotestsrc ! videoconvert ! tee name=t ! queue ! autovideosink t. ! queue ! autovideosink t. ! queue ! autovideosink

[링크 : http:// https://medium.com/may-i-lab/gstreamer-gstreamer-기초-da5015f531fc]

Posted by 구차니