Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / media / formats / mp4 / avc.h
bloba774ddd1b7320aaae000bfa885a2b56dadb23420
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_
8 #include <vector>
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"
15 namespace media {
17 struct SubsampleEntry;
19 namespace mp4 {
21 struct AVCDecoderConfigurationRecord;
23 class MEDIA_EXPORT AVC {
24 public:
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
32 // encrypted data.
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,
59 const uint8* ptr);
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 {
67 public:
68 explicit AVCBitstreamConverter(
69 scoped_ptr<AVCDecoderConfigurationRecord> avc_config);
71 // BitstreamConverter interface
72 bool ConvertFrame(std::vector<uint8>* frame_buf,
73 bool is_keyframe,
74 std::vector<SubsampleEntry>* subsamples) const override;
75 private:
76 ~AVCBitstreamConverter() override;
77 scoped_ptr<AVCDecoderConfigurationRecord> avc_config_;
80 } // namespace mp4
81 } // namespace media
83 #endif // MEDIA_FORMATS_MP4_AVC_H_