ffmpeg_h264_to_annex_b_bitstream_converter.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) 2012 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_FILTERS_FFMPEG_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_
  5. #define MEDIA_FILTERS_FFMPEG_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "media/base/media_export.h"
  8. #include "media/filters/ffmpeg_bitstream_converter.h"
  9. #include "media/filters/h264_to_annex_b_bitstream_converter.h"
  10. // Forward declarations for FFmpeg datatypes used.
  11. struct AVCodecParameters;
  12. struct AVPacket;
  13. namespace media {
  14. // Bitstream converter that converts H.264 bitstream based FFmpeg packets into
  15. // H.264 Annex B bytestream format.
  16. class MEDIA_EXPORT FFmpegH264ToAnnexBBitstreamConverter
  17. : public FFmpegBitstreamConverter {
  18. public:
  19. // The |stream_codec_parameters| will be used during conversion and should be
  20. // the AVCodecParameters for the stream sourcing these packets. A reference to
  21. // |stream_codec_parameters| is retained, so it must outlive this class.
  22. explicit FFmpegH264ToAnnexBBitstreamConverter(
  23. AVCodecParameters* stream_codec_parameters);
  24. FFmpegH264ToAnnexBBitstreamConverter(
  25. const FFmpegH264ToAnnexBBitstreamConverter&) = delete;
  26. FFmpegH264ToAnnexBBitstreamConverter& operator=(
  27. const FFmpegH264ToAnnexBBitstreamConverter&) = delete;
  28. ~FFmpegH264ToAnnexBBitstreamConverter() override;
  29. // FFmpegBitstreamConverter implementation.
  30. // Converts |packet| to H.264 Annex B bytestream format. This conversion is
  31. // on single NAL unit basis which is contained within the |packet| with the
  32. // exception of the first packet which is prepended with the AVC decoder
  33. // configuration record information. For example:
  34. //
  35. // NAL unit #1 ==> bytestream buffer #1 (AVC configuraion + NAL unit #1)
  36. // NAL unit #2 ==> bytestream buffer #2 (NAL unit #2)
  37. // ...
  38. // NAL unit #n ==> bytestream buffer #n (NAL unit #n)
  39. //
  40. // Returns true if conversion succeeded. In this case, the output will be
  41. // stored into the |packet|. But user should be aware that this conversion can
  42. // free and reallocate the |packet|, if it needs to do so to fit it in.
  43. // FFmpeg allocation methods will be used for buffer allocation to ensure
  44. // compatibility with FFmpeg's memory management.
  45. //
  46. // Returns false if conversion failed. In this case, the |packet| will not
  47. // be changed.
  48. bool ConvertPacket(AVPacket* packet) override;
  49. private:
  50. // Actual converter class.
  51. H264ToAnnexBBitstreamConverter converter_;
  52. // Flag for indicating whether global parameter sets have been processed.
  53. bool configuration_processed_;
  54. // Variable to hold a pointer to memory where we can access the global
  55. // data from the FFmpeg file format's global headers.
  56. raw_ptr<AVCodecParameters> stream_codec_parameters_;
  57. };
  58. } // namespace media
  59. #endif // MEDIA_FILTERS_FFMPEG_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_