fixed coverity issues
[platform/core/api/mediacodec.git] / include / media_codec_bitstream.h
1 /*
2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __TIZEN_MEDIA_CODEC_BITSTREAM_H__
18 #define __TIZEN_MEDIA_CODEC_BITSTREAM_H__
19
20 #include <tizen.h>
21 #include <media_codec_private.h>
22
23 typedef struct _mc_bitstream_t mc_bitstream_t;
24
25 typedef enum {
26         NAL_SLICE_NO_PARTITIONING = 1,
27         NAL_SLICE_PART_A,
28         NAL_SLICE_PART_B,
29         NAL_SLICE_PART_C,
30         NAL_SLICE_IDR,
31         NAL_SEI,
32         NAL_SEQUENCE_PARAMETER_SET,
33         NAL_PICTURE_PARAMETER_SET,
34         NAL_PICTURE_DELIMITER,
35         NAL_END_OF_SEQUENCE,
36         NAL_END_OF_STREAM,
37         NAL_FILLER_DATA,
38         NAL_PREFIX_SVC = 14
39 } mc_nal_unit_type_e;
40
41 enum {
42         MC_EXIST_SPS    = 1 << 0,
43         MC_EXIST_PPS    = 1 << 1,
44         MC_EXIST_IDR    = 1 << 2,
45         MC_EXIST_SLICE  = 1 << 3,
46
47         MC_VALID_HEADER = (MC_EXIST_SPS | MC_EXIST_PPS),
48         MC_VALID_FIRST_SLICE = (MC_EXIST_SPS | MC_EXIST_PPS | MC_EXIST_IDR)
49 };
50
51 #define CHECK_VALID_PACKET(state, expected_state) \
52         ((state & (expected_state)) == (expected_state))
53
54 static const unsigned int mask[33] = {
55         0x00000000, 0x00000001, 0x00000003, 0x00000007,
56         0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
57         0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
58         0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
59         0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
60         0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
61         0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
62         0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
63         0xffffffff
64 };
65
66 struct _mc_bitstream_t {
67         unsigned char *data;
68         unsigned int numBytes;
69         unsigned int bytePos;
70         unsigned int buffer;
71         unsigned int dataBitPos;
72         unsigned int bitcnt;
73 };
74
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78
79 #define MC_READ16B(x) ((((const unsigned char*)(x))[0] << 8) | ((const unsigned char*)(x))[1])
80
81 #define MC_READ32B(x) ((((const unsigned char*)(x))[0] << 24) | \
82                 (((const unsigned char*)(x))[1] << 16) | \
83                 (((const unsigned char*)(x))[2] <<  8) | \
84                 ((const unsigned char*)(x))[3])
85
86 void mc_init_bits(mc_bitstream_t *stream, unsigned char *data, int size);
87 short mc_show_bits(mc_bitstream_t *stream, unsigned char nbits, unsigned int *pulOutData);
88 short mc_read_bits(mc_bitstream_t *stream, unsigned char nbits, unsigned int *pulOutData);
89 short mc_byte_align(mc_bitstream_t *stream);
90
91 bool _mc_is_voss(unsigned char *buf, int size, int *codec_size);
92 bool _mc_is_ivop(unsigned char *p, int size, int pos);
93 bool _mc_is_vop(unsigned char *p, int size, int pos);
94
95 int __mc_decode_sps(mc_bitstream_t *pstream, int *width, int *height);
96 unsigned int __mc_bytestream_to_nal(unsigned char* data, int size);
97 int _mc_check_h264_bytestream(unsigned char *nal, int byte_length, bool port, bool *codec_config, bool *sync_flag, bool *slice);
98 int _mc_check_valid_h263_frame(unsigned char *p, int size);
99 bool _mc_check_h263_out_bytestream(unsigned char *p, int buf_length, bool* need_sync_flag);
100 int _mc_check_mpeg4_out_bytestream(unsigned char *buf, int buf_length, bool* need_codec_data, bool *need_sync_flag);
101
102 int _mc_get_h264_codecdata_size(guint8 *data, int size);
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif /* __TIZEN_MEDIA_CODEC_BITSTREAM_H__ */