From d8f77809c604527818f793eb55115211951ca639 Mon Sep 17 00:00:00 2001 From: jeremygao Date: Thu, 12 Mar 2020 23:02:33 +0800 Subject: [PATCH] =?UTF-8?q?--bug=3D=E8=A7=A3=E5=86=B3=E8=BF=9E=E9=BA=A6?= =?UTF-8?q?=E6=B7=B7=E6=B5=81=E5=9C=BA=E6=99=AF=E4=B8=8Bcodec=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E5=AF=BC=E8=87=B4=E7=9A=84=E8=A7=86=E9=A2=91=E5=8D=A1?= =?UTF-8?q?=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/bilibili/flv.js/issues/355#issue-346089113 --- src/demux/flv-demuxer.js | 14 ++++++++++++++ src/remux/mp4-remuxer.js | 1 + 2 files changed, 15 insertions(+) diff --git a/src/demux/flv-demuxer.js b/src/demux/flv-demuxer.js index 9cd1e27c..b1be80a8 100644 --- a/src/demux/flv-demuxer.js +++ b/src/demux/flv-demuxer.js @@ -56,6 +56,7 @@ class FLVDemuxer { this._onScriptDataArrived = null; this._onTrackMetadata = null; this._onDataAvailable = null; + this._onSeek = null; this._dataOffset = probeData.dataOffset; this._firstParse = true; @@ -128,6 +129,7 @@ class FLVDemuxer { this._onScriptDataArrived = null; this._onTrackMetadata = null; this._onDataAvailable = null; + this._onSeek = null; } static probe(buffer) { @@ -213,6 +215,14 @@ class FLVDemuxer { this._onDataAvailable = callback; } + get seek() { + return this._onSeek; + } + + set seek(callback) { + this._onSeek = callback; + } + // timestamp base for output samples, must be in milliseconds get timestampBase() { return this._timestampBase; @@ -530,6 +540,8 @@ class FLVDemuxer { if (aacData.packetType === 0) { // AAC sequence header (AudioSpecificConfig) if (meta.config) { + // flush stashed samples if AudioSpecificConfig is changed + this.seek && this.seek(); Log.w(this.TAG, 'Found another AudioSpecificConfig!'); } let misc = aacData.data; @@ -894,6 +906,8 @@ class FLVDemuxer { meta.duration = this._duration; } else { if (typeof meta.avcc !== 'undefined') { + // flush stashed samples if AVCDecoderConfigurationRecord is changed + this.seek && this.seek(); Log.w(this.TAG, 'Found another AVCDecoderConfigurationRecord!'); } } diff --git a/src/remux/mp4-remuxer.js b/src/remux/mp4-remuxer.js index 3742e17b..b9919417 100644 --- a/src/remux/mp4-remuxer.js +++ b/src/remux/mp4-remuxer.js @@ -83,6 +83,7 @@ class MP4Remuxer { bindDataSource(producer) { producer.onDataAvailable = this.remux.bind(this); producer.onTrackMetadata = this._onTrackMetadataReceived.bind(this); + producer.seek = this.seek.bind(this); return this; }