Skip to content

Commit

Permalink
MetaDataArrived: Refine bilibili#309
Browse files Browse the repository at this point in the history
  • Loading branch information
xqq committed May 4, 2018
1 parent 97eac6e commit 88e9bf8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions d.ts/flv.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ declare namespace FlvJs {
LOADING_COMPLETE: string,
RECOVERED_EARLY_EOF: string,
MEDIA_INFO: string,
METADATA_ARRIVED: string,
STATISTICS_INFO: string
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Transmuxer {
ctl.on(TransmuxingEvents.LOADING_COMPLETE, this._onLoadingComplete.bind(this));
ctl.on(TransmuxingEvents.RECOVERED_EARLY_EOF, this._onRecoveredEarlyEof.bind(this));
ctl.on(TransmuxingEvents.MEDIA_INFO, this._onMediaInfo.bind(this));
ctl.on(TransmuxingEvents.METADATA_ARRIVED, this._onMetadataArrived.bind(this));
ctl.on(TransmuxingEvents.METADATA_ARRIVED, this._onMetaDataArrived.bind(this));
ctl.on(TransmuxingEvents.STATISTICS_INFO, this._onStatisticsInfo.bind(this));
ctl.on(TransmuxingEvents.RECOMMEND_SEEKPOINT, this._onRecommendSeekpoint.bind(this));
}
Expand Down Expand Up @@ -165,7 +165,7 @@ class Transmuxer {
});
}

_onMetadataArrived(metadata) {
_onMetaDataArrived(metadata) {
Promise.resolve().then(() => {
this._emitter.emit(TransmuxingEvents.METADATA_ARRIVED, metadata);
});
Expand Down
4 changes: 2 additions & 2 deletions src/core/transmuxing-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class TransmuxingController {

this._demuxer.onError = this._onDemuxException.bind(this);
this._demuxer.onMediaInfo = this._onMediaInfo.bind(this);
this._demuxer.onMetadataArrived = this._onMetadataArrived.bind(this);
this._demuxer.onMetaDataArrived = this._onMetaDataArrived.bind(this);

this._remuxer.bindDataSource(this._demuxer
.bindDataSource(this._ioctl
Expand Down Expand Up @@ -315,7 +315,7 @@ class TransmuxingController {
}
}

_onMetadataArrived(metadata) {
_onMetaDataArrived(metadata) {
this._emitter.emit(TransmuxingEvents.METADATA_ARRIVED, metadata);
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/transmuxing-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let TransmuxingWorker = function (self) {
controller.on(TransmuxingEvents.LOADING_COMPLETE, onLoadingComplete.bind(this));
controller.on(TransmuxingEvents.RECOVERED_EARLY_EOF, onRecoveredEarlyEof.bind(this));
controller.on(TransmuxingEvents.MEDIA_INFO, onMediaInfo.bind(this));
controller.on(TransmuxingEvents.METADATA_ARRIVED, onMetadataArrived.bind(this));
controller.on(TransmuxingEvents.METADATA_ARRIVED, onMetaDataArrived.bind(this));
controller.on(TransmuxingEvents.STATISTICS_INFO, onStatisticsInfo.bind(this));
controller.on(TransmuxingEvents.RECOMMEND_SEEKPOINT, onRecommendSeekpoint.bind(this));
break;
Expand Down Expand Up @@ -138,7 +138,7 @@ let TransmuxingWorker = function (self) {
self.postMessage(obj);
}

function onMetadataArrived(metadata) {
function onMetaDataArrived(metadata) {
let obj = {
msg: TransmuxingEvents.METADATA_ARRIVED,
data: metadata
Expand Down
19 changes: 10 additions & 9 deletions src/demux/flv-demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FLVDemuxer {

this._onError = null;
this._onMediaInfo = null;
this._onMetadataArrived = null;
this._onMetaDataArrived = null;
this._onTrackMetadata = null;
this._onDataAvailable = null;

Expand Down Expand Up @@ -123,7 +123,7 @@ class FLVDemuxer {

this._onError = null;
this._onMediaInfo = null;
this._onMetadataArrived = null;
this._onMetaDataArrived = null;
this._onTrackMetadata = null;
this._onDataAvailable = null;
}
Expand Down Expand Up @@ -177,12 +177,12 @@ class FLVDemuxer {
this._onMediaInfo = callback;
}

get onMetadataArrived() {
return this._onMetadataArrived;
get onMetaDataArrived() {
return this._onMetaDataArrived;
}

set onMetadataArrived(callback) {
this._onMetadataArrived = callback;
set onMetaDataArrived(callback) {
this._onMetaDataArrived = callback;
}

// prototype: function(type: number, info: string): void
Expand Down Expand Up @@ -369,6 +369,10 @@ class FLVDemuxer {
this._metadata = scriptData;
let onMetaData = this._metadata.onMetaData;

if (this._onMetaDataArrived) {
this._onMetaDataArrived(Object.assign({}, onMetaData));
}

if (typeof onMetaData.hasAudio === 'boolean') { // hasAudio
if (this._hasAudioFlagOverrided === false) {
this._hasAudio = onMetaData.hasAudio;
Expand Down Expand Up @@ -424,9 +428,6 @@ class FLVDemuxer {
this._dispatch = false;
this._mediaInfo.metadata = onMetaData;
Log.v(this.TAG, 'Parsed onMetaData');
if(this._onMetadataArrived) {
this._onMetadataArrived(Object.assign({}, onMetaData));
}
if (this._mediaInfo.isComplete()) {
this._onMediaInfo(this._mediaInfo);
}
Expand Down

0 comments on commit 88e9bf8

Please sign in to comment.