diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/BitstreamConverter.h | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2 kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip | |
sync with upstream
Diffstat (limited to 'xbmc/utils/BitstreamConverter.h')
| -rw-r--r-- | xbmc/utils/BitstreamConverter.h | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/xbmc/utils/BitstreamConverter.h b/xbmc/utils/BitstreamConverter.h new file mode 100644 index 0000000..9244870 --- /dev/null +++ b/xbmc/utils/BitstreamConverter.h | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2010-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #pragma once | ||
| 10 | |||
| 11 | #include <stdint.h> | ||
| 12 | |||
| 13 | extern "C" { | ||
| 14 | #include <libavutil/avutil.h> | ||
| 15 | #include <libavformat/avformat.h> | ||
| 16 | #include <libavfilter/avfilter.h> | ||
| 17 | #include <libavcodec/avcodec.h> | ||
| 18 | } | ||
| 19 | |||
| 20 | typedef struct | ||
| 21 | { | ||
| 22 | const uint8_t *data; | ||
| 23 | const uint8_t *end; | ||
| 24 | int head; | ||
| 25 | uint64_t cache; | ||
| 26 | } nal_bitstream; | ||
| 27 | |||
| 28 | typedef struct mpeg2_sequence | ||
| 29 | { | ||
| 30 | uint32_t width; | ||
| 31 | uint32_t height; | ||
| 32 | uint32_t fps_rate; | ||
| 33 | uint32_t fps_scale; | ||
| 34 | float ratio; | ||
| 35 | uint32_t ratio_info; | ||
| 36 | } mpeg2_sequence; | ||
| 37 | |||
| 38 | typedef struct | ||
| 39 | { | ||
| 40 | int profile_idc; | ||
| 41 | int level_idc; | ||
| 42 | int sps_id; | ||
| 43 | |||
| 44 | int chroma_format_idc; | ||
| 45 | int separate_colour_plane_flag; | ||
| 46 | int bit_depth_luma_minus8; | ||
| 47 | int bit_depth_chroma_minus8; | ||
| 48 | int qpprime_y_zero_transform_bypass_flag; | ||
| 49 | int seq_scaling_matrix_present_flag; | ||
| 50 | |||
| 51 | int log2_max_frame_num_minus4; | ||
| 52 | int pic_order_cnt_type; | ||
| 53 | int log2_max_pic_order_cnt_lsb_minus4; | ||
| 54 | |||
| 55 | int max_num_ref_frames; | ||
| 56 | int gaps_in_frame_num_value_allowed_flag; | ||
| 57 | int pic_width_in_mbs_minus1; | ||
| 58 | int pic_height_in_map_units_minus1; | ||
| 59 | |||
| 60 | int frame_mbs_only_flag; | ||
| 61 | int mb_adaptive_frame_field_flag; | ||
| 62 | |||
| 63 | int direct_8x8_inference_flag; | ||
| 64 | |||
| 65 | int frame_cropping_flag; | ||
| 66 | int frame_crop_left_offset; | ||
| 67 | int frame_crop_right_offset; | ||
| 68 | int frame_crop_top_offset; | ||
| 69 | int frame_crop_bottom_offset; | ||
| 70 | } sps_info_struct; | ||
| 71 | |||
| 72 | class CBitstreamParser | ||
| 73 | { | ||
| 74 | public: | ||
| 75 | CBitstreamParser(); | ||
| 76 | ~CBitstreamParser(); | ||
| 77 | |||
| 78 | static bool Open(){ return true; }; | ||
| 79 | static void Close(); | ||
| 80 | static bool CanStartDecode(const uint8_t *buf, int buf_size); | ||
| 81 | }; | ||
| 82 | |||
| 83 | class CBitstreamConverter | ||
| 84 | { | ||
| 85 | public: | ||
| 86 | CBitstreamConverter(); | ||
| 87 | ~CBitstreamConverter(); | ||
| 88 | |||
| 89 | bool Open(enum AVCodecID codec, uint8_t *in_extradata, int in_extrasize, bool to_annexb); | ||
| 90 | void Close(void); | ||
| 91 | bool NeedConvert(void) const { return m_convert_bitstream; }; | ||
| 92 | bool Convert(uint8_t *pData, int iSize); | ||
| 93 | uint8_t* GetConvertBuffer(void) const; | ||
| 94 | int GetConvertSize() const; | ||
| 95 | uint8_t* GetExtraData(void) const; | ||
| 96 | int GetExtraSize() const; | ||
| 97 | void ResetStartDecode(void); | ||
| 98 | bool CanStartDecode() const; | ||
| 99 | |||
| 100 | static bool mpeg2_sequence_header(const uint8_t *data, const uint32_t size, mpeg2_sequence *sequence); | ||
| 101 | |||
| 102 | protected: | ||
| 103 | static int avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size); | ||
| 104 | static int avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size); | ||
| 105 | int isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len); | ||
| 106 | // bitstream to bytestream (Annex B) conversion support. | ||
| 107 | bool IsIDR(uint8_t unit_type); | ||
| 108 | bool IsSlice(uint8_t unit_type); | ||
| 109 | bool BitstreamConvertInitAVC(void *in_extradata, int in_extrasize); | ||
| 110 | bool BitstreamConvertInitHEVC(void *in_extradata, int in_extrasize); | ||
| 111 | bool BitstreamConvert(uint8_t* pData, int iSize, uint8_t **poutbuf, int *poutbuf_size); | ||
| 112 | static void BitstreamAllocAndCopy(uint8_t **poutbuf, int *poutbuf_size, | ||
| 113 | const uint8_t *sps_pps, uint32_t sps_pps_size, const uint8_t *in, uint32_t in_size); | ||
| 114 | |||
| 115 | typedef struct omx_bitstream_ctx { | ||
| 116 | uint8_t length_size; | ||
| 117 | uint8_t first_idr; | ||
| 118 | uint8_t idr_sps_pps_seen; | ||
| 119 | uint8_t *sps_pps_data; | ||
| 120 | uint32_t size; | ||
| 121 | } omx_bitstream_ctx; | ||
| 122 | |||
| 123 | uint8_t *m_convertBuffer; | ||
| 124 | int m_convertSize; | ||
| 125 | uint8_t *m_inputBuffer; | ||
| 126 | int m_inputSize; | ||
| 127 | |||
| 128 | uint32_t m_sps_pps_size; | ||
| 129 | omx_bitstream_ctx m_sps_pps_context; | ||
| 130 | bool m_convert_bitstream; | ||
| 131 | bool m_to_annexb; | ||
| 132 | |||
| 133 | uint8_t *m_extradata; | ||
| 134 | int m_extrasize; | ||
| 135 | bool m_convert_3byteTo4byteNALSize; | ||
| 136 | bool m_convert_bytestream; | ||
| 137 | AVCodecID m_codec; | ||
| 138 | bool m_start_decode; | ||
| 139 | }; | ||
