SDP: протокол описания сеанса
Узнайте, как SDP описывает формат мультимедиа, кодек и сетевую информацию, которыми обмениваются узлы для согласования соединения.
«SDP: протокол описания сеанса» — бесплатный урок Real-Time Streaming Systems (WebRTC + Live Data) на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Real-Time Streaming Systems (WebRTC + Live Data), и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Real-Time Streaming Systems (WebRTC + Live Data) содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
What is SDP?
SDP stands for Session Description Protocol. It's a text-based format used in WebRTC to describe the capabilities and parameters of a media session.
Think of it as a blueprint for what kind of audio, video, and data a peer wants to send or receive, and how it can be reached.
SDP's Role in WebRTC
Before two WebRTC peers can send data directly, they need to agree on many things:
- What media types (audio, video, data) they support.
- Which codecs to use (e.g., Opus for audio, VP8 for video).
- Their network addresses and connection methods.
SDP is the standard way to exchange this crucial information.
SDP in Offer/Answer
WebRTC uses an "Offer/Answer" model for negotiation. One peer creates an SDP Offer, describing its capabilities. The other peer receives it and creates an SDP Answer, indicating its own capabilities and agreement.
This exchange happens via a signaling server, which we discussed in the previous lesson.
SDP Message Structure
An SDP message is a collection of lines, each starting with a single lowercase letter followed by an equals sign (=). These lines are grouped into a session description and one or more media descriptions.
Common lines include: v=, o=, s=, t=, c=, m=, and a=.
SDP: Version & Origin
Every SDP message begins with a version line and an origin line:
v=0: Specifies the SDP protocol version. Always 0 for WebRTC.o=: Describes the session's originator and identifier.IN IP4
The <sess-id> and <sess-version> are unique numbers, and <address> is typically 127.0.0.1 for local generation.
SDP: Session Name & Time
Next, we find the session name and time description:
s=-: The session name. Often just a hyphen for WebRTC.t=0 0: The session's active time.0 0means permanent/always active for WebRTC.
These lines provide basic context for the overall session.
SDP: Connection Data
The c= line provides connection data, specifically the IP address for the session. In WebRTC, this is often set to 0.0.0.0 or 127.0.0.1 as the actual peer-to-peer connection addresses are negotiated later via ICE candidates.
Example: c=IN IP4 0.0.0.0
SDP: Media Descriptions (`m=`)
The m= line is critical! It describes a specific media stream (audio, video, or data channel). An SDP can have multiple m= lines.
Format: m=
<media>:audio,video, orapplication(for data channels).<port>: The port number (often 9 for WebRTC, actual port from ICE).<protocol>: E.g.,UDP/TLS/RTP/SAVPF.<fmt list>: A list of supported payload types/codecs.
SDP: Attributes (`a=`)
a= lines provide additional attributes for the session or a specific media stream. They are highly flexible and carry a lot of WebRTC-specific information.
a=rtpmap:: Maps payload types to codecs./ a=fingerprint:...: TLS certificate fingerprint.a=sendrecv,a=sendonly,a=recvonly: Directionality of media.a=ice-ufrag,a=ice-pwd: Used for ICE connectivity checks.
See a Simplified SDP
Here's a simplified example of what an SDP offer might look like. Notice the different lines and their roles in describing the session and media capabilities.
Try running it to see the raw SDP text!
function main() {
const sdpExample = `v=0
o=- 3749449080 3749449080 IN IP4 127.0.0.1
s=-
t=0 0
c=IN IP4 0.0.0.0
m=audio 9 UDP/TLS/RTP/SAVPF 111
a=rtpmap:111 opus/48000/2
a=mid:audio
a=sendrecv
a=ice-ufrag:abcdefg
a=ice-pwd:hijklmn
a=fingerprint:sha-256 A1:B2:C3:D4:E5:F6:A7:B8:C9:D0:E1:F2:A3:B4:C5:D6:E7:F8:A9:B0:C1:D2:E3:F4:A5:B6:C7:D8
`;
console.log("Simplified SDP Offer:");
console.log(sdpExample);
}
main();Quick Check on SDP
Which SDP line primarily describes the type of media (audio, video, or data), its associated port, transport protocol, and supported formats?
Recap: SDP Essentials
Great job! You've learned about SDP, the Session Description Protocol, which is fundamental to WebRTC.
- SDP is a text format for describing media and network capabilities.
- It's used in the Offer/Answer model to negotiate connections.
- Key lines include
v=,o=,s=,t=,c=,m=, anda=. - The
m=line describes media, anda=lines provide rich attributes.
Next, we'll dive into ICE candidates, which help peers find the best network path!
Часто задаваемые вопросы
Урок «SDP: протокол описания сеанса» бесплатный?
Да — полный текст урока «SDP: протокол описания сеанса» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Real-Time Streaming Systems (WebRTC + Live Data), подпишись на CoddyKit PRO. Курс Real-Time Streaming Systems (WebRTC + Live Data) содержит 4 уроков всего.
Чему я научусь в уроке «SDP: протокол описания сеанса»?
Узнайте, как SDP описывает формат мультимедиа, кодек и сетевую информацию, которыми обмениваются узлы для согласования соединения. Ты практикуешь Real-Time Streaming Systems (WebRTC + Live Data) с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Real-Time Streaming Systems (WebRTC + Live Data)?
Предыдущий опыт не требуется. Real-Time Streaming Systems (WebRTC + Live Data) на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.
Сколько времени занимает урок «SDP: протокол описания сеанса»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Real-Time Streaming Systems (WebRTC + Live Data)?
Да. Каждый урок Real-Time Streaming Systems (WebRTC + Live Data) включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Роль серверов сигнализации
- SDP: протокол описания сеанса
- Кандидаты ICE и подключение
- Повторное согласование и состояние соединения