1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #ifndef SRC_SEGMENT_PARSER_H_
9 #define SRC_SEGMENT_PARSER_H_
10 
11 #include <cstdint>
12 
13 #include "src/master_parser.h"
14 #include "webm/callback.h"
15 #include "webm/reader.h"
16 #include "webm/status.h"
17 
18 namespace webm {
19 
20 // Parses Segment elements from a WebM byte stream. This class adheres to the
21 // ElementParser interface; see element_parser.h for further documentation on
22 // how it should be used.
23 // Spec reference:
24 // http://matroska.org/technical/specs/index.html#Segment
25 // http://www.webmproject.org/docs/container/#Segment
26 class SegmentParser : public MasterParser {
27  public:
28   SegmentParser();
29 
30   Status Init(const ElementMetadata& metadata, std::uint64_t max_size) override;
31 
32   void InitAfterSeek(const Ancestory& child_ancestory,
33                      const ElementMetadata& child_metadata) override;
34 
35   Status Feed(Callback* callback, Reader* reader,
36               std::uint64_t* num_bytes_read) override;
37 
38   bool WasSkipped() const override;
39 
40  private:
41   // Set to true iff Callback::OnSegmentBegin has completed.
42   bool begin_done_;
43 
44   // Set to true iff the base class has completed parsing.
45   bool parse_completed_;
46 
47   // The action requested by Callback::OnSegmentBegin.
48   Action action_ = Action::kRead;
49 };
50 
51 }  // namespace webm
52 
53 #endif  // SRC_SEGMENT_PARSER_H_
54