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 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21221 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -198,6 +198,9 @@ BFileGameSound::StopPlaying()
|
|||||||
{
|
{
|
||||||
status_t error = BStreamingGameSound::StopPlaying();
|
status_t error = BStreamingGameSound::StopPlaying();
|
||||||
|
|
||||||
|
if (!fAudioStream || !fAudioStream->stream)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
// start reading next time from the start of the file
|
// start reading next time from the start of the file
|
||||||
int64 frame = 0;
|
int64 frame = 0;
|
||||||
fAudioStream->stream->SeekToFrame(&frame);
|
fAudioStream->stream->SeekToFrame(&frame);
|
||||||
@@ -230,7 +233,13 @@ BFileGameSound::FillBuffer(void *inBuffer,
|
|||||||
if (fPlayPosition == 0 || fPlayPosition + inByteCount >= fBufferSize) {
|
if (fPlayPosition == 0 || fPlayPosition + inByteCount >= fBufferSize) {
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fPlayPosition + bytes > fBufferSize)
|
||||||
|
bytes = fBufferSize - fPlayPosition;
|
||||||
|
|
||||||
|
if (bytes == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (fPausing) {
|
if (fPausing) {
|
||||||
Lock();
|
Lock();
|
||||||
|
|
||||||
@@ -349,7 +358,9 @@ BFileGameSound::Init(const entry_ref* file)
|
|||||||
|
|
||||||
// is this is an audio file?
|
// is this is an audio file?
|
||||||
media_format playFormat;
|
media_format playFormat;
|
||||||
fAudioStream->stream->EncodedFormat(&playFormat);
|
if ((error = fAudioStream->stream->EncodedFormat(&playFormat)) != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
if (!playFormat.IsAudio())
|
if (!playFormat.IsAudio())
|
||||||
return B_MEDIA_BAD_FORMAT;
|
return B_MEDIA_BAD_FORMAT;
|
||||||
|
|
||||||
@@ -394,7 +405,8 @@ BFileGameSound::Load()
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (fPlayPosition != 0) {
|
if (fPlayPosition != 0) {
|
||||||
memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition);
|
if (fBufferSize > fPlayPosition)
|
||||||
|
memcpy(fBuffer, fBuffer + fPlayPosition, fBufferSize - fPlayPosition);
|
||||||
fPlayPosition = fBufferSize - fPlayPosition;
|
fPlayPosition = fBufferSize - fPlayPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,6 +415,16 @@ BFileGameSound::Load()
|
|||||||
fAudioStream->stream->ReadFrames(fBuffer + fPlayPosition, &frames);
|
fAudioStream->stream->ReadFrames(fBuffer + fPlayPosition, &frames);
|
||||||
fBufferSize = fPlayPosition + frames * fFrameSize;
|
fBufferSize = fPlayPosition + frames * fFrameSize;
|
||||||
fPlayPosition = 0;
|
fPlayPosition = 0;
|
||||||
|
|
||||||
|
if (fBufferSize == 0) {
|
||||||
|
if (fLooping) {
|
||||||
|
// start reading next time from the start of the file
|
||||||
|
int64 frame = 0;
|
||||||
|
fAudioStream->stream->SeekToFrame(&frame);
|
||||||
|
} else {
|
||||||
|
StopPlaying();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
// Project Includes ------------------------------------------------------------
|
||||||
#include <GameSoundDefs.h>
|
#include <GameSoundDefs.h>
|
||||||
|
#include <MediaDefs.h>
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
// Local Includes --------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -190,6 +190,9 @@ BGameSoundDevice::CreateBuffer(gs_id * sound,
|
|||||||
void
|
void
|
||||||
BGameSoundDevice::ReleaseBuffer(gs_id sound)
|
BGameSoundDevice::ReleaseBuffer(gs_id sound)
|
||||||
{
|
{
|
||||||
|
if (sound <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (fSounds[sound-1])
|
if (fSounds[sound-1])
|
||||||
{
|
{
|
||||||
// We must stop playback befor destroying the sound or else
|
// We must stop playback befor destroying the sound or else
|
||||||
@@ -207,12 +210,12 @@ BGameSoundDevice::Buffer(gs_id sound,
|
|||||||
gs_audio_format * format,
|
gs_audio_format * format,
|
||||||
void * data)
|
void * data)
|
||||||
{
|
{
|
||||||
if (!format) return B_BAD_VALUE;
|
if (!format || sound <= 0)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
memcpy(format, &fSounds[sound-1]->Format(), sizeof(gs_audio_format));
|
memcpy(format, &fSounds[sound-1]->Format(), sizeof(gs_audio_format));
|
||||||
|
|
||||||
if (fSounds[sound-1]->Data())
|
if (fSounds[sound-1]->Data()) {
|
||||||
{
|
|
||||||
data = malloc(format->buffer_size);
|
data = malloc(format->buffer_size);
|
||||||
memcpy(data, fSounds[sound-1]->Data(), format->buffer_size);
|
memcpy(data, fSounds[sound-1]->Data(), format->buffer_size);
|
||||||
}
|
}
|
||||||
@@ -224,38 +227,40 @@ BGameSoundDevice::Buffer(gs_id sound,
|
|||||||
status_t
|
status_t
|
||||||
BGameSoundDevice::StartPlaying(gs_id sound)
|
BGameSoundDevice::StartPlaying(gs_id sound)
|
||||||
{
|
{
|
||||||
status_t error = EALREADY;
|
if (sound <= 0)
|
||||||
|
return B_BAD_VALUE;
|
||||||
if (!fSounds[sound-1]->IsPlaying())
|
|
||||||
{
|
if (!fSounds[sound-1]->IsPlaying()) {
|
||||||
// tell the producer to start playing the sound
|
// tell the producer to start playing the sound
|
||||||
error = fSounds[sound-1]->StartPlaying();
|
return fSounds[sound-1]->StartPlaying();
|
||||||
}
|
}
|
||||||
else fSounds[sound-1]->Reset();
|
|
||||||
|
|
||||||
return error;
|
fSounds[sound-1]->Reset();
|
||||||
|
return EALREADY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BGameSoundDevice::StopPlaying(gs_id sound)
|
BGameSoundDevice::StopPlaying(gs_id sound)
|
||||||
{
|
{
|
||||||
status_t error = EALREADY;
|
if (sound <= 0)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
if (fSounds[sound-1]->IsPlaying())
|
if (fSounds[sound-1]->IsPlaying()) {
|
||||||
{
|
|
||||||
// Tell the producer to stop play this sound
|
// Tell the producer to stop play this sound
|
||||||
fSounds[sound-1]->Reset();
|
fSounds[sound-1]->Reset();
|
||||||
error = fSounds[sound-1]->StopPlaying();
|
return fSounds[sound-1]->StopPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return EALREADY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BGameSoundDevice::IsPlaying(gs_id sound)
|
BGameSoundDevice::IsPlaying(gs_id sound)
|
||||||
{
|
{
|
||||||
|
if (sound <= 0)
|
||||||
|
return false;
|
||||||
return fSounds[sound-1]->IsPlaying();
|
return fSounds[sound-1]->IsPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user