1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: GameProducer.cpp 23 // Author: Christopher ML Zumwalt May (zummy@users.sf.net) 24 // Description: A MediaKit producer node which mixes sound from the GameKit 25 // and sends them to the audio mixer 26 //------------------------------------------------------------------------------ 27 28 #ifndef _GAMEPRODUCER_H 29 #define _GAMEPRODUCER_H 30 31 // Standard Includes ----------------------------------------------------------- 32 33 // System Includes ------------------------------------------------------------- 34 #include <media/BufferProducer.h> 35 #include <media/MediaEventLooper.h> 36 #include <GameSoundDefs.h> 37 38 // Project Includes ------------------------------------------------------------ 39 40 // Local Includes -------------------------------------------------------------- 41 42 // Local Defines --------------------------------------------------------------- 43 44 // Globals --------------------------------------------------------------------- 45 class GameSoundBuffer; 46 47 // GameProducer class ------------------------------------------------------------- 48 class GameProducer : public BBufferProducer, public BMediaEventLooper 49 { 50 public: 51 GameProducer(GameSoundBuffer * object, 52 const gs_audio_format * format); 53 ~GameProducer(); 54 55 // BMediaNode methods 56 BMediaAddOn* AddOn(int32* internal_id) const; 57 58 // BBufferProducer methods 59 status_t FormatSuggestionRequested(media_type type, 60 int32 quality, 61 media_format* format); 62 63 status_t FormatProposal(const media_source& output, 64 media_format* format); 65 66 status_t FormatChangeRequested(const media_source& source, 67 const media_destination& destination, 68 media_format* io_format, 69 int32* _deprecated_); 70 71 status_t GetNextOutput(int32* cookie, 72 media_output* out_output); 73 74 status_t DisposeOutputCookie(int32 cookie); 75 76 status_t SetBufferGroup(const media_source& for_source, 77 BBufferGroup* group); 78 79 80 status_t GetLatency(bigtime_t* out_latency); 81 82 status_t PrepareToConnect(const media_source& what, 83 const media_destination& where, 84 media_format* format, 85 media_source* out_source, 86 char* out_name); 87 88 void Connect(status_t error, 89 const media_source& source, 90 const media_destination& destination, 91 const media_format& format, 92 char* io_name); 93 94 void Disconnect(const media_source& what, 95 const media_destination& where); 96 97 void LateNoticeReceived(const media_source& what, 98 bigtime_t how_much, 99 bigtime_t performance_time); 100 101 void EnableOutput(const media_source & what, 102 bool enabled, 103 int32* _deprecated_); 104 105 status_t SetPlayRate(int32 numer, 106 int32 denom); 107 108 status_t HandleMessage(int32 message, 109 const void* data, 110 size_t size); 111 112 void AdditionalBufferRequested(const media_source& source, 113 media_buffer_id prev_buffer, 114 bigtime_t prev_time, 115 const media_seek_tag* prev_tag); 116 117 void LatencyChanged(const media_source& source, 118 const media_destination& destination, 119 bigtime_t new_latency, 120 uint32 flags); 121 122 // BMediaEventLooper methods 123 void NodeRegistered(); 124 void SetRunMode(run_mode mode); 125 void HandleEvent(const media_timed_event* event, 126 bigtime_t lateness, 127 bool realTimeEvent = false); 128 129 // GameProducer 130 status_t StartPlaying(GameSoundBuffer* sound); 131 status_t StopPlaying(GameSoundBuffer* sound); 132 bool IsPlaying(GameSoundBuffer* sound) const; 133 134 int32 SoundCount() const; 135 136 private: 137 BBuffer* FillNextBuffer(bigtime_t event_time); 138 139 BBufferGroup * fBufferGroup; 140 bigtime_t fLatency, fInternalLatency; 141 media_output fOutput; 142 bool fOutputEnabled; 143 media_format fPreferredFormat; 144 145 bigtime_t fStartTime; 146 size_t fFrameSize; 147 int64 fFramesSent; 148 GameSoundBuffer * fObject; 149 size_t fBufferSize; 150 }; 151 152 #endif 153