Skip to content

Commit 7a442c9

Browse files
authored
Merge pull request #1968 from CastagnaIT/cleanup_bento
[Depends][Bento4] Cleanups to remove some patches
2 parents 630afb4 + acf8233 commit 7a442c9

File tree

9 files changed

+102
-32
lines changed

9 files changed

+102
-32
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a9b231b63159b3a4d9e47c5328b476308852bf092ccb9ce98f7cf46a386465ce
1+
6ba2f975cd0537f32ea28f9f55251d75083ee1560360ea00e6860073c29774c1

depends/common/bento4/bento4.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bento4 https://github.com/xbmc/Bento4/archive/refs/tags/1.6.0-641-3-Omega.tar.gz
1+
bento4 https://github.com/xbmc/Bento4/archive/refs/tags/1.6.0-641-4-Piers.tar.gz

src/codechandler/AVCCodecHandler.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@
1212

1313
using namespace UTILS;
1414

15+
namespace
16+
{
17+
unsigned int ReadGolomb(AP4_BitReader& bits)
18+
{
19+
unsigned int leadingZeros = 0;
20+
while (bits.ReadBit() == 0)
21+
{
22+
leadingZeros++;
23+
if (leadingZeros >= 32)
24+
return 0; // safeguard
25+
}
26+
if (leadingZeros)
27+
{
28+
return (1 << leadingZeros) - 1 + bits.ReadBits(leadingZeros);
29+
}
30+
else
31+
{
32+
return 0;
33+
}
34+
}
35+
} // unnamed namespace
36+
1537
AVCCodecHandler::AVCCodecHandler(AP4_SampleDescription* sd)
1638
: CodecHandler{sd},
1739
m_countPictureSetIds{0},
@@ -87,7 +109,8 @@ void AVCCodecHandler::UpdatePPSId(const AP4_DataBuffer& buffer)
87109
if (!m_needSliceInfo)
88110
return;
89111

90-
//Search the Slice header NALU
112+
// Iterate data to find all NALU units slice headers of type 5 "Coded slice of an IDR picture"
113+
// to get the pic_parameter_set_id value of last NALU
91114
const AP4_Byte* data(buffer.GetData());
92115
AP4_Size dataSize(buffer.GetDataSize());
93116
for (; dataSize;)
@@ -126,25 +149,20 @@ void AVCCodecHandler::UpdatePPSId(const AP4_DataBuffer& buffer)
126149
if (m_countPictureSetIds < 2)
127150
m_needSliceInfo = false;
128151

129-
unsigned int nal_unit_type = *data & 0x1F;
152+
unsigned int nalUnitType = *data & 0x1F;
130153

131-
if (
132-
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_OF_NON_IDR_PICTURE ||
133-
nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_OF_IDR_PICTURE //||
134-
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_A ||
135-
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_B ||
136-
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_C
137-
)
154+
// Following code is a simplification of AP4_AvcFrameParser::ParseSliceHeader from AP4_AvcFrameParser::Feed
155+
if (nalUnitType == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_OF_IDR_PICTURE)
138156
{
139157
AP4_DataBuffer unescaped(data, dataSize);
140158
AP4_NalParser::Unescape(unescaped);
141159
AP4_BitReader bits(unescaped.GetData(), unescaped.GetDataSize());
142160

143161
bits.SkipBits(8); // NAL Unit Type
144162

145-
AP4_AvcFrameParser::ReadGolomb(bits); // first_mb_in_slice
146-
AP4_AvcFrameParser::ReadGolomb(bits); // slice_type
147-
m_pictureId = AP4_AvcFrameParser::ReadGolomb(bits); //picture_set_id
163+
ReadGolomb(bits); // first_mb_in_slice
164+
ReadGolomb(bits); // slice_type
165+
m_pictureId = ReadGolomb(bits); // pic_parameter_set_id
148166
}
149167
// move to the next NAL unit
150168
data += naluSize;

src/codechandler/AVCCodecHandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ class ATTR_DLL_LOCAL AVCCodecHandler : public CodecHandler
2424
unsigned int m_countPictureSetIds;
2525
bool m_needSliceInfo;
2626
STREAMCODEC_PROFILE m_codecProfile;
27+
AP4_UI08 m_pictureId{0};
28+
AP4_UI08 m_pictureIdPrev{AP4_AVC_PPS_MAX_ID};
2729
};

src/codechandler/CodecHandler.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
#include "CodecHandler.h"
1010

11+
#include "utils/Bento4Utils.h"
12+
13+
using namespace UTILS;
14+
1115
namespace
1216
{
1317
constexpr const char* NETFLIX_FRAMERATE_UUID = "NetflixFrameRate";
@@ -19,21 +23,26 @@ bool CodecHandler::GetInformation(kodi::addon::InputstreamInfo& info)
1923
m_sampleDescription->GetType() != AP4_SampleDescription::Type::TYPE_UNKNOWN)
2024
{
2125
// Netflix Framerate
22-
AP4_Atom* atom;
23-
AP4_UnknownUuidAtom* nxfr;
24-
atom = m_sampleDescription->GetDetails().GetChild(
26+
AP4_Atom* atom = m_sampleDescription->GetDetails().GetChild(
2527
reinterpret_cast<const AP4_UI08*>(NETFLIX_FRAMERATE_UUID));
26-
if (atom && (nxfr = dynamic_cast<AP4_UnknownUuidAtom*>(atom)) &&
27-
nxfr->GetData().GetDataSize() == 10)
28+
29+
auto* unknownUuidAtom = dynamic_cast<AP4_UnknownUuidAtom*>(atom);
30+
if (unknownUuidAtom)
2831
{
29-
unsigned int fpsRate = nxfr->GetData().GetData()[7] | nxfr->GetData().GetData()[6] << 8;
30-
unsigned int fpsScale = nxfr->GetData().GetData()[9] | nxfr->GetData().GetData()[8] << 8;
32+
auto* accessor = reinterpret_cast<BENTO4::FMP4UnknownUuidAtom*>(unknownUuidAtom);
33+
const AP4_DataBuffer& data = accessor->GetData();
3134

32-
if (info.GetFpsScale() != fpsScale || info.GetFpsRate() != fpsRate)
35+
if (data.GetDataSize() == 10)
3336
{
34-
info.SetFpsScale(fpsScale);
35-
info.SetFpsRate(fpsRate);
36-
return true;
37+
unsigned int fpsRate = data.GetData()[7] | data.GetData()[6] << 8;
38+
unsigned int fpsScale = data.GetData()[9] | data.GetData()[8] << 8;
39+
40+
if (info.GetFpsScale() != fpsScale || info.GetFpsRate() != fpsRate)
41+
{
42+
info.SetFpsScale(fpsScale);
43+
info.SetFpsRate(fpsRate);
44+
return true;
45+
}
3746
}
3847
}
3948
}

src/codechandler/CodecHandler.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class ATTR_DLL_LOCAL CodecHandler
2424
{
2525
public:
2626
CodecHandler(AP4_SampleDescription* sd, AP4_Track* track = nullptr)
27-
: m_sampleDescription(sd), m_naluLengthSize(0), m_pictureId(0), m_pictureIdPrev(0xFF),
28-
m_track(track){};
27+
: m_sampleDescription(sd), m_track(track){};
2928
virtual ~CodecHandler(){};
3029

3130
virtual void UpdatePPSId(const AP4_DataBuffer& buffer) {}
@@ -65,9 +64,7 @@ class ATTR_DLL_LOCAL CodecHandler
6564

6665
AP4_SampleDescription* m_sampleDescription;
6766
std::vector<uint8_t> m_extraData;
68-
AP4_UI08 m_naluLengthSize;
69-
AP4_UI08 m_pictureId;
70-
AP4_UI08 m_pictureIdPrev;
67+
AP4_UI08 m_naluLengthSize{0};
7168
AP4_Track* m_track;
7269

7370
protected:

src/samplereader/FragmentedSampleReader.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "codechandler/VP9CodecHandler.h"
1919
#include "codechandler/WebVTTCodecHandler.h"
2020
#include "common/AdaptiveCencSampleDecrypter.h"
21+
#include "utils/Bento4Utils.h"
2122
#include "utils/CharArrayParser.h"
2223
#include "utils/Utils.h"
2324
#include "utils/log.h"
@@ -30,6 +31,8 @@ namespace
3031
{
3132
constexpr uint8_t MP4_TFRFBOX_UUID[] = {0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
3233
0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f};
34+
35+
constexpr AP4_UI32 FMP4_SAMPLE_FORMAT_WVTT = AP4_ATOM_TYPE('w', 'v', 't', 't');
3336
} // unnamed namespace
3437

3538

@@ -583,7 +586,7 @@ void CFragmentedSampleReader::UpdateSampleDescription()
583586
case AP4_SAMPLE_FORMAT_STPP:
584587
m_codecHandler = new TTMLCodecHandler(desc, false);
585588
break;
586-
case AP4_SAMPLE_FORMAT_WVTT:
589+
case FMP4_SAMPLE_FORMAT_WVTT:
587590
m_codecHandler = new WebVTTCodecHandler(desc, false);
588591
break;
589592
case AP4_SAMPLE_FORMAT_VP9:
@@ -601,7 +604,15 @@ void CFragmentedSampleReader::UpdateSampleDescription()
601604

602605
void CFragmentedSampleReader::ParseTrafTfrf(AP4_UuidAtom* uuidAtom)
603606
{
604-
const AP4_DataBuffer& buf{AP4_DYNAMIC_CAST(AP4_UnknownUuidAtom, uuidAtom)->GetData()};
607+
auto* unknownUuidAtom = dynamic_cast<AP4_UnknownUuidAtom*>(uuidAtom);
608+
if (!unknownUuidAtom)
609+
{
610+
LOG::LogF(LOGERROR, "Invalid atom type passed to ParseTrafTfrf. Expected AP4_UnknownUuidAtom.");
611+
return;
612+
}
613+
614+
auto* accessor = reinterpret_cast<BENTO4::FMP4UnknownUuidAtom*>(unknownUuidAtom);
615+
const AP4_DataBuffer& buf{accessor->GetData()};
605616
CCharArrayParser parser;
606617
parser.Reset(buf.GetData(), buf.GetDataSize());
607618

src/utils/Bento4Utils.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2025 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+
#ifdef INPUTSTREAM_TEST_BUILD
12+
#include "test/KodiStubs.h"
13+
#else
14+
#include <kodi/AddonBase.h>
15+
#endif
16+
17+
#include <bento4/Ap4.h>
18+
19+
namespace UTILS
20+
{
21+
namespace BENTO4
22+
{
23+
24+
// \brief Accessory for accessing AP4_UnknownUuidAtom data
25+
class ATTR_DLL_LOCAL FMP4UnknownUuidAtom : public AP4_UnknownUuidAtom
26+
{
27+
public:
28+
const AP4_DataBuffer& GetData() { return m_Data; }
29+
};
30+
31+
} // namespace BASE64
32+
} // namespace UTILS

src/utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(SOURCES
1616

1717
set(HEADERS
1818
Base64Utils.h
19+
Bento4Utils.h
1920
CharArrayParser.h
2021
CryptoUtils.h
2122
CurlUtils.h

0 commit comments

Comments
 (0)