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