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