BASS_HLS_StreamCreateURL fails with BASS_ERROR_FILEFORM on valid HLS stream

Started by velonica,

velonica

### Environment
- BASS version: 2.4.18.2 (NuGet Un4seen.Bass 2.4.18.2)
- BASSHLS version: likely 2.4.18.x (bundled basshls.dll, ~24KB)
- Platform: Windows 10 / .NET 8.0
- Language: C#

### Stream URL
https://iovliveplay.radio.cn/fm/1600000000643h.m3u8

### Problem
`BASS_HLS_StreamCreateURL` returns error code 2 (`BASS_ERROR_FILEFORM` / "Unsupported file format") when attempting to open this HLS stream. Both `BASS_StreamCreateURL` and `BASS_HLS_StreamCreateURL` fail with the same error. The HTTP response from the server is 200 OK, so the URL is reachable and the server accepts the request.

### m3u8 playlist contents (fetched successfully by HttpClient)
```
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:592159220
#EXT-X-TARGETDURATION:4
#EXTINF:3.018,
1600000000643h-592159220.ts?ctyun_app=fm&ctyun_stream=1600000000643h&ctyun_rate=125.000
#EXTINF:3.019,
1600000000643h-592159221.ts?ctyun_app=fm&ctyun_stream=1600000000643h&ctyun_rate=125.000
#EXTINF:3.019,
1600000000643h-592159222.ts?ctyun_app=fm&ctyun_stream=1600000000643h&ctyun_rate=125.000
#EXTINF:3.018,
1600000000643h-592159223.ts?ctyun_app=fm&ctyun_stream=1600000000643h&ctyun_rate=125.000
#EXTINF:3.019,
1600000000643h-592159224.ts?ctyun_app=fm&ctyun_stream=1600000000643h&ctyun_rate=125.000
```

### .ts segment info (fetched directly via HTTP)
- Content-Type: `video/mp2t` (standard MPEG-TS)
- Content-Length: ~53 KB per segment
- Server: OpenResty CDN
- Query string parameters in segment URLs: `ctyun_app=fm`, `ctyun_stream=1600000000643h`, `ctyun_rate=125.000`
- Playlist uses **relative URLs** for segments (no leading slash)

### Reproduction code

```csharp
BassNet.Registration("your@email.com", "YOURKEY");
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

// Set user agent (required by this server)
var ua = Marshal.StringToHGlobalAnsi(
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36");
Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, ua);
Marshal.FreeHGlobal(ua);

// Load basshls plugin
var basshlsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "basshls.dll");
if (Bass.BASS_PluginLoad(basshlsPath) == 0)
    Console.WriteLine($"BASS_PluginLoad failed: {Bass.BASS_ErrorGetCode()}");

var url = "https://iovliveplay.radio.cn/fm/1600000000643h.m3u8";

int s = BassHls.BASS_HLS_StreamCreateURL(
    url, 0,
    BASSFlag.BASS_STREAM_STATUS | BASSFlag.BASS_STREAM_AUTOFREE,
    null, IntPtr.Zero);

Console.WriteLine(s != 0 ? $"OK: handle={s}" : $"FAIL: {Bass.BASS_ErrorGetCode()}");
// Output: FAIL: 2 (BASS_ERROR_FILEFORM)
```

### Observations
1. The m3u8 playlist is valid HLS v3 (EXTM3U, EXT-X-VERSION:3, EXT-X-TARGETDURATION, EXTINF)
2. The server returns HTTP 200 for both the playlist and the .ts segment requests
3. The .ts segments are standard MPEG-TS (Content-Type: video/mp2t)
4. The playlist uses relative segment URLs (e.g. `segment.ts?param=value`)
5. FFmpeg plays this stream without issues: `ffmpeg -i <url> -ac 2 -ar 44100 -f s16le -` decodes and outputs PCM audio correctly
6. This appears to be a commercial Chinese radio stream served via a CDN (similar to what CNR/CCTV uses)

### Workaround
FFmpeg subprocess can decode the stream and output PCM to BASS push stream, but this adds complexity and latency compared to native BASSHLS.

Chris

Hi,
ErrorCode 2 will mean BASS_ERROR_FILEOPEN, (BASS_ERROR_FILEFORM is ErrorCode 41)
Just add in your code
BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST, 1);
So that Bass can Process Playlists.

velonica

Tried BASS_SetConfig(BASS_CONFIG_NET_PLAYLIST, 1) — still getting error 41. The stream plays fine in PotPlayer and FFmpeg, but BASSHLS fails. The m3u8 uses relative segment URLs with query strings attached directly to the filename
(e.g. segment.ts?ctyun_app=fm&...), which is non-standard. FFmpeg handles it fine, BASSHLS apparently does not.

Chris

Ok I can that confirm. with the basshls (2.4.5.0) and with basshls (2.4.4.0) the url-stream will return Error 41,
but adding bass_aac via BASS_PluginLoad will fix it.
I did here also a quick test with a older basshls (2.4.3.1) , with that Version it will work without adding bass_aac.

Testplatform: Win10 , C-demo netradio

velonica

Thanks! Loading the BASS_AAC plugin via BASS_PluginLoad fixed the issue. Really appreciate your help.

Ian @ un4seen

There were some changes in the Media Foundation processing in BASS 2.4.18, and some more since then. Your HLS stream seems to be working (without BASS_AAC) using the latest build. Perhaps a change in 2.4.18 broke the stream and a later change fixed it again? Please give this latest build a try:

    www.un4seen.com/stuff/bass.zip

Chris

I did here a quick Test with the Updated Bass.dll (2.4.18.11). will working fine (without BASS_AAC).

velonica

BASS 2.4.18.11 can play my previous stream without needing to load bass_aac.
However, a newly discovered problematic URL requires bass_aac.dll to be loaded, otherwise it fails with error code 41 (BASS_ERROR_FILEFORM).

TEST URL (DYNAMIC - WILL EXPIRE)
https://livekcz.cztv.tv/kcz/fm1034.m3u8?auth_key=1776757117-0-0-dca91b85885b53a7c9fec9740874b18e

Note: This is a dynamic URL that will expire. To obtain a fresh URL for testing, call the Changzhou API:
  GET https://kcz.cztv.tv/api/v1/channel/fm
Response contains an array under data.data[]. Each item has a stream_url field, e.g.:
  {"id":7,"channel_name":"103.4新闻","stream_url":"https://livekcz.cztv.tv/kcz/fm1034.m3u8?auth_key=..."}

Ian @ un4seen

It unfortunately looks like the Media Foundation AAC decoder doesn't support that stream's data for some reason. It's failing with a MF_E_INVALIDMEDIATYPE (0xc00d36b4) error. Downloading/extracting the stream's data to a file and trying to play it with Windows' Media Player gives the same error, so the problem doesn't seem to be caused by something BASS is doing.

velonica

The stream might be using a less common encoding format, so I ended up loading the bass_aac plugin to handle it.