27
Windows 7: Building Great Audio Communications Applications Larry Osterman Principal SDE Microsoft Corporation PC13

Larry Osterman Principal SDE Microsoft Corporation PC13

Embed Size (px)

Citation preview

Page 1: Larry Osterman Principal SDE Microsoft Corporation PC13

Windows 7: Building Great Audio Communications Applications

Larry OstermanPrincipal SDEMicrosoft Corporation

PC13

Page 2: Larry Osterman Principal SDE Microsoft Corporation PC13

What’s new for audio in Windows 7 Vista audio overview Windows 7 feature details:

Device Roles Stream Switching Bluetooth Audio Ducking

Demo Q&A

Agenda

Page 3: Larry Osterman Principal SDE Microsoft Corporation PC13

Communications is clearly the wave of the future

New features focused on communications scenarios Multimedia IM VOIP LiveMeeting Etc.

Audio Changes for Windows 7

Page 4: Larry Osterman Principal SDE Microsoft Corporation PC13

Improved device role detection Bluetooth audio in-box Stream switching Improved audio latency Automatic attenuation of

audio samples (ducking) Other stuff

Audio Changes for Windows 7

Page 5: Larry Osterman Principal SDE Microsoft Corporation PC13

First significant architectural changes since Windows 98

Most of audio stack moved from kernel mode to user mode

Addition of per-application volume controls

Vista Audio Concepts

Page 6: Larry Osterman Principal SDE Microsoft Corporation PC13

Vista And Windows 7 Audio Architecture

WASAPI

Audio Driver

DeviceTopology Audio Client

Audio Engine

Endpoint VolumeMMDeviceAPI

Direct Sound

WINMM

WAVE APIMixer API

SWMIDIPlaySound Media Foundation

Policy Engine

Page 7: Larry Osterman Principal SDE Microsoft Corporation PC13

Audio Applications Reference “Endpoints”

Audio Endpoints

hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL,

CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);

IMMDevice *defaultDevice = NULL;hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender,

eConsole, &defaultDevice);

Endpoints support an “Activation” ModelIAudioSessionManager *endpointVolume = NULL;hr = defaultDevice->Activate(__uuidof(IAudioSessionManager),

CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&sessionManager);

Page 8: Larry Osterman Principal SDE Microsoft Corporation PC13

Volume control based on “audio sessions” An audio session is a collection of

audio streams Each session represents a slider in the

mixer application Each stream is a associated with a session One process may have more than one session One session may span multiple processes

Volume Control

Page 9: Larry Osterman Principal SDE Microsoft Corporation PC13

Improved device role detection Added eCommunications audio role Added OEM configurable heuristics to

improve role detection General jack location Geometric location Jack detection ability Jack subtype Etc.

Audio Changes for Windows 7

Page 10: Larry Osterman Principal SDE Microsoft Corporation PC13

Reduced latency for shared mode audio

Audio Changes for Windows 7

40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 940

100200300400500600700800

Vista latency (ms)

40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 940

100200300400500600700800900

Windows 7 latency (ms)

Page 11: Larry Osterman Principal SDE Microsoft Corporation PC13

Stream Switching May not require any code changes to

your application Depends on use of default eConsole or

eCommunications device Works for waveXxx, MediaFoundation,

DirectSound, DirectShow Does not work for WASAPI

WASAPI is a low level API

Audio Changes For Windows 7

Page 12: Larry Osterman Principal SDE Microsoft Corporation PC13

Bluetooth audio in-box Supports both Headset/Handsfree profile

and A2DP (high quality audio playback) Supports enhanced call control messages

Audio Changes For Windows 7

Page 13: Larry Osterman Principal SDE Microsoft Corporation PC13

Based on Windows low level HID APIs http://msdn.microsoft.com/en-us/library/ms78

9924.aspx New messages are in the Telephony HID

usage page Support the following usages

Dial Number Dial Memory Redial Ring Others

Call Control HID Messages

Page 14: Larry Osterman Principal SDE Microsoft Corporation PC13

Associating a HID device with an audio endpoint Retrieve the PKEY_Device_BaseContainerId from the

endpoint Using the base container ID look up the HID device

associated with that base container Open (CreateFile) the HID collection

for that device

Call Control HID messages

Page 15: Larry Osterman Principal SDE Microsoft Corporation PC13

Ducking

demo

Page 16: Larry Osterman Principal SDE Microsoft Corporation PC13

Depends on use of eCommunications role New streams opened on eCommunications role

duck non-communications streams Provides notification mechanism to enable

advanced behaviors for applications Supports opt-out for both users

and applications

Automatic Attenuation of Audio Samples

Page 17: Larry Osterman Principal SDE Microsoft Corporation PC13

Let’s talk about simple communications applications Simple Media Player “Voice Chat between two machines”

Let’s add support for ducking to these applications

Building a Communications Application

Page 18: Larry Osterman Principal SDE Microsoft Corporation PC13

Voice chat application Application uses the WAVE APIs to capture

audio samples from the microphone Need to change the application to use

the eCommunications role Wave APIs:

Use WAVE_MAPPER with WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE

DirectShow/DirectSound: Activate IDirectSound/IDirectSoundCapture/IBaseFilter from default device

MediaFoundation: Add the MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_AUDCAP_ROLE attribute to the graph specifying eCommunications

Building A Communications Application

Page 19: Larry Osterman Principal SDE Microsoft Corporation PC13

Next we’ll work on the media playerApplication uses DirectShow to render a file with a

progress slider. It also supports basic transport controls Let’s change the application so that it pauses

when a communications stream is startedRegister for ducking notifications with

IAudioSessionManager2::RegisterDuckNotification Implement the IAudioVolumeDuckNotification interface

Building A Communications Application

Page 20: Larry Osterman Principal SDE Microsoft Corporation PC13

Finally let’s add support to opt out of ducking Ducking is applied over a second or so,

so it can interfere with media playback Games are likely to want to opt out so that

game audio isn’t accidentally ducked when using in-game voice chat

Notifications and opt-out are independent Opt out is easy

Just call IAudioSessionControl2 :: SetDuckingPreference to opt out

Building a Communications Application

Page 21: Larry Osterman Principal SDE Microsoft Corporation PC13

Capture Monitor HDMI Audio Windows Media Player Device Selection Device Specific Audio HID controls Audio HID controls work

when not logged on Reduced power consumption of

DirectSound and DShow APIs Reduced power consumption of MMCSS

Other Windows 7 Audio Features

Page 22: Larry Osterman Principal SDE Microsoft Corporation PC13

All Developers Use the default console or

communication device Voice Chat developers

Use the default eCommunications device Add support for BT call controls

Media Player developers Listen for ducking notifications and pause audio

streams when ducking Other developers

Opt out of ducking if appropriate

Call To Action

Page 23: Larry Osterman Principal SDE Microsoft Corporation PC13

PDC Documentation PDC Documentation contains preliminary

documentation and whitepapers for all of the stuff I’ve presented in this talk

Larry Osterman’s Blog http://blogs.msdn.com/larryosterman

Other Resources

Page 24: Larry Osterman Principal SDE Microsoft Corporation PC13

questions?

Page 25: Larry Osterman Principal SDE Microsoft Corporation PC13

Evals & Recordings

Please fill

out your

evaluation for

this session at:

This session will be available as a recording at:

www.microsoftpdc.com

Page 26: Larry Osterman Principal SDE Microsoft Corporation PC13

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 27: Larry Osterman Principal SDE Microsoft Corporation PC13