Example #1
0
  bool LessThan(SimpleTextTrackEvent* aOne, SimpleTextTrackEvent* aTwo) const
  {
    if (aOne->mTime < aTwo->mTime) {
      return true;
    } else if (aOne->mTime > aTwo->mTime) {
      return false;
    }

    int32_t positionOne = TrackChildPosition(aOne);
    int32_t positionTwo = TrackChildPosition(aTwo);
    if (positionOne < positionTwo) {
      return true;
    } else if (positionOne > positionTwo) {
      return false;
    }

    if (aOne->mName.EqualsLiteral("enter") ||
        aTwo->mName.EqualsLiteral("exit")) {
      return true;
    }
    return false;
  }
bool CompareTextTracks::LessThan(TextTrack* aOne, TextTrack* aTwo) const {
  // Protect against nullptr TextTrack objects; treat them as
  // sorting toward the end.
  if (!aOne) {
    return false;
  }
  if (!aTwo) {
    return true;
  }
  TextTrackSource sourceOne = aOne->GetTextTrackSource();
  TextTrackSource sourceTwo = aTwo->GetTextTrackSource();
  if (sourceOne != sourceTwo) {
    return sourceOne == TextTrackSource::Track ||
           (sourceOne == AddTextTrack && sourceTwo == MediaResourceSpecific);
  }
  switch (sourceOne) {
    case Track: {
      int32_t positionOne = TrackChildPosition(aOne);
      int32_t positionTwo = TrackChildPosition(aTwo);
      // If either position one or positiontwo are -1 then something has gone
      // wrong. In this case we should just put them at the back of the list.
      return positionOne != -1 && positionTwo != -1 &&
             positionOne < positionTwo;
    }
    case AddTextTrack:
      // For AddTextTrack sources the tracks will already be in the correct
      // relative order in the source array. Assume we're called in iteration
      // order and can therefore always report aOne < aTwo to maintain the
      // original temporal ordering.
      return true;
    case MediaResourceSpecific:
      // No rules for Media Resource Specific tracks yet.
      break;
  }
  return true;
}