<commit_before>/**
 * Copyright 2015 CANAL+ Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import nextTick from "next-tick";
import {
  defer as observableDefer,
  fromEvent as observableFromEvent,
  Observable,
  Observer,
  of as observableOf,
} from "rxjs";
import { take } from "rxjs/operators";
import log from "../log";
import castToObservable from "../utils/castToObservable";
import EventEmitter from "../utils/eventemitter";
import tryCatch from "../utils/rx-tryCatch";
import {
  ICompatMediaKeySystemAccess,
  ICompatMediaKeySystemConfiguration,
  ICompatTextTrack,
  ICompatVTTCue,
  isFirefox,
  isIE11,
  isIEOrEdge,
  MediaSource_,
  READY_STATES,
  VTTCue_,
} from "./constants";
import * as events from "./events";
import {
  exitFullscreen,
  isFullscreen,
  requestFullscreen,
} from "./fullscreen";

import {
  createSession,
  CustomMediaKeySystemAccess,
  getInitData,
  ICustomMediaKeys,
  ICustomMediaKeySession,
  ICustomMediaKeySystemAccess,
  requestMediaKeySystemAccess,
  setMediaKeys,
} from "./eme";

export interface ICustomSourceBuffer<T> {
  addEventListener : (eventName : string, cb : (arg : any) => void) => void;
  removeEventListener : (
    eventName : string,
    callback : (arg : any) => void
  ) => void;
  buffered : TimeRanges;
  changeType? : (type: string) => void;
  updating : boolean;
  timestampOffset : number;
  appendBuffer(data : T) : void;
  remove(from : number, to : number) : void;
  abort() : void;
}

/**
 * Returns true if the given codec is supported by the browser's MediaSource
 * implementation.
 * @returns {Boolean}
 */
function isCodecSupported(codec : string) : boolean {
  if (!MediaSource_) {
    return false;
  }

  /* tslint:disable no-unbound-method */
  if (typeof MediaSource_.isTypeSupported === "function") {
  /* tslint:enable no-unbound-method */
    return MediaSource_.isTypeSupported(codec);
  }

  return true;
}

function isVTTCue(cue : ICompatVTTCue|TextTrackCue) : cue is ICompatVTTCue {
  return typeof (window as any).VTTCue === "function" &&
    cue instanceof (window as any).VTTCue;
}

/**
 * Returns true if the browser has the minimum needed EME APIs to decrypt a
 * content.
 * @returns {Boolean}
 */
function hasEMEAPIs() : boolean {
  return typeof requestMediaKeySystemAccess === "function";
}

/**
 * TODO(pierre): fix patchSegmentInPlace to work with IE11. Maybe
 * try to put free atom inside traf children
 *
 * Returns true if the current target is tolerant enough for us to
 * simply be able to "patch" an ISOBMFF segment or if we have to create a
 * new one from scratch instead.
 *
 * TODO understand what the fudge Pierre meant here
 * @returns {Boolean}
 */
function canPatchISOBMFFSegment() {
  return !isIE11;<commit_msg>compat/smooth: patch ISOBMFF even on Edge (Rollback)<commit_after>/**
 * Copyright 2015 CANAL+ Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import nextTick from "next-tick";
import {
  defer as observableDefer,
  fromEvent as observableFromEvent,
  Observable,
  Observer,
  of as observableOf,
} from "rxjs";
import { take } from "rxjs/operators";
import log from "../log";
import castToObservable from "../utils/castToObservable";
import EventEmitter from "../utils/eventemitter";
import tryCatch from "../utils/rx-tryCatch";
import {
  ICompatMediaKeySystemAccess,
  ICompatMediaKeySystemConfiguration,
  ICompatTextTrack,
  ICompatVTTCue,
  isFirefox,
  isIE11,
  isIEOrEdge,
  MediaSource_,
  READY_STATES,
  VTTCue_,
} from "./constants";
import * as events from "./events";
import {
  exitFullscreen,
  isFullscreen,
  requestFullscreen,
} from "./fullscreen";

import {
  createSession,
  CustomMediaKeySystemAccess,
  getInitData,
  ICustomMediaKeys,
  ICustomMediaKeySession,
  ICustomMediaKeySystemAccess,
  requestMediaKeySystemAccess,
  setMediaKeys,
} from "./eme";

export interface ICustomSourceBuffer<T> {
  addEventListener : (eventName : string, cb : (arg : any) => void) => void;
  removeEventListener : (
    eventName : string,
    callback : (arg : any) => void
  ) => void;
  buffered : TimeRanges;
  changeType? : (type: string) => void;
  updating : boolean;
  timestampOffset : number;
  appendBuffer(data : T) : void;
  remove(from : number, to : number) : void;
  abort() : void;
}

/**
 * Returns true if the given codec is supported by the browser's MediaSource
 * implementation.
 * @returns {Boolean}
 */
function isCodecSupported(codec : string) : boolean {
  if (!MediaSource_) {
    return false;
  }

  /* tslint:disable no-unbound-method */
  if (typeof MediaSource_.isTypeSupported === "function") {
  /* tslint:enable no-unbound-method */
    return MediaSource_.isTypeSupported(codec);
  }

  return true;
}

function isVTTCue(cue : ICompatVTTCue|TextTrackCue) : cue is ICompatVTTCue {
  return typeof (window as any).VTTCue === "function" &&
    cue instanceof (window as any).VTTCue;
}

/**
 * Returns true if the browser has the minimum needed EME APIs to decrypt a
 * content.
 * @returns {Boolean}
 */
function hasEMEAPIs() : boolean {
  return typeof requestMediaKeySystemAccess === "function";
}

/**
 * TODO(pierre): fix patchSegmentInPlace to work with IE11. Maybe
 * try to put free atom inside traf children
 *
 * Returns true if the current target is tolerant enough for us to
 * simply be able to "patch" an ISOBMFF segment or if we have to create a
 * new one from scratch instead.
 *
 * TODO understand what the fudge Pierre meant here
 * @returns {Boolean}
 */
function canPatchISOBMFFSegment() {
  return !isIEOrEdge;
{'fraction_non_alphanumeric': 0.10160183066361556, 'fraction_numerical': 0.003966437833714722, 'mean_word_length': 4.02760736196319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3263819', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1955, 'n_words': 671}