From 336cd62973f0795a8510dce7132f32fe4ffa28be Mon Sep 17 00:00:00 2001 From: CastagnaIT Date: Thu, 15 Aug 2024 10:26:02 +0200 Subject: [PATCH 1/4] [AVCCodecHandler] Some code cleanups Most rilevant change, add our implementation of ReadGolomb in order to remove bento4 custom patch --- src/codechandler/AVCCodecHandler.cpp | 42 +++++++++++++++------- src/codechandler/AVCCodecHandler.h | 54 ++++++++++++++-------------- src/codechandler/CodecHandler.h | 9 ++--- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/src/codechandler/AVCCodecHandler.cpp b/src/codechandler/AVCCodecHandler.cpp index 7f7ef7398..9d816e01b 100644 --- a/src/codechandler/AVCCodecHandler.cpp +++ b/src/codechandler/AVCCodecHandler.cpp @@ -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}, @@ -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;) @@ -145,15 +168,10 @@ 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); @@ -161,9 +179,9 @@ void AVCCodecHandler::UpdatePPSId(const AP4_DataBuffer& buffer) 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; diff --git a/src/codechandler/AVCCodecHandler.h b/src/codechandler/AVCCodecHandler.h index b39aba54a..79719ad17 100644 --- a/src/codechandler/AVCCodecHandler.h +++ b/src/codechandler/AVCCodecHandler.h @@ -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}; +}; diff --git a/src/codechandler/CodecHandler.h b/src/codechandler/CodecHandler.h index a77ffdb48..2c8d5d257 100644 --- a/src/codechandler/CodecHandler.h +++ b/src/codechandler/CodecHandler.h @@ -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) {} @@ -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); From 70709a4a8f51efbcfc3b8350f22d499ee32f2f62 Mon Sep 17 00:00:00 2001 From: CastagnaIT Date: Thu, 15 Aug 2024 10:36:04 +0200 Subject: [PATCH 2/4] [FragmentedSampleReader][Cleanup] add our wvtt format define Added to remove bento4 custom patch --- src/samplereader/FragmentedSampleReader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/samplereader/FragmentedSampleReader.cpp b/src/samplereader/FragmentedSampleReader.cpp index 3adc07b1c..1015083c9 100644 --- a/src/samplereader/FragmentedSampleReader.cpp +++ b/src/samplereader/FragmentedSampleReader.cpp @@ -28,6 +28,8 @@ 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'); } // unnamed namespace @@ -484,7 +486,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: From 3f08c82475e68266cd30d82feaae083af862e8b5 Mon Sep 17 00:00:00 2001 From: CastagnaIT Date: Sat, 24 Aug 2024 13:52:09 +0200 Subject: [PATCH 3/4] [FragmentSampleReader] Use custom AP4_UnknownUuidAtom This allow to remove custom bento4 changes --- src/samplereader/FragmentedSampleReader.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/samplereader/FragmentedSampleReader.cpp b/src/samplereader/FragmentedSampleReader.cpp index 1015083c9..e5663cd83 100644 --- a/src/samplereader/FragmentedSampleReader.cpp +++ b/src/samplereader/FragmentedSampleReader.cpp @@ -30,6 +30,14 @@ constexpr uint8_t MP4_TFRFBOX_UUID[] = {0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46 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 @@ -507,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(uuidAtom)->GetData()}; CCharArrayParser parser; parser.Reset(buf.GetData(), buf.GetDataSize()); From 612a45de91c3ec47605f14918b7223d03bf18212 Mon Sep 17 00:00:00 2001 From: CastagnaIT Date: Sat, 24 Aug 2024 15:56:03 +0200 Subject: [PATCH 4/4] bento4 temp --- depends/common/bento4/bento4.sha256 | 2 +- depends/common/bento4/bento4.txt | 2 +- depends/common/bento4/flags.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/depends/common/bento4/bento4.sha256 b/depends/common/bento4/bento4.sha256 index ea118ca9d..ab6838c11 100644 --- a/depends/common/bento4/bento4.sha256 +++ b/depends/common/bento4/bento4.sha256 @@ -1 +1 @@ -a9b231b63159b3a4d9e47c5328b476308852bf092ccb9ce98f7cf46a386465ce \ No newline at end of file +c9af58502fc592cdc211ca199961df4b17bfbe36456dbf3b2eeb0dc2ce313beb \ No newline at end of file diff --git a/depends/common/bento4/bento4.txt b/depends/common/bento4/bento4.txt index 72cf572be..7b99a5fd1 100644 --- a/depends/common/bento4/bento4.txt +++ b/depends/common/bento4/bento4.txt @@ -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 diff --git a/depends/common/bento4/flags.txt b/depends/common/bento4/flags.txt index 059c17e45..11b57a7d7 100644 --- a/depends/common/bento4/flags.txt +++ b/depends/common/bento4/flags.txt @@ -1 +1 @@ --DBUILD_APPS=OFF +-DBUILD_APPS=OFF -DUSE_DEFAULT_OSX_ARCHITECTURES=OFF