00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __AlsaSoundCard_h
00030 #define __AlsaSoundCard_h
00031
00032 #if HAVE_CONFIG_H
00033 #include "config.h"
00034 #endif
00035
00036 #include "AlsaInterface.hpp"
00037 #include "AlsaSoundCardInterface.hpp"
00038 #include "AlsaMixer.hpp"
00039 #include <string>
00040 #include <map>
00041 #include <boost/shared_ptr.hpp>
00042 #include <alsa/asoundlib.h>
00043
00045
00047
00048 namespace Gizmod {
00049
00051
00053
00058 class AlsaSoundCard : public AlsaSoundCardInterface {
00059 public:
00060
00061
00062
00063 std::string getCardHardwareID() const;
00064 int getCardID() const;
00065 std::string getCardName() const;
00066 std::string getCardNameLong() const;
00067 AlsaMixer const * getMixer(std::string Name);
00068 size_t getNumMixers();
00069 void setAllPlaybackSwitches(bool Enabled);
00070 void shutdown();
00071
00072
00073 AlsaSoundCard(AlsaInterface * piAlsa, int CardID);
00074 virtual ~AlsaSoundCard();
00075
00076
00077 static int MixerCallback(snd_mixer_t * Mixer, unsigned int EventMask, snd_mixer_elem_t * MixerElement);
00078
00079 private:
00080
00081 void init();
00082 int mixerCallback(snd_mixer_t * Mixer, unsigned int EventMask, snd_mixer_elem_t * MixerElement);
00083 void threadProc();
00084
00085
00086 int mCardID;
00087 std::string mCardHWID;
00088 std::string mCardName;
00089 std::string mCardNameLong;
00090 snd_ctl_t * mCTLHandle;
00091 snd_ctl_card_info_t * mHWInfo;
00092 snd_mixer_t * mMixerHandle;
00093 std::map< std::string, boost::shared_ptr<AlsaMixer> > mMixers;
00094 bool mShutdown;
00095 bool mWatching;
00096
00100 struct AlsaSoundCardThreadProc {
00101 AlsaSoundCardThreadProc(AlsaSoundCard * pAlsaSoundCard) : mpAlsaSoundCard(pAlsaSoundCard) {
00102 mpAlsaSoundCard->mThreading = false;
00103 };
00104
00106 void operator()() {
00107 mpAlsaSoundCard->mThreading = true;
00108 mpAlsaSoundCard->threadProc();
00109 mpAlsaSoundCard->mThreading = false;
00110 }
00111
00112 AlsaSoundCard * mpAlsaSoundCard;
00113 };
00114 bool mThreading;
00115 AlsaSoundCardThreadProc mThreadProc;
00116
00117 private:
00118
00119 friend class boost::serialization::access;
00120 template<class Archive>
00121 void serialize(Archive & ar, const unsigned int version) {
00122 ar & mCardID;
00123 ar & mCardHWID;
00124 ar & mCardName;
00125 ar & mCardNameLong;
00126 }
00127 };
00128
00130
00131 }
00132
00133 #endif // __AlsaSoundCard_h