2 * Coda multi-standard codec IP - H.264 helper functions
4 * Copyright (C) 2012 Vista Silicon S.L.
5 * Javier Martin, <javier.martin@vista-silicon.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/kernel.h>
15 #include <linux/string.h>
16 #include <linux/videodev2.h>
19 static const u8 coda_filler_size
[8] = { 0, 7, 14, 13, 12, 11, 10, 9 };
21 static const u8
*coda_find_nal_header(const u8
*buf
, const u8
*end
)
26 val
= val
<< 8 | *buf
++;
29 } while (val
!= 0x00000001);
34 int coda_sps_parse_profile(struct coda_ctx
*ctx
, struct vb2_buffer
*vb
)
36 const u8
*buf
= vb2_plane_vaddr(vb
, 0);
37 const u8
*end
= buf
+ vb2_get_plane_payload(vb
, 0);
41 buf
= coda_find_nal_header(buf
, end
);
44 } while ((*buf
++ & 0x1f) != 0x7);
46 ctx
->params
.h264_profile_idc
= buf
[0];
47 ctx
->params
.h264_level_idc
= buf
[2];
52 int coda_h264_filler_nal(int size
, char *p
)
62 memset(p
+ 5, 0xff, size
- 6);
63 /* Add rbsp stop bit and trailing at the end */
69 int coda_h264_padding(int size
, char *p
)
74 diff
= size
- (size
& ~0x7);
78 nal_size
= coda_filler_size
[diff
];
79 coda_h264_filler_nal(nal_size
, p
);
84 int coda_h264_profile(int profile_idc
)
86 switch (profile_idc
) {
87 case 66: return V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE
;
88 case 77: return V4L2_MPEG_VIDEO_H264_PROFILE_MAIN
;
89 case 88: return V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED
;
90 case 100: return V4L2_MPEG_VIDEO_H264_PROFILE_HIGH
;
91 default: return -EINVAL
;
95 int coda_h264_level(int level_idc
)
98 case 10: return V4L2_MPEG_VIDEO_H264_LEVEL_1_0
;
99 case 9: return V4L2_MPEG_VIDEO_H264_LEVEL_1B
;
100 case 11: return V4L2_MPEG_VIDEO_H264_LEVEL_1_1
;
101 case 12: return V4L2_MPEG_VIDEO_H264_LEVEL_1_2
;
102 case 13: return V4L2_MPEG_VIDEO_H264_LEVEL_1_3
;
103 case 20: return V4L2_MPEG_VIDEO_H264_LEVEL_2_0
;
104 case 21: return V4L2_MPEG_VIDEO_H264_LEVEL_2_1
;
105 case 22: return V4L2_MPEG_VIDEO_H264_LEVEL_2_2
;
106 case 30: return V4L2_MPEG_VIDEO_H264_LEVEL_3_0
;
107 case 31: return V4L2_MPEG_VIDEO_H264_LEVEL_3_1
;
108 case 32: return V4L2_MPEG_VIDEO_H264_LEVEL_3_2
;
109 case 40: return V4L2_MPEG_VIDEO_H264_LEVEL_4_0
;
110 case 41: return V4L2_MPEG_VIDEO_H264_LEVEL_4_1
;
111 default: return -EINVAL
;