2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __TIZEN_MEDIA_CODEC_BITSTREAM_H__
18 #define __TIZEN_MEDIA_CODEC_BITSTREAM_H__
21 #include <media_codec_port.h>
23 typedef struct _mc_bitstream_t mc_bitstream_t;
27 NAL_SLICE_NO_PARTITIONING = 1,
33 NAL_SEQUENCE_PARAMETER_SET,
34 NAL_PICTURE_PARAMETER_SET,
35 NAL_PICTURE_DELIMITER,
44 MC_EXIST_SPS = 1 << 0,
45 MC_EXIST_PPS = 1 << 1,
46 MC_EXIST_IDR = 1 << 2,
47 MC_EXIST_SLICE = 1 << 3,
49 MC_VALID_HEADER = ( MC_EXIST_SPS | MC_EXIST_PPS ),
50 MC_VALID_FIRST_SLICE = ( MC_EXIST_SPS | MC_EXIST_PPS | MC_EXIST_IDR )
53 #define CHECK_VALID_PACKET(state, expected_state) \
54 ((state & (expected_state)) == (expected_state))
56 static const unsigned int mask[33] =
58 0x00000000, 0x00000001, 0x00000003, 0x00000007,
59 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
60 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
61 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
62 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
63 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
64 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
65 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
69 struct _mc_bitstream_t
72 unsigned int numBytes;
75 unsigned int dataBitPos;
84 #define MC_READ16B(x) ((((const unsigned char*)(x))[0] << 8) | ((const unsigned char*)(x))[1])
86 #define MC_READ32B(x) ((((const unsigned char*)(x))[0] << 24) | \
87 (((const unsigned char*)(x))[1] << 16) | \
88 (((const unsigned char*)(x))[2] << 8) | \
89 ((const unsigned char*)(x))[3])
91 void mc_init_bits(mc_bitstream_t *stream, unsigned char *data, int size);
92 short mc_show_bits(mc_bitstream_t *stream, unsigned char nbits, unsigned int *pulOutData);
93 short mc_read_bits( mc_bitstream_t *stream, unsigned char nbits, unsigned int *pulOutData );
94 short mc_byte_align( mc_bitstream_t *stream );
96 bool _mc_is_voss(unsigned char *buf, int size, int *codec_size);
97 bool _mc_is_ivop(unsigned char *p, int size, int pos);
98 bool _mc_is_vop(unsigned char *p, int size, int pos);
101 int __mc_decode_sps(mc_bitstream_t *pstream, int *width, int *height);
102 unsigned int __mc_bytestream_to_nal( unsigned char* data, int size );
103 int _mc_check_h264_bytestream ( unsigned char *nal, int byte_length, bool port, bool *codec_config, bool *sync_flag, bool *slice);
104 int _mc_check_valid_h263_frame(unsigned char *p, int size);
105 bool _mc_check_h263_out_bytestream(unsigned char *p, int buf_length, bool* need_sync_flag);
106 int _mc_check_mpeg4_out_bytestream(unsigned char *buf, int buf_length, bool* need_codec_data, bool *need_sync_flag);
113 #endif /* __TIZEN_MEDIA_CODEC_BITSTREAM_H__ */