1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Coda multi-standard codec IP - MPEG-4 helper functions
5 * Copyright (C) 2019 Pengutronix, Philipp Zabel
8 #include <linux/kernel.h>
9 #include <linux/videodev2.h>
13 int coda_mpeg4_profile(int profile_idc)
15 switch (profile_idc) {
17 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE;
19 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE;
21 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE;
23 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE;
25 return V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY;
31 int coda_mpeg4_level(int level_idc)
35 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_0;
37 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_1;
39 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_2;
41 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_3;
43 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_4;
45 return V4L2_MPEG_VIDEO_MPEG4_LEVEL_5;
52 * Check if the buffer starts with the MPEG-4 visual object sequence and visual
53 * object headers, for example:
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 };
66 u8 start_code_prefix[3];
67 } u = { { 0x00, 0x00, 0x01, 0xb5 } };
70 memcmp(buf, vos_start, 4) != 0 ||
71 memcmp(buf + 5, u.vo_start, 4) != 0)
75 (size >= 33 && memcmp(buf + 30, u.start_code_prefix, 3) == 0))
79 (size >= 34 && memcmp(buf + 31, u.start_code_prefix, 3) == 0))
83 (size >= 35 && memcmp(buf + 32, u.start_code_prefix, 3) == 0))