Changeset 21221

Show
Ignore:
Timestamp:
05/23/07 15:40:57 (18 months ago)
Author:
korli
Message:

don't try to stop a non inited BFileGameSound
now stops BFileGameSound at the end of the track if not looping
GameSoundDevice now checks the sound_id is valid
added a header include in GSUtility.h

Location:
haiku/trunk/src/kits/game
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/kits/game/FileGameSound.cpp

    r20682 r21221  
    199199        status_t error = BStreamingGameSound::StopPlaying(); 
    200200         
     201        if (!fAudioStream || !fAudioStream->stream) 
     202                return B_OK; 
     203                  
    201204        // start reading next time from the start of the file 
    202205        int64 frame = 0; 
     
    231234                        Load(); 
    232235                } 
    233                          
     236                 
     237                if (fPlayPosition + bytes > fBufferSize) 
     238                        bytes = fBufferSize - fPlayPosition; 
     239                         
     240                if (bytes == 0) 
     241                        return; 
     242                 
    234243                if (fPausing) { 
    235244                        Lock(); 
     
    350359        // is this is an audio file?             
    351360        media_format playFormat; 
    352         fAudioStream->stream->EncodedFormat(&playFormat); 
     361        if ((error = fAudioStream->stream->EncodedFormat(&playFormat)) != B_OK) 
     362                return error; 
     363         
    353364        if (!playFormat.IsAudio())  
    354365                return B_MEDIA_BAD_FORMAT; 
     
    395406         
    396407        if (fPlayPosition != 0) { 
    397                 memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition); 
     408                if (fBufferSize > fPlayPosition) 
     409                        memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition); 
    398410                fPlayPosition = fBufferSize - fPlayPosition; 
    399411        } 
     
    404416        fBufferSize = fPlayPosition + frames * fFrameSize; 
    405417        fPlayPosition = 0; 
     418         
     419        if (fBufferSize == 0) { 
     420                if (fLooping) { 
     421                        // start reading next time from the start of the file 
     422                        int64 frame = 0; 
     423                        fAudioStream->stream->SeekToFrame(&frame); 
     424                } else { 
     425                        StopPlaying(); 
     426                } 
     427        } 
    406428                 
    407429        return true; 
  • haiku/trunk/src/kits/game/GSUtility.h

    r1401 r21221  
    3434// Project Includes ------------------------------------------------------------ 
    3535#include <GameSoundDefs.h> 
     36#include <MediaDefs.h> 
    3637 
    3738// Local Includes -------------------------------------------------------------- 
  • haiku/trunk/src/kits/game/GameSoundDevice.cpp

    r3854 r21221  
    191191BGameSoundDevice::ReleaseBuffer(gs_id sound) 
    192192{ 
     193        if (sound <= 0) 
     194                return; 
     195 
    193196        if (fSounds[sound-1]) 
    194197        { 
     
    208211                                                 void * data) 
    209212{ 
    210         if (!format) return B_BAD_VALUE; 
     213        if (!format || sound <= 0) 
     214                return B_BAD_VALUE; 
    211215 
    212216        memcpy(format, &fSounds[sound-1]->Format(), sizeof(gs_audio_format)); 
    213217         
    214         if (fSounds[sound-1]->Data()) 
    215         { 
     218        if (fSounds[sound-1]->Data()) { 
    216219                data = malloc(format->buffer_size); 
    217220                memcpy(data, fSounds[sound-1]->Data(), format->buffer_size); 
     
    225228BGameSoundDevice::StartPlaying(gs_id sound) 
    226229{ 
    227         status_t error = EALREADY; 
    228          
    229         if (!fSounds[sound-1]->IsPlaying()) 
    230         { 
     230        if (sound <= 0) 
     231                return B_BAD_VALUE; 
     232                 
     233        if (!fSounds[sound-1]->IsPlaying()) { 
    231234                // tell the producer to start playing the sound 
    232                 error = fSounds[sound-1]->StartPlaying(); 
    233         } 
    234         else fSounds[sound-1]->Reset(); 
    235          
    236         return error; 
     235                return fSounds[sound-1]->StartPlaying(); 
     236        } 
     237         
     238        fSounds[sound-1]->Reset(); 
     239        return EALREADY; 
    237240} 
    238241 
     
    241244BGameSoundDevice::StopPlaying(gs_id sound) 
    242245{ 
    243         status_t error = EALREADY; 
    244          
    245         if (fSounds[sound-1]->IsPlaying()) 
    246         { 
     246        if (sound <= 0) 
     247                return B_BAD_VALUE; 
     248         
     249        if (fSounds[sound-1]->IsPlaying()) { 
    247250                // Tell the producer to stop play this sound 
    248251                fSounds[sound-1]->Reset();   
    249                 error = fSounds[sound-1]->StopPlaying(); 
    250         } 
    251          
    252         return error; 
     252                return fSounds[sound-1]->StopPlaying(); 
     253        } 
     254         
     255        return EALREADY; 
    253256} 
    254257 
     
    257260BGameSoundDevice::IsPlaying(gs_id sound) 
    258261{ 
     262        if (sound <= 0) 
     263                return false; 
    259264        return fSounds[sound-1]->IsPlaying(); 
    260265}