d/patches: Add post-release-candidate fixes from upstream
Simon McVittie
1 year, 10 months ago
0 | From: Sam Lantinga <slouken@libsdl.org> | |
1 | Date: Fri, 27 May 2022 16:01:54 -0700 | |
2 | Subject: Allow more than one cycle with no music data | |
3 | ||
4 | Apparently libmad needs up to 4 cycles. We just want this to catch infinite loops, so using a larger number is fine. | |
5 | ||
6 | Bug: https://github.com/libsdl-org/SDL_mixer/issues/402 | |
7 | Origin: upstream, 2.5.2, commit:7099e660a6b2b61822575f06755ee998f0fc67fa | |
8 | --- | |
9 | src/music.c | 5 +++-- | |
10 | 1 file changed, 3 insertions(+), 2 deletions(-) | |
11 | ||
12 | diff --git a/src/music.c b/src/music.c | |
13 | index 7ca56f5..304b1fa 100644 | |
14 | --- a/src/music.c | |
15 | +++ b/src/music.c | |
16 | @@ -289,6 +289,7 @@ int music_pcm_getaudio(void *context, void *data, int bytes, int volume, | |
17 | Uint8 *dst; | |
18 | int len = bytes; | |
19 | int zero_cycles = 0; | |
20 | + const int MAX_ZERO_CYCLES = 10; /* just try to catch infinite loops */ | |
21 | SDL_bool done = SDL_FALSE; | |
22 | ||
23 | if (volume == MIX_MAX_VOLUME) { | |
24 | @@ -303,8 +304,8 @@ int music_pcm_getaudio(void *context, void *data, int bytes, int volume, | |
25 | } | |
26 | if (consumed == 0) { | |
27 | ++zero_cycles; | |
28 | - if (zero_cycles > 1) { | |
29 | - /* We went more than one cycle with no data, we're done */ | |
30 | + if (zero_cycles > MAX_ZERO_CYCLES) { | |
31 | + /* We went too many cycles with no data, we're done */ | |
32 | done = SDL_TRUE; | |
33 | } | |
34 | continue; |
0 | From: Sam Lantinga <slouken@libsdl.org> | |
1 | Date: Fri, 27 May 2022 13:05:54 -0700 | |
2 | Subject: Back out master volume affecting music | |
3 | ||
4 | Origin: upstream, 2.5.2, commit:c0f1cffbbf8f693ad74a1be51b44d6f7fed661ba | |
5 | --- | |
6 | src/music.c | 6 +++--- | |
7 | 1 file changed, 3 insertions(+), 3 deletions(-) | |
8 | ||
9 | diff --git a/src/music.c b/src/music.c | |
10 | index 8263128..6ef8047 100644 | |
11 | --- a/src/music.c | |
12 | +++ b/src/music.c | |
13 | @@ -324,14 +324,14 @@ void SDLCALL music_mixer(void *udata, Uint8 *stream, int len) | |
14 | /* Handle fading */ | |
15 | if (music_playing->fading != MIX_NO_FADING) { | |
16 | if (music_playing->fade_step++ < music_playing->fade_steps) { | |
17 | - int volume = Mix_MasterVolume(-1); | |
18 | + int volume; | |
19 | int fade_step = music_playing->fade_step; | |
20 | int fade_steps = music_playing->fade_steps; | |
21 | ||
22 | if (music_playing->fading == MIX_FADING_OUT) { | |
23 | - volume = (volume * (music_volume * (fade_steps-fade_step))) / (fade_steps * MIX_MAX_VOLUME); | |
24 | + volume = (music_volume * (fade_steps-fade_step)) / fade_steps; | |
25 | } else { /* Fading in */ | |
26 | - volume = (volume * (music_volume * fade_step)) / (fade_steps * MIX_MAX_VOLUME); | |
27 | + volume = ( music_volume * fade_step ) / fade_steps; | |
28 | } | |
29 | music_internal_volume(volume); | |
30 | } else { |
0 | From: Sam Lantinga <slouken@libsdl.org> | |
1 | Date: Fri, 27 May 2022 14:03:52 -0700 | |
2 | Subject: Better fix for music decoders that return no data, | |
3 | e.g. a zero length song | |
4 | ||
5 | If we get no music data twice in a row, we'll stop decoding music for that iteration of the callback. | |
6 | ||
7 | Bug: https://github.com/libsdl-org/SDL_mixer/issues/293 | |
8 | Origin: upstream, 2.5.2, commit:b1fc474a780ce4821da4ea4b0ea2eba03ef820a7 | |
9 | --- | |
10 | src/music.c | 17 +++++++++++++++-- | |
11 | 1 file changed, 15 insertions(+), 2 deletions(-) | |
12 | ||
13 | diff --git a/src/music.c b/src/music.c | |
14 | index 6ef8047..7ca56f5 100644 | |
15 | --- a/src/music.c | |
16 | +++ b/src/music.c | |
17 | @@ -288,6 +288,7 @@ int music_pcm_getaudio(void *context, void *data, int bytes, int volume, | |
18 | Uint8 *snd = (Uint8 *)data; | |
19 | Uint8 *dst; | |
20 | int len = bytes; | |
21 | + int zero_cycles = 0; | |
22 | SDL_bool done = SDL_FALSE; | |
23 | ||
24 | if (volume == MIX_MAX_VOLUME) { | |
25 | @@ -300,6 +301,15 @@ int music_pcm_getaudio(void *context, void *data, int bytes, int volume, | |
26 | if (consumed < 0) { | |
27 | break; | |
28 | } | |
29 | + if (consumed == 0) { | |
30 | + ++zero_cycles; | |
31 | + if (zero_cycles > 1) { | |
32 | + /* We went more than one cycle with no data, we're done */ | |
33 | + done = SDL_TRUE; | |
34 | + } | |
35 | + continue; | |
36 | + } | |
37 | + zero_cycles = 0; | |
38 | ||
39 | if (volume == MIX_MAX_VOLUME) { | |
40 | dst += consumed; | |
41 | @@ -318,9 +328,11 @@ int music_pcm_getaudio(void *context, void *data, int bytes, int volume, | |
42 | /* Mixing function */ | |
43 | void SDLCALL music_mixer(void *udata, Uint8 *stream, int len) | |
44 | { | |
45 | + SDL_bool done = SDL_FALSE; | |
46 | + | |
47 | (void)udata; | |
48 | ||
49 | - while (music_playing && music_active && len > 0) { | |
50 | + while (music_playing && music_active && len > 0 && !done) { | |
51 | /* Handle fading */ | |
52 | if (music_playing->fading != MIX_NO_FADING) { | |
53 | if (music_playing->fade_step++ < music_playing->fade_steps) { | |
54 | @@ -331,7 +343,7 @@ void SDLCALL music_mixer(void *udata, Uint8 *stream, int len) | |
55 | if (music_playing->fading == MIX_FADING_OUT) { | |
56 | volume = (music_volume * (fade_steps-fade_step)) / fade_steps; | |
57 | } else { /* Fading in */ | |
58 | - volume = ( music_volume * fade_step ) / fade_steps; | |
59 | + volume = (music_volume * fade_step) / fade_steps; | |
60 | } | |
61 | music_internal_volume(volume); | |
62 | } else { | |
63 | @@ -351,6 +363,7 @@ void SDLCALL music_mixer(void *udata, Uint8 *stream, int len) | |
64 | if (left != 0) { | |
65 | /* Either an error or finished playing with data left */ | |
66 | music_playing->playing = SDL_FALSE; | |
67 | + done = SDL_TRUE; | |
68 | } | |
69 | if (left > 0) { | |
70 | stream += (len - left); |
0 | From: Sam Lantinga <slouken@libsdl.org> | |
1 | Date: Fri, 27 May 2022 09:28:04 -0700 | |
2 | Subject: Document that the master volume doesn't affect music | |
3 | ||
4 | Origin: upstream, 2.5.2, commit:6366d06f62e2a4baeb88751efd57522087f22266 | |
5 | --- | |
6 | include/SDL_mixer.h | 4 ++-- | |
7 | 1 file changed, 2 insertions(+), 2 deletions(-) | |
8 | ||
9 | diff --git a/include/SDL_mixer.h b/include/SDL_mixer.h | |
10 | index 55aaae2..09f870f 100644 | |
11 | --- a/include/SDL_mixer.h | |
12 | +++ b/include/SDL_mixer.h | |
13 | @@ -590,8 +590,8 @@ extern DECLSPEC int SDLCALL Mix_VolumeMusic(int volume); | |
14 | /* Get the current volume value in the range of 0-128 of a music stream */ | |
15 | extern DECLSPEC int SDLCALL Mix_GetMusicVolume(Mix_Music *music); | |
16 | ||
17 | -/* Set the master volume. | |
18 | - This did not affect the member variables of music, channel or chunck volume. | |
19 | +/* Set the master volume for all channels. | |
20 | + This did not affect the member variables of channel or chunk volume. | |
21 | If the specified volume is -1, just return the current master volume. | |
22 | */ | |
23 | extern DECLSPEC int SDLCALL Mix_MasterVolume(int volume); |
0 | From: Sam Lantinga <slouken@libsdl.org> | |
1 | Date: Fri, 27 May 2022 09:34:45 -0700 | |
2 | Subject: Don't reassign the volume each time through the loop, | |
3 | instead update it after the application callback if needed. | |
4 | ||
5 | Origin: upstream, 2.5.2, commit:943fda956222ec733c5b857f78d318bd3a02f469 | |
6 | --- | |
7 | src/mixer.c | 12 +++++++----- | |
8 | 1 file changed, 7 insertions(+), 5 deletions(-) | |
9 | ||
10 | diff --git a/src/mixer.c b/src/mixer.c | |
11 | index 5532509..c679a7f 100644 | |
12 | --- a/src/mixer.c | |
13 | +++ b/src/mixer.c | |
14 | @@ -326,7 +326,7 @@ static void SDLCALL | |
15 | mix_channels(void *udata, Uint8 *stream, int len) | |
16 | { | |
17 | Uint8 *mix_input; | |
18 | - int i, mixable, volume, master_vol; | |
19 | + int i, mixable, master_vol; | |
20 | Uint32 sdl_ticks; | |
21 | ||
22 | (void)udata; | |
23 | @@ -337,8 +337,7 @@ mix_channels(void *udata, Uint8 *stream, int len) | |
24 | /* Mix the music (must be done before the channels are added) */ | |
25 | mix_music(music_data, stream, len); | |
26 | ||
27 | - volume = Mix_MasterVolume(-1); | |
28 | - master_vol = volume; | |
29 | + master_vol = SDL_AtomicGet(&master_volume); | |
30 | ||
31 | /* Mix any playing channels... */ | |
32 | sdl_ticks = SDL_GetTicks(); | |
33 | @@ -372,18 +371,18 @@ mix_channels(void *udata, Uint8 *stream, int len) | |
34 | } | |
35 | } | |
36 | if (mix_channel[i].playing > 0) { | |
37 | + int volume = (master_vol * (mix_channel[i].volume * mix_channel[i].chunk->volume)) / (MIX_MAX_VOLUME * MIX_MAX_VOLUME); | |
38 | int index = 0; | |
39 | int remaining = len; | |
40 | while (mix_channel[i].playing > 0 && index < len) { | |
41 | remaining = len - index; | |
42 | - volume = (master_vol * (mix_channel[i].volume * mix_channel[i].chunk->volume)) / (MIX_MAX_VOLUME * MIX_MAX_VOLUME); | |
43 | mixable = mix_channel[i].playing; | |
44 | if (mixable > remaining) { | |
45 | mixable = remaining; | |
46 | } | |
47 | ||
48 | mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable); | |
49 | - SDL_MixAudioFormat(stream+index,mix_input,mixer.format,mixable,volume); | |
50 | + SDL_MixAudioFormat(stream+index, mix_input, mixer.format, mixable, volume); | |
51 | if (mix_input != mix_channel[i].samples) | |
52 | SDL_free(mix_input); | |
53 | ||
54 | @@ -394,6 +393,9 @@ mix_channels(void *udata, Uint8 *stream, int len) | |
55 | /* rcg06072001 Alert app if channel is done playing. */ | |
56 | if (!mix_channel[i].playing && !mix_channel[i].looping) { | |
57 | _Mix_channel_done_playing(i); | |
58 | + | |
59 | + /* Update the volume after the application callback */ | |
60 | + volume = (master_vol * (mix_channel[i].volume * mix_channel[i].chunk->volume)) / (MIX_MAX_VOLUME * MIX_MAX_VOLUME); | |
61 | } | |
62 | } | |
63 |
0 | From: Sam Lantinga <slouken@libsdl.org> | |
1 | Date: Fri, 27 May 2022 13:20:24 -0700 | |
2 | Subject: Play the last chunk that was decoded by mpg123 | |
3 | ||
4 | Bug: https://github.com/libsdl-org/SDL_mixer/issues/281 | |
5 | Origin: upstream, 2.5.2, commit:0126a8890a227a650813ab0485df9fb9e7702539 | |
6 | --- | |
7 | src/codecs/music_mpg123.c | 8 +++++++- | |
8 | 1 file changed, 7 insertions(+), 1 deletion(-) | |
9 | ||
10 | diff --git a/src/codecs/music_mpg123.c b/src/codecs/music_mpg123.c | |
11 | index 0e32dc1..a8198d8 100644 | |
12 | --- a/src/codecs/music_mpg123.c | |
13 | +++ b/src/codecs/music_mpg123.c | |
14 | @@ -360,7 +360,7 @@ static int MPG123_GetSome(void *context, void *data, int bytes, SDL_bool *done) | |
15 | { | |
16 | MPG123_Music *music = (MPG123_Music *)context; | |
17 | int filled, result; | |
18 | - size_t amount; | |
19 | + size_t amount = 0; | |
20 | long rate; | |
21 | int channels, encoding, format; | |
22 | ||
23 | @@ -412,6 +412,12 @@ static int MPG123_GetSome(void *context, void *data, int bytes, SDL_bool *done) | |
24 | break; | |
25 | ||
26 | case MPG123_DONE: | |
27 | + if (amount > 0) { | |
28 | + if (SDL_AudioStreamPut(music->stream, music->buffer, (int)amount) < 0) { | |
29 | + return -1; | |
30 | + } | |
31 | + break; | |
32 | + } | |
33 | if (music->play_count == 1) { | |
34 | music->play_count = 0; | |
35 | SDL_AudioStreamFlush(music->stream); |
0 | Play-the-last-chunk-that-was-decoded-by-mpg123.patch | |
1 | Document-that-the-master-volume-doesn-t-affect-music.patch | |
2 | Don-t-reassign-the-volume-each-time-through-the-loop-inst.patch | |
3 | Back-out-master-volume-affecting-music.patch | |
4 | Better-fix-for-music-decoders-that-return-no-data-e.g.-a-.patch | |
5 | Allow-more-than-one-cycle-with-no-music-data.patch |