xref: /haiku/src/add-ons/media/media-add-ons/opensound/OpenSoundDeviceEngine.h (revision d3ebd7843a3213faec345614eb49802fef872436)
1 /*
2  * OpenSound media addon for BeOS and Haiku
3  *
4  * Copyright (c) 2007, François Revol (revol@free.fr)
5  * Distributed under the terms of the MIT License.
6  */
7 
8 #ifndef _OPENSOUNDDEVICEENGINE_H
9 #define _OPENSOUNDDEVICEENGINE_H
10 
11 #include "OpenSoundDevice.h"
12 
13 class OpenSoundDeviceEngine
14 {
15 	public:
16 		OpenSoundDeviceEngine(oss_audioinfo *info);
17 		virtual ~OpenSoundDeviceEngine(void);
18 
19 		virtual status_t InitCheck(void) const;
FD()20 		int			FD() const { return fFD; };
Info()21 		const oss_audioinfo *Info() const { return &fAudioInfo; };
22 
23 		status_t	Open(int mode/* OPEN_* */);
24 		status_t	Close();
25 
26 		//BDadaIO...
27 virtual	ssize_t		Read(void *buffer, size_t size);
28 virtual	ssize_t		Write(const void *buffer, size_t size);
29 
30 
31 		/* chain of engines for the same physical in/out */
NextPlay()32 		OpenSoundDeviceEngine *NextPlay() const { return fNextPlay; };
NextRec()33 		OpenSoundDeviceEngine *NextRec() const { return fNextRec; };
34 
OpenMode()35 		int			OpenMode() const { return fOpenMode; };
InUse()36 		bool		InUse() const { return (fOpenMode != 0); };
37 
38 		status_t	UpdateInfo();
39 		// shortcuts
Caps()40 		int			Caps() const { return fAudioInfo.caps; };
CardLatency(void)41 		bigtime_t	CardLatency(void) const { return (fAudioInfo.latency < 0) ? 0 : fAudioInfo.latency; };
42 		bigtime_t	PlaybackLatency(void);
43 		bigtime_t	RecordingLatency(void);
44 
45 
46 		int			GetChannels(void);
47 		status_t	SetChannels(int chans);
48 
49 		int			GetFormat(void);
50 		status_t	SetFormat(int fmt);
51 
52 		int			GetSpeed(void);
53 		status_t	SetSpeed(int speed);
54 
55 		void		GetMediaFormat(media_format &format);
56 
57 		size_t		GetISpace(audio_buf_info *info=NULL);
58 		size_t		GetOSpace(audio_buf_info *info=NULL);
59 
60 		int64		GetCurrentIPtr(int32* fifoed = NULL,
61 						oss_count_t* info = NULL);
62 		int64		GetCurrentOPtr(int32* fifoed = NULL,
63 						size_t* fragmentPos = NULL);
64 
65 		int32		GetIOverruns();
66 		int32		GetOUnderruns();
67 
68 		size_t		DriverBufferSize() const;
69 
70 		status_t	StartRecording(void);
71 
72 		// suggest possibles
73 		status_t	WildcardFormatFor(int fmt, media_format &format, bool rec=false);
74 		// suggest best
75 		status_t	PreferredFormatFor(int fmt, media_format &format, bool rec=false);
76 		// try this format
77 		status_t	AcceptFormatFor(int fmt, media_format &format, bool rec=false);
78 		// apply this format
79 		status_t	SpecializeFormatFor(int fmt, media_format &format, bool rec=true);
80 
81 	private:
82 		status_t 				fInitCheckStatus;
83 		oss_audioinfo			fAudioInfo;
84 friend class OpenSoundAddOn;
85 		OpenSoundDeviceEngine	*fNextPlay;
86 		OpenSoundDeviceEngine	*fNextRec;
87 		int						fOpenMode; // OPEN_*
88 		int						fFD;
89 		media_format			fMediaFormat;
90 		int64					fPlayedFramesCount;
91 		bigtime_t				fPlayedRealTime;
92 		size_t					fDriverBufferSize;
93 };
94 
95 #endif
96