Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fire 'INIT_DEMUXER' event #134

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions d.ts/src/core/transmuxing-events.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare enum TransmuxingEvents {
IO_ERROR = "io_error",
DEMUX_ERROR = "demux_error",
INIT_DEMUXER = "init_demuxer",
INIT_SEGMENT = "init_segment",
MEDIA_SEGMENT = "media_segment",
LOADING_COMPLETE = "loading_complete",
Expand Down
2 changes: 1 addition & 1 deletion d.ts/src/player/player-engine-worker-msg-def.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type WorkerMessagePacketPlayerEventError = WorkerMessagePacketPlayerEvent
};
export type WorkerMessagePacketPlayerEventExtraData = WorkerMessagePacketPlayerEvent & {
msg: 'player_event';
event: PlayerEvents.METADATA_ARRIVED | PlayerEvents.SCRIPTDATA_ARRIVED | PlayerEvents.TIMED_ID3_METADATA_ARRIVED | PlayerEvents.SYNCHRONOUS_KLV_METADATA_ARRIVED | PlayerEvents.ASYNCHRONOUS_KLV_METADATA_ARRIVED | PlayerEvents.SMPTE2038_METADATA_ARRIVED | PlayerEvents.SCTE35_METADATA_ARRIVED | PlayerEvents.PES_PRIVATE_DATA_DESCRIPTOR | PlayerEvents.PES_PRIVATE_DATA_ARRIVED;
event: PlayerEvents.METADATA_ARRIVED | PlayerEvents.SCRIPTDATA_ARRIVED | PlayerEvents.TIMED_ID3_METADATA_ARRIVED | PlayerEvents.SYNCHRONOUS_KLV_METADATA_ARRIVED | PlayerEvents.ASYNCHRONOUS_KLV_METADATA_ARRIVED | PlayerEvents.SMPTE2038_METADATA_ARRIVED | PlayerEvents.SCTE35_METADATA_ARRIVED | PlayerEvents.PES_PRIVATE_DATA_DESCRIPTOR | PlayerEvents.PES_PRIVATE_DATA_ARRIVED | PlayerEvents.INIT_DEMUXER;
extraData: any;
};
export type WorkerMessagePacketTransmuxingEvent = WorkerMessagePacket & {
Expand Down
3 changes: 2 additions & 1 deletion d.ts/src/player/player-events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare enum PlayerEvents {
PES_PRIVATE_DATA_DESCRIPTOR = "pes_private_data_descriptor",
PES_PRIVATE_DATA_ARRIVED = "pes_private_data_arrived",
STATISTICS_INFO = "statistics_info",
DESTROYING = "destroying"
DESTROYING = "destroying",
INIT_DEMUXER = "init_demuxer"
}
export default PlayerEvents;
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ A series of constants that can be used with `Player.on()` / `Player.off()`. They
| PES_PRIVATE_DATA_ARRIVED | Provides ISO/IEC 13818-1 PES packets containing private data (stream_type=0x06) callback |
| STATISTICS_INFO | Provides playback statistics information like dropped frames, current speed, etc. |
| DESTROYING | Fired when the player begins teardown |
| INIT_DEMUXER | Fired when demuxer first created |

### mpegts.ErrorTypes

Expand Down
8 changes: 8 additions & 0 deletions src/core/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Transmuxer {
if (this._controller) {
let ctl = this._controller;
ctl.on(TransmuxingEvents.IO_ERROR, this._onIOError.bind(this));
ctl.on(TransmuxingEvents.INIT_DEMUXER, this._onInitDemuxer.bind(this));
ctl.on(TransmuxingEvents.DEMUX_ERROR, this._onDemuxError.bind(this));
ctl.on(TransmuxingEvents.INIT_SEGMENT, this._onInitSegment.bind(this));
ctl.on(TransmuxingEvents.MEDIA_SEGMENT, this._onMediaSegment.bind(this));
Expand Down Expand Up @@ -239,6 +240,12 @@ class Transmuxer {
});
}

_onInitDemuxer(probeData) {
Promise.resolve().then(() => {
this._emitter.emit(TransmuxingEvents.INIT_DEMUXER, probeData);
});
}

_onDemuxError(type, info) {
Promise.resolve().then(() => {
this._emitter.emit(TransmuxingEvents.DEMUX_ERROR, type, info);
Expand Down Expand Up @@ -281,6 +288,7 @@ class Transmuxer {
Object.setPrototypeOf(data, MediaInfo.prototype);
this._emitter.emit(message.msg, data);
break;
case TransmuxingEvents.INIT_DEMUXER:
case TransmuxingEvents.METADATA_ARRIVED:
case TransmuxingEvents.SCRIPTDATA_ARRIVED:
case TransmuxingEvents.TIMED_ID3_METADATA_ARRIVED:
Expand Down
4 changes: 4 additions & 0 deletions src/core/transmuxing-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ class TransmuxingController {
}
}

if (this._demuxer) {
this._emitter.emit(TransmuxingEvents.INIT_DEMUXER, probeData);
}

if (!probeData.match && !probeData.needMoreData) {
// Both probing as FLV / MPEG-TS failed, report error
probeData = null;
Expand Down
1 change: 1 addition & 0 deletions src/core/transmuxing-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
enum TransmuxingEvents {
IO_ERROR = 'io_error',
DEMUX_ERROR = 'demux_error',
INIT_DEMUXER = 'init_demuxer',
INIT_SEGMENT = 'init_segment',
MEDIA_SEGMENT = 'media_segment',
LOADING_COMPLETE = 'loading_complete',
Expand Down
8 changes: 8 additions & 0 deletions src/core/transmuxing-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ let TransmuxingWorker = function (self) {
case 'init':
controller = new TransmuxingController(e.data.param[0], e.data.param[1]);
controller.on(TransmuxingEvents.IO_ERROR, onIOError.bind(this));
controller.on(TransmuxingEvents.INIT_DEMUXER, onInitDemuxer.bind(this));
controller.on(TransmuxingEvents.DEMUX_ERROR, onDemuxError.bind(this));
controller.on(TransmuxingEvents.INIT_SEGMENT, onInitSegment.bind(this));
controller.on(TransmuxingEvents.MEDIA_SEGMENT, onMediaSegment.bind(this));
Expand Down Expand Up @@ -236,6 +237,13 @@ let TransmuxingWorker = function (self) {
});
}

function onInitDemuxer(probeData) {
self.postMessage({
msg: TransmuxingEvents.INIT_DEMUXER,
data: probeData,
});
}

function onDemuxError(type, info) {
self.postMessage({
msg: TransmuxingEvents.DEMUX_ERROR,
Expand Down
3 changes: 3 additions & 0 deletions src/player/player-engine-main-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class PlayerEngineMainThread implements PlayerEngine {
this._transmuxer.on(TransmuxingEvents.IO_ERROR, (detail: any, info: any) => {
this._emitter.emit(PlayerEvents.ERROR, ErrorTypes.NETWORK_ERROR, detail, info);
});
this._transmuxer.on(TransmuxingEvents.INIT_DEMUXER, (probeData: any) => {
this._emitter.emit(PlayerEvents.INIT_DEMUXER, probeData);
});
this._transmuxer.on(TransmuxingEvents.DEMUX_ERROR, (detail: any, info: any) => {
this._emitter.emit(PlayerEvents.ERROR, ErrorTypes.MEDIA_ERROR, detail, info);
});
Expand Down
3 changes: 2 additions & 1 deletion src/player/player-engine-worker-msg-def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export type WorkerMessagePacketPlayerEventExtraData = WorkerMessagePacketPlayerE
| PlayerEvents.SMPTE2038_METADATA_ARRIVED
| PlayerEvents.SCTE35_METADATA_ARRIVED
| PlayerEvents.PES_PRIVATE_DATA_DESCRIPTOR
| PlayerEvents.PES_PRIVATE_DATA_ARRIVED,
| PlayerEvents.PES_PRIVATE_DATA_ARRIVED
| PlayerEvents.INIT_DEMUXER,
extraData: any,
};

Expand Down
3 changes: 3 additions & 0 deletions src/player/player-engine-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ const PlayerEngineWorker = (self: DedicatedWorkerGlobalScope) => {
info: info,
} as WorkerMessagePacketPlayerEventError);
});
transmuxer.on(TransmuxingEvents.INIT_DEMUXER, (probeData: any) => {
emitPlayerEventsExtraData(PlayerEvents.INIT_DEMUXER, probeData);
});
transmuxer.on(TransmuxingEvents.DEMUX_ERROR, (detail: any, info: any) => {
self.postMessage({
msg: 'player_event',
Expand Down
3 changes: 2 additions & 1 deletion src/player/player-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ enum PlayerEvents {
PES_PRIVATE_DATA_DESCRIPTOR = 'pes_private_data_descriptor',
PES_PRIVATE_DATA_ARRIVED = 'pes_private_data_arrived',
STATISTICS_INFO = 'statistics_info',
DESTROYING = 'destroying'
DESTROYING = 'destroying',
INIT_DEMUXER = 'init_demuxer',
};

export default PlayerEvents;