From gtoombs at lakeheadu.ca Sun Jan 5 22:11:06 2014 From: gtoombs at lakeheadu.ca (Greg Toombs) Date: Sun, 5 Jan 2014 22:11:06 -0500 Subject: [sdlsound] Unclear on SDL_Sound SOUND_SAMPLEFLAG_EAGAIN Message-ID: I'm cross-posting this to Stack Overflow - http://stackoverflow.com/questions/20942108/sdl-sound-sound-sampleflag-eagain-behaviour I briefly perused the source code for SDL_Sound but, as with the above post, I'm still not sure what the flag means. Any clarification would be appreciated. Thanks folks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From icculus at icculus.org Mon Jan 6 23:16:11 2014 From: icculus at icculus.org (Ryan C. Gordon) Date: Mon, 06 Jan 2014 23:16:11 -0500 Subject: [sdlsound] Unclear on SDL_Sound SOUND_SAMPLEFLAG_EAGAIN In-Reply-To: References: Message-ID: <52CB7F8B.4080308@icculus.org> On 01/05/2014 10:11 PM, Greg Toombs wrote: > I'm cross-posting this to Stack Overflow - > http://stackoverflow.com/questions/20942108/sdl-sound-sound-sampleflag-eagain-behaviour > > I briefly perused the source code for SDL_Sound but, as with the above > post, I'm still not sure what the flag means. Any clarification would be > appreciated. Thanks folks. It means try to decode again, it was probably a temporary problem. For example, if you have a RWops that's pulling audio data from a web server, and SDL_sound has decoded all the data available and is waiting for more to come over the network, EAGAIN might get set. If that web server unexpectedly drops the connection halfway through, that won't report EAGAIN. That reports SOUND_SAMPLEFLAG_ERROR. SOUND_SAMPLEFLAG_EAGAIN means we just couldn't finish the operation right now, so we gave control back to your app instead of waiting until we could. --ryan. From gtoombs at lakeheadu.ca Tue Jan 7 00:01:08 2014 From: gtoombs at lakeheadu.ca (Greg Toombs) Date: Tue, 07 Jan 2014 00:01:08 -0500 Subject: [sdlsound] Unclear on SDL_Sound SOUND_SAMPLEFLAG_EAGAIN Message-ID: Ok. So does that mean that, if a subsequent decode succeeds, it's safe to use the whole buffer? In other words, if I see EAGAIN, how do I interpret the returned byte count?? -------- Original message -------- From: "Ryan C. Gordon" Date: 2014/01/06 23:16 (GMT-05:00) To: SDL_sound mailing list Subject: Re: [sdlsound] Unclear on SDL_Sound SOUND_SAMPLEFLAG_EAGAIN On 01/05/2014 10:11 PM, Greg Toombs wrote: > I'm cross-posting this to Stack Overflow - > http://stackoverflow.com/questions/20942108/sdl-sound-sound-sampleflag-eagain-behaviour > > I briefly perused the source code for SDL_Sound but, as with the above > post, I'm still not sure what the flag means. Any clarification would be > appreciated. Thanks folks. It means try to decode again, it was probably a temporary problem. For example, if you have a RWops that's pulling audio data from a web server, and SDL_sound has decoded all the data available and is waiting for more to come over the network, EAGAIN might get set. If that web server unexpectedly drops the connection halfway through, that won't report EAGAIN. That reports SOUND_SAMPLEFLAG_ERROR. SOUND_SAMPLEFLAG_EAGAIN means we just couldn't finish the operation right now, so we gave control back to your app instead of waiting until we could. --ryan. _______________________________________________ sdlsound mailing list sdlsound at icculus.org http://icculus.org/mailman/listinfo/sdlsound -------------- next part -------------- An HTML attachment was scrubbed... URL: From icculus at icculus.org Tue Jan 7 00:30:54 2014 From: icculus at icculus.org (Ryan C. Gordon) Date: Tue, 07 Jan 2014 00:30:54 -0500 Subject: [sdlsound] Unclear on SDL_Sound SOUND_SAMPLEFLAG_EAGAIN In-Reply-To: References: Message-ID: <52CB910E.6030501@icculus.org> On 01/07/2014 12:01 AM, Greg Toombs wrote: > Ok. So does that mean that, if a subsequent decode succeeds, it's safe > to use the whole buffer? In other words, if I see EAGAIN, how do I > interpret the returned byte count? The returned byte count from Sound_Decode() is the number of decoded samples you have to work with. It's never safe to work with the whole buffer, it's only safe to work with the number of samples Sound_Decode() reported are in the buffer (which will actually _be_ the whole buffer in normal conditions). If it returns less than sample->buffer_size, you're either at the end of the data or there was a problem...the EOF, ERROR, and EAGAIN flags tell you which happened: EOF for "no more data," ERROR for "no more data because something went wrong" and EAGAIN for "no more data, but try again and there might be." EAGAIN isn't uncommon; most of the decoders will set it if they get a short read, because they aren't sure if they're at the end of the buffer or had a problem and the RWops is just handing over what it managed to get before reporting a problem. Often times the next attempt to decode will return zero bytes and an EOF flag. It's worth noting that this is a lot of explaining for a flag you might not need. Here's what the playsound_simple.c demo app does: /* if there wasn't previously an error or EOF, read more. */ if ( ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) && ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) ) { data->decoded_bytes = Sound_Decode(sample); data->decoded_ptr = sample->buffer; } /* if */ It doesn't check EAGAIN...it either got enough data or it didn't, or there's definitely no more data coming or it needs to keep checking. --ryan. From nyocurio at gmail.com Tue Jan 7 02:33:40 2014 From: nyocurio at gmail.com (Jonas Kulla) Date: Tue, 7 Jan 2014 08:33:40 +0100 Subject: [sdlsound] Unclear on SDL_Sound SOUND_SAMPLEFLAG_EAGAIN In-Reply-To: <52CB910E.6030501@icculus.org> References: <52CB910E.6030501@icculus.org> Message-ID: 2014/1/7 Ryan C. Gordon > On 01/07/2014 12:01 AM, Greg Toombs wrote: > >> Ok. So does that mean that, if a subsequent decode succeeds, it's safe >> to use the whole buffer? In other words, if I see EAGAIN, how do I >> interpret the returned byte count? >> > > It's worth noting that this is a lot of explaining for a flag you might > not need. Here's what the playsound_simple.c demo app does: > > /* if there wasn't previously an error or EOF, read more. */ > if ( ((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) && > ((sample->flags & SOUND_SAMPLEFLAG_EOF) == 0) ) > { > data->decoded_bytes = Sound_Decode(sample); > data->decoded_ptr = sample->buffer; > } /* if */ > > It doesn't check EAGAIN...it either got enough data or it didn't, or > there's definitely no more data coming or it needs to keep checking. Yeah, I also check for EAGAIN only if the returned byte count is 0. Jonas -------------- next part -------------- An HTML attachment was scrubbed... URL: