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_VIRTUAL_BLOCK_PARSER_H_ 9 #define SRC_VIRTUAL_BLOCK_PARSER_H_ 10 11 #include <cassert> 12 #include <cstdint> 13 14 #include "src/block_header_parser.h" 15 #include "src/element_parser.h" 16 #include "webm/callback.h" 17 #include "webm/dom_types.h" 18 #include "webm/element.h" 19 #include "webm/reader.h" 20 #include "webm/status.h" 21 22 namespace webm { 23 24 // Spec reference: 25 // http://matroska.org/technical/specs/index.html#BlockVirtual 26 // http://www.webmproject.org/docs/container/#BlockVirtual 27 // http://matroska.org/technical/specs/index.html#block_virtual 28 class VirtualBlockParser : public ElementParser { 29 public: 30 Status Init(const ElementMetadata& metadata, std::uint64_t max_size) override; 31 32 Status Feed(Callback* callback, Reader* reader, 33 std::uint64_t* num_bytes_read) override; 34 35 // Gets the parsed block header information. This must not be called until the 36 // parse has been successfully completed. value()37 const VirtualBlock& value() const { 38 assert(state_ == State::kDone); 39 return value_; 40 } 41 42 // Gets the parsed block header information. This must not be called until the 43 // parse has been successfully completed. mutable_value()44 VirtualBlock* mutable_value() { 45 assert(state_ == State::kDone); 46 return &value_; 47 } 48 49 private: 50 std::uint64_t my_size_; 51 std::uint64_t total_bytes_read_ = 0; 52 53 VirtualBlock value_{}; 54 55 BlockHeaderParser parser_; 56 57 enum class State { 58 /* clang-format off */ 59 // State Transitions to state When 60 kReadingHeader, // kValidatingSize header parsed 61 kValidatingSize, // kDone no errors 62 kDone, // No transitions from here (must call Init) 63 /* clang-format on */ 64 } state_ = State::kReadingHeader; 65 }; 66 67 } // namespace webm 68 69 #endif // SRC_VIRTUAL_BLOCK_PARSER_H_ 70