Audio / Video Playback

Interested in helping out?  Check out our bugs!  New to Chromium?  GoodFirstBug is your friend!

Filing a new bug: Template 
Documentation:
 
Much of the documentation below is out of date and has significant gaps. For the most up to date documentation please see the README.md file in the media/ directory (which is where all the code for Chromium's media pipeline lives).
 

Overview

There are several major components to Chromium's media playback implementation, here are three most folks are commonly interested in:
  • Pipeline
    • Chromium's implementation of a media playback engine
    • Handles audio/video synchronization and resource fetching
  • FFmpeg{DemuxerAudioDecoderVideoDecoder}
    • Open source library used for container parsing and software audio and video decoding.
  • Blink's HTMLMediaElement
    • Implements the HTML and Javascript bindings as specified by WHATWG
    • Handles rendering the user agent controls

Pipeline

The pipeline is a pull-based media playback engine that abstracts each step of media playback into (at least) 6 different filters: data source, demuxing, audio decoding, video decoding, audio rendering, and video rendering.  The pipeline manages the lifetime of the renderer and exposes a thread safe interface to clients. The filters are connected together to form a filter graph.
 
Design goals:
  - Use Chromium threading constructs such as TaskRunner
  - Filters do not determine threading model
  - All filter actions are asynchronous and use callbacks to signal completion
  - Upstream filters are oblivious to downstream filters (i.e., DataSource is unaware of Demuxer)
  - Prefer explicit types and methods over general types and methods (i.e., prefer foo->Bar() over foo->SendMessage(MSG_BAR))
  - Can run inside security sandbox
  - Runs on Windows, Mac and Linux on x86 and ARM
  - Supports arbitrary audio/video codecs
 
Design non-goals:
  - Dynamic loading of filters via shared libraries
  - Buffer management negotiation
  - Building arbitrary filter graphs
  - Supporting filters beyond the scope of media playback
 
The original research into supporting video in Chromium started in September 2008.  Before deciding to implement our own media playback engine we considered the following alternative technologies:
  - DirectShow (Windows specific, cannot run inside sandbox without major hacking)
  - GStreamer (Windows support questionable at the time, extra ~2MB of DLLs due to library dependencies, targets many of our non-goals)
  - VLC (cannot use due to GPL)
  - MPlayer (cannot use due to GPL)
  - OpenMAX (complete overkill for our purposes)
  - liboggplay (specific to Ogg Theora/Vorbis)
 
Our approach was to write our own media playback engine that was audio/video codec agnostic and focused on playback.  Using FFmpeg avoids both the use of proprietary/commercial codecs and allows Chromium's media engine to support a wide variety of formats depending on FFmpeg's build configuration.
 
 
As previously mentioned, the pipeline is completely pull-based and relies on the sound card to drive playback.  As the sound card requests additional data, the audio renderer requests decoded audio data from the audio decoder, which requests encoded buffers from the demuxer, which reads from the data source, and so on. As decoded audio data data is fed into the sound card the pipeline's global clock is updated.  The video renderer polls the global clock upon each vsync to determine when to request decoded frames from the video decoder and when to render new frames to the video display. In the absence of a sound card or an audio track, the system clock is used to drive video decoding and rendering. Relevant source code is in the media directory.
 
The pipeline uses a state machine to handle playback and events such as pausing, seeking, and stopping.  A state transition typically consists of notifying all filters of the event and waiting for completion callbacks before completing the transition (diagram from pipeline_impl.h):
//   [ *Created ]                       [ Any State ]
// | Start() | Stop()
// V V
// [ Starting ] [ Stopping ]
// | |
// V V
// [ Playing ] <---------. [ Stopped ]
// | | Seek() |
// | V |
// | [ Seeking ] ----'
// | ^
// | Suspend() |
// V |
// [ Suspending ] |
// | |
// V |
// [ Suspended ] |
// | Resume() |
// V |
// [ Resuming ] ---------'
The pull-based design allows pause to be implemented by setting the playback rate to zero, causing the audio and video renderers to stop requesting data from upstream filters.  Without any pending requests the entire pipeline enters an implicit paused state.

Integration

The following diagram shows the current integration of the media playback pipeline into WebKit and Chromium browser; this is slightly out of date, but the gist remains the same.
 

(1) WebKit requests to create a media player, which in Chromium's case creates WebMediaPlayerImpl and Pipeline.

(2) BufferedDataSource requests to fetch the current video URL via ResourceLoader.

(3) ResourceDispatcher forwards the request to the browser process.

(4) A URLRequest is created for the request, which may already have cached data present in HttpCache.  Data is sent back to BufferedDataSource as it becomes available.

(5) FFmpeg demuxes and decodes audio/video data.

(6) Due to sandboxing, AudioRendererImpl cannot open an audio device directly and requests the browser to open the device on its behalf.

(7) The browser opens a new audio device and forwards audio callbacks to the corresponding render process.

(8) Invalidates are sent to WebKit as new frames are available.

 

Audio / Video Playback的更多相关文章

  1. [jPlayer] HTML5 Audio & Video for jQuery

    ---------------------------------------------------------------------------------------------------- ...

  2. stagefright框架(一)Video Playback的流程

    在Android上,預設的多媒體框架(multimedia framework)是OpenCORE. OpenCORE的優點是兼顧了跨平台的移植性,而且已經過多方驗證,所以相對來說較為穩定:但是其缺點 ...

  3. 从Chrome源码看audio/video流媒体实现二(转)

    第一篇主要介绍了Chrome加载音视频的缓冲控制机制和编解码基础,本篇将比较深入地介绍解码播放的过程.以Chromium 69版本做研究. 由于Chromium默认不能播放Mp4,所以需要需要改一下源 ...

  4. HTML5 Audio/Video 标签,属性,方法,事件汇总

    HTML5 Audio/Video 标签,属性,方法,事件汇总 (转) 2011-06-28 13:16:48   <audio> 标签属性:src:音乐的URLpreload:预加载au ...

  5. Capturing Audio & Video in HTML5

    使用HTML5抓取 Audio & Video 原文地址: http://www.html5rocks.com/en/tutorials/getusermedia/intro/ 本地化的文章: ...

  6. [转载]HTML5 Audio/Video 标签,属性,方法,事件汇总

    <audio> 标签属性: src:音乐的URL preload:预加载 autoplay:自动播放 loop:循环播放 controls:浏览器自带的控制条 <audio id=& ...

  7. 如何让windows版Safari支持H5 audio/video?

    今天在windows版Safari上看效果的时候惊奇地发现它竟然不支持HTML5的audio/video, 这样的话就无法复现不少ios上出现的问题. 在同事提醒下, 发现Safari HTML5 A ...

  8. HTML 5 Audio/Video DOM buffered 属性

    1.实例1获取视频第一段缓冲范围部分,以秒计: myVid=document.getElementById("video1"); alert("Start: " ...

  9. js 多媒体audio video

    本文主要简单的介绍一下audio 和 video两个标签的用法 <audio src="music.mp3"></audio> <video src= ...

随机推荐

  1. node10---GET请求和POST请求的参数

    GET请求的参数在URL中,在原生Node中,需要使用url模块来识别参数字符串.在Express中,不需要使用url模块了.可以直接使用req.query对象. ● POST请求在express中不 ...

  2. windows+ubuntu双系统,在windows中访问ubuntu文件

    今天被告知ubuntu磁盘空间不足,百度得知可以通过autoremove命令清理,然而,,再也进不去ubuntu系统了,具体表现为第一次选择ubuntu之后一直是空白紫屏,如果强制关机再开机后选择ub ...

  3. linux系统定时任务crond入门

    1,Crond: Crond是linux系统中用来定期执行命令或指定程序任务的一种服务或者软件.(Centos5以后默认存在) 当优化开机自启动的时候,第一个就是crond. Crond服务默认情况( ...

  4. Javascript四种调用模式中的this指向

    第一种:函数直接调用执行的模式 function add(a,b){ console.log(this); return a+b; } add(,) //this===window 这里的this指向 ...

  5. 由ubuntu装好想到的

    这篇不是技术文,有点唠叨的总结.不喜勿喷. 最近开始全面学ubuntu,一翻书回忆起本科没选但是去听了的Linux.当时看的还是楚广明的fedora教程,这多年过去综合很多人的说 法,fedora不稳 ...

  6. Android 实现下拉刷新和上拉加载更多的RECYCLERVIEW和SCROLLVIEW

    PullRefreshRecyclerView.java /** * 类说明:下拉刷新上拉加载更多的RecyclerView * Author: gaobaiq * Date: 2016/5/9 18 ...

  7. Golang环境配置Centos

      1.下载go程序包( go1.7rc1.linux-amd64.tar.gz)(http://www.golangtc.com/static/go/1.7rc1/go1.7rc1.linux-am ...

  8. cg基础

    1. row-major or column-major 2.orthogonal matrices 3.why cameras always point along the world coordi ...

  9. poj1170 - 转换成背包

    题目链接 有5种物品,给出每个物品的单价. 给出几个这些物品的组合和这个组合的价格.买组合要比一件件的买便宜. 问给定的购买计划最少花多少钱. ---------------------------- ...

  10. C语言-100加减求和

    ----------------------------度娘的思路------------------------------------------------------ Action() { / ...