Multi-Device Timing CG
TPAC 2015
Breakout session

W3C

Multi-Device
Timing CG
TPAC 2015
Breakout session

28 October 2015

François Daoust
fd@w3.org
@tidoust

TPAC 2015 logo with fancy background.

Multi-Device Timing CG

Goal is to define a common, multi-device, timing mechanism and a practical programming model for time-sensitive, multi-device Web applications.

  1. Created in February 2015 following discussions in Web and TV IG
  2. Chaired by Ingar M. Arntzen, Motion Corporation
  3. 28 participants (wanna join?)
  4. Develops the Timing Object specification
  5. Home page: https://www.w3.org/Community/webtiming

Table of Contents

  1. Some use cases
  2. How to sync content across devices
  3. The Timing Object specification
  4. Is it doable?
  5. Next steps

Part 1
Some
use cases

Media use cases

Other use cases

Orders of magnitude for sync (*)

> 100 ms
"Non-visual" or not closely related content
signing use cases should not require more precise sync
< 25 ms
Frame accuracy
"Lip sync", video on one device while audio plays on another device
< 10 ms
Echoless audio sync.
Needed for multiple devices to play audio or music together
Most likely the maximum accuracy that we may achieve in browsers
< 1 μs
GPS

(*) sync ≠ instantaneous propagation,
network latency still exists!

Part 2
Cross-device
sync

Clock synchronization

A Web app must be able to instruct the user agent to follow an external (*) clock.

(*) from a server, local peer or perhaps media transport stream

Clock synchronization

To synchronize its clock with that of a server, the client sends a request to the server that returns server timestamps. It then computes the current clock skew, and repeats that process once in a while

Clock synchronization

... can be achieved in JS (*)

(*) although native support would be better
(and required for UDP-based protocols)

Shared timeline

An app must be able to distribute the timeline (*):

    At 15:53:29.813 according to the sync clock,
        the position is 5.3s
            and the playback rate is 1.0

(*) and updates to that timeline, taking into account that
user agents can compute the position on their own:
pos(t) = pos0 + playback_rate * (t - t0)

Shared timeline

... can be achieved in JS (*)

(*) typically via a WebSocket connection

Synchronized media playback

The HTML5 spec on media elements

A media resource has a media timeline that maps times (in seconds) to positions in the media resource [...]. The media timeline also has an associated clock. Which clock is used is user-agent defined, [...] but it should approximate the user's wall clock.

Need a way to tell the user agent to use our timeline, and in particular to follow our clock!

Synchronized media playback

... can be somewhat achieved in JS (*)

(*) through skips and continuous adjustments to playbackrate
but support depends on the user agent, codec and platform
and this is more a hack than anything else, right?

In short

Clock synchronization
Can be done in JS, restricted to protocols exposed to web apps
(but no UDP-based protocols, no access to internal media clock)
Shared timeline
Can be done in JS
Sync media playback
Harder to do in JS
playbackrate was not designed for that
Depends on the previous two bits
(cannot be standardised in isolation)

Cool demos?
Sure, go to http://kwz.me/MW
and wait for controller...

Demos courtesy of Norut / Motion Corporation

Part 3
Timing
Object spec

Timing as a Web resource

Timing State Vector

      interface TimingStateVector {
        readonly attribute double position;
        readonly attribute double velocity;
        readonly attribute double acceleration;
        readonly attribute double timestamp;
      };
    

pos(t) = pos0 + velocity * (t - t0) + 1/2 * acceleration * (t - t0)2

Timing provider

Leave the door open to different clock synchronization mechanisms (*)

(*) Provider provides JS library to create TimingProvider objects.

Timing provider

      callback interface TimingProvider {
        readonly attribute TimingStateVector   vector;
        readonly attribute unrestricted double startPosition;
        readonly attribute unrestricted double endPosition;
        readonly attribute DOMString           readyState;
        readonly attribute unrestricted double skew;
        Promise update(TimingStateVectorUpdate newVector);
      };
    

Timing Object

      interface TimingObject : EventTarget {
        readonly attribute TimingProvider timingProviderSource;
        readonly attribute TimingObjectState readyState;
        readonly attribute unrestricted double startPosition;
        readonly attribute unrestricted double endPosition;
                 [attribute EventHandler ...]
        TimingStateVector query();
        Promise update(TimingStateVectorUpdate newVector);
      };
    

Media element extension

      partial interface HTMLMediaElement {
        attribute TimingObject timingsrc;
      };
    

When set, the media element would follow the media timeline of the TimingObject (*) and its associated clock.

(*) real master, no automatic pausing for buffering

Code example

      var provider = [provider specific];
      var timing = new TimingObject(provider);
      var video = document.getElementById('vid');
      video.timingsrc = timing;
      timing.update({ position: 5.0, velocity: 1.0 });
       
      var vec = timing.query();
      console.log("pos:" + vec.position + " vel:" + vec.velocity);
    

Timed data

Timed data

      interface TimingTextTrack : TextTrack {
        attribute TimingObject timingsrc;
      };
    

Same as TextTrack but no dependency on MediaElement.

Example at: http://webtiming.github.io/sequencer/

Added benefits

  • Exposes timing as a first class citizen on the Web
  • Supports single-device cases (could replace MediaController?) (*)
  • Leaves the door open to different clock synchronization mechanisms
  • Not restricted to media
  • Not restricted to read-only scenarios, clients may update timeline
  • Can be implemented incrementally
  • Alignment with Web Audio, Web Animations seems doable

(*) which may soon be deprecated

Part 4
Is it
doable?

Spec-wise

... It's complicated

  • Not sure how to spec the "observer" mechanism
  • Security issues with third-party code (*)
  • Requires updating most of media algorithms in HTML5 :( (**)

(*) WebRTC-identity-provider-like solution?
(**) although changes are not that huge in practice

Implementation-wise

... It's complicated

  • Media renderer is a complicated beast
  • Rendered code may be done by third-parties
  • Clock may be managed by hardware
  • Broadcasters' clocks are tied to broadcasting infrastructure

External orgs looking at it

  • DVB TM-CSS (included in HbbTV 2.0)
  • IEEE 1588 PTP (used by UPnP (I think))
  • IETF NTP
  • MPEG Media Transport (MMT)
  • Wifi Alliance Timing Measurement

Part 5
Next steps

Next steps

  • End of exploratory phase
  • Need feedback from potential implementers
  • Discuss possible bug reports and improvements to playbackrate
  • CG needs more contributions for spec to move forward (wanna join?)
  • Spec would be in scope of Timed Media WG (*)

(*) provided the spec is mature enough and the WG created!

Thank you

François Daoust
fd@w3.org
@tidoust

W3C TPAC 2015 in Sapporo, Japan

MediaScape EU project
This project has received funding from the European Union’s Seventh Framework Programme for research, technological development and demonstration under grant agreement 610404