diff --git a/src/servers/media_addon/MediaFilePlayer.cpp b/src/servers/media_addon/MediaFilePlayer.cpp index de872ea20a..9ce78188b5 100644 --- a/src/servers/media_addon/MediaFilePlayer.cpp +++ b/src/servers/media_addon/MediaFilePlayer.cpp @@ -4,34 +4,39 @@ * Distributed under the terms of the MIT License. */ -#include -#include "MediaFilePlayer.h" -#include "ObjectList.h" -#include +#include "MediaFilePlayer.h" + +#include +#include + #include + BObjectList list; -MediaFilePlayer * -FindMediaFilePlayer(MediaFilePlayer *player, void *media_name) + +MediaFilePlayer* +FindMediaFilePlayer(MediaFilePlayer* player, void* media_name) { - if (!strcmp(player->Name(), (const char *)media_name)) + if (strcmp(player->Name(), (const char*)media_name) == 0) return player; return NULL; } void -PlayMediaFile(const char *media_type, const char *media_name) +PlayMediaFile(const char* media_type, const char* media_name) { entry_ref ref; - if (BMediaFiles().GetRefFor(media_type, media_name, &ref)!=B_OK + if (BMediaFiles().GetRefFor(media_type, media_name, &ref) != B_OK || !BEntry(&ref).Exists()) return; - MediaFilePlayer *player = list.EachElement(FindMediaFilePlayer, (void *)media_name); - if (player) { + MediaFilePlayer* player = list.EachElement(FindMediaFilePlayer, + (void*)media_name); + + if (player != NULL) { if (*(player->Ref()) == ref) { player->Restart(); return; @@ -42,7 +47,7 @@ PlayMediaFile(const char *media_type, const char *media_name) player = NULL; } - if (!player) { + if (player == NULL) { player = new MediaFilePlayer(media_type, media_name, &ref); if (player->InitCheck() == B_OK) list.AddItem(player); @@ -53,8 +58,9 @@ PlayMediaFile(const char *media_type, const char *media_name) -MediaFilePlayer::MediaFilePlayer(const char *media_type, - const char *media_name, entry_ref *ref) : +MediaFilePlayer::MediaFilePlayer(const char* media_type, + const char* media_name, entry_ref* ref) + : fInitCheck(B_ERROR), fRef(*ref), fSoundPlayer(NULL), @@ -63,14 +69,14 @@ MediaFilePlayer::MediaFilePlayer(const char *media_type, fName = strdup(media_name); fPlayFile = new BMediaFile(&fRef); - if ((fInitCheck = fPlayFile->InitCheck()) InitCheck(); + if (fInitCheck != B_OK) return; - } memset(&fPlayFormat, 0, sizeof(fPlayFormat)); for (int i=0; i < fPlayFile->CountTracks(); i++) { - BMediaTrack *track = fPlayFile->TrackAt(i); + BMediaTrack* track = fPlayFile->TrackAt(i); if (track == NULL) continue; fPlayFormat.type = B_MEDIA_RAW_AUDIO; @@ -88,11 +94,12 @@ MediaFilePlayer::MediaFilePlayer(const char *media_type, return; } - fSoundPlayer = new BSoundPlayer(&fPlayFormat.u.raw_audio, media_name, PlayFunction, - NULL, this); - if ((fInitCheck = fSoundPlayer->InitCheck()) != B_OK) { + fSoundPlayer = new BSoundPlayer(&fPlayFormat.u.raw_audio, + media_name, PlayFunction, NULL, this); + + fInitCheck = fSoundPlayer->InitCheck(); + if (fInitCheck != B_OK) return; - } fSoundPlayer->SetVolume(1.0f); fSoundPlayer->SetHasData(true); @@ -115,10 +122,24 @@ MediaFilePlayer::InitCheck() } +const char* +MediaFilePlayer::Name() +{ + return fName; +} + + +const entry_ref* +MediaFilePlayer::Ref() +{ + return &fRef; +} + + bool MediaFilePlayer::IsPlaying() { - return (fSoundPlayer && fSoundPlayer->HasData()); + return (fSoundPlayer != NULL && fSoundPlayer->HasData()); } void @@ -140,13 +161,13 @@ MediaFilePlayer::Stop() void -MediaFilePlayer::PlayFunction(void *cookie, void * buffer, size_t size, const media_raw_audio_format & format) +MediaFilePlayer::PlayFunction(void* cookie, void* buffer, + size_t size, const media_raw_audio_format& format) { - MediaFilePlayer *player = (MediaFilePlayer *)cookie; + MediaFilePlayer* player = (MediaFilePlayer*)cookie; int64 frames = 0; player->fPlayTrack->ReadFrames(buffer, &frames); - if (frames <=0) { + if (frames <= 0) player->fSoundPlayer->SetHasData(false); - } } diff --git a/src/servers/media_addon/MediaFilePlayer.h b/src/servers/media_addon/MediaFilePlayer.h index 4c85458a15..508be95a0c 100644 --- a/src/servers/media_addon/MediaFilePlayer.h +++ b/src/servers/media_addon/MediaFilePlayer.h @@ -5,41 +5,46 @@ #ifndef _MEDIA_FILE_PLAYER_H #define _MEDIA_FILE_PLAYER_H + #include -#include +#include #include #include -#include +#include -void PlayMediaFile(const char *media_type, const char *media_name); +void PlayMediaFile(const char* media_type, const char* media_name); class MediaFilePlayer { public: - MediaFilePlayer(const char *media_type, const char *media_name, - entry_ref *ref); - ~MediaFilePlayer(); + MediaFilePlayer(const char* media_type, + const char* media_name, + entry_ref* ref); + ~MediaFilePlayer(); - bool IsPlaying(); - void Restart(); - void Stop(); - status_t InitCheck(); - const char *Name() { return fName; }; - const entry_ref *Ref() { return &fRef; }; - - static void PlayFunction(void *cookie, void * buffer, - size_t size, const media_raw_audio_format & format); + status_t InitCheck(); + + bool IsPlaying(); + void Restart(); + void Stop(); + + const char* Name(); + const entry_ref* Ref(); + + static void PlayFunction(void* cookie, void* buffer, + size_t size, + const media_raw_audio_format& format); private: - char *fName; - status_t fInitCheck; - entry_ref fRef; - BSoundPlayer *fSoundPlayer; - BMediaFile *fPlayFile; - BMediaTrack *fPlayTrack; - media_format fPlayFormat; + char* fName; + status_t fInitCheck; + entry_ref fRef; + BSoundPlayer* fSoundPlayer; + BMediaFile* fPlayFile; + BMediaTrack* fPlayTrack; + media_format fPlayFormat; }; #endif // _MEDIA_FILE_PLAYER_H