Skip to content
Snippets Groups Projects
Commit 444feddf authored by Adrien Béraud's avatar Adrien Béraud
Browse files

android: fix segfault when probing formats

Change-Id: I15f9c2d8b1414c58cf77c58b8a0c4b6d3068a76e
Tuleap: #537
parent 0abf627b
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <vector> #include <vector>
#include <array>
namespace ring { namespace video { namespace ring { namespace video {
...@@ -43,9 +44,9 @@ struct android_fmt { ...@@ -43,9 +44,9 @@ struct android_fmt {
enum VideoPixelFormat ring_format; enum VideoPixelFormat ring_format;
}; };
static const struct android_fmt and_formats[] { static const std::array<android_fmt, 2> and_formats {
{ 17, "NV21", VIDEO_PIXFMT_NV21 }, android_fmt { 17, "NV21", VIDEO_PIXFMT_NV21 },
{ 842094169, "YUV420", VIDEO_PIXFMT_YUV420P }, android_fmt { 842094169, "YUV420", VIDEO_PIXFMT_YUV420P },
}; };
class VideoDeviceImpl { class VideoDeviceImpl {
...@@ -71,7 +72,7 @@ class VideoDeviceImpl { ...@@ -71,7 +72,7 @@ class VideoDeviceImpl {
std::vector<VideoSize> sizes_ {}; std::vector<VideoSize> sizes_ {};
std::vector<FrameRate> rates_ {}; std::vector<FrameRate> rates_ {};
const struct android_fmt *fmt_ {nullptr}; const android_fmt* fmt_ {nullptr};
VideoSize size_ {}; VideoSize size_ {};
FrameRate rate_ {}; FrameRate rate_ {};
}; };
...@@ -83,26 +84,19 @@ VideoDeviceImpl::selectFormat() ...@@ -83,26 +84,19 @@ VideoDeviceImpl::selectFormat()
* formats_ contains camera parameters as returned by the GetCameraInfo * formats_ contains camera parameters as returned by the GetCameraInfo
* signal, find the matching V4L2 formats * signal, find the matching V4L2 formats
*/ */
unsigned int current, best = UINT_MAX; unsigned best = UINT_MAX;
for(const auto &fmt : formats_) { for(auto fmt : formats_) {
const struct android_fmt *and_fmt; auto f = and_formats.begin();
for(and_fmt = std::begin(and_formats); for (; f != and_formats.end(); ++f) {
and_formats < std::end(and_formats); if (f->code == fmt) {
and_fmt++) { auto pos = std::distance(and_formats.begin(), f);
if (fmt == and_fmt->code) { if (pos < best)
current = and_fmt - std::begin(and_formats); best = pos;
break; break;
} }
} }
if (f == and_formats.end())
/* No match found, we should add it */
if (and_fmt == std::end(and_formats)) {
RING_WARN("AndroidVideo: No format matching %d", fmt); RING_WARN("AndroidVideo: No format matching %d", fmt);
continue;
}
if (current < best)
best = current;
} }
if (best != UINT_MAX) { if (best != UINT_MAX) {
...@@ -119,6 +113,9 @@ VideoDeviceImpl::VideoDeviceImpl(const std::string& path) : name(path) ...@@ -119,6 +113,9 @@ VideoDeviceImpl::VideoDeviceImpl(const std::string& path) : name(path)
{ {
std::vector<unsigned> sizes; std::vector<unsigned> sizes;
std::vector<unsigned> rates; std::vector<unsigned> rates;
formats_.reserve(16);
sizes.reserve(16);
rates.reserve(16);
emitSignal<DRing::VideoSignal::GetCameraInfo>(name, &formats_, &sizes, &rates); emitSignal<DRing::VideoSignal::GetCameraInfo>(name, &formats_, &sizes, &rates);
for (size_t i=0, n=sizes.size(); i<n; i+=2) for (size_t i=0, n=sizes.size(); i<n; i+=2)
sizes_.emplace_back(sizes[i], sizes[i+1]); sizes_.emplace_back(sizes[i], sizes[i+1]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment