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 b339974
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 35 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
9 changes: 3 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,7 @@ import {
Observable,
startWith,
} from "rxjs";
import { IStreamOrchestratorEvent } from "../types";
import { IStreamOrchestratorEvent, IStreamStatusEvent } from "../types";

/**
* Returns an Observable which emits ``true`` when all PeriodStreams given are
Expand Down Expand Up @@ -53,11 +53,8 @@ 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),
startWith(false),
distinctUntilChanged()
);
Expand Down
3 changes: 1 addition & 2 deletions src/core/stream/orchestrator/stream_orchestrator.ts
Original file line number Diff line number Diff line change
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 b339974

Please sign in to comment.