2009-08-28 18:39:55 +04:00
|
|
|
/*
|
2010-04-13 17:01:56 +04:00
|
|
|
* Copyright 2009-2010, Haiku, Inc. All rights reserved.
|
2009-08-28 18:39:55 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _SOUND_PLAYER_H
|
2002-07-09 16:24:59 +04:00
|
|
|
#define _SOUND_PLAYER_H
|
|
|
|
|
|
|
|
|
2009-08-28 18:39:55 +04:00
|
|
|
#include <exception>
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <BufferProducer.h>
|
|
|
|
#include <Locker.h>
|
2009-08-28 18:39:55 +04:00
|
|
|
#include <MediaDefs.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
|
2007-10-16 00:13:55 +04:00
|
|
|
class BContinuousParameter;
|
|
|
|
class BParameterWeb;
|
2002-07-09 16:24:59 +04:00
|
|
|
class BSound;
|
2009-12-04 01:16:54 +03:00
|
|
|
namespace BPrivate {
|
|
|
|
class SoundPlayNode;
|
|
|
|
}
|
2005-11-13 02:27:14 +03:00
|
|
|
|
2009-08-28 18:39:55 +04:00
|
|
|
|
2005-11-13 02:27:14 +03:00
|
|
|
class sound_error : public std::exception {
|
2009-08-28 18:39:55 +04:00
|
|
|
const char* m_str_const;
|
2002-07-09 16:24:59 +04:00
|
|
|
public:
|
2009-08-28 18:39:55 +04:00
|
|
|
sound_error(const char* string);
|
|
|
|
const char* what() const throw();
|
2002-07-09 16:24:59 +04:00
|
|
|
};
|
|
|
|
|
2009-08-28 18:39:55 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
class BSoundPlayer {
|
|
|
|
public:
|
2009-12-03 22:48:11 +03:00
|
|
|
enum sound_player_notification {
|
|
|
|
B_STARTED = 1,
|
|
|
|
B_STOPPED,
|
|
|
|
B_SOUND_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*BufferPlayerFunc)(void*, void* buffer, size_t size,
|
|
|
|
const media_raw_audio_format& format);
|
|
|
|
typedef void (*EventNotifierFunc)(void*, sound_player_notification what,
|
|
|
|
...);
|
2009-08-28 18:39:55 +04:00
|
|
|
|
2009-12-03 22:48:11 +03:00
|
|
|
public:
|
2009-08-28 18:39:55 +04:00
|
|
|
BSoundPlayer(const char* name = NULL,
|
2009-12-03 22:48:11 +03:00
|
|
|
BufferPlayerFunc playerFunction = NULL,
|
|
|
|
EventNotifierFunc
|
|
|
|
eventNotifierFunction = NULL,
|
2009-08-28 18:39:55 +04:00
|
|
|
void* cookie = NULL);
|
|
|
|
BSoundPlayer(
|
|
|
|
const media_raw_audio_format* format,
|
|
|
|
const char* name = NULL,
|
2009-12-03 22:48:11 +03:00
|
|
|
BufferPlayerFunc playerFunction = NULL,
|
|
|
|
EventNotifierFunc
|
|
|
|
eventNotifierFunction = NULL,
|
2009-08-28 18:39:55 +04:00
|
|
|
void* cookie = NULL);
|
|
|
|
BSoundPlayer(
|
|
|
|
const media_node& toNode,
|
2009-12-03 22:48:11 +03:00
|
|
|
const media_multi_audio_format*
|
|
|
|
format = NULL,
|
2009-08-28 18:39:55 +04:00
|
|
|
const char* name = NULL,
|
|
|
|
const media_input* input = NULL,
|
2009-12-03 22:48:11 +03:00
|
|
|
BufferPlayerFunc playerFunction = NULL,
|
|
|
|
EventNotifierFunc
|
|
|
|
eventNotifierFunction = NULL,
|
2009-08-28 18:39:55 +04:00
|
|
|
void* cookie = NULL);
|
|
|
|
virtual ~BSoundPlayer();
|
|
|
|
|
|
|
|
status_t InitCheck();
|
|
|
|
media_raw_audio_format Format() const;
|
|
|
|
|
|
|
|
status_t Start();
|
|
|
|
void Stop(bool block = true, bool flush = true);
|
|
|
|
|
|
|
|
BufferPlayerFunc BufferPlayer() const;
|
|
|
|
void SetBufferPlayer(void (*PlayBuffer)(void*,
|
|
|
|
void* buffer, size_t size,
|
|
|
|
const media_raw_audio_format& format));
|
2009-12-03 22:48:11 +03:00
|
|
|
|
2009-08-28 18:39:55 +04:00
|
|
|
EventNotifierFunc EventNotifier() const;
|
2009-12-03 22:48:11 +03:00
|
|
|
void SetNotifier(
|
|
|
|
EventNotifierFunc eventNotifierFunction);
|
2009-08-28 18:39:55 +04:00
|
|
|
void* Cookie() const;
|
|
|
|
void SetCookie(void* cookie);
|
2009-12-03 22:48:11 +03:00
|
|
|
void SetCallbacks(
|
|
|
|
BufferPlayerFunc playerFunction = NULL,
|
|
|
|
EventNotifierFunc
|
|
|
|
eventNotifierFunction = NULL,
|
2009-08-28 18:39:55 +04:00
|
|
|
void* cookie = NULL);
|
|
|
|
|
|
|
|
typedef int32 play_id;
|
|
|
|
|
|
|
|
bigtime_t CurrentTime();
|
|
|
|
bigtime_t PerformanceTime();
|
|
|
|
status_t Preroll();
|
|
|
|
play_id StartPlaying(BSound* sound,
|
|
|
|
bigtime_t atTime = 0);
|
|
|
|
play_id StartPlaying(BSound* sound,
|
|
|
|
bigtime_t atTime,
|
|
|
|
float withVolume);
|
|
|
|
status_t SetSoundVolume(play_id sound, float newVolume);
|
|
|
|
bool IsPlaying(play_id id);
|
|
|
|
status_t StopPlaying(play_id id);
|
|
|
|
status_t WaitForSound(play_id id);
|
|
|
|
|
|
|
|
// On [0..1]
|
|
|
|
float Volume();
|
|
|
|
void SetVolume(float volume);
|
|
|
|
|
|
|
|
// -xx - +xx (see GetVolumeInfo())
|
|
|
|
// If 'forcePoll' is false, a cached value will be used if new
|
|
|
|
// enough.
|
|
|
|
float VolumeDB(bool forcePoll = false);
|
|
|
|
void SetVolumeDB(float dB);
|
|
|
|
status_t GetVolumeInfo(media_node* _node,
|
|
|
|
int32* _parameterID, float* _minDB,
|
|
|
|
float* _maxDB);
|
|
|
|
bigtime_t Latency();
|
|
|
|
|
|
|
|
virtual bool HasData();
|
|
|
|
void SetHasData(bool hasData);
|
|
|
|
|
|
|
|
// TODO: Needs Perform() method for FBC!
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2009-12-03 22:48:11 +03:00
|
|
|
void SetInitError(status_t error);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
private:
|
2009-08-28 18:39:55 +04:00
|
|
|
static void _SoundPlayBufferFunc(void* cookie,
|
|
|
|
void* buffer, size_t size,
|
|
|
|
const media_raw_audio_format& format);
|
|
|
|
|
|
|
|
// FBC padding
|
|
|
|
virtual status_t _Reserved_SoundPlayer_0(void*, ...);
|
|
|
|
virtual status_t _Reserved_SoundPlayer_1(void*, ...);
|
|
|
|
virtual status_t _Reserved_SoundPlayer_2(void*, ...);
|
|
|
|
virtual status_t _Reserved_SoundPlayer_3(void*, ...);
|
|
|
|
virtual status_t _Reserved_SoundPlayer_4(void*, ...);
|
|
|
|
virtual status_t _Reserved_SoundPlayer_5(void*, ...);
|
|
|
|
virtual status_t _Reserved_SoundPlayer_6(void*, ...);
|
|
|
|
virtual status_t _Reserved_SoundPlayer_7(void*, ...);
|
|
|
|
|
2009-12-03 22:48:11 +03:00
|
|
|
void _Init(const media_node* node,
|
|
|
|
const media_multi_audio_format* format,
|
|
|
|
const char* name, const media_input* input,
|
|
|
|
BufferPlayerFunc playerFunction,
|
|
|
|
EventNotifierFunc eventNotifierFunction,
|
|
|
|
void* cookie);
|
|
|
|
void _GetVolumeSlider();
|
2009-08-28 18:39:55 +04:00
|
|
|
|
2009-12-03 22:48:11 +03:00
|
|
|
void _NotifySoundDone(play_id sound, bool gotToPlay);
|
2009-08-28 18:39:55 +04:00
|
|
|
|
2010-04-13 17:01:56 +04:00
|
|
|
// TODO: those two shouldn't be virtual
|
|
|
|
virtual void Notify(sound_player_notification what, ...);
|
|
|
|
virtual void PlayBuffer(void* buffer, size_t size,
|
2009-12-03 22:48:11 +03:00
|
|
|
const media_raw_audio_format& format);
|
|
|
|
|
|
|
|
private:
|
2009-12-04 01:16:54 +03:00
|
|
|
friend class BPrivate::SoundPlayNode;
|
2009-08-28 18:39:55 +04:00
|
|
|
|
2009-12-04 01:16:54 +03:00
|
|
|
struct playing_sound {
|
|
|
|
playing_sound* next;
|
2009-12-03 22:48:11 +03:00
|
|
|
off_t current_offset;
|
|
|
|
BSound* sound;
|
|
|
|
play_id id;
|
|
|
|
int32 delta;
|
|
|
|
int32 rate;
|
|
|
|
sem_id wait_sem;
|
|
|
|
float volume;
|
|
|
|
};
|
|
|
|
|
2009-12-04 01:16:54 +03:00
|
|
|
struct waiting_sound {
|
|
|
|
waiting_sound* next;
|
2009-12-03 22:48:11 +03:00
|
|
|
bigtime_t start_time;
|
|
|
|
BSound* sound;
|
|
|
|
play_id id;
|
|
|
|
int32 rate;
|
|
|
|
float volume;
|
|
|
|
};
|
2009-08-28 18:39:55 +04:00
|
|
|
|
2009-12-04 01:16:54 +03:00
|
|
|
BPrivate::SoundPlayNode* fPlayerNode;
|
2009-12-03 22:48:11 +03:00
|
|
|
|
2009-12-04 01:16:54 +03:00
|
|
|
playing_sound* fPlayingSounds;
|
|
|
|
waiting_sound* fWaitingSounds;
|
2009-08-28 18:39:55 +04:00
|
|
|
|
2009-12-03 22:48:11 +03:00
|
|
|
BufferPlayerFunc fPlayBufferFunc;
|
|
|
|
EventNotifierFunc fNotifierFunc;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2009-08-28 18:39:55 +04:00
|
|
|
BLocker fLocker;
|
|
|
|
float fVolumeDB;
|
|
|
|
media_input fMediaInput;
|
|
|
|
// Usually the system mixer
|
|
|
|
media_output fMediaOutput;
|
|
|
|
// The playback node
|
|
|
|
void* fCookie;
|
|
|
|
// Opaque handle passed to hooks
|
|
|
|
int32 fFlags;
|
|
|
|
|
|
|
|
status_t fInitStatus;
|
|
|
|
BContinuousParameter* fVolumeSlider;
|
|
|
|
bigtime_t fLastVolumeUpdate;
|
|
|
|
BParameterWeb* fParameterWeb;
|
|
|
|
|
2009-12-03 22:48:11 +03:00
|
|
|
uint32 _reserved[15];
|
2009-08-28 18:39:55 +04:00
|
|
|
};
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2009-08-28 18:39:55 +04:00
|
|
|
#endif // _SOUND_PLAYER_H
|