Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / media / formats / mp4 / avc.h
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.
4
5 #ifndef MEDIA_FORMATS_MP4_AVC_H_
6 #define MEDIA_FORMATS_MP4_AVC_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "media/base/media_export.h"
12
13 namespace media {
14
15 struct SubsampleEntry;
16
17 namespace mp4 {
18
19 struct AVCDecoderConfigurationRecord;
20
21 class MEDIA_EXPORT AVC {
22  public:
23   static bool ConvertFrameToAnnexB(int length_size, std::vector<uint8>* buffer);
24
25   // Inserts the SPS & PPS data from |avc_config| into |buffer|.
26   // |buffer| is expected to contain AnnexB conformant data.
27   // |subsamples| contains the SubsampleEntry info if |buffer| contains
28   // encrypted data.
29   // Returns true if the param sets were successfully inserted.
30   static bool InsertParamSetsAnnexB(
31       const AVCDecoderConfigurationRecord& avc_config,
32       std::vector<uint8>* buffer,
33       std::vector<SubsampleEntry>* subsamples);
34
35   static bool ConvertConfigToAnnexB(
36       const AVCDecoderConfigurationRecord& avc_config,
37       std::vector<uint8>* buffer);
38
39   // Verifies that the contents of |buffer| conform to
40   // Section 7.4.1.2.3 of ISO/IEC 14496-10.
41   // |subsamples| contains the information about what parts of the buffer are
42   // encrypted and which parts are clear.
43   // Returns true if |buffer| contains conformant Annex B data
44   // TODO(acolwell): Remove the std::vector version when we can use,
45   // C++11's std::vector<T>::data() method.
46   static bool IsValidAnnexB(const std::vector<uint8>& buffer,
47                             const std::vector<SubsampleEntry>& subsamples);
48   static bool IsValidAnnexB(const uint8* buffer, size_t size,
49                             const std::vector<SubsampleEntry>& subsamples);
50
51   // Given a |buffer| and |subsamples| information and |pts| pointer into the
52   // |buffer| finds the index of the subsample |ptr| is pointing into.
53   static int FindSubsampleIndex(const std::vector<uint8>& buffer,
54                                 const std::vector<SubsampleEntry>* subsamples,
55                                 const uint8* ptr);
56 };
57
58 }  // namespace mp4
59 }  // namespace media
60
61 #endif  // MEDIA_FORMATS_MP4_AVC_H_