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

client.sendBinary with camera stream crashing recent versions #16

Closed
xgarb opened this issue Jun 13, 2019 · 4 comments
Closed

client.sendBinary with camera stream crashing recent versions #16

xgarb opened this issue Jun 13, 2019 · 4 comments
Assignees
Labels
bug Something isn't working resolved the issue was resolved

Comments

@xgarb
Copy link

xgarb commented Jun 13, 2019

For versions above 0.4.0 sending binary (video frames) is crashing in my script:

Cut down code on ESP32 (Arduino IDE)

void loop() {
  auto client = socket_server.accept();
  client.onMessage(handle_message);
  while (client.available()) {
    client.poll();
    fb = esp_camera_fb_get();
    client.sendBinary((const char *)fb->buf, fb->len);
    esp_camera_fb_return(fb);
    fb = NULL;
  }
}

JS in browser:

document.addEventListener("DOMContentLoaded", function(event) {
  var baseHost = document.location.origin;
  const WS_URL = "ws://" + window.location.host + ":82";
  const ws = new WebSocket(WS_URL);

  ws.onmessage = message => {
    if (message.data instanceof Blob) {
      var urlObject = URL.createObjectURL(message.data);
      view.src = urlObject;
    }
  };
});

It works great in 0.4.0 so I don't know if some code was changed for send.binary in later versions?

Crash report....

[D][WiFiClient.cpp:482] connected(): Disconnected: RES: 0, ERR: 128
[E][WiFiClient.cpp:365] write(): fail on fd 63, errno: 11, "No more processes"
[E][WiFiClient.cpp:365] write(): fail on fd 63, errno: 11, "No more processes"
[E][WiFiClient.cpp:365] write(): fail on fd 63, errno: 11, "No more processes"
[E][WiFiClient.cpp:365] write(): fail on fd 63, errno: 11, "No more processes"
[E][WiFiClient.cpp:365] write(): fail on fd 63, errno: 11, "No more processes"
abort() was called at PC 0x40136eeb on core 1

Backtrace: 0x40091408:0x3ffb1d20 0x40091639:0x3ffb1d40 0x40136eeb:0x3ffb1d60 0x40136f32:0x3ffb1d80 0x401362bf:0x3ffb1da0 0x401363ae:0x3ffb1dc0 0x40136365:0x3ffb1de0 0x400d575b:0x3ffb1e00 0x400d57b6:0x3ffb1e30 0x400d4b8a:0x3ffb1e60 0x400d3339:0x3ffb1e80 0x400d9be9:0x3ffb1fb0 0x4008d3a5:0x3ffb1fd0

Rebooting...

Decoding stack results
0x40091408: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 155
0x40091639: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 170
0x40136eeb: __cxxabiv1::__terminate(void ()()) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc line 47
0x40136f32: std::terminate() at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc line 57
0x401362bf: __cxxabiv1::__cxa_throw(void, std::type_info*, void ()(void)) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_throw.cc line 87
0x401363ae: operator new(unsigned int) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/new_op.cc line 54
0x40136365: operator new[](unsigned int) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/new_opv.cc line 32
0x400d575b: websockets::internals::WebsocketsEndpoint::send(char const*, unsigned int, unsigned char, bool, bool, char const*) at C:\Users\Dude\Documents\Arduino\libraries\ArduinoWebsockets\src\websockets_endpoint.cpp line 367
0x400d57b6: websockets::internals::WebsocketsEndpoint::send(char const*, unsigned int, unsigned char, bool) at C:\Users\Dude\Documents\Arduino\libraries\ArduinoWebsockets\src\websockets_endpoint.cpp line 321
0x400d4b8a: websockets::WebsocketsClient::sendBinary(char const*, unsigned int) at C:\Users\Dude\Documents\Arduino\libraries\ArduinoWebsockets\src\websockets_client.cpp line 396
0x400d3339: loop() at C:\Users\Dude\Documents\Arduino\CameraWebServerWeChatWebSockets/CameraWebServerWeChatWebSockets.ino line 358
0x400d9be9: loopTask(void*) at C:\Users\Dude\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.3-rc1\cores\esp32\main.cpp line 19
0x4008d3a5: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143

@gilmaimon gilmaimon self-assigned this Jun 13, 2019
@gilmaimon
Copy link
Owner

Thank you, I am on it.
I will try to re-produce the behaviour you are getting, I will post any updates I'll have here.

gilmaimon added a commit that referenced this issue Jun 14, 2019
…ation for masking in send. Also masking key is now 0 by default so sending messages that are masked costs almost no extra computation. This should act as a fix to memory over-use in issue #16
@gilmaimon gilmaimon added the bug Something isn't working label Jun 14, 2019
@gilmaimon
Copy link
Owner

100% A bug!
I belive I've found the issue. I did a mistake and the code was very wastefull with dynamic memory (which an esp32 doesn't have much of). I've uploaded a patch. It should work much better now. Please let me know!

Thank you very much for your issues and for using the library, It is priceless and extremely helpful.

Thank you.

@xgarb
Copy link
Author

xgarb commented Jun 17, 2019

I've tested in Chrome and Firefox and this version is working perfectly with my script. Thanks for the fix and your programming help.

@gilmaimon gilmaimon added the resolved the issue was resolved label Jun 17, 2019
@gilmaimon
Copy link
Owner

Awesome, closed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved the issue was resolved
Projects
None yet
Development

No branches or pull requests

2 participants