[coscup 2013] audio competing

49
Web Developer or OS Developer? Experience from FirefoxOS Alive COSCUP 2013

Upload: alive-kuo

Post on 13-Jul-2015

225 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: [COSCUP 2013] Audio Competing

Web Developer or OS Developer?

Experience from FirefoxOS

Alive COSCUP 2013

Page 2: [COSCUP 2013] Audio Competing

me @alivedise http://alivedise.github.io http://github.com/alivedise [email protected] [email protected] ~2.5year Frontend Exp.

聽說COSCUP一定要放貓

Page 3: [COSCUP 2013] Audio Competing

Operating System

?

http://www.flickr.com/photos/klaikong/6041270516/

Page 4: [COSCUP 2013] Audio Competing

Operating System

Page 5: [COSCUP 2013] Audio Competing

FirefoxOS….OS?

Storage Management

fileSystem(yet)

DeviceStorageWatcher

Memory Management

Page Visibility

mozAppType

User Interface

Multi Window Management

Statusbar

System Overlay

App Overlay

Web Activity

Keyboard

Hardware Resource

Management

Wi-Fi

Radio

GPS

Bluetooth

Power

CPU WakeLock

Audio/Media

Multi-Tasking

mozBrowser remote=true

Card view

Page 6: [COSCUP 2013] Audio Competing

• Multi Channel • Audio Competing • Background Play

Audio Management

Page 7: [COSCUP 2013] Audio Competing

The beginning of everything..

http://bugzil.la/805333

Page 8: [COSCUP 2013] Audio Competing

805333

Page 9: [COSCUP 2013] Audio Competing

Why do we need multi- channel on OS?

Page 10: [COSCUP 2013] Audio Competing

Sounds within FxOS - <audio/>

Page 11: [COSCUP 2013] Audio Competing

Sounds within FxOS - radio

Page 12: [COSCUP 2013] Audio Competing

Sounds within FxOS - alarm

Page 13: [COSCUP 2013] Audio Competing

Sounds within FxOS - voice

Page 14: [COSCUP 2013] Audio Competing

The world of single channel..

Peace

Page 15: [COSCUP 2013] Audio Competing

But..

Too peaceful.

Page 16: [COSCUP 2013] Audio Competing

This means:

When you mute the device, your alarm also is muted. So..

Page 17: [COSCUP 2013] Audio Competing

Overslept ♪♪♪~

Zzzzz..

Page 18: [COSCUP 2013] Audio Competing

How does OS avoid that?

Different settings for audios on different purposes.

Page 19: [COSCUP 2013] Audio Competing

On the other hand..

Competing

Page 20: [COSCUP 2013] Audio Competing

On Desktop browser, we don’t need competing.

Page 21: [COSCUP 2013] Audio Competing

How about mobile OS?

Page 22: [COSCUP 2013] Audio Competing

Cases • one <audio/> in one app. • two <audio/> in one app. • two <audio/> in two apps. • one <audio/> and one not-audio-sound in two apps.

Page 23: [COSCUP 2013] Audio Competing

It’s all about UX.

User wants to listen music in background.. User has difficulty to mute the background app.. User needs the alarm to sound anyway..

Page 24: [COSCUP 2013] Audio Competing

Android solution: audio focus • http://developer.android.com/training/managing-audio/audio-focus.html

• App is responsible to request the audio focus on demand and release the focus actively.

Page 25: [COSCUP 2013] Audio Competing

Problems • How to request audio focus in web? • Volume control of different type of audio source. • Telephony is not using audio tag. • FM is not using audio tag. • …

Page 26: [COSCUP 2013] Audio Competing

Proposal • New attribute for media tags. • Background play and competing needs permission check.

• Expose current occupied media info to system.

Page 27: [COSCUP 2013] Audio Competing

Page Visibility • HTML5 Page Visibility • The page visibility state is simple on desktop browsers by toggling tabs.

• A little complicated on FirefoxOS • Window(App) has opening/closing transitions. • Screen off means page visibility is hidden, too. • Background page has higher possibility to be killed. (Memory Management!)

Page 28: [COSCUP 2013] Audio Competing

mozAudioChannelType

telephony alarm

notification content

normal(default)

Page 29: [COSCUP 2013] Audio Competing

Multi channel volume settings

• ringer, desktop-notification

audio.volume.notification

• music, FMRadio

audio.volume.content

• alarm

audio.volume.alarm

• telephony

audio.volume.voice

• Bluetooth SCO

audio.volume.bt_sco

Page 30: [COSCUP 2013] Audio Competing

Usage

OR

manifest.webapp

app.html

app.js

Page 31: [COSCUP 2013] Audio Competing

Interrupted Event

Page 32: [COSCUP 2013] Audio Competing

Current Competing Policies •  Channel with higher priority interrupts the

lower channel. •  Foreground page is always playable. But

interruption occurs or not depends on the channel of the media element.

•  When screen is off, the current app or page is not brought to background now if it’s playing normal channel audio now. (Memory and Power concern!)

•  Audio elements being interrupted could know by ‘mozinterruptbegin’ and ‘mozinterruptend’.

content� normal�

Page 33: [COSCUP 2013] Audio Competing

Gecko sidemozAudioChannelType

audio

App

nsIDOMHTMLAudioElement

nsIDOMHTMLMediaElement

nsHTMLMediaElement

nsIAudioChannelAgentCallback

nsIAudioChannelAgent

nsBuiltinDecoder

nsMediaOmxDecoder

nsMediaDecoder

DataSource

MediaStreamSource

MediaResource

- SetReadMode()

create

IOMX

OMX

MediaExtractorOMXCodec

MediaSource - Tell()- Seek()- Read()- GetLength()

hw codec

sw codec

MediaBuffer

- CanPlayChanged()

- "mozinterruptbegin" event- "mozinterruptend" event

OmxDecoder

nsHTMLAudioElement

nsIChannel

create

nsMediaOmxReader

nsBuiltinDecoderReader

create

create

MediaOmxStateMachine

nsBuiltinDecoderStateMachine

nsDecoderStateMachine

create

nsIThreadnsIThread

control

create

nsDocument

- NotifyOwnerDocumentActivityChanged()

FileMediaResource

ChannelMediaResource

nsAudioStream

nsNativeAudioStream

libsydneyaudio

AudioTrack

AudioFlinger

- Write()- Pause()- Resume()- IsPaused()- Drain()- GetMinWriteSize()- GetPosition()- SetVolume()

platform: Firefox OS(gonk)branch: Firefox OS 1.01 (b2g18)

will be replaced to libcubeb in v1.2

Audio Streams Diagram

https://github.com/sotaroikeda/firefox-diagrams

Page 34: [COSCUP 2013] Audio Competing

Since API is implemented..

World peace?

Page 35: [COSCUP 2013] Audio Competing

No…

Don’t forget the dependency tree.

Page 36: [COSCUP 2013] Audio Competing

Incoming Issues • Silent mode under multi channels • Background play ability of existing web pages • Background play and competing for video • Short playing sound is hard to adjust. • DTMF tones • Power consumptions. • Bluetooth earphone has its own profile. • …

Page 37: [COSCUP 2013] Audio Competing

Policy for Silent mode • Easy for single channel • Multi channels

• The default channel for volume rockers is ‘notification’. (Same as Android)

• Silent mode interesting channels • notification • content/normal

• Alarm is not affected by silent mode.

Page 38: [COSCUP 2013] Audio Competing

Policy for video element • <video> doesn’t need to play at background.

• Currently, use ‘visibilitychange’ event. • <video> by default shall be able to compete the background playing content channel. • Separate background play and audio competing for video element.

Page 39: [COSCUP 2013] Audio Competing

Background play issues • Existing web pages: “Hey, I’m a music site!”

• grooveshark • youtube • …

• How to play when screen is off without adding mozAudioChannelType to each web site? • Depart screen off state from invisible page visibility state.

Page 40: [COSCUP 2013] Audio Competing

CE Certification • EN 50332-1 • Output level through earphone

should be under 85 dBA. • Prompt a warning when earphone is

plugged and the volume is greater than 85 dBA.

• The cool down time of CE warning popup is continuous 20 hours music listening.

Page 41: [COSCUP 2013] Audio Competing

OS level policy for CE • Only apply to content/normal channel. • Output power is hardware-dependent. Exactly, we don’t know the db value for specific devices. • The CE maximum value is customizable for different OEM via default settings.

Page 42: [COSCUP 2013] Audio Competing

After all..

Page 43: [COSCUP 2013] Audio Competing

UX logic in backend and frontend���

backend

frontend

Page 44: [COSCUP 2013] Audio Competing

Find out solutions for existing web sites without new API.���

• As a platform, it’s difficult to make decisions. • New API takes time to be mature.

Page 45: [COSCUP 2013] Audio Competing

The scope is undefined before you look into it. ���

Page 46: [COSCUP 2013] Audio Competing

To be honest, I wrote few code in these issues. But lots of online/offline discussions.

Page 47: [COSCUP 2013] Audio Competing

The position of Frontend

https://speakerdeck.com/josephj/f2e-the-keystone

Page 48: [COSCUP 2013] Audio Competing

• It doesn’t matter you are making a web site, a web app or an operating system.

• Frontend is the one connecting UX and Backend, and struggle for ideal design and real requirement.

Page 49: [COSCUP 2013] Audio Competing

Thanks! Not the end, to be continued..