forked from video-dev/hls.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sample AES decryption with 48 AVC Closes: video-dev#3102
- Loading branch information
Krystian Kuczek
committed
Oct 19, 2020
1 parent
489fbe3
commit 78b9bcd
Showing
46 changed files
with
79,096 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** | ||
* HLS config | ||
*/ | ||
import BufferController from './controller/buffer-controller'; | ||
import * as Cues from './utils/cues'; | ||
import EMEController from './controller/eme-controller'; | ||
import { MediaKeyFunc } from './utils/mediakeys-helper'; | ||
declare type ABRControllerConfig = { | ||
abrEwmaFastLive: number; | ||
abrEwmaSlowLive: number; | ||
abrEwmaFastVoD: number; | ||
abrEwmaSlowVoD: number; | ||
abrEwmaDefaultEstimate: number; | ||
abrBandWidthFactor: number; | ||
abrBandWidthUpFactor: number; | ||
abrMaxWithRealBitrate: boolean; | ||
maxStarvationDelay: number; | ||
maxLoadingDelay: number; | ||
}; | ||
export declare type BufferControllerConfig = { | ||
appendErrorMaxRetry: number; | ||
liveDurationInfinity: boolean; | ||
liveBackBufferLength: number; | ||
}; | ||
declare type CapLevelControllerConfig = { | ||
capLevelToPlayerSize: boolean; | ||
}; | ||
export declare type DRMSystemOptions = { | ||
audioRobustness?: string; | ||
videoRobustness?: string; | ||
}; | ||
export declare type EMEControllerConfig = { | ||
licenseXhrSetup?: (xhr: XMLHttpRequest, url: string) => void; | ||
emeEnabled: boolean; | ||
widevineLicenseUrl?: string; | ||
drmSystemOptions: DRMSystemOptions; | ||
requestMediaKeySystemAccessFunc: MediaKeyFunc | null; | ||
}; | ||
declare type FragmentLoaderConfig = { | ||
fLoader: any; | ||
fragLoadingTimeOut: number; | ||
fragLoadingMaxRetry: number; | ||
fragLoadingRetryDelay: number; | ||
fragLoadingMaxRetryTimeout: number; | ||
}; | ||
declare type FPSControllerConfig = { | ||
capLevelOnFPSDrop: boolean; | ||
fpsDroppedMonitoringPeriod: number; | ||
fpsDroppedMonitoringThreshold: number; | ||
}; | ||
declare type LevelControllerConfig = { | ||
startLevel?: number; | ||
}; | ||
declare type MP4RemuxerConfig = { | ||
stretchShortVideoTrack: boolean; | ||
maxAudioFramesDrift: number; | ||
}; | ||
declare type PlaylistLoaderConfig = { | ||
pLoader: any; | ||
manifestLoadingTimeOut: number; | ||
manifestLoadingMaxRetry: number; | ||
manifestLoadingRetryDelay: number; | ||
manifestLoadingMaxRetryTimeout: number; | ||
levelLoadingTimeOut: number; | ||
levelLoadingMaxRetry: number; | ||
levelLoadingRetryDelay: number; | ||
levelLoadingMaxRetryTimeout: number; | ||
}; | ||
declare type StreamControllerConfig = { | ||
autoStartLoad: boolean; | ||
startPosition: number; | ||
defaultAudioCodec?: string; | ||
initialLiveManifestSize: number; | ||
maxBufferLength: number; | ||
maxBufferSize: number; | ||
maxBufferHole: number; | ||
lowBufferWatchdogPeriod: number; | ||
highBufferWatchdogPeriod: number; | ||
nudgeOffset: number; | ||
nudgeMaxRetry: number; | ||
maxFragLookUpTolerance: number; | ||
liveSyncDurationCount: number; | ||
liveMaxLatencyDurationCount: number; | ||
liveSyncDuration?: number; | ||
liveMaxLatencyDuration?: number; | ||
maxMaxBufferLength: number; | ||
startFragPrefetch: boolean; | ||
testBandwidth: boolean; | ||
}; | ||
declare type TimelineControllerConfig = { | ||
cueHandler: Cues.CuesInterface; | ||
enableCEA708Captions: boolean; | ||
enableWebVTT: boolean; | ||
captionsTextTrack1Label: string; | ||
captionsTextTrack1LanguageCode: string; | ||
captionsTextTrack2Label: string; | ||
captionsTextTrack2LanguageCode: string; | ||
captionsTextTrack3Label: string; | ||
captionsTextTrack3LanguageCode: string; | ||
captionsTextTrack4Label: string; | ||
captionsTextTrack4LanguageCode: string; | ||
renderTextTracksNatively: boolean; | ||
}; | ||
declare type TSDemuxerConfig = { | ||
forceKeyFrameOnDiscontinuity: boolean; | ||
}; | ||
export declare type HlsConfig = { | ||
debug: boolean; | ||
enableWorker: boolean; | ||
enableSoftwareAES: boolean; | ||
minAutoBitrate: number; | ||
loader: any; | ||
xhrSetup?: (xhr: XMLHttpRequest, url: string) => void; | ||
audioStreamController?: any; | ||
audioTrackController?: any; | ||
subtitleStreamController?: any; | ||
subtitleTrackController?: any; | ||
timelineController?: any; | ||
emeController?: typeof EMEController; | ||
abrController: any; | ||
bufferController: typeof BufferController; | ||
capLevelController: any; | ||
fpsController: any; | ||
} & ABRControllerConfig & BufferControllerConfig & CapLevelControllerConfig & EMEControllerConfig & FPSControllerConfig & FragmentLoaderConfig & LevelControllerConfig & MP4RemuxerConfig & PlaylistLoaderConfig & StreamControllerConfig & TimelineControllerConfig & TSDemuxerConfig; | ||
export declare const hlsDefaultConfig: HlsConfig; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import EventHandler from '../event-handler'; | ||
import { TrackSet } from '../types/track'; | ||
import { Segment } from '../types/segment'; | ||
declare type ExtendedSourceBuffer = SourceBuffer & { | ||
ended?: boolean; | ||
}; | ||
declare type SourceBufferName = 'video' | 'audio'; | ||
declare type SourceBuffers = Partial<Record<SourceBufferName, ExtendedSourceBuffer>>; | ||
interface SourceBufferFlushRange { | ||
start: number; | ||
end: number; | ||
type: SourceBufferName; | ||
} | ||
declare class BufferController extends EventHandler { | ||
private _msDuration; | ||
private _levelDuration; | ||
private _levelTargetDuration; | ||
private _live; | ||
private _objectUrl; | ||
private _needsFlush; | ||
private _needsEos; | ||
private config; | ||
audioTimestampOffset?: number; | ||
bufferCodecEventsExpected: number; | ||
private _bufferCodecEventsTotal; | ||
media: HTMLMediaElement | null; | ||
mediaSource: MediaSource | null; | ||
segments: Segment[]; | ||
parent?: string; | ||
appending: boolean; | ||
appended: number; | ||
appendError: number; | ||
flushBufferCounter: number; | ||
tracks: TrackSet; | ||
pendingTracks: TrackSet; | ||
sourceBuffer: SourceBuffers; | ||
flushRange: SourceBufferFlushRange[]; | ||
constructor(hls: any); | ||
destroy(): void; | ||
onLevelPtsUpdated(data: { | ||
details: any; | ||
type: SourceBufferName; | ||
start: number; | ||
}): void; | ||
onManifestParsed(data: { | ||
altAudio: boolean; | ||
audio: boolean; | ||
video: boolean; | ||
}): void; | ||
onMediaAttaching(data: { | ||
media: HTMLMediaElement; | ||
}): void; | ||
onMediaDetaching(): void; | ||
checkPendingTracks(): void; | ||
private _onMediaSourceOpen; | ||
private _onMediaSourceClose; | ||
private _onMediaSourceEnded; | ||
private _onSBUpdateEnd; | ||
private _onSBUpdateError; | ||
onBufferReset(): void; | ||
onBufferCodecs(tracks: TrackSet): void; | ||
createSourceBuffers(tracks: TrackSet): void; | ||
onBufferAppending(data: Segment): void; | ||
onBufferEos(data: { | ||
type?: SourceBufferName; | ||
}): void; | ||
checkEos(): void; | ||
onBufferFlushing(data: { | ||
startOffset: number; | ||
endOffset: number; | ||
type?: SourceBufferName; | ||
}): void; | ||
flushLiveBackBuffer(): void; | ||
onLevelUpdated({ details }: { | ||
details: { | ||
totalduration: number; | ||
targetduration?: number; | ||
averagetargetduration?: number; | ||
live: boolean; | ||
fragments: any[]; | ||
}; | ||
}): void; | ||
/** | ||
* Update Media Source duration to current level duration or override to Infinity if configuration parameter | ||
* 'liveDurationInfinity` is set to `true` | ||
* More details: https://github.com/video-dev/hls.js/issues/355 | ||
*/ | ||
updateMediaElementDuration(): void; | ||
updateSeekableRange(levelDetails: any): void; | ||
doFlush(): void; | ||
doAppending(): void; | ||
flushBuffer(startOffset: number, endOffset: number, sbType: SourceBufferName): boolean; | ||
/** | ||
* Removes first buffered range from provided source buffer that lies within given start and end offsets. | ||
* | ||
* @param {string} type Type of the source buffer, logging purposes only. | ||
* @param {SourceBuffer} sb Target SourceBuffer instance. | ||
* @param {number} startOffset | ||
* @param {number} endOffset | ||
* | ||
* @returns {boolean} True when source buffer remove requested. | ||
*/ | ||
removeBufferRange(type: string, sb: ExtendedSourceBuffer, startOffset: number, endOffset: number): boolean; | ||
} | ||
export default BufferController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* @author Stephan Hesse <disparat@gmail.com> | <tchakabam@gmail.com> | ||
* | ||
* DRM support for Hls.js | ||
*/ | ||
import EventHandler from '../event-handler'; | ||
import { KeySystems, MediaKeyFunc } from '../utils/mediakeys-helper'; | ||
/** | ||
* Controller to deal with encrypted media extensions (EME) | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Encrypted_Media_Extensions_API | ||
* | ||
* @class | ||
* @constructor | ||
*/ | ||
declare class EMEController extends EventHandler { | ||
private _widevineLicenseUrl?; | ||
private _licenseXhrSetup?; | ||
private _emeEnabled; | ||
private _requestMediaKeySystemAccess; | ||
private _drmSystemOptions; | ||
private _config; | ||
private _mediaKeysList; | ||
private _media; | ||
private _hasSetMediaKeys; | ||
private _requestLicenseFailureCount; | ||
private mediaKeysPromise; | ||
/** | ||
* @constructs | ||
* @param {Hls} hls Our Hls.js instance | ||
*/ | ||
constructor(hls: any); | ||
/** | ||
* @param {string} keySystem Identifier for the key-system, see `KeySystems` enum | ||
* @returns {string} License server URL for key-system (if any configured, otherwise causes error) | ||
* @throws if a unsupported keysystem is passed | ||
*/ | ||
getLicenseServerUrl(keySystem: KeySystems): string; | ||
/** | ||
* Requests access object and adds it to our list upon success | ||
* @private | ||
* @param {string} keySystem System ID (see `KeySystems`) | ||
* @param {Array<string>} audioCodecs List of required audio codecs to support | ||
* @param {Array<string>} videoCodecs List of required video codecs to support | ||
* @throws When a unsupported KeySystem is passed | ||
*/ | ||
private _attemptKeySystemAccess; | ||
get requestMediaKeySystemAccess(): MediaKeyFunc; | ||
/** | ||
* Handles obtaining access to a key-system | ||
* @private | ||
* @param {string} keySystem | ||
* @param {MediaKeySystemAccess} mediaKeySystemAccess https://developer.mozilla.org/en-US/docs/Web/API/MediaKeySystemAccess | ||
*/ | ||
private _onMediaKeySystemAccessObtained; | ||
/** | ||
* Handles key-creation (represents access to CDM). We are going to create key-sessions upon this | ||
* for all existing keys where no session exists yet. | ||
* | ||
* @private | ||
*/ | ||
private _onMediaKeysCreated; | ||
/** | ||
* @private | ||
* @param {*} keySession | ||
*/ | ||
private _onNewMediaKeySession; | ||
/** | ||
* @private | ||
* @param {MediaKeySession} keySession | ||
* @param {ArrayBuffer} message | ||
*/ | ||
private _onKeySessionMessage; | ||
/** | ||
* @private | ||
* @param e {MediaEncryptedEvent} | ||
*/ | ||
private _onMediaEncrypted; | ||
/** | ||
* @private | ||
*/ | ||
private _attemptSetMediaKeys; | ||
/** | ||
* @private | ||
*/ | ||
private _generateRequestWithPreferredKeySession; | ||
/** | ||
* @private | ||
* @param {string} url License server URL | ||
* @param {ArrayBuffer} keyMessage Message data issued by key-system | ||
* @param {function} callback Called when XHR has succeeded | ||
* @returns {XMLHttpRequest} Unsent (but opened state) XHR object | ||
* @throws if XMLHttpRequest construction failed | ||
*/ | ||
private _createLicenseXhr; | ||
/** | ||
* @private | ||
* @param {XMLHttpRequest} xhr | ||
* @param {string} url License server URL | ||
* @param {ArrayBuffer} keyMessage Message data issued by key-system | ||
* @param {function} callback Called when XHR has succeeded | ||
*/ | ||
private _onLicenseRequestReadyStageChange; | ||
/** | ||
* @private | ||
* @param {MediaKeysListItem} keysListItem | ||
* @param {ArrayBuffer} keyMessage | ||
* @returns {ArrayBuffer} Challenge data posted to license server | ||
* @throws if KeySystem is unsupported | ||
*/ | ||
private _generateLicenseRequestChallenge; | ||
/** | ||
* @private | ||
* @param keyMessage | ||
* @param callback | ||
*/ | ||
private _requestLicense; | ||
onMediaAttached(data: { | ||
media: HTMLMediaElement; | ||
}): void; | ||
onMediaDetached(): void; | ||
onManifestParsed(data: any): void; | ||
} | ||
export default EMEController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Fragment from '../loader/fragment'; | ||
/** | ||
* Returns first fragment whose endPdt value exceeds the given PDT. | ||
* @param {Array<Fragment>} fragments - The array of candidate fragments | ||
* @param {number|null} [PDTValue = null] - The PDT value which must be exceeded | ||
* @param {number} [maxFragLookUpTolerance = 0] - The amount of time that a fragment's start/end can be within in order to be considered contiguous | ||
* @returns {*|null} fragment - The best matching fragment | ||
*/ | ||
export declare function findFragmentByPDT(fragments: Array<Fragment>, PDTValue: number | null, maxFragLookUpTolerance: number): Fragment | null; | ||
/** | ||
* Finds a fragment based on the SN of the previous fragment; or based on the needs of the current buffer. | ||
* This method compensates for small buffer gaps by applying a tolerance to the start of any candidate fragment, thus | ||
* breaking any traps which would cause the same fragment to be continuously selected within a small range. | ||
* @param {*} fragPrevious - The last frag successfully appended | ||
* @param {Array<Fragment>} fragments - The array of candidate fragments | ||
* @param {number} [bufferEnd = 0] - The end of the contiguous buffered range the playhead is currently within | ||
* @param {number} maxFragLookUpTolerance - The amount of time that a fragment's start/end can be within in order to be considered contiguous | ||
* @returns {*} foundFrag - The best matching fragment | ||
*/ | ||
export declare function findFragmentByPTS(fragPrevious: Fragment, fragments: Array<Fragment>, bufferEnd?: number, maxFragLookUpTolerance?: number): Fragment | null; | ||
/** | ||
* The test function used by the findFragmentBySn's BinarySearch to look for the best match to the current buffer conditions. | ||
* @param {*} candidate - The fragment to test | ||
* @param {number} [bufferEnd = 0] - The end of the current buffered range the playhead is currently within | ||
* @param {number} [maxFragLookUpTolerance = 0] - The amount of time that a fragment's start can be within in order to be considered contiguous | ||
* @returns {number} - 0 if it matches, 1 if too low, -1 if too high | ||
*/ | ||
export declare function fragmentWithinToleranceTest(bufferEnd: number | undefined, maxFragLookUpTolerance: number | undefined, candidate: Fragment): 1 | 0 | -1; | ||
/** | ||
* The test function used by the findFragmentByPdt's BinarySearch to look for the best match to the current buffer conditions. | ||
* This function tests the candidate's program date time values, as represented in Unix time | ||
* @param {*} candidate - The fragment to test | ||
* @param {number} [pdtBufferEnd = 0] - The Unix time representing the end of the current buffered range | ||
* @param {number} [maxFragLookUpTolerance = 0] - The amount of time that a fragment's start can be within in order to be considered contiguous | ||
* @returns {boolean} True if contiguous, false otherwise | ||
*/ | ||
export declare function pdtWithinToleranceTest(pdtBufferEnd: number, maxFragLookUpTolerance: number, candidate: Fragment): boolean; |
Oops, something went wrong.