aboutsummaryrefslogtreecommitdiff
path: root/pd/portaudio_v18/pa_beos/PlaybackNode.h
blob: c95820565b18c98e5abcc729c077062ea924ab2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * $Id: PlaybackNode.h,v 1.1.1.1 2002/01/22 00:52:08 phil Exp $
 * PortAudio Portable Real-Time Audio Library
 * Latest Version at: http://www.portaudio.com
 * BeOS Media Kit Implementation by Joshua Haberman
 *
 * Copyright (c) 2001 Joshua Haberman <joshua@haberman.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * Any person wishing to distribute modifications to the Software is
 * requested to send the modifications to the original developer so that
 * they can be incorporated into the canonical version.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#include <be/media/MediaRoster.h>
#include <be/media/MediaEventLooper.h>
#include <be/media/BufferProducer.h>

#include "portaudio.h"

class PaPlaybackNode :
            public BBufferProducer,
            public BMediaEventLooper
{

public:
    PaPlaybackNode( uint32 channels, float frame_rate, uint32 frames_per_buffer,
                    PortAudioCallback *callback, void *user_data );
    ~PaPlaybackNode();


    /* Local methods ******************************************/

    BBuffer *FillNextBuffer(bigtime_t time);
    void SetSampleFormat(PaSampleFormat inFormat, PaSampleFormat outFormat);
    bool IsRunning();
    PaTimestamp GetStreamTime();

    /* BMediaNode methods *************************************/

    BMediaAddOn* AddOn( int32 * ) const;
    status_t HandleMessage( int32 message, const void *data, size_t size );

    /* BMediaEventLooper methods ******************************/

    void HandleEvent( const media_timed_event *event, bigtime_t lateness,
                      bool realTimeEvent );
    void NodeRegistered();

    /* BBufferProducer methods ********************************/

    status_t FormatSuggestionRequested( media_type type, int32 quality,
                                        media_format* format );
    status_t FormatProposal( const media_source& output, media_format* format );
    status_t FormatChangeRequested( const media_source& source,
                                    const media_destination& destination, media_format* io_format, int32* );

    status_t GetNextOutput( int32* cookie, media_output* out_output );
    status_t DisposeOutputCookie( int32 cookie );

    void LateNoticeReceived( const media_source& what, bigtime_t how_much,
                             bigtime_t performance_time );
    void EnableOutput( const media_source& what, bool enabled, int32* _deprecated_ );

    status_t PrepareToConnect( const media_source& what,
                               const media_destination& where, media_format* format,
                               media_source* out_source, char* out_name );
    void Connect(status_t error, const media_source& source,
                 const media_destination& destination, const media_format& format,
                 char* io_name);
    void Disconnect(const media_source& what, const media_destination& where);

    status_t SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup);

    bool         mAborted;

private:
    media_output mOutput;
    media_format mPreferredFormat;
    uint32       mOutputSampleWidth, mFramesPerBuffer;
    BBufferGroup *mBufferGroup;
    bigtime_t    mDownstreamLatency, mInternalLatency, mStartTime;
    uint64       mSamplesSent;
    PortAudioCallback *mCallback;
    void         *mUserData;
    bool         mRunning;

};