Changeset 189


Ignore:
Timestamp:
Jun 29, 2013, 11:27:09 PM (10 years ago)
Author:
roman
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Utilities/Miscellaneous/AudioSessionVolumeNotification/AudioSessionVolumeNotification.cpp

    r165 r189  
    1111#define __C ATLENSURE_SUCCEEDED
    1212
    13 //class CNotification :
    14 //      public IAudioSessionEvents
    15 //{
    16 //private:
    17 //      INT m_nSessionIndex;
    18 //
    19 //public:
    20 //// CNotification
    21 //      CNotification(INT nSessionIndex) :
    22 //              m_nSessionIndex(nSessionIndex)
    23 //      {
    24 //      }
    25 //
    26 //// IUnknown
    27 //      STDMETHOD(QueryInterface)(REFIID, VOID** ppvObject)
    28 //      {
    29 //              _tprintf(_T("m_nSessionIndex %d, QueryInterface\n"));
    30 //              return E_NOINTERFACE;
    31 //      }
    32 //    STDMETHOD_(ULONG, AddRef)()
    33 //      {
    34 //              return 2;
    35 //      }
    36 //    STDMETHOD_(ULONG, Release)()
    37 //      {
    38 //              return 1;
    39 //      }
    40 //
    41 //// IAudioSessionEvents
    42 //    STDMETHOD(OnDisplayNameChanged)(LPCWSTR NewDisplayName, LPCGUID EventContext)
    43 //      {
    44 //              return S_OK;
    45 //      }
    46 //    STDMETHOD(OnIconPathChanged)(LPCWSTR NewIconPath, LPCGUID EventContext)
    47 //      {
    48 //              return S_OK;
    49 //      }
    50 //    STDMETHOD(OnSimpleVolumeChanged)(float NewVolume, BOOL NewMute, LPCGUID EventContext)
    51 //      {
    52 //              _tprintf(_T("m_nSessionIndex %d, NewVolume %.2f, NewMute %d\n"), m_nSessionIndex, NewVolume, NewMute);
    53 //              return S_OK;
    54 //      }
    55 //    STDMETHOD(OnChannelVolumeChanged)(DWORD ChannelCount, float NewChannelVolumeArray[], DWORD ChangedChannel, LPCGUID EventContext)
    56 //      {
    57 //              _tprintf(_T("m_nSessionIndex %d, ChannelCount %d, NewChannelVolumeArray][ { %.2f, ... }, ChangedChannel %d\n"), m_nSessionIndex, ChannelCount, NewChannelVolumeArray[0], ChangedChannel);
    58 //              return S_OK;
    59 //      }
    60 //    STDMETHOD(OnGroupingParamChanged)(LPCGUID NewGroupingParam, LPCGUID EventContext)
    61 //      {
    62 //              return S_OK;
    63 //      }
    64 //    STDMETHOD(OnStateChanged)(AudioSessionState NewState)
    65 //      {
    66 //              return S_OK;
    67 //      }
    68 //    STDMETHOD(OnSessionDisconnected)(AudioSessionDisconnectReason DisconnectReason)
    69 //      {
    70 //              return S_OK;
    71 //      }
    72 //};
     13class CNotification :
     14        public IAudioSessionEvents
     15{
     16private:
     17        INT m_nSessionIndex;
     18
     19public:
     20// CNotification
     21        CNotification(INT nSessionIndex) :
     22                m_nSessionIndex(nSessionIndex)
     23        {
     24        }
     25
     26// IUnknown
     27        STDMETHOD(QueryInterface)(REFIID, VOID** ppvObject)
     28        {
     29                _tprintf(_T("m_nSessionIndex %d, QueryInterface\n"));
     30                return E_NOINTERFACE;
     31        }
     32    STDMETHOD_(ULONG, AddRef)()
     33        {
     34                return 2;
     35        }
     36    STDMETHOD_(ULONG, Release)()
     37        {
     38                return 1;
     39        }
     40
     41// IAudioSessionEvents
     42    STDMETHOD(OnDisplayNameChanged)(LPCWSTR NewDisplayName, LPCGUID EventContext)
     43        {
     44                return S_OK;
     45        }
     46    STDMETHOD(OnIconPathChanged)(LPCWSTR NewIconPath, LPCGUID EventContext)
     47        {
     48                return S_OK;
     49        }
     50    STDMETHOD(OnSimpleVolumeChanged)(float NewVolume, BOOL NewMute, LPCGUID EventContext)
     51        {
     52                _tprintf(_T("m_nSessionIndex %d, NewVolume %.2f, NewMute %d\n"), m_nSessionIndex, NewVolume, NewMute);
     53                return S_OK;
     54        }
     55    STDMETHOD(OnChannelVolumeChanged)(DWORD ChannelCount, float NewChannelVolumeArray[], DWORD ChangedChannel, LPCGUID EventContext)
     56        {
     57                _tprintf(_T("m_nSessionIndex %d, ChannelCount %d, NewChannelVolumeArray][ { %.2f, ... }, ChangedChannel %d\n"), m_nSessionIndex, ChannelCount, NewChannelVolumeArray[0], ChangedChannel);
     58                return S_OK;
     59        }
     60    STDMETHOD(OnGroupingParamChanged)(LPCGUID NewGroupingParam, LPCGUID EventContext)
     61        {
     62                return S_OK;
     63        }
     64    STDMETHOD(OnStateChanged)(AudioSessionState NewState)
     65        {
     66                return S_OK;
     67        }
     68    STDMETHOD(OnSessionDisconnected)(AudioSessionDisconnectReason DisconnectReason)
     69        {
     70                return S_OK;
     71        }
     72};
    7373
    7474int _tmain(int argc, _TCHAR* argv[])
     
    8686        __C(pAudioSessionEnumerator->GetCount(&nSessionCount));
    8787        _tprintf(_T("nSessionCount %d\n"), nSessionCount);
    88         //for(INT nSessionIndex = 0; nSessionIndex < nSessionCount; nSessionIndex++)
    89         //{
    90         //      CComPtr<IAudioSessionControl> pSessionControl;
    91         //      if(FAILED(pAudioSessionEnumerator->GetSession(nSessionIndex, &pSessionControl)))
    92         //              continue;
    93         //      CComHeapPtr<WCHAR> pszDisplayName;
    94         //      __C(pSessionControl->GetDisplayName(&pszDisplayName));
    95         //      _tprintf(_T("nSessionIndex %d, pszDisplayName \"%s\"\n"), nSessionIndex, CString(pszDisplayName));
    96         //      CNotification* pNotification = new CNotification(nSessionIndex);
    97         //      __C(pSessionControl->RegisterAudioSessionNotification(pNotification));
    98         //}
     88        for(INT nSessionIndex = 0; nSessionIndex < nSessionCount; nSessionIndex++)
     89        {
     90                CComPtr<IAudioSessionControl> pSessionControl;
     91                if(FAILED(pAudioSessionEnumerator->GetSession(nSessionIndex, &pSessionControl)))
     92                        continue;
     93                CComHeapPtr<WCHAR> pszDisplayName;
     94                __C(pSessionControl->GetDisplayName(&pszDisplayName));
     95                _tprintf(_T("nSessionIndex %d, pszDisplayName \"%s\"\n"), nSessionIndex, CString(pszDisplayName));
     96                CNotification* pNotification = new CNotification(nSessionIndex);
     97                __C(pSessionControl->RegisterAudioSessionNotification(pNotification));
     98        }
    9999        for(; ; )
    100100        {
     
    105105                                continue;
    106106                        CComQIPtr<IAudioMeterInformation> pMeterInformation = pSessionControl;
     107                        DWORD nMask;
     108                        __C(pMeterInformation->QueryHardwareSupport(&nMask));
    107109                        FLOAT fPeakValue;
    108110                        __C(pMeterInformation->GetPeakValue(&fPeakValue));
    109                         _tprintf(_T("nSessionIndex %d, fPeakValue %.2f\n"), nSessionIndex, fPeakValue);
     111                        _tprintf(_T("nSessionIndex %d, fPeakValue %.2f, nMask 0x%x\n"), nSessionIndex, fPeakValue, nMask);
    110112                }
    111113                Sleep(1000);
Note: See TracChangeset for help on using the changeset viewer.