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

[Depends][Bento4] Cleanups to remove some patches #1654

Draft
wants to merge 4 commits into
base: Piers
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion depends/common/bento4/bento4.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a9b231b63159b3a4d9e47c5328b476308852bf092ccb9ce98f7cf46a386465ce
c9af58502fc592cdc211ca199961df4b17bfbe36456dbf3b2eeb0dc2ce313beb
2 changes: 1 addition & 1 deletion depends/common/bento4/bento4.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bento4 https://github.com/xbmc/Bento4/archive/refs/tags/1.6.0-641-3-Omega.tar.gz
bento4 https://github.com/CastagnaIT/Bento4/archive/refs/heads/bento_eac3_test.tar.gz
2 changes: 1 addition & 1 deletion depends/common/bento4/flags.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-DBUILD_APPS=OFF
-DBUILD_APPS=OFF -DUSE_DEFAULT_OSX_ARCHITECTURES=OFF
42 changes: 30 additions & 12 deletions src/codechandler/AVCCodecHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@

using namespace UTILS;

namespace
{
unsigned int ReadGolomb(AP4_BitReader& bits)
{
unsigned int leading_zeros = 0;
while (bits.ReadBit() == 0)
{
leading_zeros++;
if (leading_zeros > 32)
return 0; // safeguard
}
if (leading_zeros)
{
return (1 << leading_zeros) - 1 + bits.ReadBits(leading_zeros);
}
else
{
return 0;
}
}
} // unnamed namespace

AVCCodecHandler::AVCCodecHandler(AP4_SampleDescription* sd)
: CodecHandler{sd},
m_countPictureSetIds{0},
Expand Down Expand Up @@ -106,7 +128,8 @@ void AVCCodecHandler::UpdatePPSId(const AP4_DataBuffer& buffer)
if (!m_needSliceInfo)
return;

//Search the Slice header NALU
// Iterate data to find all NALU units slice headers of type 5 "Coded slice of an IDR picture"
// to get the pic_parameter_set_id value of last NALU
const AP4_Byte* data(buffer.GetData());
AP4_Size dataSize(buffer.GetDataSize());
for (; dataSize;)
Expand Down Expand Up @@ -145,25 +168,20 @@ void AVCCodecHandler::UpdatePPSId(const AP4_DataBuffer& buffer)
if (m_countPictureSetIds < 2)
m_needSliceInfo = false;

unsigned int nal_unit_type = *data & 0x1F;
unsigned int nalUnitType = *data & 0x1F;

if (
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_OF_NON_IDR_PICTURE ||
nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_OF_IDR_PICTURE //||
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_A ||
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_B ||
//nal_unit_type == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_DATA_PARTITION_C
)
// Following code is a simplification of AP4_AvcFrameParser::ParseSliceHeader from AP4_AvcFrameParser::Feed
if (nalUnitType == AP4_AVC_NAL_UNIT_TYPE_CODED_SLICE_OF_IDR_PICTURE)
{
AP4_DataBuffer unescaped(data, dataSize);
AP4_NalParser::Unescape(unescaped);
AP4_BitReader bits(unescaped.GetData(), unescaped.GetDataSize());

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

AP4_AvcFrameParser::ReadGolomb(bits); // first_mb_in_slice
AP4_AvcFrameParser::ReadGolomb(bits); // slice_type
m_pictureId = AP4_AvcFrameParser::ReadGolomb(bits); //picture_set_id
ReadGolomb(bits); // first_mb_in_slice
ReadGolomb(bits); // slice_type
m_pictureId = ReadGolomb(bits); // pic_parameter_set_id
}
// move to the next NAL unit
data += naluSize;
Expand Down
54 changes: 28 additions & 26 deletions src/codechandler/AVCCodecHandler.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/*
* Copyright (C) 2022 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 "CodecHandler.h"

class ATTR_DLL_LOCAL AVCCodecHandler : public CodecHandler
{
public:
AVCCodecHandler(AP4_SampleDescription* sd);
bool ExtraDataToAnnexB() override;
void UpdatePPSId(const AP4_DataBuffer& buffer) override;
bool GetInformation(kodi::addon::InputstreamInfo& info) override;
STREAMCODEC_PROFILE GetProfile() override { return m_codecProfile; };

private:
unsigned int m_countPictureSetIds;
STREAMCODEC_PROFILE m_codecProfile;
bool m_needSliceInfo;
};
/*
* Copyright (C) 2022 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 "CodecHandler.h"

class ATTR_DLL_LOCAL AVCCodecHandler : public CodecHandler
{
public:
AVCCodecHandler(AP4_SampleDescription* sd);
bool ExtraDataToAnnexB() override;
void UpdatePPSId(const AP4_DataBuffer& buffer) override;
bool GetInformation(kodi::addon::InputstreamInfo& info) override;
STREAMCODEC_PROFILE GetProfile() override { return m_codecProfile; };

private:
unsigned int m_countPictureSetIds;
STREAMCODEC_PROFILE m_codecProfile;
bool m_needSliceInfo;
AP4_UI08 m_pictureId{0};
AP4_UI08 m_pictureIdPrev{AP4_AVC_PPS_MAX_ID};
};
9 changes: 3 additions & 6 deletions src/codechandler/CodecHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
class ATTR_DLL_LOCAL CodecHandler
{
public:
CodecHandler(AP4_SampleDescription* sd)
: m_sampleDescription(sd), m_naluLengthSize(0), m_pictureId(0), m_pictureIdPrev(0xFF){};
virtual ~CodecHandler(){};
CodecHandler(AP4_SampleDescription* sd) : m_sampleDescription(sd) {}
virtual ~CodecHandler() = default;

virtual void UpdatePPSId(const AP4_DataBuffer& buffer) {}

Expand All @@ -46,9 +45,7 @@ class ATTR_DLL_LOCAL CodecHandler

AP4_SampleDescription* m_sampleDescription;
AP4_DataBuffer m_extraData;
AP4_UI08 m_naluLengthSize;
AP4_UI08 m_pictureId;
AP4_UI08 m_pictureIdPrev;
AP4_UI08 m_naluLengthSize{0};

protected:
bool UpdateInfoCodecName(kodi::addon::InputstreamInfo& info, const char* codecName);
Expand Down
14 changes: 12 additions & 2 deletions src/samplereader/FragmentedSampleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ namespace
{
constexpr uint8_t MP4_TFRFBOX_UUID[] = {0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f};

constexpr AP4_UI32 MP4_SAMPLE_FORMAT_WVTT = AP4_ATOM_TYPE('w', 'v', 't', 't');

class MP4UnknownUuidAtom : public AP4_UnknownUuidAtom
{
public:
// Expose atom data
const AP4_DataBuffer& GetData() { return m_Data; }
};

} // unnamed namespace


Expand Down Expand Up @@ -484,7 +494,7 @@ void CFragmentedSampleReader::UpdateSampleDescription()
case AP4_SAMPLE_FORMAT_STPP:
m_codecHandler = new TTMLCodecHandler(desc, false);
break;
case AP4_SAMPLE_FORMAT_WVTT:
case MP4_SAMPLE_FORMAT_WVTT:
m_codecHandler = new WebVTTCodecHandler(desc, false);
break;
case AP4_SAMPLE_FORMAT_VP9:
Expand All @@ -505,7 +515,7 @@ void CFragmentedSampleReader::UpdateSampleDescription()

void CFragmentedSampleReader::ParseTrafTfrf(AP4_UuidAtom* uuidAtom)
{
const AP4_DataBuffer& buf{AP4_DYNAMIC_CAST(AP4_UnknownUuidAtom, uuidAtom)->GetData()};
const AP4_DataBuffer& buf{static_cast<MP4UnknownUuidAtom*>(uuidAtom)->GetData()};
CCharArrayParser parser;
parser.Reset(buf.GetData(), buf.GetDataSize());

Expand Down