mylisabox / flutter_mjpeg

Flutter widget to show mjpeg stream from URL
BSD 2-Clause "Simplified" License
30 stars 23 forks source link

Invalid image data from stream #18

Closed malamalca closed 1 year ago

malamalca commented 2 years ago

This bug is continuation of #14

Stream playback via http is much better with latest update - there are no more visible glitches. Despite that I am still getting errors about corrupted images (see below).

The second problem is similar to #14. The stream is still glitchy when playing it via encrypted connection (https).

I think that the problem with race conditions in async routines is still not fully solved. Animation frames (jpeg images) are still overlapping when streaming via ssl.

The following _Exception was thrown resolving an image codec:
Exception: Invalid image data

When the exception was thrown, this was the stack:
#0      _futurize (dart:ui/painting.dart:5275:5)
#1      ImageDescriptor.encoded (dart:ui/painting.dart:5143:12)
#2      instantiateImageCodec (dart:ui/painting.dart:1999:60)
<asynchronous suspension>
...
vanyasem commented 2 years ago

While waiting for the fix, consider migrating to https://gitee.com/yowfung/flutter_mjpeg_view

It's in Chinese and a bit messy, but it properly reads the stream

jaumard commented 1 year ago

That should be fixed thanks to https://github.com/mylisabox/flutter_mjpeg/pull/24 Try 2.0.2 and let me know

guycalledseven commented 1 year ago

@jaumard I am using 2.0.3 and experience this behaviour again

Flutter Channel stable, 3.3.9, on macOS 12.6.1 21G217 darwin-arm,

════════ Exception caught by image resource service ════════════════════════════
The following _Exception was thrown resolving an image codec:
Exception: Invalid image data

When the exception was thrown, this was the stack
#0      _futurize (dart:ui/painting.dart:5886:5)
#1      ImageDescriptor.encoded (dart:ui/painting.dart:5741:12)
#2      instantiateImageCodecFromBuffer (dart:ui/painting.dart:2092:60)
#3      PaintingBinding.instantiateImageCodecFromBuffer
package:flutter/…/painting/binding.dart:153
#4      MemoryImage._loadAsync
package:flutter/…/painting/image_provider.dart:1090
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════
cybrox commented 1 year ago

Hi @guycalledseven, sorry I've only seen this just now.

While my PR that caused @jaumard to close this issue did improve the situation, I don't think flutter_mjpeg can make any definitive guarantees to prevent this exception. I have opened an issue with Flutter itself regarding this a while ago.

This library can ensure that it captures the SOI and EOI markers of a JPEG correctly and that it sends the contents as a proper frame to Flutter for rendering. It cannot however make sure that the bytes between the SOI and EOI markers are acutally a valid JPEG. It would be up to Flutter to properly use the errorBuilder in this case (as is intended and written in their documentation).

guycalledseven commented 1 year ago

very cool, thanks for update @cybrox