Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / filters / ffmpeg_h264_to_annex_b_bitstream_converter.h
blob14bd40b587734a33c9cf086e7e25aa287f1fd05f
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.
5 #ifndef MEDIA_FILTERS_FFMPEG_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_
6 #define MEDIA_FILTERS_FFMPEG_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_
8 #include "base/basictypes.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"
13 // Forward declarations for FFmpeg datatypes used.
14 struct AVCodecContext;
15 struct AVPacket;
17 namespace media {
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_context| will be used during conversion and should be the
25 // AVCodecContext for the stream sourcing these packets. A reference to
26 // |stream_codec_context| is retained, so it must outlive this class.
27 explicit FFmpegH264ToAnnexBBitstreamConverter(
28 AVCodecContext* stream_codec_context);
30 ~FFmpegH264ToAnnexBBitstreamConverter() override;
32 // FFmpegBitstreamConverter implementation.
33 // Converts |packet| to H.264 Annex B bytestream format. This conversion is
34 // on single NAL unit basis which is contained within the |packet| with the
35 // exception of the first packet which is prepended with the AVC decoder
36 // configuration record information. For example:
38 // NAL unit #1 ==> bytestream buffer #1 (AVC configuraion + NAL unit #1)
39 // NAL unit #2 ==> bytestream buffer #2 (NAL unit #2)
40 // ...
41 // NAL unit #n ==> bytestream buffer #n (NAL unit #n)
43 // Returns true if conversion succeeded. In this case, the output will be
44 // stored into the |packet|. But user should be aware that this conversion can
45 // free and reallocate the |packet|, if it needs to do so to fit it in.
46 // FFmpeg allocation methods will be used for buffer allocation to ensure
47 // compatibility with FFmpeg's memory management.
49 // Returns false if conversion failed. In this case, the |packet| will not
50 // be changed.
51 bool ConvertPacket(AVPacket* packet) override;
53 private:
54 // Actual converter class.
55 H264ToAnnexBBitstreamConverter converter_;
57 // Flag for indicating whether global parameter sets have been processed.
58 bool configuration_processed_;
60 // Variable to hold a pointer to memory where we can access the global
61 // data from the FFmpeg file format's global headers.
62 AVCodecContext* stream_codec_context_;
64 DISALLOW_COPY_AND_ASSIGN(FFmpegH264ToAnnexBBitstreamConverter);
67 } // namespace media
69 #endif // MEDIA_FILTERS_FFMPEG_H264_TO_ANNEX_B_BITSTREAM_CONVERTER_H_