Skip to content

Commit

Permalink
add isEmptyStream on buffer status event to handle empty stream speci…
Browse files Browse the repository at this point in the history
…ficities
  • Loading branch information
peaBerberian committed Dec 6, 2022
1 parent ed0ba4b commit 65eb57c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 36 deletions.
2 changes: 0 additions & 2 deletions src/core/init/media_source_content_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,6 @@ export default class MediaSourceContentInitializer extends ContentInitializer {
return this.trigger("periodStreamCleared", evt.value);
case "representationChange":
return this.trigger("representationChange", evt.value);
case "complete-stream":
return this.trigger("completeStream", evt.value);
case "bitrateEstimationChange":
return this.trigger("bitrateEstimationChange", evt.value);
case "added-segment":
Expand Down
5 changes: 0 additions & 5 deletions src/core/init/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ export interface IContentInitializerEvents {
*/
period : Period;
};
/**
* The last (chronologically) `Period` for a given type has pushed all
* the segments it needs until the end.
*/
completeStream: { type: IBufferType };
/** Emitted when a new `Adaptation` is being considered. */
adaptationChange: {
/** The type of buffer for which the Representation is changing. */
Expand Down
6 changes: 0 additions & 6 deletions src/core/stream/events_generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
IActivePeriodChangedEvent,
IAdaptationChangeEvent,
IBitrateEstimationChangeEvent,
ICompletedStreamEvent,
IEncryptionDataEncounteredEvent,
IEndOfStreamEvent,
ILockedStreamEvent,
Expand Down Expand Up @@ -88,11 +87,6 @@ const EVENTS = {
value: { type, bitrate } };
},

streamComplete(bufferType: IBufferType) : ICompletedStreamEvent {
return { type: "complete-stream",
value: { type: bufferType } };
},

endOfStream() : IEndOfStreamEvent {
return { type: "end-of-stream",
value: undefined };
Expand Down
14 changes: 8 additions & 6 deletions src/core/stream/orchestrator/are_streams_complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
Observable,
startWith,
} from "rxjs";
import { IStreamOrchestratorEvent } from "../types";
import Manifest from "../../../manifest";
import { IStreamOrchestratorEvent, IStreamStatusEvent } from "../types";

/**
* Returns an Observable which emits ``true`` when all PeriodStreams given are
Expand All @@ -38,10 +39,12 @@ import { IStreamOrchestratorEvent } from "../types";
* segments needed for this Stream have been downloaded.
*
* When the Observable returned here emits, every Stream are finished.
* @param {Object} manifest
* @param {...Observable} streams
* @returns {Observable}
*/
export default function areStreamsComplete(
manifest : Manifest,
...streams : Array<Observable<IStreamOrchestratorEvent>>
) : Observable<boolean> {
/**
Expand All @@ -53,11 +56,10 @@ export default function areStreamsComplete(
const isCompleteArray : Array<Observable<boolean>> = streams
.map((stream) => {
return stream.pipe(
filter((evt) => {
return evt.type === "complete-stream" ||
(evt.type === "stream-status" && !evt.value.hasFinishedLoading);
}),
map((evt) => evt.type === "complete-stream"),
filter((evt) : evt is IStreamStatusEvent => evt.type === "stream-status"),
map((evt) =>
(evt.value.hasFinishedLoading || evt.value.isEmptyStream) &&
manifest.getPeriodAfter(evt.value.period) === null),
startWith(false),
distinctUntilChanged()
);
Expand Down
5 changes: 2 additions & 3 deletions src/core/stream/orchestrator/stream_orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default function StreamOrchestrator(

// Emits an "end-of-stream" event once every PeriodStream are complete.
// Emits a 'resume-stream" when it's not
const endOfStream$ = combineLatest([areStreamsComplete(...streamsArray),
const endOfStream$ = combineLatest([areStreamsComplete(manifest, ...streamsArray),
isLastPeriodKnown$])
.pipe(map(([areComplete, isLastPeriodKnown]) => areComplete && isLastPeriodKnown),
distinctUntilChanged(),
Expand Down Expand Up @@ -498,8 +498,7 @@ export default function StreamOrchestrator(
if (evt.value.hasFinishedLoading) {
const nextPeriod = manifest.getPeriodAfter(basePeriod);
if (nextPeriod === null) {
return observableConcat(observableOf(evt),
observableOf(EVENTS.streamComplete(bufferType)));
return observableOf(evt);
}

// current Stream is full, create the next one if not
Expand Down
1 change: 1 addition & 0 deletions src/core/stream/period/create_empty_adaptation_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default function createEmptyAdaptationStream(
bufferType,
position,
imminentDiscontinuity: null,
isEmptyStream: true,
hasFinishedLoading,
neededSegments: [],
shouldRefreshManifest: false } });
Expand Down
1 change: 1 addition & 0 deletions src/core/stream/representation/representation_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export default function RepresentationStream<TSegmentDataType>({
position: observation.position.last,
bufferType,
imminentDiscontinuity: status.imminentDiscontinuity,
isEmptyStream: false,
hasFinishedLoading: status.hasFinishedLoading,
neededSegments: status.neededSegments } });
let bufferRemoval = EMPTY;
Expand Down
14 changes: 5 additions & 9 deletions src/core/stream/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export interface IStreamStatusEvent {
* end of the Period.
*/
hasFinishedLoading : boolean;
/**
* If `true`, this stream is a placeholder stream which will never load any
* segment.
*/
isEmptyStream : boolean;
/**
* Segments that will be scheduled for download to fill the buffer until
* the buffer goal (first element of that list might already be ).
Expand Down Expand Up @@ -317,13 +322,6 @@ export interface IEndOfStreamEvent { type: "end-of-stream";
export interface IResumeStreamEvent { type: "resume-stream";
value: undefined; }

/**
* The last (chronologically) `PeriodStream` for a given type has pushed all
* the segments it needs until the end.
*/
export interface ICompletedStreamEvent { type: "complete-stream";
value : { type: IBufferType }; }

/**
* A situation needs the MediaSource to be reloaded.
*
Expand Down Expand Up @@ -499,7 +497,6 @@ export type IPeriodStreamEvent = IPeriodStreamReadyEvent |

/** Event coming from function(s) managing multiple PeriodStreams. */
export type IMultiplePeriodStreamsEvent = IPeriodStreamClearedEvent |
ICompletedStreamEvent |

// From a PeriodStream

Expand Down Expand Up @@ -531,7 +528,6 @@ export type IStreamOrchestratorEvent = IActivePeriodChangedEvent |
IResumeStreamEvent |

IPeriodStreamClearedEvent |
ICompletedStreamEvent |

// From a PeriodStream

Expand Down
8 changes: 3 additions & 5 deletions tests/integration/scenarios/end_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "../../contents/DASH_static_SegmentTimeline";
import RxPlayer from "../../../src";
import sleep from "../../utils/sleep.js";
import { waitForLoadedStateAfterLoadVideo } from "../../utils/waitForPlayerState";
import waitForState, { waitForLoadedStateAfterLoadVideo } from "../../utils/waitForPlayerState";

let player;

Expand Down Expand Up @@ -71,13 +71,11 @@ describe("end number", function () {
await sleep(500);
expect(xhrMock.getLockedXHR().length).to.equal(2);
xhrMock.flush();
player.seekTo(19.7);
player.seekTo(19);
await sleep(50);
expect(xhrMock.getLockedXHR().length).to.equal(2);
xhrMock.flush();
await sleep(5000);
expect(xhrMock.getLockedXHR().length).to.equal(0);
expect(player.getPlayerState()).to.eql("ENDED");
await waitForState(player, "ENDED", ["BUFFERING", "RELOADING", "PLAYING"]);
expect(player.getPosition()).to.be.closeTo(20, 1);
});

Expand Down

0 comments on commit 65eb57c

Please sign in to comment.