vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / media-add-ons / opensound / OpenSoundDevice.h
blob7dc0898757f319924baee3beff972d883bf56925
1 /*
2 * Copyright (c) 2002-2007, Jerome Duval (jerome.duval@free.fr)
3 * Distributed under the terms of the MIT License.
4 */
6 #ifndef _OPENSOUNDDEVICE_H
7 #define _OPENSOUNDDEVICE_H
9 #include <OS.h>
10 #include <List.h>
11 #include <MediaFormats.h>
12 #include <Locker.h>
13 #include "soundcard.h"
16 //#define OSS_PREFIX "/dev/audio/oss/"
17 #define OSS_PREFIX "/dev/oss/"
18 // should be fixed later
19 #define OSS_MIXER_DEV "/dev/mixer"
21 #define MAX_CONTROLS 128
22 #define MAX_CHANNELS 32
23 #define NB_BUFFERS 32
25 #define DEFAULT_BUFFER_SIZE 2048
27 /* define to support encoded audio (AC3, MPEG, ...) when the card supports it */
28 //#define ENABLE_NON_RAW_SUPPORT 1
29 //XXX: make it a BParameter ?
31 #define ENABLE_REC 1
33 // timeout in OpenSoundNode::RunThread()
34 #define MIN_SNOOZING 2000
36 // pretend we don't drift
37 #define DISABLE_DRIFT 1
40 /* bit mask of supported formats for raw_audio */
41 /* also used to mark the raw_audio node input&outputs */
42 //XXX: _OE ?
43 #define AFMT_SUPPORTED_PCM (AFMT_U8|AFMT_S8|\
44 AFMT_S16_NE|\
45 AFMT_S24_NE|AFMT_S32_NE|\
46 AFMT_S16_OE|\
47 AFMT_S24_OE|AFMT_S32_OE|\
48 AFMT_FLOAT)
51 extern const int gSupportedFormats[];
52 extern const char *gSupportedFormatsNames[];
54 class OpenSoundDeviceEngine;
55 class OpenSoundDeviceMixer;
58 class OpenSoundDevice
60 public:
61 explicit OpenSoundDevice(oss_card_info *cardinfo);
62 virtual ~OpenSoundDevice(void);
64 status_t InitDriver();
65 virtual status_t InitCheck(void) const;
67 status_t AddEngine(oss_audioinfo *info);
68 status_t AddMixer(oss_mixerinfo *info);
69 // status_t AddMidi();
71 int32 CountEngines();
72 int32 CountMixers();
73 OpenSoundDeviceEngine *EngineAt(int32 i);
74 OpenSoundDeviceMixer *MixerAt(int32 i);
76 OpenSoundDeviceEngine *NextFreeEngineAt(int32 i, bool rec=false);
78 BLocker *Locker() { return &fLocker; };
80 static float convert_oss_rate_to_media_rate(int rate);
81 static int convert_media_rate_to_oss_rate(float rate);
82 static uint32 convert_oss_format_to_media_format(int fmt);
83 static int convert_oss_format_to_endian(int fmt);
84 static int16 convert_oss_format_to_valid_bits(int fmt);
85 static int convert_media_format_to_oss_format(uint32 fmt);
86 static int select_oss_rate(const oss_audioinfo *info, int rate);
87 static int select_oss_format(int fmt);
89 static status_t get_media_format_description_for(int fmt, media_format_description *desc, int count=1);
90 static status_t register_media_formats();
91 static status_t get_media_format_for(int fmt, media_format &format);
93 public:
94 oss_card_info fCardInfo;
96 private:
97 status_t fInitCheckStatus;
98 BList fEngines;
99 BList fMixers;
100 friend class OpenSoundNode; // ugly
101 friend class OpenSoundDeviceEngine; // ugly
102 audio_buf_info fFragments;
103 BLocker fLocker;
106 #endif