blob: 959f3fde47f0583e509132e882118a052202b6d5 [file] [log] [blame]
deadbeefe814a0d2017-02-25 18:15:09 -08001/*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_RTP_PARAMETERS_CONVERSION_H_
12#define PC_RTP_PARAMETERS_CONVERSION_H_
deadbeefe814a0d2017-02-25 18:15:09 -080013
deadbeefe814a0d2017-02-25 18:15:09 -080014#include <vector>
15
Danil Chapovalov00c71832018-06-15 15:58:38 +020016#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080017#include "api/rtc_error.h"
18#include "api/rtp_parameters.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "media/base/stream_params.h"
21#include "pc/session_description.h"
deadbeefe814a0d2017-02-25 18:15:09 -080022
23namespace webrtc {
24
25// NOTE: Some functions are templated for convenience, such that template-based
26// code dealing with AudioContentDescription and VideoContentDescription can
27// use this easily. Such methods are usable with cricket::AudioCodec and
28// cricket::VideoCodec.
29
30//***************************************************************************
31// Functions for converting from new webrtc:: structures to old cricket::
32// structures.
33//
34// As the return values imply, all of these functions do validation of the
35// parameters and return an error if they're invalid. It's expected that any
36// default values (such as video clock rate of 90000) have been filled by the
37// time the webrtc:: structure is being converted to the cricket:: one.
38//
39// These are expected to be used when parameters are passed into an RtpSender
40// or RtpReceiver, and need to be validated and converted so they can be
41// applied to the media engine level.
42//***************************************************************************
43
44// Returns error on invalid input. Certain message types are only valid for
45// certain feedback types.
46RTCErrorOr<cricket::FeedbackParam> ToCricketFeedbackParam(
47 const RtcpFeedback& feedback);
48
49// Verifies that the codec kind is correct, and it has mandatory parameters
50// filled, with values in valid ranges.
51template <typename C>
52RTCErrorOr<C> ToCricketCodec(const RtpCodecParameters& codec);
53
54// Verifies that payload types aren't duplicated, in addition to normal
55// validation.
56template <typename C>
57RTCErrorOr<std::vector<C>> ToCricketCodecs(
58 const std::vector<RtpCodecParameters>& codecs);
59
deadbeefe814a0d2017-02-25 18:15:09 -080060// SSRCs are allowed to be ommitted. This may be used for receive parameters
61// where SSRCs are unsignaled.
62RTCErrorOr<cricket::StreamParamsVec> ToCricketStreamParamsVec(
63 const std::vector<RtpEncodingParameters>& encodings);
64
65//*****************************************************************************
66// Functions for converting from old cricket:: structures to new webrtc::
67// structures. Unlike the above functions, these are permissive with regards to
68// input validation; it's assumed that any necessary validation already
69// occurred.
70//
71// These are expected to be used either to convert from audio/video engine
72// capabilities to RtpCapabilities, or to convert from already-parsed SDP
73// (in the form of cricket:: structures) to webrtc:: structures. The latter
74// functionality is not yet implemented.
75//*****************************************************************************
76
Artem Titov880fa812021-07-30 22:30:23 +020077// Returns empty value if `cricket_feedback` is a feedback type not
deadbeefe814a0d2017-02-25 18:15:09 -080078// supported/recognized.
Danil Chapovalov00c71832018-06-15 15:58:38 +020079absl::optional<RtcpFeedback> ToRtcpFeedback(
deadbeefe814a0d2017-02-25 18:15:09 -080080 const cricket::FeedbackParam& cricket_feedback);
81
zhihuang24366392017-03-08 17:15:06 -080082std::vector<RtpEncodingParameters> ToRtpEncodings(
83 const cricket::StreamParamsVec& stream_params);
84
85template <typename C>
86RtpCodecParameters ToRtpCodecParameters(const C& cricket_codec);
87
deadbeefe814a0d2017-02-25 18:15:09 -080088template <typename C>
89RtpCodecCapability ToRtpCodecCapability(const C& cricket_codec);
90
91template <class C>
92RtpCapabilities ToRtpCapabilities(
93 const std::vector<C>& cricket_codecs,
94 const cricket::RtpHeaderExtensions& cricket_extensions);
95
zhihuang24366392017-03-08 17:15:06 -080096template <class C>
97RtpParameters ToRtpParameters(
98 const std::vector<C>& cricket_codecs,
99 const cricket::RtpHeaderExtensions& cricket_extensions,
100 const cricket::StreamParamsVec& stream_params);
101
deadbeefe814a0d2017-02-25 18:15:09 -0800102} // namespace webrtc
103
Steve Anton10542f22019-01-11 09:11:00 -0800104#endif // PC_RTP_PARAMETERS_CONVERSION_H_