Skip to content

Commit a4c1b42

Browse files
committed
feat(mediaplayer): HLS / Low-Latency HLS playback (Windows)
Add an HLS source layered on top of the existing OS-codec media player. It parses the M3U8, selects a single rendition, starts near the live edge, and stitches segments (and LL-HLS EXT-X-PART parts) into one continuous byte stream that the existing MPEG-TS / fragmented-MP4 demuxers consume. A background reader paces delivery to the stream's measured average bitrate so the wall-clock present path is fed at real time (not flooded), with enough burst to deliver segment-start keyframes promptly. Scope: Windows (WinHTTP fetch), clear streams, single rendition. Android/Quest support is planned. The existing RTSP and MPEG-TS implementations are NOT touched — basis_rtsp.c, basis_ts.c (and basis_rtmp.c, basis_mp4.c, basis_http.c, basis_url.c, the Windows decode/HTTP backends) have zero source edits. basis_media_core.c only gains an additive ".m3u8" branch ahead of the plain byte-source path; every other URL (rtsp/rtmp/.ts/.mp4) takes the identical existing route. No C# changes. - protocol/basis_hls.c/.h: new HLS source (M3U8 parse, segment/part scheduler, paced read-ahead buffer) - basis_media_core.c: route .m3u8 to the HLS source, feeding basis_ts_run / basis_mp4_run unchanged - CMakeLists.txt: add basis_hls.c to the portable core - README.md: document HLS support and the Windows / clear / single-rendition scope
1 parent e18a455 commit a4c1b42

5 files changed

Lines changed: 856 additions & 0 deletions

File tree

Basis/Packages/com.basis.mediaplayer/Native~/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ set(CORE_SOURCES
6767
protocol/basis_rtmp.c
6868
protocol/basis_ts.c
6969
protocol/basis_mp4.c
70+
protocol/basis_hls.c
7071
)
7172

7273
# ---------------------------------------------------------------------------

Basis/Packages/com.basis.mediaplayer/Native~/basis_media_core.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "protocol/basis_ts.h"
2222
#include "protocol/basis_mp4.h"
2323
#include "protocol/basis_http.h"
24+
#include "protocol/basis_hls.h"
2425

2526
#include <stdlib.h>
2627
#include <string.h>
@@ -192,6 +193,32 @@ static int ends_with_ci(const char* s, const char* suffix) {
192193
return 1;
193194
}
194195

196+
/* HLS / LL-HLS: the URL is a playlist, not a continuous byte stream. The HLS
197+
* source fetches+parses the M3U8, stitches segments (and LL-HLS parts) into one
198+
* byte stream, and the existing TS/fMP4 demuxers consume it. Windows fetches via
199+
* WinHTTP; Android/Quest support is planned. */
200+
static void run_hls(basis_media_engine_t* e) {
201+
#if defined(_WIN32)
202+
basis_http_provider_t provider = {
203+
basis_win_http_open, basis_win_http_read, basis_win_http_close
204+
};
205+
int is_fmp4 = 0;
206+
void* hls = basis_hls_open(e->url, &provider, e->sink.is_running, e->sink.user, &is_fmp4);
207+
if (!hls) {
208+
basis_engine_set_error(e, "failed to open HLS playlist");
209+
return;
210+
}
211+
basis_engine_set_state(e, BASIS_MEDIA_STATE_BUFFERING);
212+
if (is_fmp4)
213+
basis_mp4_run(&e->sink, basis_hls_read, hls);
214+
else
215+
basis_ts_run(&e->sink, basis_hls_read, hls);
216+
basis_hls_close(hls);
217+
#else
218+
basis_engine_set_error(e, "HLS playback currently requires the Windows backend.");
219+
#endif
220+
}
221+
195222
static void run_http_like(basis_media_engine_t* e) {
196223
/* Android: the OS extractor can demux the URL itself (TLS included). */
197224
if (basis_decoder_try_open_url(e->decoder, e->url)) {
@@ -200,6 +227,13 @@ static void run_http_like(basis_media_engine_t* e) {
200227
return;
201228
}
202229

230+
/* HLS playlists are not a single continuous stream — hand off to the HLS
231+
* source before the plain TS/fMP4 byte-source path. (.m3u8 may carry a query.) */
232+
if (strstr(e->parts.path, ".m3u8")) {
233+
run_hls(e);
234+
return;
235+
}
236+
203237
void* src = NULL;
204238
basis_read_fn rd = NULL;
205239

0 commit comments

Comments
 (0)