1 // Copyright 2014 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_FORMATS_MP4_AVC_H_
6 #define MEDIA_FORMATS_MP4_AVC_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/media_export.h"
13 #include "media/formats/mp4/bitstream_converter.h"
17 struct SubsampleEntry
;
21 struct AVCDecoderConfigurationRecord
;
23 class MEDIA_EXPORT AVC
{
25 static bool ConvertFrameToAnnexB(int length_size
,
26 std::vector
<uint8
>* buffer
,
27 std::vector
<SubsampleEntry
>* subsamples
);
29 // Inserts the SPS & PPS data from |avc_config| into |buffer|.
30 // |buffer| is expected to contain AnnexB conformant data.
31 // |subsamples| contains the SubsampleEntry info if |buffer| contains
33 // Returns true if the param sets were successfully inserted.
34 static bool InsertParamSetsAnnexB(
35 const AVCDecoderConfigurationRecord
& avc_config
,
36 std::vector
<uint8
>* buffer
,
37 std::vector
<SubsampleEntry
>* subsamples
);
39 static bool ConvertConfigToAnnexB(
40 const AVCDecoderConfigurationRecord
& avc_config
,
41 std::vector
<uint8
>* buffer
);
43 // Verifies that the contents of |buffer| conform to
44 // Section 7.4.1.2.3 of ISO/IEC 14496-10.
45 // |subsamples| contains the information about what parts of the buffer are
46 // encrypted and which parts are clear.
47 // Returns true if |buffer| contains conformant Annex B data
48 // TODO(acolwell): Remove the std::vector version when we can use,
49 // C++11's std::vector<T>::data() method.
50 static bool IsValidAnnexB(const std::vector
<uint8
>& buffer
,
51 const std::vector
<SubsampleEntry
>& subsamples
);
52 static bool IsValidAnnexB(const uint8
* buffer
, size_t size
,
53 const std::vector
<SubsampleEntry
>& subsamples
);
55 // Given a |buffer| and |subsamples| information and |pts| pointer into the
56 // |buffer| finds the index of the subsample |ptr| is pointing into.
57 static int FindSubsampleIndex(const std::vector
<uint8
>& buffer
,
58 const std::vector
<SubsampleEntry
>* subsamples
,
62 // AVCBitstreamConverter converts AVC/H.264 bitstream from MP4 container format
63 // with embedded NALU lengths into AnnexB bitstream format (described in ISO/IEC
64 // 14496-10) with 4-byte start codes. It also knows how to handle CENC-encrypted
65 // streams and adjusts subsample data for those streams while converting.
66 class AVCBitstreamConverter
: public BitstreamConverter
{
68 explicit AVCBitstreamConverter(
69 scoped_ptr
<AVCDecoderConfigurationRecord
> avc_config
);
71 // BitstreamConverter interface
72 bool ConvertFrame(std::vector
<uint8
>* frame_buf
,
74 std::vector
<SubsampleEntry
>* subsamples
) const override
;
76 ~AVCBitstreamConverter() override
;
77 scoped_ptr
<AVCDecoderConfigurationRecord
> avc_config_
;
83 #endif // MEDIA_FORMATS_MP4_AVC_H_