bitstream_converter.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2015 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_BITSTREAM_CONVERTER_H_
  5. #define MEDIA_FORMATS_MP4_BITSTREAM_CONVERTER_H_
  6. #include <stdint.h>
  7. #include <vector>
  8. #include "base/memory/ref_counted.h"
  9. #include "media/base/media_export.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace media {
  12. struct SubsampleEntry;
  13. namespace mp4 {
  14. // BitstreamConverter provides a unified interface for performing some common
  15. // bitstream conversions (e.g. H.264 MP4 bitstream to Annex B, and elementary
  16. // AAC stream to ADTS).
  17. class MEDIA_EXPORT BitstreamConverter
  18. : public base::RefCountedThreadSafe<BitstreamConverter> {
  19. public:
  20. // Describes the result of Analyze(). Not all analyses are implemented or
  21. // enabled across mp4::BitstreamConverter implementations, hence the use of
  22. // absl::optional<>.
  23. struct MEDIA_EXPORT AnalysisResult {
  24. AnalysisResult();
  25. AnalysisResult(const AnalysisResult&);
  26. ~AnalysisResult();
  27. absl::optional<bool> is_conformant;
  28. absl::optional<bool> is_keyframe;
  29. };
  30. // Converts a single frame/buffer |frame_buf| into the output format.
  31. // Returns true iff the conversion was successful.
  32. // |frame_buf| is an input/output parameter, it contains input frame data and
  33. // contains converted output data if conversion was successful.
  34. // |is_keyframe| indicates whether it's a key frame or not.
  35. // |subsamples| is an input/output parameter that contains CENC subsample
  36. // information. The conversion code should |subsamples| to determine if parts
  37. // of input frame are encrypted and should update |subsamples| if necessary,
  38. // to make sure it correctly describes the converted output frame. See
  39. // SubsampleEntry definition in media/base/decrypt_config.h for more info.
  40. // |analysis_result| is an output parameter that contains the AnalysisResult
  41. // found during conversion.
  42. virtual bool ConvertAndAnalyzeFrame(
  43. std::vector<uint8_t>* frame_buf,
  44. bool is_keyframe,
  45. std::vector<SubsampleEntry>* subsamples,
  46. AnalysisResult* analysis_result) const = 0;
  47. protected:
  48. friend class base::RefCountedThreadSafe<BitstreamConverter>;
  49. virtual ~BitstreamConverter();
  50. // Inspects an already converted frame for conformance. If conformant,
  51. // inspects further to see if the converted frame appears to be a keyframe.
  52. // Note, the checks may not be exhaustive (or implemented at all).
  53. virtual AnalysisResult Analyze(
  54. std::vector<uint8_t>* frame_buf,
  55. std::vector<SubsampleEntry>* subsamples) const = 0;
  56. };
  57. } // namespace mp4
  58. } // namespace media
  59. #endif // MEDIA_FORMATS_MP4_BITSTREAM_CONVERTER_H_