diff --git a/src/frame_streams/sdl/sdl_video_frame_stream2.cpp b/src/frame_streams/sdl/sdl_video_frame_stream2.cpp index 44b7c62..f281251 100644 --- a/src/frame_streams/sdl/sdl_video_frame_stream2.cpp +++ b/src/frame_streams/sdl/sdl_video_frame_stream2.cpp @@ -50,12 +50,19 @@ std::shared_ptr> SDLVideo2InputDevice::subscribe(vo // choose a good spec, large res but <= 1080p int speccount {0}; SDL_CameraSpec** specs = SDL_GetCameraSupportedFormats(_dev, &speccount); - if (specs != nullptr) { + if (specs != nullptr && speccount > 0) { spec = *specs[speccount-1]; // start with last, as its usually the smallest - for (int spec_i = 1; spec_i < speccount; spec_i++) { + for (int spec_i = 0; spec_i < speccount; spec_i++) { if (specs[spec_i]->height > 1080) { continue; } + + if (spec.format == SDL_PIXELFORMAT_MJPG && spec.format != specs[spec_i]->format) { + // we hard prefer anything else over mjpg + spec = *specs[spec_i]; + continue; + } + if (spec.height > specs[spec_i]->height) { continue; } @@ -67,14 +74,17 @@ std::shared_ptr> SDLVideo2InputDevice::subscribe(vo continue; } + // HACK: prefer nv12 over yuy2, SDL has sse2 optimized conversion for our usecase if (spec.format == SDL_PIXELFORMAT_NV12 && specs[spec_i]->format == SDL_PIXELFORMAT_YUY2) { - // HACK: prefer nv12 over yuy2 continue; } // seems to be better spec = *specs[spec_i]; } + + } + if (specs != nullptr) { SDL_free(specs); } diff --git a/src/frame_streams/sdl/video.hpp b/src/frame_streams/sdl/video.hpp index f9b1851..4067986 100644 --- a/src/frame_streams/sdl/video.hpp +++ b/src/frame_streams/sdl/video.hpp @@ -5,6 +5,7 @@ #include #include +#include #include // https://youtu.be/71Iw4Q74OaE @@ -36,6 +37,7 @@ struct SDLVideoFrame { SDL_DuplicateSurface(other.surface.get()), &SDL_DestroySurface }; + assert(surface); } } SDLVideoFrame& operator=(const SDLVideoFrame& other) = delete; diff --git a/src/frame_streams/sdl/video_push_converter.hpp b/src/frame_streams/sdl/video_push_converter.hpp index 0b486ec..24d55b7 100644 --- a/src/frame_streams/sdl/video_push_converter.hpp +++ b/src/frame_streams/sdl/video_push_converter.hpp @@ -18,6 +18,7 @@ struct PushConversionVideoStream : public RealStream { ~PushConversionVideoStream(void) {} bool push(const SDLVideoFrame& value) override { + assert(value.surface); SDL_Surface* surf = value.surface.get(); if (surf->format != _forced_format) { //std::cerr << "PCVS: need to convert from " << SDL_GetPixelFormatName(surf->format) << " to " << SDL_GetPixelFormatName(_forced_format) << "\n";