Skip to content

Commit e05ac58

Browse files
authored
Merge pull request #308 from alnitak/switchToDrMp3
- use dr_mp3.h instead of minimp3.h for MP3 streaming - fix crash when calling addAudioDataStream before the play #306
2 parents 5f87730 + afb5471 commit e05ac58

17 files changed

+341
-2238
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "Flutter debug",
99
"type": "dart",
1010
"request": "launch",
11-
"program": "lib/buffer_stream/websocket.dart",
11+
"program": "lib/buffer_stream/web_radio.dart",
1212
"flutterMode": "debug",
1313
// "env": {
1414
// "NO_OPUS_OGG_LIBS": "1"

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"tasks": [
44
{
55
"label": "compile linux debug verbose",
6-
"command": "cd ${workspaceFolder}/example; flutter build linux -t lib/buffer_stream/websocket.dart --debug --verbose",
6+
"command": "cd ${workspaceFolder}/example; flutter build linux -t lib/buffer_stream/web_radio.dart --debug --verbose",
77
// "args": ["build", "linux", "--verbose"],
88
"type": "shell"
99
},

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#### 3.3.4 (10 Sep 2025)
2+
- use of dr_mp3.h instead of minimp3 for streaming MP3
3+
- fix crash when calling addAudioDataStream before play #306
4+
15
#### 3.3.3 (4 Sep 2025)
26
- fix seek a buffer stream actually seeks at half the wanted position #296
37

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ packages:
132132
path: ".."
133133
relative: true
134134
source: path
135-
version: "3.3.2"
135+
version: "3.3.3"
136136
flutter_test:
137137
dependency: "direct dev"
138138
description: flutter

lib/src/exceptions/exceptions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ abstract class SoLoudCppException extends SoLoudException {
113113
case PlayerErrors.streamEndedAlready:
114114
return const SoLoudStreamEndedAlreadyCppException();
115115
case PlayerErrors.failedToCreateOpusDecoder:
116-
return const SoLoudFailedToCreateOpusDecoderCppException();
116+
return const SoLoudFailedToCreateDecoderCppException();
117117
case PlayerErrors.failedToDecodeOpusPacket:
118118
return const SoLoudFailedToDecodeOpusPacketCppException();
119119
case PlayerErrors.bufferStreamCanBePlayedOnlyOnce:

lib/src/exceptions/exceptions_from_cpp.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ class SoLoudStreamEndedAlreadyCppException extends SoLoudCppException {
289289
}
290290

291291
/// An error occurred while creating an Opus decoder.
292-
class SoLoudFailedToCreateOpusDecoderCppException extends SoLoudCppException {
293-
/// Creates a new [SoLoudFailedToCreateOpusDecoderCppException].
294-
const SoLoudFailedToCreateOpusDecoderCppException([super.message]);
292+
class SoLoudFailedToCreateDecoderCppException extends SoLoudCppException {
293+
/// Creates a new [SoLoudFailedToCreateDecoderCppException].
294+
const SoLoudFailedToCreateDecoderCppException([super.message]);
295295

296296
@override
297297
String get description =>
298-
'Failed to create an Opus decoder. This could happen when some internal '
299-
'error occurred while creating the decoder. Maybe not enough memory. '
300-
'(on the C++ side).';
298+
'Failed to create decoder. This could happen when some internal '
299+
'error occurred while creating the decoder. Maybe not enough memory or '
300+
'maybe the data is corrupted. (on the C++ side).';
301301
}
302302

303303
/// An error occurred while decoding Opus data.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
A low-level audio plugin for Flutter,
44
mainly meant for games and immersive apps.
55
Based on the SoLoud (C++) audio engine.
6-
version: 3.3.3
6+
version: 3.3.4
77
homepage: https://github.com/alnitak/flutter_soloud
88
maintainer: Marco Bavagnoli (@lildeimos)
99
platforms:

src/audiobuffer/audiobuffer.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ namespace SoLoud
3939
{
4040
std::lock_guard<std::mutex> lock(buffer_lock_mutex);
4141

42+
// When using BufferType::AUTO, samplerate and channels are got from the stream. Hence we need to update them
43+
// regardless of how are set by setBufferStream. But these parameters need to be set after the play
44+
// function is called and the instance of this class is created.
45+
if (mParent->autoTypeSamplerate != 0.f) {
46+
mBaseSamplerate = mParent->autoTypeSamplerate;
47+
mSamplerate = mParent->autoTypeSamplerate;
48+
mChannels = mParent->autoTypeChannels;
49+
}
50+
4251
// This happens when using RELEASED buffer type
4352
if (mParent->mBuffer.getFloatsBufferSize() == 0)
4453
{
@@ -226,6 +235,9 @@ namespace SoLoud
226235
if (pcmFormat.dataType == BufferType::OPUS)
227236
pcmFormat.dataType = BufferType::AUTO;
228237

238+
mInstance = nullptr;
239+
autoTypeChannels = 0;
240+
autoTypeSamplerate = 0.f;
229241
mBytesReceived = 0;
230242
mUncompressedBytesReceived = 0;
231243
mSampleCount = 0;
@@ -317,7 +329,7 @@ namespace SoLoud
317329
static_cast<const unsigned char *>(aData) + aDataLen);
318330
mBytesReceived += aDataLen;
319331
// Performing some buffering. We need some data to be added expecially when using opus or mp3.
320-
if (buffer.size() > 1024 * 16) // 16 KB of data.
332+
if (buffer.size() > 1024 * 32) // 16 KB of data.
321333
{
322334
// For PCM data we must align the data to the bytes per sample.
323335
if (!(mPCMformat.dataType == BufferType::AUTO))
@@ -381,14 +393,13 @@ namespace SoLoud
381393
{
382394
mPCMformat.sampleRate = sampleRate;
383395
mBaseSamplerate = sampleRate;
384-
mInstance->mSamplerate = sampleRate;
385-
mInstance->mBaseSamplerate = sampleRate;
396+
autoTypeSamplerate = sampleRate;
386397
}
387398
if (channels != -1)
388399
{
389400
mPCMformat.channels = channels;
390401
mChannels = channels;
391-
mInstance->mChannels = channels;
402+
autoTypeChannels = channels;
392403
}
393404
}
394405

src/audiobuffer/audiobuffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace SoLoud
4747
ActiveSound* mParent;
4848
dartOnBufferingCallback_t mOnBufferingCallback;
4949
dartOnMetadataCallback_t mOnMetadataCallback;
50+
unsigned int autoTypeChannels;
51+
float autoTypeSamplerate;
5052
unsigned int mMaxBufferSize;
5153
int64_t mSampleCount;
5254
uint64_t mBytesConsumed;

0 commit comments

Comments
 (0)