Shaka Player Embedded
time_ranges.cc
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/js/mse/time_ranges.h"
16 
17 #include <sstream>
18 #include <stdexcept>
19 
20 #include "src/js/js_error.h"
21 
22 namespace shaka {
23 namespace js {
24 namespace mse {
25 
26 namespace {
27 
28 JsError OutOfRange(uint32_t index, size_t max) {
29  std::stringstream ss;
30  ss << "The given index " << index << " was greater than the number ";
31  ss << "of elements " << max;
32  return JsError::DOMException(IndexSizeError, ss.str());
33 }
34 
35 } // namespace
36 
37 TimeRanges::TimeRanges(media::BufferedRanges ranges) : ranges_(ranges) {}
38 // \cond Doxygen_Skip
39 TimeRanges::~TimeRanges() {}
40 // \endcond Doxygen_Skip
41 
43  return true;
44 }
45 
46 ExceptionOr<double> TimeRanges::Start(uint32_t index) const {
47  if (index >= ranges_.size())
48  return OutOfRange(index, ranges_.size());
49  return ranges_[index].start;
50 }
51 
52 ExceptionOr<double> TimeRanges::End(uint32_t index) const {
53  if (index >= ranges_.size())
54  return OutOfRange(index, ranges_.size());
55  return ranges_[index].end;
56 }
57 
58 
60  AddGenericProperty("length", &TimeRanges::length);
61 
62  AddMemberFunction("start", &TimeRanges::Start);
63  AddMemberFunction("end", &TimeRanges::End);
64 }
65 
66 } // namespace mse
67 } // namespace js
68 } // namespace shaka
ExceptionOr< double > Start(uint32_t index) const
Definition: time_ranges.cc:46
std::vector< BufferedRange > BufferedRanges
Definition: types.h:26
bool IsShortLived() const override
Definition: time_ranges.cc:42
static JsError DOMException(ExceptionCode code)
Definition: js_error.cc:115
TimeRanges(media::BufferedRanges ranges)
Definition: time_ranges.cc:37
uint32_t length() const
Definition: time_ranges.h:35
ExceptionOr< double > End(uint32_t index) const
Definition: time_ranges.cc:52