1
2
3
4
5
6
7
8#include <linux/kernel.h>
9#include <linux/videodev2.h>
10#include "coda.h"
11
12int coda_mpeg2_profile(int profile_idc)
13{
14 switch (profile_idc) {
15 case 5:
16 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_SIMPLE;
17 case 4:
18 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_MAIN;
19 case 3:
20 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_SNR_SCALABLE;
21 case 2:
22 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_SPATIALLY_SCALABLE;
23 case 1:
24 return V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH;
25 default:
26 return -EINVAL;
27 }
28}
29
30int coda_mpeg2_level(int level_idc)
31{
32 switch (level_idc) {
33 case 10:
34 return V4L2_MPEG_VIDEO_MPEG2_LEVEL_LOW;
35 case 8:
36 return V4L2_MPEG_VIDEO_MPEG2_LEVEL_MAIN;
37 case 6:
38 return V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH_1440;
39 case 4:
40 return V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH;
41 default:
42 return -EINVAL;
43 }
44}
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64u32 coda_mpeg2_parse_headers(struct coda_ctx *ctx, u8 *buf, u32 size)
65{
66 static const u8 sequence_header_start[4] = { 0x00, 0x00, 0x01, 0xb3 };
67 static const union {
68 u8 extension_start[4];
69 u8 start_code_prefix[3];
70 } u = { { 0x00, 0x00, 0x01, 0xb5 } };
71
72 if (size < 22 ||
73 memcmp(buf, sequence_header_start, 4) != 0)
74 return 0;
75
76 if ((size == 22 ||
77 (size >= 25 && memcmp(buf + 22, u.start_code_prefix, 3) == 0)) &&
78 memcmp(buf + 12, u.extension_start, 4) == 0)
79 return 22;
80
81 if ((size == 86 ||
82 (size > 89 && memcmp(buf + 86, u.start_code_prefix, 3) == 0)) &&
83 memcmp(buf + 76, u.extension_start, 4) == 0)
84 return 86;
85
86 return 0;
87}
88