h264_annex_b_to_avc_bitstream_converter.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2020 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_H264_ANNEX_B_TO_AVC_BITSTREAM_CONVERTER_H_
  5. #define MEDIA_FORMATS_MP4_H264_ANNEX_B_TO_AVC_BITSTREAM_CONVERTER_H_
  6. #include <stdint.h>
  7. #include <vector>
  8. #include "base/containers/flat_map.h"
  9. #include "base/containers/span.h"
  10. #include "media/base/media_export.h"
  11. #include "media/formats/mp4/box_definitions.h"
  12. #include "media/formats/mp4/mp4_status.h"
  13. #include "media/video/h264_parser.h"
  14. namespace media {
  15. // H264AnnexBToAvcBitstreamConverter is a class to convert H.264 bitstream from
  16. // Annex B (ISO/IEC 14496-10) to AVC (as specified in ISO/IEC 14496-15).
  17. class MEDIA_EXPORT H264AnnexBToAvcBitstreamConverter {
  18. public:
  19. H264AnnexBToAvcBitstreamConverter();
  20. H264AnnexBToAvcBitstreamConverter(const H264AnnexBToAvcBitstreamConverter&) =
  21. delete;
  22. H264AnnexBToAvcBitstreamConverter& operator=(
  23. const H264AnnexBToAvcBitstreamConverter&) = delete;
  24. ~H264AnnexBToAvcBitstreamConverter();
  25. // Converts a video chunk from a format with in-place decoder configuration
  26. // into a format where configuration needs to be sent separately.
  27. //
  28. // |input| - where to read the data from
  29. // |output| - where to put the converted video data
  30. // If error kH264BufferTooSmall is returned, it means that |output| was not
  31. // big enough to contain a converted video chunk. In this case |size_out|
  32. // is populated.
  33. // |config_changed_out| is set to True if the video chunk
  34. // processed by this call contained decoder configuration information.
  35. // In this case latest configuration information can be obtained
  36. // from GetCurrentConfig().
  37. // |size_out| - number of bytes written to |output|, or desired size of
  38. // |output| if it's too small.
  39. MP4Status ConvertChunk(base::span<const uint8_t> input,
  40. base::span<uint8_t> output,
  41. bool* config_changed_out,
  42. size_t* size_out);
  43. // Returns the latest version of decoder configuration, found in converted
  44. // video chunks.
  45. const mp4::AVCDecoderConfigurationRecord& GetCurrentConfig();
  46. private:
  47. H264Parser parser_;
  48. mp4::AVCDecoderConfigurationRecord config_;
  49. using blob = std::vector<uint8_t>;
  50. base::flat_map<int, blob> id2sps_;
  51. base::flat_map<int, blob> id2pps_;
  52. int active_sps_id_ = -1;
  53. int active_pps_id_ = -1;
  54. };
  55. } // namespace media
  56. #endif // MEDIA_FORMATS_MP4_H264_ANNEX_B_TO_AVC_BITSTREAM_CONVERTER_H_