1 /* 2 * $Id: PlaybackNode.h,v 1.1.1.1 2002/01/22 00:52:08 phil Exp $ 3 * PortAudio Portable Real-Time Audio Library 4 * Latest Version at: http://www.portaudio.com 5 * BeOS Media Kit Implementation by Joshua Haberman 6 * 7 * Copyright (c) 2001 Joshua Haberman <joshua@haberman.com> 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining 10 * a copy of this software and associated documentation files 11 * (the "Software"), to deal in the Software without restriction, 12 * including without limitation the rights to use, copy, modify, merge, 13 * publish, distribute, sublicense, and/or sell copies of the Software, 14 * and to permit persons to whom the Software is furnished to do so, 15 * subject to the following conditions: 16 * 17 * The above copyright notice and this permission notice shall be 18 * included in all copies or substantial portions of the Software. 19 * 20 * Any person wishing to distribute modifications to the Software is 21 * requested to send the modifications to the original developer so that 22 * they can be incorporated into the canonical version. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 27 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 28 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 29 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34 #include <be/media/MediaRoster.h> 35 #include <be/media/MediaEventLooper.h> 36 #include <be/media/BufferProducer.h> 37 38 #include "portaudio.h" 39 40 class PaPlaybackNode : 41 public BBufferProducer, 42 public BMediaEventLooper 43 { 44 45 public: 46 PaPlaybackNode( uint32 channels, float frame_rate, uint32 frames_per_buffer, 47 PortAudioCallback *callback, void *user_data ); 48 ~PaPlaybackNode(); 49 50 51 /* Local methods ******************************************/ 52 53 BBuffer *FillNextBuffer(bigtime_t time); 54 void SetSampleFormat(PaSampleFormat inFormat, PaSampleFormat outFormat); 55 bool IsRunning(); 56 PaTimestamp GetStreamTime(); 57 58 /* BMediaNode methods *************************************/ 59 60 BMediaAddOn* AddOn( int32 * ) const; 61 status_t HandleMessage( int32 message, const void *data, size_t size ); 62 63 /* BMediaEventLooper methods ******************************/ 64 65 void HandleEvent( const media_timed_event *event, bigtime_t lateness, 66 bool realTimeEvent ); 67 void NodeRegistered(); 68 69 /* BBufferProducer methods ********************************/ 70 71 status_t FormatSuggestionRequested( media_type type, int32 quality, 72 media_format* format ); 73 status_t FormatProposal( const media_source& output, media_format* format ); 74 status_t FormatChangeRequested( const media_source& source, 75 const media_destination& destination, media_format* io_format, int32* ); 76 77 status_t GetNextOutput( int32* cookie, media_output* out_output ); 78 status_t DisposeOutputCookie( int32 cookie ); 79 80 void LateNoticeReceived( const media_source& what, bigtime_t how_much, 81 bigtime_t performance_time ); 82 void EnableOutput( const media_source& what, bool enabled, int32* _deprecated_ ); 83 84 status_t PrepareToConnect( const media_source& what, 85 const media_destination& where, media_format* format, 86 media_source* out_source, char* out_name ); 87 void Connect(status_t error, const media_source& source, 88 const media_destination& destination, const media_format& format, 89 char* io_name); 90 void Disconnect(const media_source& what, const media_destination& where); 91 92 status_t SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup); 93 94 bool mAborted; 95 96 private: 97 media_output mOutput; 98 media_format mPreferredFormat; 99 uint32 mOutputSampleWidth, mFramesPerBuffer; 100 BBufferGroup *mBufferGroup; 101 bigtime_t mDownstreamLatency, mInternalLatency, mStartTime; 102 uint64 mSamplesSent; 103 PortAudioCallback *mCallback; 104 void *mUserData; 105 bool mRunning; 106 107 }; 108 109