Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / platform / coda / coda-mpeg4.c
blob483a4fba1b4fe477c32928c718c1bd01d723ed47
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Coda multi-standard codec IP - MPEG-4 helper functions
5 * Copyright (C) 2019 Pengutronix, Philipp Zabel
6 */
8 #include <linux/kernel.h>
9 #include <linux/videodev2.h>
11 #include "coda.h"
13 int coda_mpeg4_profile(int profile_idc)
15 switch (profile_idc) {
16 case 0:
17 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE;
18 case 15:
19 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE;
20 case 2:
21 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE;
22 case 1:
23 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE;
24 case 11:
25 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY;
26 default:
27 return -EINVAL;
31 int coda_mpeg4_level(int level_idc)
33 switch (level_idc) {
34 case 0:
35 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_0;
36 case 1:
37 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_1;
38 case 2:
39 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_2;
40 case 3:
41 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_3;
42 case 4:
43 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_4;
44 case 5:
45 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_5;
46 default:
47 return -EINVAL;
52 * Check if the buffer starts with the MPEG-4 visual object sequence and visual
53 * object headers, for example:
55 * 00 00 01 b0 f1
56 * 00 00 01 b5 a9 13 00 00 01 00 00 00 01 20 08
57 * d4 8d 88 00 f5 04 04 08 14 30 3f
59 * Returns the detected header size in bytes or 0.
61 u32 coda_mpeg4_parse_headers(struct coda_ctx *ctx, u8 *buf, u32 size)
63 static const u8 vos_start[4] = { 0x00, 0x00, 0x01, 0xb0 };
64 static const union {
65 u8 vo_start[4];
66 u8 start_code_prefix[3];
67 } u = { { 0x00, 0x00, 0x01, 0xb5 } };
69 if (size < 30 ||
70 memcmp(buf, vos_start, 4) != 0 ||
71 memcmp(buf + 5, u.vo_start, 4) != 0)
72 return 0;
74 if (size == 30 ||
75 (size >= 33 && memcmp(buf + 30, u.start_code_prefix, 3) == 0))
76 return 30;
78 if (size == 31 ||
79 (size >= 34 && memcmp(buf + 31, u.start_code_prefix, 3) == 0))
80 return 31;
82 if (size == 32 ||
83 (size >= 35 && memcmp(buf + 32, u.start_code_prefix, 3) == 0))
84 return 32;
86 return 0;