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