1 /* SoundPlayer.h */ 2 /* Copyright 1998 Be Incorporated. All rights reserved. */ 3 4 #if !defined(_SOUND_PLAYER_H) 5 #define _SOUND_PLAYER_H 6 7 8 #include <MediaDefs.h> 9 #include <BufferProducer.h> 10 #include <Locker.h> 11 #include <exception> 12 13 14 class BContinuousParameter; 15 class BParameterWeb; 16 class BSound; 17 class _SoundPlayNode; 18 19 class sound_error : public std::exception { 20 const char * m_str_const; 21 public: 22 sound_error(const char * str); 23 const char * what() const throw (); 24 }; 25 26 class BSoundPlayer { 27 friend class _SoundPlayNode; 28 public: 29 enum sound_player_notification { 30 B_STARTED = 1, 31 B_STOPPED, 32 B_SOUND_DONE 33 }; 34 35 BSoundPlayer( 36 const char * name = NULL, 37 void (*PlayBuffer)(void *, void * buffer, size_t size, const media_raw_audio_format & format) = NULL, 38 void (*Notifier)(void *, sound_player_notification what, ...) = NULL, 39 void * cookie = NULL); 40 BSoundPlayer( 41 const media_raw_audio_format * format, 42 const char * name = NULL, 43 void (*PlayBuffer)(void *, void * buffer, size_t size, const media_raw_audio_format & format) = NULL, 44 void (*Notifier)(void *, sound_player_notification what, ...) = NULL, 45 void * cookie = NULL); 46 BSoundPlayer( 47 const media_node & toNode, 48 const media_multi_audio_format * format = NULL, 49 const char * name = NULL, 50 const media_input * input = NULL, 51 void (*PlayBuffer)(void *, void * buffer, size_t size, const media_raw_audio_format & format) = NULL, 52 void (*Notifier)(void *, sound_player_notification what, ...) = NULL, 53 void * cookie = NULL); 54 virtual ~BSoundPlayer(); 55 56 status_t InitCheck(); // new in R4.1 57 media_raw_audio_format Format() const; // new in R4.1 58 59 status_t Start(); 60 void Stop( 61 bool block = true, 62 bool flush = true); 63 64 typedef void (*BufferPlayerFunc)(void *, void *, size_t, const media_raw_audio_format &); 65 BufferPlayerFunc BufferPlayer() const; 66 void SetBufferPlayer( 67 void (*PlayBuffer)(void *, void * buffer, size_t size, const media_raw_audio_format & format)); 68 typedef void (*EventNotifierFunc)(void *, sound_player_notification what, ...); 69 EventNotifierFunc EventNotifier() const; 70 void SetNotifier( 71 void (*Notifier)(void *, sound_player_notification what, ...)); 72 void * Cookie() const; 73 void SetCookie( 74 void * cookie); 75 void SetCallbacks( // atomic change 76 void (*PlayBuffer)(void *, void * buffer, size_t size, const media_raw_audio_format & format) = NULL, 77 void (*Notifier)(void *, sound_player_notification what, ...) = NULL, 78 void * cookie = NULL); 79 80 typedef int32 play_id; 81 82 bigtime_t CurrentTime(); 83 bigtime_t PerformanceTime(); 84 status_t Preroll(); 85 play_id StartPlaying( 86 BSound * sound, 87 bigtime_t at_time = 0); 88 play_id StartPlaying( 89 BSound * sound, 90 bigtime_t at_time, 91 float with_volume); 92 status_t SetSoundVolume( 93 play_id sound, // update only non-NULL values 94 float new_volume); 95 bool IsPlaying( 96 play_id id); 97 status_t StopPlaying( 98 play_id id); 99 status_t WaitForSound( 100 play_id id); 101 102 float Volume(); /* 0 - 1.0 */ 103 void SetVolume( /* 0 - 1.0 */ 104 float new_volume); 105 float VolumeDB( /* -xx - +xx (see GetVolumeInfo()) */ 106 bool forcePoll = false); /* if false, cached value will be used if new enough */ 107 void SetVolumeDB( 108 float volume_dB); 109 status_t GetVolumeInfo( 110 media_node * out_node, 111 int32 * out_parameter_id, 112 float * out_min_dB, 113 float * out_max_dB); 114 bigtime_t Latency(); 115 116 virtual bool HasData(); 117 void SetHasData( // this does more than just set a flag 118 bool has_data); 119 120 protected: 121 122 void SetInitError( // new in R4.1 123 status_t in_error); 124 125 private: 126 127 virtual status_t _Reserved_SoundPlayer_0(void *, ...); 128 virtual status_t _Reserved_SoundPlayer_1(void *, ...); 129 virtual status_t _Reserved_SoundPlayer_2(void *, ...); 130 virtual status_t _Reserved_SoundPlayer_3(void *, ...); 131 virtual status_t _Reserved_SoundPlayer_4(void *, ...); 132 virtual status_t _Reserved_SoundPlayer_5(void *, ...); 133 virtual status_t _Reserved_SoundPlayer_6(void *, ...); 134 virtual status_t _Reserved_SoundPlayer_7(void *, ...); 135 136 _SoundPlayNode * fPlayerNode; 137 struct _playing_sound { 138 _playing_sound * next; 139 off_t cur_offset; 140 BSound * sound; 141 play_id id; 142 int32 delta; 143 int32 rate; 144 float volume; 145 }; 146 _playing_sound * _m_sounds; 147 struct _waiting_sound { 148 _waiting_sound * next; 149 bigtime_t start_time; 150 BSound * sound; 151 play_id id; 152 int32 rate; 153 float volume; 154 }; 155 _waiting_sound * _m_waiting; 156 void (*fPlayBufferFunc)(void * cookie, void * buffer, size_t size, const media_raw_audio_format & format); 157 void (*fNotifierFunc)(void * cookie, sound_player_notification what, ...); 158 BLocker fLocker; 159 float fVolumeDB; 160 media_input fMediaInput; // the system mixer 161 media_output fMediaOutput; // the player node 162 void * fCookie; 163 int32 fFlags; 164 165 status_t fInitStatus; // new in R4.1 166 BContinuousParameter * fVolumeSlider; 167 bigtime_t fLastVolumeUpdate; 168 BParameterWeb *fParameterWeb; 169 uint32 _m_reserved[15]; 170 171 void NotifySoundDone( 172 play_id sound, 173 bool got_to_play); 174 175 void get_volume_slider(); 176 void Init( 177 const media_node * node, 178 const media_multi_audio_format * format, 179 const char * name, 180 const media_input * input, 181 void (*PlayBuffer)(void *, void * buffer, size_t size, const media_raw_audio_format & format), 182 void (*Notifier)(void *, sound_player_notification what, ...), 183 void * cookie); 184 // for B_STARTED and B_STOPPED, the argument is BSoundPlayer* (this) 185 // for B_SOUND_DONE, the arguments are play_id and true/false for whether it got to play data at all 186 virtual void Notify( 187 sound_player_notification what, 188 ...); 189 // get data into the buffer to play -- this version will use the queued BSound system 190 virtual void PlayBuffer( 191 void * buffer, 192 size_t size, 193 const media_raw_audio_format & format); 194 }; 195 196 197 #endif /* _SOUND_PLAYER_H */ 198