mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
Suppress range request warning for HLS-adjacent requests (closes #354)
This commit is contained in:
@@ -598,6 +598,8 @@ export class HlsInputFormat extends InputFormat {
|
|||||||
throw new TypeError('HLS inputs require `InputOptions.source` to be a PathedSource or a ref to one.');
|
throw new TypeError('HLS inputs require `InputOptions.source` to be a PathedSource or a ref to one.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input._rootSource._usedForHls = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+30
-13
@@ -80,6 +80,11 @@ export abstract class Source extends EventEmitter<SourceEvents> {
|
|||||||
_disposed = false;
|
_disposed = false;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_refCount = 0;
|
_refCount = 0;
|
||||||
|
/**
|
||||||
|
* Used internally to mark if a source stems from an HLS reading operation. Used to suppress certain warnings.
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
_usedForHls = false;
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
private _sizePromise: Promise<number | null> | null = null;
|
private _sizePromise: Promise<number | null> | null = null;
|
||||||
@@ -270,9 +275,13 @@ export abstract class PathedSource extends Source {
|
|||||||
throw new TypeError('requestHandler must return or resolve to a Source or SourceRef.');
|
throw new TypeError('requestHandler must return or resolve to a Source or SourceRef.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return result instanceof Source
|
const ref = result instanceof Source
|
||||||
? result.ref()
|
? result.ref()
|
||||||
: result;
|
: result;
|
||||||
|
|
||||||
|
ref.source._usedForHls ||= this._usedForHls;
|
||||||
|
|
||||||
|
return ref;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (result instanceof Promise) {
|
if (result instanceof Promise) {
|
||||||
@@ -794,19 +803,27 @@ export class UrlSource extends PathedSource {
|
|||||||
this._fileSizeDetermined = true; // Yes, this is correct even if file size is still null
|
this._fileSizeDetermined = true; // Yes, this is correct even if file size is still null
|
||||||
|
|
||||||
if (response.status !== 206) {
|
if (response.status !== 206) {
|
||||||
const origin = new URL(
|
if (!this._usedForHls) {
|
||||||
this._url instanceof Request ? this._url.url : this._url,
|
const url = new URL(
|
||||||
typeof window !== 'undefined' ? window.location.href : undefined,
|
this._url instanceof Request ? this._url.url : this._url,
|
||||||
).origin;
|
typeof window !== 'undefined' ? window.location.href : undefined,
|
||||||
|
);
|
||||||
|
|
||||||
if (origin !== 'null') {
|
if (
|
||||||
if (!warnedOrigins.has(origin)) {
|
url.origin !== 'null'
|
||||||
console.warn(
|
// Don't show the warning for M3U8 playlist files, it's irrelevant for those
|
||||||
`HTTP server (origin ${origin}) did not respond to a range request with 206 Partial`
|
&& !(url.pathname.endsWith('.m3u8') || url.pathname.endsWith('.m3u'))
|
||||||
+ ' Content, meaning the entire resource will now be downloaded. To enable efficient media'
|
) {
|
||||||
+ ' file streaming across a network, please make sure your server supports range requests.',
|
if (!warnedOrigins.has(url.origin)) {
|
||||||
);
|
console.log(this._usedForHls, this._url, url.pathname);
|
||||||
warnedOrigins.add(origin);
|
console.warn(
|
||||||
|
`HTTP server (origin ${url.origin}) did not respond to a range request with 206 Partial`
|
||||||
|
+ ' Content, meaning the entire resource will now be downloaded. To enable efficient'
|
||||||
|
+ ' media file streaming across a network, please make sure your server supports'
|
||||||
|
+ ' range requests.',
|
||||||
|
);
|
||||||
|
warnedOrigins.add(url.origin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable @stylistic/max-len */
|
/* eslint-disable @stylistic/max-len */
|
||||||
import { ALL_FORMATS, BufferSource, EncodedPacketSink, Input, InputAudioTrack, InputVideoTrack, UrlSource } from 'mediabunny';
|
import { ALL_FORMATS, BufferSource, EncodedPacketSink, Input, InputAudioTrack, InputVideoTrack, UrlSource } from 'mediabunny';
|
||||||
import { expect, test } from 'vitest';
|
import { expect, test, vi } from 'vitest';
|
||||||
import { HLS, HLS_FORMATS, HlsInputFormat } from '../../src/input-format.js';
|
import { HLS, HLS_FORMATS, HlsInputFormat } from '../../src/input-format.js';
|
||||||
import { assert, rejectAfter } from '../../src/misc.js';
|
import { assert, rejectAfter } from '../../src/misc.js';
|
||||||
import { CustomPathedSource } from '../../src/source.js';
|
import { CustomPathedSource } from '../../src/source.js';
|
||||||
@@ -718,7 +718,9 @@ test.concurrent('Advanced Apple HLS', { timeout: 30_000 }, async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test.concurrent('Live HLS', { timeout: 30_000 }, async () => {
|
test.concurrent.only('Live HLS', { timeout: 30_000 }, async () => {
|
||||||
|
const consoleSpy = vi.spyOn(console, 'warn');
|
||||||
|
|
||||||
using input = new Input({
|
using input = new Input({
|
||||||
source: new UrlSource('https://stream.mux.com/v69RSHhFelSm4701snP22dYz2jICy4E4FUyk02rW4gxRM.m3u8'),
|
source: new UrlSource('https://stream.mux.com/v69RSHhFelSm4701snP22dYz2jICy4E4FUyk02rW4gxRM.m3u8'),
|
||||||
formats: ALL_FORMATS,
|
formats: ALL_FORMATS,
|
||||||
@@ -781,6 +783,9 @@ test.concurrent('Live HLS', { timeout: 30_000 }, async () => {
|
|||||||
rejectAfter(2000, 'Baby you make me smile'),
|
rejectAfter(2000, 'Baby you make me smile'),
|
||||||
]);
|
]);
|
||||||
expect(metadataDuration).toBeGreaterThan((Date.now() / 1000) - 3600);
|
expect(metadataDuration).toBeGreaterThan((Date.now() / 1000) - 3600);
|
||||||
|
|
||||||
|
// The server doesn't answer with range requests but since it's HLS we suppress that warning
|
||||||
|
expect(consoleSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.concurrent('#EXT-X-I-FRAME-STREAM-INF tags are parsed properly', async () => {
|
test.concurrent('#EXT-X-I-FRAME-STREAM-INF tags are parsed properly', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user