100cffa1cSbeveloper/*
2bf7ab50dSStephan Aßmus * Copyright 2002 David Shipman,
3bf7ab50dSStephan Aßmus * Copyright 2003-2007 Marcus Overhagen
4b289aaf6SAxel Dörfler * Copyright 2007-2010 Haiku Inc. All rights reserved.
5bf7ab50dSStephan Aßmus * Distributed under the terms of the MIT License.
6bf7ab50dSStephan Aßmus */
7b289aaf6SAxel Dörfler#ifndef AUDIO_MIXER_H
8b289aaf6SAxel Dörfler#define AUDIO_MIXER_H
900cffa1cSbeveloper
10a9cf57cfSAxel Dörfler
11bf7ab50dSStephan Aßmus#include <BufferConsumer.h>
12bf7ab50dSStephan Aßmus#include <BufferGroup.h>
13bf7ab50dSStephan Aßmus#include <BufferProducer.h>
14bf7ab50dSStephan Aßmus#include <Controllable.h>
15bf7ab50dSStephan Aßmus#include <MediaEventLooper.h>
16bf7ab50dSStephan Aßmus#include <MediaNode.h>
1700cffa1cSbeveloper
18a9cf57cfSAxel Dörfler
19be2a2489Sbeveloperclass MixerCore;
20b289aaf6SAxel Dörflerclass MixerOutput;
21be2a2489Sbeveloper
22a9cf57cfSAxel Dörfler
23a9cf57cfSAxel Dörflerclass AudioMixer : public BBufferConsumer, public BBufferProducer,
24a9cf57cfSAxel Dörfler	public BControllable, public BMediaEventLooper {
25a9cf57cfSAxel Dörflerpublic:
26b289aaf6SAxel Dörfler								AudioMixer(BMediaAddOn* addOn,
27b289aaf6SAxel Dörfler									bool isSystemMixer);
28b289aaf6SAxel Dörfler	virtual						~AudioMixer();
29bf7ab50dSStephan Aßmus
30b289aaf6SAxel Dörfler			void				DisableNodeStop();
31a9cf57cfSAxel Dörfler
32b289aaf6SAxel Dörfler	// AudioMixer support
33b289aaf6SAxel Dörfler			void				ApplySettings();
3426bf7cd3Sbeveloper
35b289aaf6SAxel Dörfler			void				PublishEventLatencyChange();
36b289aaf6SAxel Dörfler			void				UpdateParameterWeb();
37bf7ab50dSStephan Aßmus
38b289aaf6SAxel Dörfler			void				HandleInputBuffer(BBuffer* buffer,
39b289aaf6SAxel Dörfler									bigtime_t lateness);
40bf7ab50dSStephan Aßmus
418c19f07fSDario Casalinuovo			status_t			CreateBufferGroup(BBufferGroup** buffer) const;
42bf7ab50dSStephan Aßmus
43b289aaf6SAxel Dörfler			status_t			SendBuffer(BBuffer* buffer,
44b289aaf6SAxel Dörfler									MixerOutput* output);
4500cffa1cSbeveloper
46b289aaf6SAxel Dörfler			float				dB_to_Gain(float db);
47b289aaf6SAxel Dörfler			float				Gain_to_dB(float gain);
48b289aaf6SAxel Dörfler
49b289aaf6SAxel Dörfler	// BMediaNode methods
50b289aaf6SAxel Dörfler	virtual	BMediaAddOn*		AddOn(int32* _internalID) const;
51b289aaf6SAxel Dörfler	virtual	void				NodeRegistered();
52b289aaf6SAxel Dörfler	virtual	void 				Stop(bigtime_t performanceTime, bool immediate);
53b289aaf6SAxel Dörfler	virtual	void 				SetTimeSource(BTimeSource* timeSource);
5400cffa1cSbeveloper
55a9cf57cfSAxel Dörflerprotected:
56b289aaf6SAxel Dörfler	// BControllable methods
57b289aaf6SAxel Dörfler	virtual	status_t 			GetParameterValue(int32 id,
58b289aaf6SAxel Dörfler									bigtime_t* _lastChange, void* _value,
59b289aaf6SAxel Dörfler									size_t* _size);
60b289aaf6SAxel Dörfler	virtual	void				SetParameterValue(int32 id, bigtime_t when,
61b289aaf6SAxel Dörfler									const void* value, size_t size);
62b289aaf6SAxel Dörfler
63b289aaf6SAxel Dörfler	// BBufferConsumer methods
64b289aaf6SAxel Dörfler	virtual	status_t			HandleMessage(int32 message, const void* data,
65b289aaf6SAxel Dörfler									size_t size);
66b289aaf6SAxel Dörfler	virtual	status_t			AcceptFormat(const media_destination& dest,
67b289aaf6SAxel Dörfler									media_format* format);
68b289aaf6SAxel Dörfler	virtual	status_t			GetNextInput(int32* cookie,
69b289aaf6SAxel Dörfler									media_input* _input);
70b289aaf6SAxel Dörfler	virtual	void				DisposeInputCookie(int32 cookie);
71b289aaf6SAxel Dörfler	virtual	void				BufferReceived(BBuffer *buffer);
72b289aaf6SAxel Dörfler	virtual	void				ProducerDataStatus(
73b289aaf6SAxel Dörfler									const media_destination& forWhom,
74b289aaf6SAxel Dörfler									int32 status, bigtime_t atPerformanceTime);
75b289aaf6SAxel Dörfler	virtual	status_t			GetLatencyFor(const media_destination& forWhom,
76b289aaf6SAxel Dörfler									bigtime_t* _latency,
77b289aaf6SAxel Dörfler									media_node_id* _timesource);
78b289aaf6SAxel Dörfler	virtual	status_t			Connected(const media_source& producer,
79b289aaf6SAxel Dörfler									const media_destination& where,
80b289aaf6SAxel Dörfler									const media_format& withFormat,
81b289aaf6SAxel Dörfler									media_input* _input);
82b289aaf6SAxel Dörfler	virtual	void				Disconnected(const media_source& producer,
83b289aaf6SAxel Dörfler									const media_destination& where);
84b289aaf6SAxel Dörfler	virtual	status_t			FormatChanged(const media_source& producer,
85b289aaf6SAxel Dörfler									const media_destination& consumer,
86b289aaf6SAxel Dörfler									int32 changeTag,
87b289aaf6SAxel Dörfler									const media_format& format);
88b289aaf6SAxel Dörfler
89b289aaf6SAxel Dörfler	// BBufferProducer methods
90b289aaf6SAxel Dörfler	virtual	status_t 			FormatSuggestionRequested(media_type type,
91b289aaf6SAxel Dörfler									int32 quality, media_format* format);
92b289aaf6SAxel Dörfler	virtual	status_t 			FormatProposal(const media_source& output,
93b289aaf6SAxel Dörfler									media_format* format);
94b289aaf6SAxel Dörfler	virtual	status_t			FormatChangeRequested(
95b289aaf6SAxel Dörfler									const media_source& source,
96b289aaf6SAxel Dörfler									const media_destination &destination,
97b289aaf6SAxel Dörfler									media_format* format,
98b289aaf6SAxel Dörfler									int32* /*deprecated*/);
99b289aaf6SAxel Dörfler	virtual	status_t			GetNextOutput(int32* cookie,
100b289aaf6SAxel Dörfler									media_output* _output);
101b289aaf6SAxel Dörfler	virtual	status_t			DisposeOutputCookie(int32 cookie);
102b289aaf6SAxel Dörfler	virtual	status_t			SetBufferGroup(const media_source& source,
103b289aaf6SAxel Dörfler									BBufferGroup* group);
104b289aaf6SAxel Dörfler	virtual	status_t			GetLatency(bigtime_t* _latency);
105b289aaf6SAxel Dörfler	virtual	status_t			PrepareToConnect(const media_source& what,
106b289aaf6SAxel Dörfler									const media_destination& where,
107b289aaf6SAxel Dörfler									media_format* format, media_source* _source,
108b289aaf6SAxel Dörfler									char* _name);
109b289aaf6SAxel Dörfler	virtual	void				Connect(status_t error,
110b289aaf6SAxel Dörfler									const media_source& source,
111b289aaf6SAxel Dörfler									const media_destination& destination,
112b289aaf6SAxel Dörfler									const media_format& format, char *_name);
113b289aaf6SAxel Dörfler	virtual	void				Disconnect(const media_source& what,
114b289aaf6SAxel Dörfler									const media_destination& where);
115b289aaf6SAxel Dörfler	virtual	void				LateNoticeReceived(const media_source& what,
116b289aaf6SAxel Dörfler									bigtime_t howMuch,
117b289aaf6SAxel Dörfler									bigtime_t performanceTime);
118b289aaf6SAxel Dörfler	virtual	void				EnableOutput(const media_source& what,
119b289aaf6SAxel Dörfler									bool enabled, int32* /*_deprecated_*/);
120b289aaf6SAxel Dörfler	virtual	void				LatencyChanged(const media_source& source,
121b289aaf6SAxel Dörfler									const media_destination& destination,
122b289aaf6SAxel Dörfler									bigtime_t newLatency, uint32 flags);
123bf7ab50dSStephan Aßmus
124bf7ab50dSStephan Aßmus		// BMediaEventLooper methods
125b289aaf6SAxel Dörfler	virtual	void				HandleEvent(const media_timed_event* event,
126b289aaf6SAxel Dörfler									bigtime_t lateness,
127b289aaf6SAxel Dörfler									bool realTimeEvent = false);
12800cffa1cSbeveloper
129a9cf57cfSAxel Dörflerprivate:
130b289aaf6SAxel Dörfler			BMediaAddOn*		fAddOn;
131b289aaf6SAxel Dörfler			MixerCore*			fCore;
132b289aaf6SAxel Dörfler			BParameterWeb*		fWeb;
133b289aaf6SAxel Dörfler			BBufferGroup*		fBufferGroup;
134b289aaf6SAxel Dörfler			bigtime_t			fDownstreamLatency;
135b289aaf6SAxel Dörfler			bigtime_t			fInternalLatency;
136b289aaf6SAxel Dörfler			bool				fDisableStop;
137b289aaf6SAxel Dörfler			media_format		fDefaultFormat;
138b289aaf6SAxel Dörfler			bigtime_t			fLastLateNotification;
139ba5e652dSAdrien Destugues			bigtime_t			fLastLateness;
140bf7ab50dSStephan Aßmus};
141a9cf57cfSAxel Dörfler
142b289aaf6SAxel Dörfler
143b289aaf6SAxel Dörfler#endif	// AUDIO_MIXER_H
144