WebRTC 中有关 Media Stream & Track & Channel 之间的关系

28 篇文章 22 订阅
3 篇文章 0 订阅

有些接触 webrtc 的朋友,对有些概念名词和概念,以及它们之间的关系云里雾里,常常被它们绕晕。下面我就带大家理一理它们之间的关系。仅供参考!

1. Media Content

我们看到所有发布的媒体内容( Media Content ) 其实是由媒体流( Media Stream ) 组成的,一个 Media Content 最常见的展现形式就是一个音视频文件,形式各种各种,也可以包括一个场景。
是个广义的定义。每个 Media Content 可以由一个或多个 Media Stream 组成,我们的音视频文件大部分包含一个 Media Stream。

2. Media Stream 

Media Stream 是由一个或多个媒体流轨道 ( Media Stream Track ) 组成,一个 Media Stream Track 你可以理解为一个麦克风,一个摄像头,当然 Media Stream 也可能来自网络的对端,因此
Media Stream Track 可以理解为一个网络 SOCKET ( 这里比喻不太恰当,其实 Media Stream Track 的数据来自 SOCKET ) ,这样更形象。

3. Media Stream Track 

Media Stream Track 分为两种类型,一个是音频( audio ) , 一种是视频 ( video )
一个或多个 Media Stream Track 可以组成一个 Media Stream, Media Stream Track 上面已有对应的描述,最直接的理解可以看成一个本地的输入设备,或者一个对等端数据的搜集和处理单元,
更形象的是 SOCKET 的比喻。有些设备是由多通道( channel )组成的,比如:音频采集设备,就有单声道,立体声,播放设备就有前后左右,上下等方向上的声音标识,这就是我们所说的通道,
视频的通道,也是从不同角度对视频的采集。至此,我们明白了一个 Media Stream Track 包含一个或多个通道,通道是设备所附带的属性,不同设备,定义不同。

在 webrtc 我们和对等端最常用的场景就是建立一个 Media Stream 进行交互,那么就需要产生 video 和 audio 的 Media Stream Track ,有了这些我们只是有采集或渲染的部分了,整个通话
其实就是建立两个 pipeline , 一个发送, 一个接收。 我们调用 addTrack 接口就会绑定一个流,这个流底层就是负责 Media Stream Track 的发送和接收,也就是上面说的 SOCKET 。具体怎么把 track 与 stream 进行绑定,请参阅我其它博客

https://blog.csdn.net/freeabc

下面是我查找它们三者之间关系的描述资料,以飨读者。

https://webrtc.org/getting-started/media-capture-and-constraints?hl=en
Streams and tracks
A MediaStream represents a stream of media content, which consists of tracks (MediaStreamTrack) of audio and video. You can retrieve all the tracks from MediaStream 
by calling MediaStream.getTracks(), which returns an array of MediaStreamTrack objects.

MediaStreamTrack
A MediaStreamTrack has a kind property that is either audio or video, indicating the kind of media it represents. Each track can be muted by toggling its enabled property. 
A track has a Boolean property remote that indicates if it is sourced by a RTCPeerConnection and coming from a remote peer.

https://developer.mozilla.org/en-US/docs/Web/API/Media_Streams_API
A MediaStream consists of zero or more MediaStreamTrack objects, representing various audio or video tracks. Each MediaStreamTrack may have one or more channels. 
The channel represents the smallest unit of a media stream, such as an audio signal associated with a given speaker, like left or right in a stereo audio track.

MediaStream objects have a single input and a single output. A MediaStream object generated by getUserMedia() is called local, and has as its source input one of 
the user's cameras or microphones. A non-local MediaStream may be representing a media element, like <video> or <audio>, a stream originating over the network, 
and obtained via the WebRTC RTCPeerConnection API, or a stream created using the Web Audio API MediaStreamAudioSourceNode.

The output of the MediaStream object is linked to a consumer. It can be a media elements, like <audio> or <video>, the WebRTC RTCPeerConnection API or a Web Audio 
API MediaStreamAudioSourceNode.


https://w3c.github.io/mediacapture-main/#mediastreamtrack

The two main components in the MediaStream API are the MediaStreamTrack and MediaStream interfaces. The MediaStreamTrack object represents media of a single type 
that originates from one media source in the User Agent, e.g. video produced by a web camera. A MediaStream is used to group several MediaStreamTrack objects into 
one unit that can be recorded or rendered in a media element.

Each MediaStream can contain zero or more MediaStreamTrack objects. All tracks in a MediaStream are intended to be synchronized when rendered. This is not a hard 
requirement, since it might not be possible to synchronize tracks from sources that have different clocks. Different MediaStream objects do not need to be synchronized.

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值