• 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/void_parser.h"
9 
10 #include <cassert>
11 #include <cstdint>
12 
13 #include "webm/callback.h"
14 #include "webm/element.h"
15 #include "webm/id.h"
16 #include "webm/reader.h"
17 #include "webm/status.h"
18 
19 namespace webm {
20 
Init(const ElementMetadata & metadata,std::uint64_t max_size)21 Status VoidParser::Init(const ElementMetadata& metadata,
22                         std::uint64_t max_size) {
23   assert(metadata.size == kUnknownElementSize || metadata.size <= max_size);
24 
25   if (metadata.size == kUnknownElementSize) {
26     return Status(Status::kInvalidElementSize);
27   }
28 
29   metadata_ = metadata;
30   bytes_remaining_ = metadata.size;
31 
32   return Status(Status::kOkCompleted);
33 }
34 
Feed(Callback * callback,Reader * reader,std::uint64_t * num_bytes_read)35 Status VoidParser::Feed(Callback* callback, Reader* reader,
36                         std::uint64_t* num_bytes_read) {
37   assert(callback != nullptr);
38   assert(reader != nullptr);
39   assert(num_bytes_read != nullptr);
40 
41   const std::uint64_t original_bytes_remaining = bytes_remaining_;
42   const Status status = callback->OnVoid(metadata_, reader, &bytes_remaining_);
43   assert(bytes_remaining_ <= original_bytes_remaining);
44 
45   *num_bytes_read = original_bytes_remaining - bytes_remaining_;
46   return status;
47 }
48 
49 }  // namespace webm
50