In some applications that use the sound card for audio collection, there is usually the following functional requirements: When the program is started, the automatic sound card is automatically selected to select a particular input terminal, such as some universal acquisition, hope will "Line in" "As the default input; and some video conferencing software, I hope" microphone "is used as the default input. Unfortunately, DirectShow does not directly support such functions.
Everyone knows that the sound card is in the DirectShow in the form of Filter, which is usually called Audio Capture Filter. Each input of the FILTER represents an input terminal of the sound card, the name of the PIN is the name of the input terminal. For different sound cards, the number and type of the input terminal may be different. Take the Avance AC97 Audio and Soundmax Digital Audio two sound cards as an example, their input PIN is (Note: listed in the "index: PIN name"):
0: mono Mix 1: Stereo Mix 2: AUX 3: TV Tuner Audio 4: CD Player 5: Line in 6: Microphone 7: Phone Line0: CD Player 1: Micro-Phone 2: Line-in 3: Mono Out 4: Wave out Mix
In DirectShow, all input PINs of the Audio Capture Filter can be enumerated by an index, but the index cannot identify the specific input terminal type of the PIN represented, and the index of different sound cards does not have general meaning. How to choose a specific type of input terminal for an unknown sound card, how can an application choose a specific type of input terminal in a unified way? There is a stupid approach, that is, guess - guess the name of the PIN as much as possible! Take "Line IN" as the default input as an example:
// Demo code 1 // We set "line in" as default, by checking the pin nameif (Pinname.com) == 0 || Pinname.comParenocase ("line-in") == 0 | | Pinname.comparenocase ("line_in") == 0 || Pinname.comParenocase ("linein") == 0 || Pinname.comParenocase ("line") == 0) {Found = true;}
The code is a bit ugly, but if there is no better way, it is not a solution. (Note: "DirectShow Practice Collection Chapter 2 of Chapter 2 is this method.) Is there a better way? Have! Then, depending on the WINDOWS MULTIMEDIA API function. Pick up the input PIN on AUDIO CAPTURE Filter to pick one of the names. The function getConnectionName for querying the name of the name of a particular input terminal using the Windows MultiMedia API function is implemented as follows:
// demo code 2 // Some frequently-used line type: // line in -> MIXERLINE_COMPONENTTYPE_SRC_LINE // microphone -> MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE // CD Player -> MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISCBOOL GetConnectionName (DWORD inLineType, CString & outName) {UINT cMixers = mixerGetNumDevs (); IF ("NO Mixer Device Present."); Return False;} // Open a Mixer and Dermine ITS Capabilities. HMixer HMixer; IF (Mixeropen (& Hmixer, 0, 0, 0, 0)! = Mmsyserr_noerror) {trace ("Could Not Open Mixer Device."); Return False;
MixerCaps Caps; IF (MixergetDevcaps ((UINT) HMixer, & Caps, SizeOf (MixerCaps))! = Mmsyserr_noError) {MixerClose (HMixer); Return False;
Trace ("Name of Device:% S / N", Caps.szpname;
MixerLine line; infrest = false; int cdest = caps.cdestination; for (int i = 0; i // For recording control if (line.dwComponentType == MIXERLINE_COMPONENTTYPE_DST_WAVEIN) {// Enumerate all source connections for this destination line UINT cConnections = line.cConnections; for (UINT j = 0; j // Compare with the user-specified line type if (line.dwComponentType == inLineType) {// Retrieve the connection name outName = line.szName; found = TRUE; break;}}}} mixerClose (hMixer); return found; } So, the demo code 1 can be modified as follows: / / Demo code 3cstring defaultConnection; getConnectionName (MixerLine_componenttype_src_line, defaultconnection); if (Pinname == DefaultConnection) {Found = true; Obviously, the second solution is superior to the first solution. But good solutions are not as good as Microsoft update DirectShow SDK, enabling an interface (such as Iamaudioconnection) on each input PIN on AUDIO CAPTURE FILTER; via the Iamaudioconnection interface, developers can easily identify the input of the PIN representative Terminal types (like Windows MultiMedia, with a integer value to mark different input terminal types).