Skip to content

Commit

Permalink
Merge pull request #738 from canalplus/misc/dont-download-video-on-au…
Browse files Browse the repository at this point in the history
…dio-elt

source-buffers: Do not create a video SourceBuffer on an audio element
  • Loading branch information
peaBerberian committed Jun 3, 2020
2 parents 060c789 + 839e97d commit 53ad2dc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/core/buffers/orchestrator/buffer_orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import ABRManager from "../../abr";
import { SegmentFetcherCreator } from "../../fetchers";
import SourceBuffersStore, {
BufferGarbageCollector,
getBufferTypes,
IBufferType,
ITextTrackSourceBufferOptions,
QueuedSourceBuffer,
Expand Down Expand Up @@ -160,7 +159,7 @@ export default function BufferOrchestrator(
return null;
}, null));

const bufferTypes = getBufferTypes();
const bufferTypes = sourceBuffersStore.getBufferTypes();

// Every PeriodBuffers for every possible types
const buffersArray = bufferTypes.map((bufferType) => {
Expand Down
2 changes: 0 additions & 2 deletions src/core/source_buffers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import QueuedSourceBuffer, {
IPushedChunkData,
} from "./queued_source_buffer";
import SourceBuffersStore, {
getBufferTypes,
ISourceBufferOptions,
ITextTrackSourceBufferOptions,
} from "./source_buffers_store";
Expand All @@ -37,5 +36,4 @@ export {
ISourceBufferOptions,
ITextTrackSourceBufferOptions,
QueuedSourceBuffer,
getBufferTypes,
};
63 changes: 40 additions & 23 deletions src/core/source_buffers/source_buffers_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ const POSSIBLE_BUFFER_TYPES : IBufferType[] = [ "audio",
"text",
"image" ];

/**
* Get all currently available buffer types.
* /!\ This list can evolve at runtime depending on feature switching.
* @returns {Array.<string>}
*/
export function getBufferTypes() : IBufferType[] {
const bufferTypes : IBufferType[] = ["audio", "video"];
if (features.nativeTextTracksBuffer != null ||
features.htmlTextTracksBuffer != null
) {
bufferTypes.push("text");
}
if (features.imageBuffer != null) {
bufferTypes.push("image");
}
return bufferTypes;
}

// Options available for a "text" SourceBuffer
export type ITextTrackSourceBufferOptions = { textTrackMode? : "native";
hideNativeSubtitle? : boolean; } |
Expand Down Expand Up @@ -162,6 +144,34 @@ export default class SourceBuffersStore {
this._onNativeSourceBufferAddedOrDisabled = [];
}

/**
* Get all currently available buffer types.
* /!\ This list can evolve at runtime depending on feature switching.
* @returns {Array.<string>}
*/
public getBufferTypes() : IBufferType[] {
const bufferTypes : IBufferType[] = this.getNativeBufferTypes();
if (features.nativeTextTracksBuffer != null ||
features.htmlTextTracksBuffer != null
) {
bufferTypes.push("text");
}
if (features.imageBuffer != null) {
bufferTypes.push("image");
}
return bufferTypes;
}

/**
* Get all "native" buffer types that should be created before beginning to
* push contents.
* @returns {Array.<string>}
*/
public getNativeBufferTypes() : IBufferType[] {
return this._mediaElement.nodeName === "AUDIO" ? ["audio"] :
["video", "audio"];
}

/**
* Returns the current "status" of the buffer in the SourceBuffer.
*
Expand Down Expand Up @@ -226,7 +236,7 @@ export default class SourceBuffersStore {
/**
* Explicitely disable the SourceBuffer for a given buffer type.
* A call to this function is needed at least for unused native buffer types
* ("audio" and "video"), to be able to emit through
* (usually "audio" and "video"), to be able to emit through
* `waitForUsableSourceBuffers` when conditions are met.
* @param {string}
*/
Expand Down Expand Up @@ -370,13 +380,20 @@ export default class SourceBuffersStore {
* created native SourceBuffers.
*/
private _areNativeSourceBuffersUsable() {
if (this._initializedSourceBuffers.audio === undefined ||
this._initializedSourceBuffers.video === undefined)
const nativeBufferTypes = this.getNativeBufferTypes();

if (nativeBufferTypes.some(sbType =>
this._initializedSourceBuffers[sbType] === undefined))
{
// one is not yet initialized/disabled
return false;
}
if (this._initializedSourceBuffers.video === null) {
return this._initializedSourceBuffers.audio !== null;

if (nativeBufferTypes.every(sbType =>
this._initializedSourceBuffers[sbType] === null))
{
// they all are disabled: we can't play the content
return false;
}
return true;
}
Expand Down

0 comments on commit 53ad2dc

Please sign in to comment.