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;
26 NAL_SLICE_NO_PARTITIONING = 1,
32 NAL_SEQUENCE_PARAMETER_SET,
33 NAL_PICTURE_PARAMETER_SET,
34 NAL_PICTURE_DELIMITER,
42 MC_EXIST_SPS = 1 << 0,
43 MC_EXIST_PPS = 1 << 1,
44 MC_EXIST_IDR = 1 << 2,
45 MC_EXIST_SLICE = 1 << 3,
47 MC_VALID_HEADER = (MC_EXIST_SPS | MC_EXIST_PPS),
48 MC_VALID_FIRST_SLICE = (MC_EXIST_SPS | MC_EXIST_PPS | MC_EXIST_IDR)
51 #define CHECK_VALID_PACKET(state, expected_state) \
52 ((state & (expected_state)) == (expected_state))
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,
66 struct _mc_bitstream_t {
68 unsigned int numBytes;
71 unsigned int dataBitPos;
79 #define MC_READ16B(x) ((((const unsigned char*)(x))[0] << 8) | ((const unsigned char*)(x))[1])
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])
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);
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);
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);
102 int _mc_get_h264_codecdata_size(guint8 *data, int size);
108 #endif /* __TIZEN_MEDIA_CODEC_BITSTREAM_H__ */