avc.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_FORMATS_MP4_AVC_H_
  5. #define MEDIA_FORMATS_MP4_AVC_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <memory>
  9. #include <vector>
  10. #include "media/base/media_export.h"
  11. #include "media/formats/mp4/bitstream_converter.h"
  12. namespace media {
  13. struct SubsampleEntry;
  14. namespace mp4 {
  15. struct AVCDecoderConfigurationRecord;
  16. class MEDIA_EXPORT AVC {
  17. public:
  18. static bool ConvertFrameToAnnexB(size_t length_size,
  19. std::vector<uint8_t>* buffer,
  20. std::vector<SubsampleEntry>* subsamples);
  21. // Inserts the SPS & PPS data from |avc_config| into |buffer|.
  22. // |buffer| is expected to contain AnnexB conformant data.
  23. // |subsamples| contains the SubsampleEntry info if |buffer| contains
  24. // encrypted data.
  25. // Returns true if the param sets were successfully inserted.
  26. static bool InsertParamSetsAnnexB(
  27. const AVCDecoderConfigurationRecord& avc_config,
  28. std::vector<uint8_t>* buffer,
  29. std::vector<SubsampleEntry>* subsamples);
  30. static bool ConvertConfigToAnnexB(
  31. const AVCDecoderConfigurationRecord& avc_config,
  32. std::vector<uint8_t>* buffer);
  33. // Analyzes the contents of |buffer| for conformance to Section 7.4.1.2.3 of
  34. // ISO/IEC 14496-10. Also analyzes |buffer| and reports if it looks like a
  35. // keyframe, if such can be determined. Determination of keyframe-ness is done
  36. // only if |buffer| is conformant or if lack of conformance is detected after
  37. // detecting keyframe-ness.
  38. // |subsamples| contains the information about what parts of the buffer are
  39. // encrypted and which parts are clear.
  40. static BitstreamConverter::AnalysisResult AnalyzeAnnexB(
  41. const uint8_t* buffer,
  42. size_t size,
  43. const std::vector<SubsampleEntry>& subsamples);
  44. // Given a |buffer| and |subsamples| information and |pts| pointer into the
  45. // |buffer| finds the index of the subsample |ptr| is pointing into.
  46. static int FindSubsampleIndex(const std::vector<uint8_t>& buffer,
  47. const std::vector<SubsampleEntry>* subsamples,
  48. const uint8_t* ptr);
  49. };
  50. // AVCBitstreamConverter converts AVC/H.264 bitstream from MP4 container format
  51. // with embedded NALU lengths into AnnexB bitstream format (described in ISO/IEC
  52. // 14496-10) with 4-byte start codes. It also knows how to handle CENC-encrypted
  53. // streams and adjusts subsample data for those streams while converting.
  54. class AVCBitstreamConverter : public BitstreamConverter {
  55. public:
  56. explicit AVCBitstreamConverter(
  57. std::unique_ptr<AVCDecoderConfigurationRecord> avc_config);
  58. AVCBitstreamConverter(const AVCBitstreamConverter&) = delete;
  59. AVCBitstreamConverter& operator=(const AVCBitstreamConverter&) = delete;
  60. // BitstreamConverter interface
  61. bool ConvertAndAnalyzeFrame(std::vector<uint8_t>* frame_buf,
  62. bool is_keyframe,
  63. std::vector<SubsampleEntry>* subsamples,
  64. AnalysisResult* analysis_result) const override;
  65. private:
  66. ~AVCBitstreamConverter() override;
  67. AnalysisResult Analyze(
  68. std::vector<uint8_t>* frame_buf,
  69. std::vector<SubsampleEntry>* subsamples) const override;
  70. std::unique_ptr<AVCDecoderConfigurationRecord> avc_config_;
  71. };
  72. } // namespace mp4
  73. } // namespace media
  74. #endif // MEDIA_FORMATS_MP4_AVC_H_