2
1

0006-Implement-SPS-Frame-parser.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. From 441247d84e8493a49d234fe062100b049956de90 Mon Sep 17 00:00:00 2001
  2. From: peak3d <pfau@peak3d.de>
  3. Date: Thu, 22 Jul 2021 10:34:42 +0200
  4. Subject: [PATCH] Implement SPS Frame parser
  5. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  6. ---
  7. Source/C++/Codecs/Ap4AvcParser.cpp | 26 ++++++++++++++++++++++++++
  8. Source/C++/Codecs/Ap4AvcParser.h | 5 +++++
  9. 2 files changed, 31 insertions(+)
  10. diff --git a/Source/C++/Codecs/Ap4AvcParser.cpp b/Source/C++/Codecs/Ap4AvcParser.cpp
  11. index 7f4fc34..cfa841d 100644
  12. --- a/Source/C++/Codecs/Ap4AvcParser.cpp
  13. +++ b/Source/C++/Codecs/Ap4AvcParser.cpp
  14. @@ -1112,6 +1112,32 @@ AP4_AvcFrameParser::AppendNalUnitData(const unsigned char* data, unsigned int da
  15. m_AccessUnitData.Append(new AP4_DataBuffer(data, data_size));
  16. }
  17. +/*----------------------------------------------------------------------
  18. +| AP4_AvcFrameParser::Feed
  19. ++---------------------------------------------------------------------*/
  20. +AP4_Result AP4_AvcFrameParser::ParseFrameForSPS(const AP4_Byte* data, AP4_Size data_size, AP4_UI08 naluLengthSize, AP4_AvcSequenceParameterSet &sps)
  21. +{
  22. + if (data_size < naluLengthSize)
  23. + return AP4_ERROR_EOS;
  24. +
  25. + while (data_size > naluLengthSize)
  26. + {
  27. + AP4_Size nalSize(0);
  28. + for (unsigned int i(0); i < naluLengthSize; ++i) { nalSize = (nalSize << 8) + *data++; };
  29. + data_size -= naluLengthSize;
  30. + if (nalSize > data_size)
  31. + return AP4_ERROR_INVALID_PARAMETERS;
  32. +
  33. + if ((*data & 0x1F) == AP4_AVC_NAL_UNIT_TYPE_SPS)
  34. + {
  35. + AP4_AvcFrameParser fp;
  36. + return fp.ParseSPS(data, data_size, sps);
  37. + }
  38. + data_size -= nalSize;
  39. + }
  40. + return AP4_SUCCESS;
  41. +}
  42. +
  43. /*----------------------------------------------------------------------
  44. | AP4_AvcFrameParser::Feed
  45. +---------------------------------------------------------------------*/
  46. diff --git a/Source/C++/Codecs/Ap4AvcParser.h b/Source/C++/Codecs/Ap4AvcParser.h
  47. index 431a294..99c5320 100644
  48. --- a/Source/C++/Codecs/Ap4AvcParser.h
  49. +++ b/Source/C++/Codecs/Ap4AvcParser.h
  50. @@ -258,6 +258,11 @@ public:
  51. AP4_AvcFrameParser();
  52. ~AP4_AvcFrameParser();
  53. + static AP4_Result ParseFrameForSPS(const AP4_Byte* data,
  54. + AP4_Size data_size,
  55. + AP4_UI08 naluLengthSize,
  56. + AP4_AvcSequenceParameterSet &sps);
  57. +
  58. /**
  59. * Feed some data to the parser and look for the next NAL Unit.
  60. *
  61. --
  62. 2.30.2