diff options
author | Mark Thompson <sw@jkqxz.net> | 2017-10-03 20:57:14 +0100 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2017-10-04 23:14:37 +0100 |
commit | a0d076f3ef95e971014c4333c71b384976484889 (patch) | |
tree | fd17c818422caf7917e855ba7170cb393351557e | |
parent | ede233a278896209cb78a1c298b5ed44d4792a23 (diff) |
lavc/v4l2: Remove use of lfind()
This is not present in older bionic and therefore fails to build there,
and the code is much simpler without it anyway.
-rw-r--r-- | libavcodec/v4l2_fmt.c | 73 | ||||
-rw-r--r-- | libavcodec/v4l2_m2m_enc.c | 32 |
2 files changed, 28 insertions, 77 deletions
diff --git a/libavcodec/v4l2_fmt.c b/libavcodec/v4l2_fmt.c index a7ce308696..6df47e3f5a 100644 --- a/libavcodec/v4l2_fmt.c +++ b/libavcodec/v4l2_fmt.c @@ -109,74 +109,33 @@ static const struct fmt_conversion { #endif }; -static int match_codec(const void *a, const void *b) -{ - if (*(enum AVCodecID *)a == ((struct fmt_conversion *)b)->avcodec) - return 0; - - return 1; -} - uint32_t ff_v4l2_format_avcodec_to_v4l2(enum AVCodecID avcodec) { - size_t len = FF_ARRAY_ELEMS(fmt_map); - struct fmt_conversion *item; - - item = lfind(&avcodec, fmt_map, &len, sizeof(fmt_map[0]), match_codec); - if (item) - return item->v4l2_fmt; - + int i; + for (i = 0; i < FF_ARRAY_ELEMS(fmt_map); i++) { + if (fmt_map[i].avcodec == avcodec) + return fmt_map[i].v4l2_fmt; + } return 0; } -static int match_fmt(const void *a, const void *b) -{ - if ( *(enum AVPixelFormat *)a == ((struct fmt_conversion *)b)->avfmt) - return 0; - - return 1; -} - uint32_t ff_v4l2_format_avfmt_to_v4l2(enum AVPixelFormat avfmt) { - size_t len = FF_ARRAY_ELEMS(fmt_map); - struct fmt_conversion *item; - - item = lfind(&avfmt, fmt_map, &len, sizeof(fmt_map[0]), match_fmt); - if (item) - return item->v4l2_fmt; - + int i; + for (i = 0; i < FF_ARRAY_ELEMS(fmt_map); i++) { + if (fmt_map[i].avfmt == avfmt) + return fmt_map[i].v4l2_fmt; + } return 0; } -struct v4l2fmt_avcodec_pair { - enum AVCodecID avcodec; - uint32_t v4l2_fmt; -}; - -static int match_codecfmt(const void *a, const void *b) -{ - struct v4l2fmt_avcodec_pair *key = (struct v4l2fmt_avcodec_pair *) a; - struct fmt_conversion *item = (struct fmt_conversion *) b; - - if (key->avcodec == item->avcodec && key->v4l2_fmt == item->v4l2_fmt) - return 0; - - return 1; -} - enum AVPixelFormat ff_v4l2_format_v4l2_to_avfmt(uint32_t v4l2_fmt, enum AVCodecID avcodec) { - struct v4l2fmt_avcodec_pair const key = { - .v4l2_fmt = v4l2_fmt, - .avcodec = avcodec, - }; - size_t len = FF_ARRAY_ELEMS(fmt_map); - struct fmt_conversion *item; - - item = lfind(&key, fmt_map, &len, sizeof(fmt_map[0]), match_codecfmt); - if (item) - return item->avfmt; - + int i; + for (i = 0; i < FF_ARRAY_ELEMS(fmt_map); i++) { + if (fmt_map[i].avcodec == avcodec && + fmt_map[i].v4l2_fmt == v4l2_fmt) + return fmt_map[i].avfmt; + } return AV_PIX_FMT_NONE; } diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c index e40a120b53..9f59be6efb 100644 --- a/libavcodec/v4l2_m2m_enc.c +++ b/libavcodec/v4l2_m2m_enc.c @@ -91,20 +91,12 @@ static inline int v4l2_get_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed i return 0; } -static int match_profile(const void *a, const void *b) -{ - if (*(unsigned int *)a == *(unsigned int *)b) - return 0; - - return 1; -} - static inline unsigned int v4l2_h264_profile_from_ff(int p) { struct h264_profile { unsigned int ffmpeg_val; unsigned int v4l2_val; - } *val, profile[] = { + } profile[] = { { FF_PROFILE_H264_CONSTRAINED_BASELINE, MPEG_VIDEO(H264_PROFILE_CONSTRAINED_BASELINE) }, { FF_PROFILE_H264_HIGH_444_PREDICTIVE, MPEG_VIDEO(H264_PROFILE_HIGH_444_PREDICTIVE) }, { FF_PROFILE_H264_HIGH_422_INTRA, MPEG_VIDEO(H264_PROFILE_HIGH_422_INTRA) }, @@ -117,12 +109,12 @@ static inline unsigned int v4l2_h264_profile_from_ff(int p) { FF_PROFILE_H264_MAIN, MPEG_VIDEO(H264_PROFILE_MAIN) }, { FF_PROFILE_H264_HIGH, MPEG_VIDEO(H264_PROFILE_HIGH) }, }; - size_t len = FF_ARRAY_ELEMS(profile); - - val = lfind(&p, profile, &len, sizeof(profile[0]), match_profile); - if (val) - return val->v4l2_val; + int i; + for (i = 0; i < FF_ARRAY_ELEMS(profile); i++) { + if (profile[i].ffmpeg_val == p) + return profile[i].v4l2_val; + } return AVERROR(ENOENT); } @@ -131,19 +123,19 @@ static inline int v4l2_mpeg4_profile_from_ff(int p) struct mpeg4_profile { unsigned int ffmpeg_val; unsigned int v4l2_val; - } *val, profile[] = { + } profile[] = { { FF_PROFILE_MPEG4_ADVANCED_CODING, MPEG_VIDEO(MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY) }, { FF_PROFILE_MPEG4_ADVANCED_SIMPLE, MPEG_VIDEO(MPEG4_PROFILE_ADVANCED_SIMPLE) }, { FF_PROFILE_MPEG4_SIMPLE_SCALABLE, MPEG_VIDEO(MPEG4_PROFILE_SIMPLE_SCALABLE) }, { FF_PROFILE_MPEG4_SIMPLE, MPEG_VIDEO(MPEG4_PROFILE_SIMPLE) }, { FF_PROFILE_MPEG4_CORE, MPEG_VIDEO(MPEG4_PROFILE_CORE) }, }; - size_t len = FF_ARRAY_ELEMS(profile); - - val = lfind(&p, profile, &len, sizeof(profile[0]), match_profile); - if (val) - return val->v4l2_val; + int i; + for (i = 0; i < FF_ARRAY_ELEMS(profile); i++) { + if (profile[i].ffmpeg_val == p) + return profile[i].v4l2_val; + } return AVERROR(ENOENT); } |