diff options
author | thexai <58434170+thexai@users.noreply.github.com> | 2024-05-12 08:53:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-12 08:53:57 +0200 |
commit | f5102b7760909b6390bfa6be0d34bfe7491b5b9a (patch) | |
tree | 38b9cfec282db3b587745c0367ccdb100f680b9c | |
parent | b0d72e8792668d69089b48af0a2ef3eb52d42e02 (diff) | |
parent | d80c9da19f0956b9edf8fb200861c1f1f45780f3 (diff) | |
download | xbmc-f5102b7760909b6390bfa6be0d34bfe7491b5b9a.tar.xz |
Merge pull request #25183 from thexai/cleanup-read/write-bits
[cleanup] Use FFmpeg for AV_RBxx, AV_WBxx and AV_WLxx functions and drop 'BitstreamWriter.cpp'
-rw-r--r-- | xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp | 10 | ||||
-rw-r--r-- | xbmc/utils/BitstreamConverter.cpp | 11 | ||||
-rw-r--r-- | xbmc/utils/BitstreamReader.cpp | 7 | ||||
-rw-r--r-- | xbmc/utils/BitstreamReader.h | 25 | ||||
-rw-r--r-- | xbmc/utils/BitstreamWriter.cpp | 109 | ||||
-rw-r--r-- | xbmc/utils/BitstreamWriter.h | 50 | ||||
-rw-r--r-- | xbmc/utils/CMakeLists.txt | 2 |
7 files changed, 19 insertions, 195 deletions
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp index ce6de6f20d..2d9e3279f0 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp @@ -28,7 +28,6 @@ #include "settings/SettingsComponent.h" #include "settings/lib/Setting.h" #include "utils/BitstreamConverter.h" -#include "utils/BitstreamWriter.h" #include "utils/CPUInfo.h" #include "utils/StringUtils.h" #include "utils/TimeUtils.h" @@ -58,6 +57,11 @@ #include <androidjni/SurfaceTexture.h> #include <androidjni/UUID.h> +extern "C" +{ +#include <libavutil/intreadwrite.h> +} + using namespace KODI::MESSAGING; enum MEDIACODEC_STATES @@ -632,10 +636,10 @@ bool CDVDVideoCodecAndroidMediaCodec::Open(CDVDStreamInfo &hints, CDVDCodecOptio offset += sizeof(annexL_hdr1); memcpy(m_hints.extradata.GetData() + offset, hints.extradata.GetData(), 4); offset += 4; - BS_WL32(buf, hints.height); + AV_WL32(buf, hints.height); memcpy(m_hints.extradata.GetData() + offset, buf, 4); offset += 4; - BS_WL32(buf, hints.width); + AV_WL32(buf, hints.width); memcpy(m_hints.extradata.GetData() + offset, buf, 4); offset += 4; memcpy(m_hints.extradata.GetData() + offset, annexL_hdr2, sizeof(annexL_hdr2)); diff --git a/xbmc/utils/BitstreamConverter.cpp b/xbmc/utils/BitstreamConverter.cpp index fe08a00a00..c485c838d8 100644 --- a/xbmc/utils/BitstreamConverter.cpp +++ b/xbmc/utils/BitstreamConverter.cpp @@ -15,14 +15,13 @@ #endif #include "BitstreamConverter.h" -#include "BitstreamReader.h" -#include "BitstreamWriter.h" #include "HevcSei.h" #include <algorithm> extern "C" { +#include <libavutil/intreadwrite.h> #ifdef HAVE_LIBDOVI #include <libdovi/rpu_parser.h> #endif @@ -626,7 +625,7 @@ bool CBitstreamConverter::Convert(uint8_t *pData, int iSize) uint8_t *nal_start = pData; while (nal_start < end) { - nal_size = BS_RB24(nal_start); + nal_size = AV_RB24(nal_start); avio_wb32(pb, nal_size); nal_start += 3; avio_write(pb, nal_start, nal_size); @@ -1087,7 +1086,7 @@ void CBitstreamConverter::BitstreamAllocAndCopy(uint8_t** poutbuf, memcpy(*poutbuf + sps_pps_size + nal_header_size + offset, in, in_size); if (!offset) { - BS_WB32(*poutbuf + sps_pps_size, 1); + AV_WB32(*poutbuf + sps_pps_size, 1); } else if (nal_header_size == 4) { @@ -1147,7 +1146,7 @@ int CBitstreamConverter::isom_write_avcc(AVIOContext *pb, const uint8_t *data, i if (len > 6) { /* check for h264 start code */ - if (BS_RB32(data) == 0x00000001 || BS_RB24(data) == 0x000001) + if (AV_RB32(data) == 0x00000001 || AV_RB24(data) == 0x000001) { uint8_t *buf=NULL, *end, *start; uint32_t sps_size=0, pps_size=0; @@ -1164,7 +1163,7 @@ int CBitstreamConverter::isom_write_avcc(AVIOContext *pb, const uint8_t *data, i { uint32_t size; uint8_t nal_type; - size = std::min<uint32_t>(BS_RB32(buf), end - buf - 4); + size = std::min<uint32_t>(AV_RB32(buf), end - buf - 4); buf += 4; nal_type = buf[0] & 0x1f; if (nal_type == 7) /* SPS */ diff --git a/xbmc/utils/BitstreamReader.cpp b/xbmc/utils/BitstreamReader.cpp index 1ec8a11057..ba71931bd9 100644 --- a/xbmc/utils/BitstreamReader.cpp +++ b/xbmc/utils/BitstreamReader.cpp @@ -8,6 +8,11 @@ #include "BitstreamReader.h" +extern "C" +{ +#include <libavutil/intreadwrite.h> +} + CBitstreamReader::CBitstreamReader(const uint8_t* buf, int len) : buffer(buf), start(buf), length(len) { @@ -90,7 +95,7 @@ const uint8_t* find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *s } p = (p < end)? p - 4 : end - 4; - *state = BS_RB32(p); + *state = AV_RB32(p); return p + 4; } diff --git a/xbmc/utils/BitstreamReader.h b/xbmc/utils/BitstreamReader.h index e25c2db217..1a3232992d 100644 --- a/xbmc/utils/BitstreamReader.h +++ b/xbmc/utils/BitstreamReader.h @@ -26,27 +26,4 @@ private: int m_posBits{0}; }; -const uint8_t* find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); - -//////////////////////////////////////////////////////////////////////////////////////////// -//! @todo refactor this so as not to need these ffmpeg routines. -//! These are not exposed in ffmpeg's API so we dupe them here. - -/* - * AVC helper functions for muxers - * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@smartjog.com> - * This is part of FFmpeg - * - * SPDX-License-Identifier: LGPL-2.1-or-later - * See LICENSES/README.md for more information. - */ -constexpr uint32_t BS_RB24(const uint8_t* x) -{ - return (x[0] << 16) | (x[1] << 8) | x[2]; -} - -constexpr uint32_t BS_RB32(const uint8_t* x) -{ - return (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3]; -} - +const uint8_t* find_start_code(const uint8_t* p, const uint8_t* end, uint32_t* state); diff --git a/xbmc/utils/BitstreamWriter.cpp b/xbmc/utils/BitstreamWriter.cpp deleted file mode 100644 index 9d247bb077..0000000000 --- a/xbmc/utils/BitstreamWriter.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#include "BitstreamWriter.h" - -CBitstreamWriter::CBitstreamWriter(uint8_t* buffer, unsigned int buffer_size, int writer_le) - : writer_le(writer_le), buf(buffer), buf_ptr(buf) -{ -} - -void CBitstreamWriter::WriteBits(int n, unsigned int value) -{ - // Write up to 32 bits into a bitstream. - unsigned int bit_buf; - int bit_left; - - if (n == 32) - { - // Write exactly 32 bits into a bitstream. - // danger, recursion in play. - int lo = value & 0xffff; - int hi = value >> 16; - if (writer_le) - { - WriteBits(16, lo); - WriteBits(16, hi); - } - else - { - WriteBits(16, hi); - WriteBits(16, lo); - } - return; - } - - bit_buf = this->bit_buf; - bit_left = this->bit_left; - - if (writer_le) - { - bit_buf |= value << (32 - bit_left); - if (n >= bit_left) { - BS_WL32(buf_ptr, bit_buf); - buf_ptr += 4; - bit_buf = (bit_left == 32) ? 0 : value >> bit_left; - bit_left += 32; - } - bit_left -= n; - } - else - { - if (n < bit_left) { - bit_buf = (bit_buf << n) | value; - bit_left -= n; - } - else { - bit_buf <<= bit_left; - bit_buf |= value >> (n - bit_left); - BS_WB32(buf_ptr, bit_buf); - buf_ptr += 4; - bit_left += 32 - n; - bit_buf = value; - } - } - - this->bit_buf = bit_buf; - this->bit_left = bit_left; -} - -void CBitstreamWriter::SkipBits(int n) -{ - // Skip the given number of bits. - // Must only be used if the actual values in the bitstream do not matter. - // If n is 0 the behavior is undefined. - bit_left -= n; - buf_ptr -= 4 * (bit_left >> 5); - bit_left &= 31; -} - -void CBitstreamWriter::FlushBits() -{ - if (!writer_le) - { - if (bit_left < 32) - bit_buf <<= bit_left; - } - while (bit_left < 32) - { - - if (writer_le) - { - *buf_ptr++ = bit_buf; - bit_buf >>= 8; - } - else - { - *buf_ptr++ = bit_buf >> 24; - bit_buf <<= 8; - } - bit_left += 8; - } - bit_left = 32; - bit_buf = 0; -} diff --git a/xbmc/utils/BitstreamWriter.h b/xbmc/utils/BitstreamWriter.h deleted file mode 100644 index 34390d8f8e..0000000000 --- a/xbmc/utils/BitstreamWriter.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -#include <stdint.h> - -class CBitstreamWriter -{ -public: - CBitstreamWriter(uint8_t *buffer, unsigned int buffer_size, int writer_le); - void WriteBits(int n, unsigned int value); - void SkipBits(int n); - void FlushBits(); - -private: - int writer_le; - uint32_t bit_buf = 0; - int bit_left = 32; - uint8_t *buf, *buf_ptr; -}; - -//////////////////////////////////////////////////////////////////////////////////////////// -//! @todo refactor this so as not to need these ffmpeg routines. -//! These are not exposed in ffmpeg's API so we dupe them here. - -/* - * AVC helper functions for muxers - * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@smartjog.com> - * This is part of FFmpeg - * - * SPDX-License-Identifier: LGPL-2.1-or-later - * See LICENSES/README.md for more information. - */ -#define BS_WB32(p, d) { \ - ((uint8_t*)(p))[3] = (d); \ - ((uint8_t*)(p))[2] = (d) >> 8; \ - ((uint8_t*)(p))[1] = (d) >> 16; \ - ((uint8_t*)(p))[0] = (d) >> 24; } - -#define BS_WL32(p, d) { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d) >> 8; \ - ((uint8_t*)(p))[2] = (d) >> 16; \ - ((uint8_t*)(p))[3] = (d) >> 24; } diff --git a/xbmc/utils/CMakeLists.txt b/xbmc/utils/CMakeLists.txt index 45f8c8c240..97ab349f0e 100644 --- a/xbmc/utils/CMakeLists.txt +++ b/xbmc/utils/CMakeLists.txt @@ -6,7 +6,6 @@ set(SOURCES ActorProtocol.cpp BitstreamConverter.cpp BitstreamReader.cpp BitstreamStats.cpp - BitstreamWriter.cpp BooleanLogic.cpp CharArrayParser.cpp CharsetConverter.cpp @@ -87,7 +86,6 @@ set(HEADERS ActorProtocol.h BitstreamConverter.h BitstreamReader.h BitstreamStats.h - BitstreamWriter.h BooleanLogic.h CharArrayParser.h CharsetConverter.h |