1 /* 2 * Copyright 2002-2009, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Marcus Overhagen 7 * Jérôme Duval 8 */ 9 #ifndef _SOUND_PLAY_NODE_H 10 #define _SOUND_PLAY_NODE_H 11 12 13 #include <Buffer.h> 14 #include <BufferGroup.h> 15 #include <BufferProducer.h> 16 #include <MediaEventLooper.h> 17 #include <SoundPlayer.h> 18 19 20 namespace BPrivate { 21 22 23 class SoundPlayNode : public BBufferProducer, public BMediaEventLooper { 24 public: 25 SoundPlayNode(const char* name, 26 BSoundPlayer* player); 27 virtual ~SoundPlayNode(); 28 29 bool IsPlaying(); 30 bigtime_t CurrentTime(); 31 32 // BMediaNode methods 33 34 virtual BMediaAddOn* AddOn(int32* _internalID) const; 35 36 protected: 37 virtual void Preroll(); 38 39 public: 40 virtual status_t HandleMessage(int32 message, const void* data, 41 size_t size); 42 43 protected: 44 virtual void NodeRegistered(); 45 virtual status_t RequestCompleted( 46 const media_request_info& info); 47 virtual void SetTimeSource(BTimeSource* timeSource); 48 virtual void SetRunMode(run_mode mode); 49 50 // BBufferProducer methods 51 52 virtual status_t FormatSuggestionRequested(media_type type, 53 int32 quality, media_format* format); 54 55 virtual status_t FormatProposal(const media_source& output, 56 media_format* format); 57 58 virtual status_t FormatChangeRequested( 59 const media_source& source, 60 const media_destination& destination, 61 media_format* format, int32* _deprecated_); 62 virtual status_t GetNextOutput(int32* cookie, 63 media_output* _output); 64 virtual status_t DisposeOutputCookie(int32 cookie); 65 66 virtual status_t SetBufferGroup(const media_source& forSource, 67 BBufferGroup* group); 68 virtual status_t GetLatency(bigtime_t* _latency); 69 70 virtual status_t PrepareToConnect(const media_source& what, 71 const media_destination& where, 72 media_format* format, media_source* _source, 73 char* _name); 74 75 virtual void Connect(status_t error, 76 const media_source& source, 77 const media_destination& destination, 78 const media_format& format, 79 char* name); 80 81 virtual void Disconnect(const media_source& what, 82 const media_destination& where); 83 84 virtual void LateNoticeReceived(const media_source& what, 85 bigtime_t howMuch, 86 bigtime_t performanceTime); 87 88 virtual void EnableOutput(const media_source& what, 89 bool enabled, int32* _deprecated_); 90 virtual void AdditionalBufferRequested( 91 const media_source& source, 92 media_buffer_id previousBuffer, 93 bigtime_t previousTime, 94 const media_seek_tag* previousTag); 95 virtual void LatencyChanged(const media_source& source, 96 const media_destination& destination, 97 bigtime_t newLatency, uint32 flags); 98 99 // BMediaEventLooper methods 100 101 protected: 102 virtual void HandleEvent(const media_timed_event* event, 103 bigtime_t lateness, 104 bool realTimeEvent = false); 105 public: 106 media_multi_audio_format Format() const; 107 108 protected: 109 virtual status_t HandleStart(const media_timed_event* event, 110 bigtime_t lateness, 111 bool realTimeEvent = false); 112 virtual status_t HandleSeek(const media_timed_event* event, 113 bigtime_t lateness, 114 bool realTimeEvent = false); 115 virtual status_t HandleWarp(const media_timed_event* event, 116 bigtime_t lateness, 117 bool realTimeEvent = false); 118 virtual status_t HandleStop(const media_timed_event* event, 119 bigtime_t lateness, 120 bool realTimeEvent = false); 121 virtual status_t SendNewBuffer(const media_timed_event* event, 122 bigtime_t lateness, 123 bool realTimeEvent = false); 124 virtual status_t HandleDataStatus(const media_timed_event* event, 125 bigtime_t lateness, 126 bool realTimeEvent = false); 127 virtual status_t HandleParameter(const media_timed_event* event, 128 bigtime_t lateness, 129 bool realTimeEvent = false); 130 131 status_t AllocateBuffers(); 132 BBuffer* FillNextBuffer(bigtime_t eventTime); 133 134 private: 135 BSoundPlayer* fPlayer; 136 137 status_t fInitStatus; 138 bool fOutputEnabled; 139 media_output fOutput; 140 BBufferGroup* fBufferGroup; 141 bigtime_t fLatency; 142 bigtime_t fInternalLatency; 143 bigtime_t fStartTime; 144 uint64 fFramesSent; 145 int32 fTooEarlyCount; 146 }; 147 148 149 } // namespace BPrivate 150 151 152 #endif // _SOUND_PLAY_NODE_H 153