コード例 #1
0
ファイル: TimeRanges.cpp プロジェクト: mirror/chromium
TimeRanges* TimeRanges::create(const blink::WebTimeRanges& webRanges) {
  TimeRanges* ranges = TimeRanges::create();

  unsigned size = webRanges.size();
  for (unsigned i = 0; i < size; ++i)
    ranges->add(webRanges[i].start, webRanges[i].end);

  return ranges;
}
コード例 #2
0
ファイル: TimeRanges.cpp プロジェクト: mirror/chromium
TimeRanges* TimeRanges::copy() const {
  TimeRanges* newSession = TimeRanges::create();

  unsigned size = m_ranges.size();
  for (unsigned i = 0; i < size; i++)
    newSession->add(m_ranges[i].m_start, m_ranges[i].m_end);

  return newSession;
}
コード例 #3
0
ファイル: TimeRanges.cpp プロジェクト: mirror/chromium
void TimeRanges::unionWith(const TimeRanges* other) {
  DCHECK(other);
  TimeRanges* unioned = copy();
  for (size_t index = 0; index < other->m_ranges.size(); ++index) {
    const Range& range = other->m_ranges[index];
    unioned->add(range.m_start, range.m_end);
  }

  m_ranges.swap(unioned->m_ranges);
}
コード例 #4
0
ファイル: MediaSource.cpp プロジェクト: ollie314/chromium
TimeRanges* MediaSource::buffered() const {
  // Implements MediaSource algorithm for HTMLMediaElement.buffered.
  // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#htmlmediaelement-extensions
  HeapVector<Member<TimeRanges>> ranges(m_activeSourceBuffers->length());
  for (size_t i = 0; i < m_activeSourceBuffers->length(); ++i)
    ranges[i] = m_activeSourceBuffers->item(i)->buffered(ASSERT_NO_EXCEPTION);

  // 1. If activeSourceBuffers.length equals 0 then return an empty TimeRanges
  //    object and abort these steps.
  if (ranges.isEmpty())
    return TimeRanges::create();

  // 2. Let active ranges be the ranges returned by buffered for each
  //    SourceBuffer object in activeSourceBuffers.
  // 3. Let highest end time be the largest range end time in the active ranges.
  double highestEndTime = -1;
  for (size_t i = 0; i < ranges.size(); ++i) {
    unsigned length = ranges[i]->length();
    if (length)
      highestEndTime = std::max(
          highestEndTime, ranges[i]->end(length - 1, ASSERT_NO_EXCEPTION));
  }

  // Return an empty range if all ranges are empty.
  if (highestEndTime < 0)
    return TimeRanges::create();

  // 4. Let intersection ranges equal a TimeRange object containing a single
  //    range from 0 to highest end time.
  TimeRanges* intersectionRanges = TimeRanges::create(0, highestEndTime);

  // 5. For each SourceBuffer object in activeSourceBuffers run the following
  //    steps:
  bool ended = readyState() == endedKeyword();
  for (size_t i = 0; i < ranges.size(); ++i) {
    // 5.1 Let source ranges equal the ranges returned by the buffered attribute
    //     on the current SourceBuffer.
    TimeRanges* sourceRanges = ranges[i].get();

    // 5.2 If readyState is "ended", then set the end time on the last range in
    //     source ranges to highest end time.
    if (ended && sourceRanges->length())
      sourceRanges->add(
          sourceRanges->start(sourceRanges->length() - 1, ASSERT_NO_EXCEPTION),
          highestEndTime);

    // 5.3 Let new intersection ranges equal the the intersection between the
    //     intersection ranges and the source ranges.
    // 5.4 Replace the ranges in intersection ranges with the new intersection
    //     ranges.
    intersectionRanges->intersectWith(sourceRanges);
  }

  return intersectionRanges;
}
コード例 #5
0
ファイル: TimeRanges.cpp プロジェクト: mirror/chromium
void TimeRanges::invert() {
  TimeRanges* inverted = TimeRanges::create();
  double posInf = std::numeric_limits<double>::infinity();
  double negInf = -std::numeric_limits<double>::infinity();

  if (!m_ranges.size()) {
    inverted->add(negInf, posInf);
  } else {
    double start = m_ranges.first().m_start;
    if (start != negInf)
      inverted->add(negInf, start);

    for (size_t index = 0; index + 1 < m_ranges.size(); ++index)
      inverted->add(m_ranges[index].m_end, m_ranges[index + 1].m_start);

    double end = m_ranges.last().m_end;
    if (end != posInf)
      inverted->add(end, posInf);
  }

  m_ranges.swap(inverted->m_ranges);
}