1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Coda multi-standard codec IP - MPEG-2 helper functions
5 * Copyright (C) 2019 Pengutronix, Philipp Zabel
8 #include <linux/kernel.h>
9 #include <linux/videodev2.h>
12 int coda_mpeg2_profile(int profile_idc
)
14 switch (profile_idc
) {
16 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_SIMPLE
;
18 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_MAIN
;
20 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_SNR_SCALABLE
;
22 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_SPATIALLY_SCALABLE
;
24 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH
;
30 int coda_mpeg2_level(int level_idc
)
34 return V4L2_MPEG_VIDEO_MPEG2_LEVEL_LOW
;
36 return V4L2_MPEG_VIDEO_MPEG2_LEVEL_MAIN
;
38 return V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH_1440
;
40 return V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH
;
47 * Check if the buffer starts with the MPEG-2 sequence header (with or without
48 * quantization matrix) and extension header, for example:
50 * 00 00 01 b3 2d 01 e0 34 08 8b a3 81
51 * 10 11 11 12 12 12 13 13 13 13 14 14 14 14 14 15
52 * 15 15 15 15 15 16 16 16 16 16 16 16 17 17 17 17
53 * 17 17 17 17 18 18 18 19 18 18 18 19 1a 1a 1a 1a
54 * 19 1b 1b 1b 1b 1b 1c 1c 1c 1c 1e 1e 1e 1f 1f 21
55 * 00 00 01 b5 14 8a 00 01 00 00
59 * 00 00 01 b3 08 00 40 15 ff ff e0 28
60 * 00 00 01 b5 14 8a 00 01 00 00
62 * Returns the detected header size in bytes or 0.
64 u32
coda_mpeg2_parse_headers(struct coda_ctx
*ctx
, u8
*buf
, u32 size
)
66 static const u8 sequence_header_start
[4] = { 0x00, 0x00, 0x01, 0xb3 };
68 u8 extension_start
[4];
69 u8 start_code_prefix
[3];
70 } u
= { { 0x00, 0x00, 0x01, 0xb5 } };
73 memcmp(buf
, sequence_header_start
, 4) != 0)
77 (size
>= 25 && memcmp(buf
+ 22, u
.start_code_prefix
, 3) == 0)) &&
78 memcmp(buf
+ 12, u
.extension_start
, 4) == 0)
82 (size
> 89 && memcmp(buf
+ 86, u
.start_code_prefix
, 3) == 0)) &&
83 memcmp(buf
+ 76, u
.extension_start
, 4) == 0)