• 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 "webm/callback.h"
9 
10 #include <cassert>
11 
12 namespace webm {
13 
OnElementBegin(const ElementMetadata &,Action * action)14 Status Callback::OnElementBegin(const ElementMetadata& /* metadata */,
15                                 Action* action) {
16   assert(action != nullptr);
17   *action = Action::kRead;
18   return Status(Status::kOkCompleted);
19 }
20 
OnUnknownElement(const ElementMetadata &,Reader * reader,std::uint64_t * bytes_remaining)21 Status Callback::OnUnknownElement(const ElementMetadata& /* metadata */,
22                                   Reader* reader,
23                                   std::uint64_t* bytes_remaining) {
24   assert(reader != nullptr);
25   assert(bytes_remaining != nullptr);
26   return Skip(reader, bytes_remaining);
27 }
28 
OnEbml(const ElementMetadata &,const Ebml &)29 Status Callback::OnEbml(const ElementMetadata& /* metadata */,
30                         const Ebml& /* ebml */) {
31   return Status(Status::kOkCompleted);
32 }
33 
OnVoid(const ElementMetadata &,Reader * reader,std::uint64_t * bytes_remaining)34 Status Callback::OnVoid(const ElementMetadata& /* metadata */, Reader* reader,
35                         std::uint64_t* bytes_remaining) {
36   assert(reader != nullptr);
37   assert(bytes_remaining != nullptr);
38   return Skip(reader, bytes_remaining);
39 }
40 
OnSegmentBegin(const ElementMetadata &,Action * action)41 Status Callback::OnSegmentBegin(const ElementMetadata& /* metadata */,
42                                 Action* action) {
43   assert(action != nullptr);
44   *action = Action::kRead;
45   return Status(Status::kOkCompleted);
46 }
47 
OnSeek(const ElementMetadata &,const Seek &)48 Status Callback::OnSeek(const ElementMetadata& /* metadata */,
49                         const Seek& /* seek */) {
50   return Status(Status::kOkCompleted);
51 }
52 
OnInfo(const ElementMetadata &,const Info &)53 Status Callback::OnInfo(const ElementMetadata& /* metadata */,
54                         const Info& /* info */) {
55   return Status(Status::kOkCompleted);
56 }
57 
OnClusterBegin(const ElementMetadata &,const Cluster &,Action * action)58 Status Callback::OnClusterBegin(const ElementMetadata& /* metadata */,
59                                 const Cluster& /* cluster */, Action* action) {
60   assert(action != nullptr);
61   *action = Action::kRead;
62   return Status(Status::kOkCompleted);
63 }
64 
OnSimpleBlockBegin(const ElementMetadata &,const SimpleBlock &,Action * action)65 Status Callback::OnSimpleBlockBegin(const ElementMetadata& /* metadata */,
66                                     const SimpleBlock& /* simple_block */,
67                                     Action* action) {
68   assert(action != nullptr);
69   *action = Action::kRead;
70   return Status(Status::kOkCompleted);
71 }
72 
OnSimpleBlockEnd(const ElementMetadata &,const SimpleBlock &)73 Status Callback::OnSimpleBlockEnd(const ElementMetadata& /* metadata */,
74                                   const SimpleBlock& /* simple_block */) {
75   return Status(Status::kOkCompleted);
76 }
77 
OnBlockGroupBegin(const ElementMetadata &,Action * action)78 Status Callback::OnBlockGroupBegin(const ElementMetadata& /* metadata */,
79                                    Action* action) {
80   assert(action != nullptr);
81   *action = Action::kRead;
82   return Status(Status::kOkCompleted);
83 }
84 
OnBlockBegin(const ElementMetadata &,const Block &,Action * action)85 Status Callback::OnBlockBegin(const ElementMetadata& /* metadata */,
86                               const Block& /* block */, Action* action) {
87   assert(action != nullptr);
88   *action = Action::kRead;
89   return Status(Status::kOkCompleted);
90 }
91 
OnBlockEnd(const ElementMetadata &,const Block &)92 Status Callback::OnBlockEnd(const ElementMetadata& /* metadata */,
93                             const Block& /* block */) {
94   return Status(Status::kOkCompleted);
95 }
96 
OnBlockGroupEnd(const ElementMetadata &,const BlockGroup &)97 Status Callback::OnBlockGroupEnd(const ElementMetadata& /* metadata */,
98                                  const BlockGroup& /* block_group */) {
99   return Status(Status::kOkCompleted);
100 }
101 
OnFrame(const FrameMetadata &,Reader * reader,std::uint64_t * bytes_remaining)102 Status Callback::OnFrame(const FrameMetadata& /* metadata */, Reader* reader,
103                          std::uint64_t* bytes_remaining) {
104   assert(reader != nullptr);
105   assert(bytes_remaining != nullptr);
106   return Skip(reader, bytes_remaining);
107 }
108 
OnClusterEnd(const ElementMetadata &,const Cluster &)109 Status Callback::OnClusterEnd(const ElementMetadata& /* metadata */,
110                               const Cluster& /* cluster */) {
111   return Status(Status::kOkCompleted);
112 }
113 
OnTrackEntry(const ElementMetadata &,const TrackEntry &)114 Status Callback::OnTrackEntry(const ElementMetadata& /* metadata */,
115                               const TrackEntry& /* track_entry */) {
116   return Status(Status::kOkCompleted);
117 }
118 
OnCuePoint(const ElementMetadata &,const CuePoint &)119 Status Callback::OnCuePoint(const ElementMetadata& /* metadata */,
120                             const CuePoint& /* cue_point */) {
121   return Status(Status::kOkCompleted);
122 }
123 
OnEditionEntry(const ElementMetadata &,const EditionEntry &)124 Status Callback::OnEditionEntry(const ElementMetadata& /* metadata */,
125                                 const EditionEntry& /* edition_entry */) {
126   return Status(Status::kOkCompleted);
127 }
128 
OnTag(const ElementMetadata &,const Tag &)129 Status Callback::OnTag(const ElementMetadata& /* metadata */,
130                        const Tag& /* tag */) {
131   return Status(Status::kOkCompleted);
132 }
133 
OnSegmentEnd(const ElementMetadata &)134 Status Callback::OnSegmentEnd(const ElementMetadata& /* metadata */) {
135   return Status(Status::kOkCompleted);
136 }
137 
Skip(Reader * reader,std::uint64_t * bytes_remaining)138 Status Callback::Skip(Reader* reader, std::uint64_t* bytes_remaining) {
139   assert(reader != nullptr);
140   assert(bytes_remaining != nullptr);
141 
142   if (*bytes_remaining == 0)
143     return Status(Status::kOkCompleted);
144 
145   Status status;
146   do {
147     std::uint64_t num_actually_skipped;
148     status = reader->Skip(*bytes_remaining, &num_actually_skipped);
149     *bytes_remaining -= num_actually_skipped;
150   } while (status.code == Status::kOkPartial);
151 
152   return status;
153 }
154 
155 }  // namespace webm
156