For Developers‎ > ‎Design Documents‎ > ‎

Audio / Video Playback

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

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{Demuxer, AudioDecoder, VideoDecoder}
    • 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.

转载于:https://www.cnblogs.com/huangguanyuan/p/9985045.html

Audio / Video Playback相关推荐

  1. 从Chrome源码看audio/video流媒体实现二

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

  2. Video Playback的流程

    1.Video Playback的流程 在Android上,预设的多媒体框架(multimedia framework)是OpenCORE.OpenCORE的优点是兼顾了跨平台的移植性,而且已经过多方 ...

  3. HTML5 Audio/Video 标签,属性,方法,事件汇总 (转)

    2019独角兽企业重金招聘Python工程师标准>>> <audio> 标签属性:src:音乐的URLpreload:预加载autoplay:自动播放loop:循环播放c ...

  4. pcm 采样率转换_Cool Audio Video Converter(音视频格式转换工具)V2.18 最新版 - 绿色先锋下载 -...

    Cool Audio Video Converter(音视频格式转换工具)是一款十分优秀好用的音频格式转换助手.如果你需要一款好用的格式转换工具,小编带来的这款Cool Audio Video Con ...

  5. android声音编辑器,音频视频编辑器app下载-Audio Video Editorv1.1.0 安卓版-腾牛安卓网...

    Audio Video Editor,一款功能强大的音频视频编辑器软件,拥有音频切割.音频合并.视频切割.视频合并.音频与视频合并等功能,不仅可以编辑手机铃声,还能够制作出优质视频. 软件介绍: MP ...

  6. Embedded video playback halted;module v4l2src0 reported:Internal data flow error

    使用opencv调用摄像头获取视频时报出如下错误 [ WARN:0] OpenCV | GStreamer warning: Cannot query video position: status=0 ...

  7. 【HTML5】 Audio/Video全解(集合贴)

    [HTML5] Audio/Video全解(集合贴) 2015-03-17  chenh_doc 目录[-] 一.标签解读 二.Media对象方法和属性 三.Media JS事件 四.浏览器对音视频格 ...

  8. 前端学习笔记day01 html 标签之音频 embed+audio+video

    1. embed标签 有时候视频很大,我们不直接从本地导入到html中,而是从优酷上直接复制html代码 即可: 2. 如果是一些小的视频文件 可以借助video标签 2.1 <video sr ...

  9. 【HTML5】媒体元素标签audio video

    在HTML5问世之前,要在网络上展示视频,音频,动画,除了使用第三方自主开发的播放器之外,使用得最多的工具就是Flash,但是需要在浏览器上安装各种插件,并且有时速度很慢.HTML5新增了两个与媒体相 ...

  10. Android中MediaMuxer和MediaCodec用例 - audio+video

    在Android的多媒体类中,MediaMuxer和MediaCodec算是比较年轻的,它们是JB 4.1和JB 4.3才引入的.前者用于将音频和视频进行混合生成多媒体文件.缺点是目前只能支持一个au ...

最新文章

  1. openMP的一点使用经验 四
  2. 数据拟合matlab算法
  3. python mp3操作
  4. vb+socket 编写入侵监听程序
  5. 03 | 高可用保证:Nacos 如何有效构建注册中心集群
  6. 如何在Elasticsearch中进行深分页
  7. haproxy 作为反向代理被攻击
  8. http协议组成(请求状态码)
  9. c语言 字符串 正序再倒序_python字符串
  10. 6.性能测试监控工具
  11. 计算机丢失msvcrtdll怎么修复,雨林木风修复msvcrtdll 【操作方案】 的详细_
  12. [ROS学习笔记]ROS中使用激光雷达(RPLIDAR)
  13. 陈强老师公开课笔记1——如何区别中介效应、调节效应与交互效应?
  14. 股东控股关系图谱简化版
  15. 反射之前奏Oracle简单版
  16. 观察者模式-百度摇号短信提醒举例说明
  17. stm32增量式编码器使用流程
  18. vue 安装(看图就够了,皮卡皮卡)
  19. PhpStudy PHP8 网站打不开502 bad gateway(静态网页能打开,php打不开)
  20. oracle 会计事件表,Oracle 总帐模块会计业务周期

热门文章

  1. 软工之404 Note Found队选题报告
  2. ARC 101E.Ribbons on Tree(容斥 DP 树形背包)
  3. ping和telnet
  4. @ResponseBody与@RestController的作用与区别
  5. 异常:操作可能会破坏运行时稳定性
  6. 物流管理系统(数据库+后台+springMVC+Mybatis+layui)(一)
  7. Ubuntu U盘启动出现“Failed to load ldlinux.c32”解决
  8. https协议为什么比http协议更加安全
  9. 随着浏览器窗口缩小表格出现横向滚动条
  10. 每天学一点Linux(一)——apt-get