1 // Copyright 2016 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_WEBM_WEBM_COLOUR_PARSER_H_
6 #define MEDIA_FORMATS_WEBM_WEBM_COLOUR_PARSER_H_
7 
8 #include "base/macros.h"
9 #include "base/optional.h"
10 #include "media/base/hdr_metadata.h"
11 #include "media/base/video_color_space.h"
12 #include "media/formats/webm/webm_parser.h"
13 
14 namespace media {
15 
16 // WebM color information, containing HDR metadata:
17 // http://www.webmproject.org/docs/container/#Colour
18 struct MEDIA_EXPORT WebMColorMetadata {
19   unsigned BitsPerChannel = 0;
20   unsigned ChromaSubsamplingHorz = 0;
21   unsigned ChromaSubsamplingVert = 0;
22   unsigned CbSubsamplingHorz = 0;
23   unsigned CbSubsamplingVert = 0;
24   unsigned ChromaSitingHorz = 0;
25   unsigned ChromaSitingVert = 0;
26 
27   VideoColorSpace color_space;
28 
29   base::Optional<HDRMetadata> hdr_metadata;
30 
31   WebMColorMetadata();
32   WebMColorMetadata(const WebMColorMetadata& rhs);
33 };
34 
35 // Parser for WebM MasteringMetadata within Colour element:
36 // http://www.webmproject.org/docs/container/#MasteringMetadata
37 class WebMMasteringMetadataParser : public WebMParserClient {
38  public:
39   WebMMasteringMetadataParser();
40   ~WebMMasteringMetadataParser() override;
41 
GetMasteringMetadata()42   MasteringMetadata GetMasteringMetadata() const { return mastering_metadata_; }
43 
44  private:
45   // WebMParserClient implementation.
46   bool OnFloat(int id, double val) override;
47 
48   MasteringMetadata mastering_metadata_;
49   DISALLOW_COPY_AND_ASSIGN(WebMMasteringMetadataParser);
50 };
51 
52 // Parser for WebM Colour element:
53 // http://www.webmproject.org/docs/container/#colour
54 class WebMColourParser : public WebMParserClient {
55  public:
56   WebMColourParser();
57   ~WebMColourParser() override;
58 
59   void Reset();
60 
61   WebMColorMetadata GetWebMColorMetadata() const;
62 
63  private:
64   // WebMParserClient implementation.
65   WebMParserClient* OnListStart(int id) override;
66   bool OnListEnd(int id) override;
67   bool OnUInt(int id, int64_t val) override;
68 
69   int64_t matrix_coefficients_;
70   int64_t bits_per_channel_;
71   int64_t chroma_subsampling_horz_;
72   int64_t chroma_subsampling_vert_;
73   int64_t cb_subsampling_horz_;
74   int64_t cb_subsampling_vert_;
75   int64_t chroma_siting_horz_;
76   int64_t chroma_siting_vert_;
77   int64_t range_;
78   int64_t transfer_characteristics_;
79   int64_t primaries_;
80   int64_t max_content_light_level_;
81   int64_t max_frame_average_light_level_;
82 
83   WebMMasteringMetadataParser mastering_metadata_parser_;
84   bool mastering_metadata_parsed_ = false;
85 
86   DISALLOW_COPY_AND_ASSIGN(WebMColourParser);
87 };
88 
89 }  // namespace media
90 
91 #endif  // MEDIA_FORMATS_WEBM_WEBM_COLOUR_PARSER_H_
92