• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/block_header_parser.h"
9 
10 #include <cassert>
11 #include <cstdint>
12 
13 #include "src/parser_utils.h"
14 
15 namespace webm {
16 
17 // Spec reference:
18 // http://matroska.org/technical/specs/index.html#block_structure
19 // http://matroska.org/technical/specs/index.html#simpleblock_structure
20 // http://matroska.org/technical/specs/index.html#block_virtual
Feed(Callback * callback,Reader * reader,std::uint64_t * num_bytes_read)21 Status BlockHeaderParser::Feed(Callback* callback, Reader* reader,
22                                std::uint64_t* num_bytes_read) {
23   assert(callback != nullptr);
24   assert(reader != nullptr);
25   assert(num_bytes_read != nullptr);
26 
27   *num_bytes_read = 0;
28 
29   Status status;
30   std::uint64_t local_num_bytes_read;
31 
32   while (true) {
33     switch (state_) {
34       case State::kReadingTrackNumber: {
35         status = uint_parser_.Feed(callback, reader, &local_num_bytes_read);
36         *num_bytes_read += local_num_bytes_read;
37         if (!status.completed_ok()) {
38           return status;
39         }
40         value_.track_number = uint_parser_.value();
41         state_ = State::kReadingTimecode;
42         continue;
43       }
44 
45       case State::kReadingTimecode: {
46         status =
47             AccumulateIntegerBytes(timecode_bytes_remaining_, reader,
48                                    &value_.timecode, &local_num_bytes_read);
49         *num_bytes_read += local_num_bytes_read;
50         timecode_bytes_remaining_ -= static_cast<int>(local_num_bytes_read);
51         if (!status.completed_ok()) {
52           return status;
53         }
54         state_ = State::kReadingFlags;
55         continue;
56       }
57 
58       case State::kReadingFlags: {
59         assert(timecode_bytes_remaining_ == 0);
60         status = ReadByte(reader, &value_.flags);
61         if (!status.completed_ok()) {
62           return status;
63         }
64         ++*num_bytes_read;
65         state_ = State::kDone;
66         continue;
67       }
68 
69       case State::kDone: {
70         return Status(Status::kOkCompleted);
71       }
72     }
73   }
74 }
75 
76 }  // namespace webm
77