@@ -466,12 +466,12 @@ shaka.media.MediaSourceEngine = class {
466
466
cleanup . push ( this . textEngine_ . destroy ( ) ) ;
467
467
}
468
468
469
+ await Promise . all ( cleanup ) ;
470
+
469
471
for ( const contentType in this . transmuxers_ ) {
470
- cleanup . push ( this . transmuxers_ [ contentType ] . destroy ( ) ) ;
472
+ this . transmuxers_ [ contentType ] . destroy ( ) ;
471
473
}
472
474
473
-
474
- await Promise . all ( cleanup ) ;
475
475
if ( this . eventManager_ ) {
476
476
this . eventManager_ . release ( ) ;
477
477
this . eventManager_ = null ;
@@ -692,7 +692,8 @@ shaka.media.MediaSourceEngine = class {
692
692
* @return {boolean }
693
693
*/
694
694
isStreamingAllowed ( ) {
695
- return this . streamingAllowed_ && ! this . usingRemotePlayback_ ;
695
+ return this . streamingAllowed_ && ! this . usingRemotePlayback_ &&
696
+ ! this . reloadingMediaSource_ ;
696
697
}
697
698
698
699
/**
@@ -1859,11 +1860,13 @@ shaka.media.MediaSourceEngine = class {
1859
1860
1860
1861
/** @type {!Array.<!shaka.util.PublicPromise> } */
1861
1862
const allWaiters = [ ] ;
1863
+ /** @type {!Array.<!shaka.util.ManifestParserUtils.ContentType> } */
1864
+ const contentTypes = Object . keys ( this . sourceBuffers_ ) ;
1862
1865
1863
1866
// Enqueue a 'wait' operation onto each queue.
1864
1867
// This operation signals its readiness when it starts.
1865
1868
// When all wait operations are ready, the real operation takes place.
1866
- for ( const contentType in this . sourceBuffers_ ) {
1869
+ for ( const contentType of contentTypes ) {
1867
1870
const ready = new shaka . util . PublicPromise ( ) ;
1868
1871
const operation = {
1869
1872
start : ( ) => ready . resolve ( ) ,
@@ -1893,7 +1896,7 @@ shaka.media.MediaSourceEngine = class {
1893
1896
// assert at the end of destroy passes. In compiled mode, the queues
1894
1897
// are wiped in destroy.
1895
1898
if ( goog . DEBUG ) {
1896
- for ( const contentType in this . sourceBuffers_ ) {
1899
+ for ( const contentType of contentTypes ) {
1897
1900
if ( this . queues_ [ contentType ] . length ) {
1898
1901
goog . asserts . assert (
1899
1902
this . queues_ [ contentType ] . length == 1 ,
@@ -1910,7 +1913,7 @@ shaka.media.MediaSourceEngine = class {
1910
1913
1911
1914
if ( goog . DEBUG ) {
1912
1915
// If we did it correctly, nothing is updating.
1913
- for ( const contentType in this . sourceBuffers_ ) {
1916
+ for ( const contentType of contentTypes ) {
1914
1917
goog . asserts . assert (
1915
1918
this . sourceBuffers_ [ contentType ] . updating == false ,
1916
1919
'SourceBuffers should not be updating after a blocking op!' ) ;
@@ -1930,7 +1933,7 @@ shaka.media.MediaSourceEngine = class {
1930
1933
null ) ;
1931
1934
} finally {
1932
1935
// Unblock the queues.
1933
- for ( const contentType in this . sourceBuffers_ ) {
1936
+ for ( const contentType of contentTypes ) {
1934
1937
this . popFromQueue_ ( contentType ) ;
1935
1938
}
1936
1939
}
@@ -1942,6 +1945,7 @@ shaka.media.MediaSourceEngine = class {
1942
1945
* @private
1943
1946
*/
1944
1947
popFromQueue_ ( contentType ) {
1948
+ goog . asserts . assert ( this . queues_ [ contentType ] , 'Queue should exist' ) ;
1945
1949
// Remove the in-progress operation, which is now complete.
1946
1950
this . queues_ [ contentType ] . shift ( ) ;
1947
1951
this . startOperation_ ( contentType ) ;
@@ -2099,48 +2103,6 @@ shaka.media.MediaSourceEngine = class {
2099
2103
null ) ;
2100
2104
}
2101
2105
2102
- /**
2103
- * Returns the source buffer parameters
2104
- * @param {shaka.util.ManifestParserUtils.ContentType } contentType
2105
- * @return {?shaka.media.MediaSourceEngine.SourceBufferParams }
2106
- * @private
2107
- */
2108
- getSourceBufferParams_ ( contentType ) {
2109
- if ( ! this . sourceBuffers_ [ contentType ] ) {
2110
- return null ;
2111
- }
2112
- return {
2113
- timestampOffset : this . sourceBuffers_ [ contentType ] . timestampOffset ,
2114
- appendWindowStart : this . sourceBuffers_ [ contentType ] . appendWindowStart ,
2115
- appendWindowEnd : this . sourceBuffers_ [ contentType ] . appendWindowEnd ,
2116
- } ;
2117
- }
2118
-
2119
- /**
2120
- * Restore source buffer parameters
2121
- * @param {shaka.util.ManifestParserUtils.ContentType } contentType
2122
- * @param {?shaka.media.MediaSourceEngine.SourceBufferParams } params
2123
- * @private
2124
- */
2125
- restoreSourceBufferParams_ ( contentType , params ) {
2126
- if ( ! params ) {
2127
- return ;
2128
- }
2129
-
2130
- if ( ! this . sourceBuffers_ [ contentType ] ) {
2131
- shaka . log . warning ( 'Attempted to restore a non-existent source buffer' ) ;
2132
- return ;
2133
- }
2134
-
2135
- this . sourceBuffers_ [ contentType ] . timestampOffset =
2136
- params . timestampOffset ;
2137
- // `end` needs to be set before `start`
2138
- this . sourceBuffers_ [ contentType ] . appendWindowEnd =
2139
- params . appendWindowEnd ;
2140
- this . sourceBuffers_ [ contentType ] . appendWindowStart =
2141
- params . appendWindowStart ;
2142
- }
2143
-
2144
2106
/**
2145
2107
* Resets the MediaSource and re-adds source buffers due to codec mismatch
2146
2108
*
@@ -2149,7 +2111,6 @@ shaka.media.MediaSourceEngine = class {
2149
2111
* @private
2150
2112
*/
2151
2113
async reset_ ( streamsByType ) {
2152
- const Functional = shaka . util . Functional ;
2153
2114
const ContentType = shaka . util . ManifestParserUtils . ContentType ;
2154
2115
this . reloadingMediaSource_ = true ;
2155
2116
this . needSplitMuxedContent_ = false ;
@@ -2171,36 +2132,19 @@ shaka.media.MediaSourceEngine = class {
2171
2132
try {
2172
2133
this . eventManager_ . removeAll ( ) ;
2173
2134
2174
- const cleanup = [ ] ;
2175
2135
for ( const contentType in this . transmuxers_ ) {
2176
- cleanup . push ( this . transmuxers_ [ contentType ] . destroy ( ) ) ;
2177
- }
2178
- for ( const contentType in this . queues_ ) {
2179
- // Make a local copy of the queue and the first item.
2180
- const q = this . queues_ [ contentType ] ;
2181
- const inProgress = q [ 0 ] ;
2182
-
2183
- // Drop everything else out of the original queue.
2184
- this . queues_ [ contentType ] = q . slice ( 0 , 1 ) ;
2185
-
2186
- // We will wait for this item to complete/fail.
2187
- if ( inProgress ) {
2188
- cleanup . push ( inProgress . p . catch ( Functional . noop ) ) ;
2189
- }
2190
-
2191
- // The rest will be rejected silently if possible.
2192
- for ( const item of q . slice ( 1 ) ) {
2193
- item . p . reject ( shaka . util . Destroyer . destroyedError ( ) ) ;
2194
- }
2136
+ this . transmuxers_ [ contentType ] . destroy ( ) ;
2195
2137
}
2196
2138
for ( const contentType in this . sourceBuffers_ ) {
2197
2139
const sourceBuffer = this . sourceBuffers_ [ contentType ] ;
2198
2140
try {
2199
2141
this . mediaSource_ . removeSourceBuffer ( sourceBuffer ) ;
2200
- } catch ( e ) { }
2142
+ } catch ( e ) {
2143
+ shaka . log . debug ( 'Exception on removeSourceBuffer' , e ) ;
2144
+ }
2201
2145
}
2202
- await Promise . all ( cleanup ) ;
2203
2146
this . transmuxers_ = { } ;
2147
+ this . sourceBuffers_ = { } ;
2204
2148
2205
2149
const previousDuration = this . mediaSource_ . duration ;
2206
2150
this . mediaSourceOpen_ = new shaka . util . PublicPromise ( ) ;
@@ -2231,23 +2175,17 @@ shaka.media.MediaSourceEngine = class {
2231
2175
onSourceBufferAdded ) ;
2232
2176
2233
2177
for ( const contentType of streamsByType . keys ( ) ) {
2234
- const previousParams = this . getSourceBufferParams_ ( contentType ) ;
2235
2178
const stream = streamsByType . get ( contentType ) ;
2236
2179
// eslint-disable-next-line no-await-in-loop
2237
2180
await this . initSourceBuffer_ ( contentType , stream , stream . codecs ) ;
2238
- if ( this . needSplitMuxedContent_ ) {
2239
- this . queues_ [ ContentType . AUDIO ] = [ ] ;
2240
- this . queues_ [ ContentType . VIDEO ] = [ ] ;
2241
- } else {
2242
- this . queues_ [ contentType ] = [ ] ;
2243
- }
2244
-
2245
- this . restoreSourceBufferParams_ ( contentType , previousParams ) ;
2246
2181
}
2247
2182
const audio = streamsByType . get ( ContentType . AUDIO ) ;
2248
2183
if ( audio && audio . isAudioMuxedInVideo ) {
2249
2184
this . needSplitMuxedContent_ = true ;
2250
2185
}
2186
+ if ( this . needSplitMuxedContent_ && ! this . queues_ [ ContentType . AUDIO ] ) {
2187
+ this . queues_ [ ContentType . AUDIO ] = [ ] ;
2188
+ }
2251
2189
2252
2190
// Fake a seek to catchup the playhead.
2253
2191
this . video_ . currentTime = currentTime ;
@@ -2393,13 +2331,12 @@ shaka.media.MediaSourceEngine = class {
2393
2331
* Returns true if it's necessary codec switch to load the new stream.
2394
2332
*
2395
2333
* @param {shaka.util.ManifestParserUtils.ContentType } contentType
2396
- * @param {shaka.extern.Stream } stream
2397
2334
* @param {string } refMimeType
2398
2335
* @param {string } refCodecs
2399
2336
* @return {boolean }
2400
2337
* @private
2401
2338
*/
2402
- isCodecSwitchNecessary_ ( contentType , stream , refMimeType , refCodecs ) {
2339
+ isCodecSwitchNecessary_ ( contentType , refMimeType , refCodecs ) {
2403
2340
if ( contentType == shaka . util . ManifestParserUtils . ContentType . TEXT ) {
2404
2341
return false ;
2405
2342
}
@@ -2443,13 +2380,12 @@ shaka.media.MediaSourceEngine = class {
2443
2380
* new stream.
2444
2381
*
2445
2382
* @param {shaka.util.ManifestParserUtils.ContentType } contentType
2446
- * @param {shaka.extern.Stream } stream
2447
2383
* @param {string } mimeType
2448
2384
* @param {string } codecs
2449
2385
* @return {boolean }
2450
2386
*/
2451
- isResetMediaSourceNecessary ( contentType , stream , mimeType , codecs ) {
2452
- if ( ! this . isCodecSwitchNecessary_ ( contentType , stream , mimeType , codecs ) ) {
2387
+ isResetMediaSourceNecessary ( contentType , mimeType , codecs ) {
2388
+ if ( ! this . isCodecSwitchNecessary_ ( contentType , mimeType , codecs ) ) {
2453
2389
return false ;
2454
2390
}
2455
2391
@@ -2540,12 +2476,3 @@ shaka.media.MediaSourceEngine.SourceBufferMode_ = {
2540
2476
* Called when an embedded 'emsg' box should trigger a manifest update.
2541
2477
*/
2542
2478
shaka . media . MediaSourceEngine . PlayerInterface ;
2543
-
2544
- /**
2545
- * @typedef {{
2546
- * timestampOffset: number,
2547
- * appendWindowStart: number,
2548
- * appendWindowEnd: number
2549
- * }}
2550
- */
2551
- shaka . media . MediaSourceEngine . SourceBufferParams ;
0 commit comments