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_BLOCK_HEADER_PARSER_H_ 9 #define SRC_BLOCK_HEADER_PARSER_H_ 10 11 #include <cassert> 12 #include <cstdint> 13 14 #include "src/parser.h" 15 #include "src/var_int_parser.h" 16 #include "webm/callback.h" 17 #include "webm/reader.h" 18 #include "webm/status.h" 19 20 namespace webm { 21 22 struct BlockHeader { 23 std::uint64_t track_number; 24 std::int16_t timecode; 25 std::uint8_t flags; 26 27 bool operator==(const BlockHeader& other) const { 28 return track_number == other.track_number && timecode == other.timecode && 29 flags == other.flags; 30 } 31 }; 32 33 class BlockHeaderParser : public Parser { 34 public: 35 Status Feed(Callback* callback, Reader* reader, 36 std::uint64_t* num_bytes_read) override; 37 38 // Gets the parsed block header information. This must not be called until the 39 // parse has been successfully completed. value()40 const BlockHeader& value() const { 41 assert(state_ == State::kDone); 42 return value_; 43 } 44 45 private: 46 BlockHeader value_; 47 48 VarIntParser uint_parser_; 49 50 int timecode_bytes_remaining_ = 2; 51 52 enum class State { 53 /* clang-format off */ 54 // State Transitions to state When 55 kReadingTrackNumber, // kReadingTimecode track parsed 56 kReadingTimecode, // kReadingFlags timecode parsed 57 kReadingFlags, // kDone flags parsed 58 kDone, // No transitions from here (must call Init) 59 /* clang-format on */ 60 } state_ = State::kReadingTrackNumber; 61 }; 62 63 } // namespace webm 64 65 #endif // SRC_BLOCK_HEADER_PARSER_H_ 66