blob: dc24a456fa0a8f3dfa4359e3805162ae2e829d6d [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
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <iosfwd>
deadbeefe814a0d2017-02-25 18:15:09 -080015#include <vector>
16
Danil Chapovalov00c71832018-06-15 15:58:38 +020017#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "api/rtc_error.h"
19#include "api/rtp_parameters.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "media/base/stream_params.h"
22#include "pc/session_description.h"
deadbeefe814a0d2017-02-25 18:15:09 -080023
24namespace webrtc {
25
26// NOTE: Some functions are templated for convenience, such that template-based
27// code dealing with AudioContentDescription and VideoContentDescription can
28// use this easily. Such methods are usable with cricket::AudioCodec and
29// cricket::VideoCodec.
30
31//***************************************************************************
32// Functions for converting from new webrtc:: structures to old cricket::
33// structures.
34//
35// As the return values imply, all of these functions do validation of the
36// parameters and return an error if they're invalid. It's expected that any
37// default values (such as video clock rate of 90000) have been filled by the
38// time the webrtc:: structure is being converted to the cricket:: one.
39//
40// These are expected to be used when parameters are passed into an RtpSender
41// or RtpReceiver, and need to be validated and converted so they can be
42// applied to the media engine level.
43//***************************************************************************
44
45// Returns error on invalid input. Certain message types are only valid for
46// certain feedback types.
47RTCErrorOr<cricket::FeedbackParam> ToCricketFeedbackParam(
48 const RtcpFeedback& feedback);
49
50// Verifies that the codec kind is correct, and it has mandatory parameters
51// filled, with values in valid ranges.
52template <typename C>
53RTCErrorOr<C> ToCricketCodec(const RtpCodecParameters& codec);
54
55// Verifies that payload types aren't duplicated, in addition to normal
56// validation.
57template <typename C>
58RTCErrorOr<std::vector<C>> ToCricketCodecs(
59 const std::vector<RtpCodecParameters>& codecs);
60
61// Validates that header extension IDs aren't duplicated.
62RTCErrorOr<cricket::RtpHeaderExtensions> ToCricketRtpHeaderExtensions(
63 const std::vector<RtpHeaderExtensionParameters>& extensions);
64
65// SSRCs are allowed to be ommitted. This may be used for receive parameters
66// where SSRCs are unsignaled.
67RTCErrorOr<cricket::StreamParamsVec> ToCricketStreamParamsVec(
68 const std::vector<RtpEncodingParameters>& encodings);
69
70//*****************************************************************************
71// Functions for converting from old cricket:: structures to new webrtc::
72// structures. Unlike the above functions, these are permissive with regards to
73// input validation; it's assumed that any necessary validation already
74// occurred.
75//
76// These are expected to be used either to convert from audio/video engine
77// capabilities to RtpCapabilities, or to convert from already-parsed SDP
78// (in the form of cricket:: structures) to webrtc:: structures. The latter
79// functionality is not yet implemented.
80//*****************************************************************************
81
82// Returns empty value if |cricket_feedback| is a feedback type not
83// supported/recognized.
Danil Chapovalov00c71832018-06-15 15:58:38 +020084absl::optional<RtcpFeedback> ToRtcpFeedback(
deadbeefe814a0d2017-02-25 18:15:09 -080085 const cricket::FeedbackParam& cricket_feedback);
86
zhihuang24366392017-03-08 17:15:06 -080087std::vector<RtpEncodingParameters> ToRtpEncodings(
88 const cricket::StreamParamsVec& stream_params);
89
90template <typename C>
91RtpCodecParameters ToRtpCodecParameters(const C& cricket_codec);
92
deadbeefe814a0d2017-02-25 18:15:09 -080093template <typename C>
94RtpCodecCapability ToRtpCodecCapability(const C& cricket_codec);
95
96template <class C>
97RtpCapabilities ToRtpCapabilities(
98 const std::vector<C>& cricket_codecs,
99 const cricket::RtpHeaderExtensions& cricket_extensions);
100
zhihuang24366392017-03-08 17:15:06 -0800101template <class C>
102RtpParameters ToRtpParameters(
103 const std::vector<C>& cricket_codecs,
104 const cricket::RtpHeaderExtensions& cricket_extensions,
105 const cricket::StreamParamsVec& stream_params);
106
deadbeefe814a0d2017-02-25 18:15:09 -0800107} // namespace webrtc
108
Steve Anton10542f22019-01-11 09:11:00 -0800109#endif // PC_RTP_PARAMETERS_CONVERSION_H_