Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cleanup] Use FFmpeg for AV_RBxx, AV_WBxx and AV_WLxx functions and drop 'BitstreamWriter.cpp' #25183

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
11 changes: 5 additions & 6 deletions xbmc/utils/BitstreamConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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 */
Expand Down
7 changes: 6 additions & 1 deletion xbmc/utils/BitstreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
25 changes: 1 addition & 24 deletions xbmc/utils/BitstreamReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,4 @@ class CBitstreamReader
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 <[email protected]>
* 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);
109 changes: 0 additions & 109 deletions xbmc/utils/BitstreamWriter.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions xbmc/utils/BitstreamWriter.h

This file was deleted.

2 changes: 0 additions & 2 deletions xbmc/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set(SOURCES ActorProtocol.cpp
BitstreamConverter.cpp
BitstreamReader.cpp
BitstreamStats.cpp
BitstreamWriter.cpp
BooleanLogic.cpp
CharArrayParser.cpp
CharsetConverter.cpp
Expand Down Expand Up @@ -88,7 +87,6 @@ set(HEADERS ActorProtocol.h
BitstreamConverter.h
BitstreamReader.h
BitstreamStats.h
BitstreamWriter.h
BooleanLogic.h
CharArrayParser.h
CharsetConverter.h
Expand Down