v4l2: v4l2_fourcc is endianness-agnostic

v4l2_fourcc(a, b, c, d) is defined as (a | (b << 8) | (c << 16) | (d << 24)
regardless of endianness (no mnemonic on big-endian architectures),
so we don't need special handling for WORDS_BIGENDIAN both in decoder
and in the test.

* v4l2.c (print_pixelformat): Change initialisation to a simple
assignment of character array.
* tests/ioctl_v4l2.c [WORDS_BIGENDIAN]: Remove.
* NEWS: Mention this fix.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Fixes: v4.10~371 "Implement Video4Linux video-input ioctls decoder"
This commit is contained in:
Eugene Syromyatnikov 2018-03-02 00:45:16 +01:00 committed by Dmitry V. Levin
parent 6675b67366
commit b82706f412
3 changed files with 13 additions and 33 deletions

1
NEWS
View File

@ -18,6 +18,7 @@ Noteworthy changes in release ?.?? (????-??-??)
* Bug fixes
* Fixed build on m68k.
* Fixed v4l2 pixelformat decoding on big-endian architectures.
Noteworthy changes in release 4.21 (2018-02-13)
===============================================

View File

@ -33,27 +33,15 @@
#include <linux/types.h>
#include <linux/videodev2.h>
#if WORDS_BIGENDIAN
# define cc0(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 24))
# define cc1(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 16))
# define cc2(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 8))
# define cc3(arg) ((unsigned int) (unsigned char) (arg))
# define fourcc(a0, a1, a2, a3) \
((unsigned int)(a3) | \
((unsigned int)(a2) << 8) | \
((unsigned int)(a1) << 16) | \
((unsigned int)(a0) << 24))
#else
# define cc0(arg) ((unsigned int) (unsigned char) (arg))
# define cc1(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 8))
# define cc2(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 16))
# define cc3(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 24))
# define fourcc(a0, a1, a2, a3) \
#define cc0(arg) ((unsigned int) (unsigned char) (arg))
#define cc1(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 8))
#define cc2(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 16))
#define cc3(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 24))
#define fourcc(a0, a1, a2, a3) \
((unsigned int)(a0) | \
((unsigned int)(a1) << 8) | \
((unsigned int)(a2) << 16) | \
((unsigned int)(a3) << 24))
#endif
static const unsigned int magic = 0xdeadbeef;

23
v4l2.c
View File

@ -84,26 +84,17 @@ typedef struct v4l2_standard struct_v4l2_standard;
static void
print_pixelformat(uint32_t fourcc)
{
const union {
uint32_t pixelformat;
unsigned char cc[sizeof(uint32_t)];
} u = {
#if WORDS_BIGENDIAN
.cc = {
(unsigned char) (fourcc >> 24),
(unsigned char) (fourcc >> 16),
(unsigned char) (fourcc >> 8),
(unsigned char) fourcc
}
#else
.pixelformat = fourcc
#endif
unsigned char a[] = {
(unsigned char) fourcc,
(unsigned char) (fourcc >> 8),
(unsigned char) (fourcc >> 16),
(unsigned char) (fourcc >> 24),
};
unsigned int i;
tprints("v4l2_fourcc(");
for (i = 0; i < sizeof(u.cc); ++i) {
unsigned char c = u.cc[i];
for (i = 0; i < ARRAY_SIZE(a); ++i) {
unsigned char c = a[i];
if (i)
tprints(", ");