2013-07-10 00:45:36 +00:00
|
|
|
|
/*
|
2016-02-07 20:46:45 -08:00
|
|
|
|
* Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
|
*
|
2016-02-07 20:46:45 -08:00
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-07-10 00:45:36 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
|
#ifndef MEDIA_BASE_CODEC_H_
|
|
|
|
|
|
#define MEDIA_BASE_CODEC_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
2022-07-05 21:06:28 +09:00
|
|
|
|
#include "absl/container/inlined_vector.h"
|
2022-06-07 13:58:27 +02:00
|
|
|
|
#include "absl/strings/string_view.h"
|
2019-06-04 15:38:50 +02:00
|
|
|
|
#include "absl/types/optional.h"
|
2023-06-20 17:12:57 +00:00
|
|
|
|
#include "api/audio_codecs/audio_format.h"
|
2022-03-29 11:04:48 +02:00
|
|
|
|
#include "api/field_trials_view.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
|
#include "api/rtp_parameters.h"
|
2017-09-29 15:00:29 +02:00
|
|
|
|
#include "api/video_codecs/sdp_video_format.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
|
#include "media/base/media_constants.h"
|
2018-10-17 16:50:07 +02:00
|
|
|
|
#include "rtc_base/system/rtc_export.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::map<std::string, std::string> CodecParameterMap;
|
|
|
|
|
|
|
|
|
|
|
|
class FeedbackParam {
|
|
|
|
|
|
public:
|
2017-02-25 18:15:09 -08:00
|
|
|
|
FeedbackParam() = default;
|
2022-06-07 13:58:27 +02:00
|
|
|
|
FeedbackParam(absl::string_view id, const std::string& param)
|
2018-06-19 15:03:05 +02:00
|
|
|
|
: id_(id), param_(param) {}
|
2022-06-07 13:58:27 +02:00
|
|
|
|
explicit FeedbackParam(absl::string_view id)
|
2018-06-19 15:03:05 +02:00
|
|
|
|
: id_(id), param_(kParamValueEmpty) {}
|
2018-04-05 11:42:24 +02:00
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
|
bool operator==(const FeedbackParam& other) const;
|
2023-06-04 23:22:36 +00:00
|
|
|
|
bool operator!=(const FeedbackParam& c) const { return !(*this == c); }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
|
|
const std::string& id() const { return id_; }
|
|
|
|
|
|
const std::string& param() const { return param_; }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2018-06-19 15:03:05 +02:00
|
|
|
|
std::string id_; // e.g. "nack", "ccm"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
std::string param_; // e.g. "", "rpsi", "fir"
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FeedbackParams {
|
|
|
|
|
|
public:
|
2017-09-28 21:19:18 +02:00
|
|
|
|
FeedbackParams();
|
2018-04-05 11:42:24 +02:00
|
|
|
|
~FeedbackParams();
|
2013-07-10 00:45:36 +00:00
|
|
|
|
bool operator==(const FeedbackParams& other) const;
|
2023-06-04 23:22:36 +00:00
|
|
|
|
bool operator!=(const FeedbackParams& c) const { return !(*this == c); }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
|
|
bool Has(const FeedbackParam& param) const;
|
|
|
|
|
|
void Add(const FeedbackParam& param);
|
|
|
|
|
|
|
|
|
|
|
|
void Intersect(const FeedbackParams& from);
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<FeedbackParam>& params() const { return params_; }
|
2018-06-19 15:03:05 +02:00
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
|
private:
|
|
|
|
|
|
bool HasDuplicateEntries() const;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<FeedbackParam> params_;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-10-17 16:50:07 +02:00
|
|
|
|
struct RTC_EXPORT Codec {
|
2023-05-31 12:35:47 +00:00
|
|
|
|
enum class Type {
|
|
|
|
|
|
kAudio,
|
|
|
|
|
|
kVideo,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum class ResiliencyType {
|
|
|
|
|
|
kNone,
|
|
|
|
|
|
kRed,
|
|
|
|
|
|
kUlpfec,
|
|
|
|
|
|
kFlexfec,
|
|
|
|
|
|
kRtx,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Type type;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
int id;
|
|
|
|
|
|
std::string name;
|
|
|
|
|
|
int clockrate;
|
2023-05-31 12:35:47 +00:00
|
|
|
|
|
|
|
|
|
|
// Audio only
|
|
|
|
|
|
// Can be used to override the target bitrate in the encoder.
|
|
|
|
|
|
// TODO(orphis): Remove in favor of alternative APIs
|
|
|
|
|
|
int bitrate;
|
|
|
|
|
|
size_t channels;
|
|
|
|
|
|
|
|
|
|
|
|
// Video only
|
|
|
|
|
|
absl::optional<std::string> packetization;
|
|
|
|
|
|
absl::InlinedVector<webrtc::ScalabilityMode, webrtc::kScalabilityModeCount>
|
|
|
|
|
|
scalability_modes;
|
|
|
|
|
|
|
2020-07-01 21:07:32 +02:00
|
|
|
|
// Non key-value parameters such as the telephone-event "0‐15" are
|
|
|
|
|
|
// represented using an empty string as key, i.e. {"": "0-15"}.
|
2013-07-10 00:45:36 +00:00
|
|
|
|
CodecParameterMap params;
|
|
|
|
|
|
FeedbackParams feedback_params;
|
|
|
|
|
|
|
2023-05-31 12:35:47 +00:00
|
|
|
|
Codec(const Codec& c);
|
|
|
|
|
|
Codec(Codec&& c);
|
|
|
|
|
|
|
2016-05-12 08:10:52 +02:00
|
|
|
|
virtual ~Codec();
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
2023-05-31 12:35:47 +00:00
|
|
|
|
// Indicates if this codec is compatible with the specified codec by
|
|
|
|
|
|
// checking the assigned id and profile values for the relevant video codecs.
|
|
|
|
|
|
// H264 levels are not compared.
|
2022-03-29 11:04:48 +02:00
|
|
|
|
bool Matches(const Codec& codec,
|
|
|
|
|
|
const webrtc::FieldTrialsView* field_trials = nullptr) const;
|
2023-04-12 10:45:07 +00:00
|
|
|
|
bool MatchesRtpCodec(const webrtc::RtpCodec& capability) const;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
|
// Find the parameter for `name` and write the value to `out`.
|
2013-07-10 00:45:36 +00:00
|
|
|
|
bool GetParam(const std::string& name, std::string* out) const;
|
|
|
|
|
|
bool GetParam(const std::string& name, int* out) const;
|
|
|
|
|
|
|
|
|
|
|
|
void SetParam(const std::string& name, const std::string& value);
|
|
|
|
|
|
void SetParam(const std::string& name, int value);
|
|
|
|
|
|
|
2014-06-19 19:50:55 +00:00
|
|
|
|
// It is safe to input a non-existent parameter.
|
|
|
|
|
|
// Returns true if the parameter existed, false if it did not exist.
|
|
|
|
|
|
bool RemoveParam(const std::string& name);
|
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
|
bool HasFeedbackParam(const FeedbackParam& param) const;
|
|
|
|
|
|
void AddFeedbackParam(const FeedbackParam& param);
|
|
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
|
// Filter `this` feedbacks params such that only those shared by both `this`
|
|
|
|
|
|
// and `other` are kept.
|
2013-07-10 00:45:36 +00:00
|
|
|
|
void IntersectFeedbackParams(const Codec& other);
|
|
|
|
|
|
|
2016-04-20 16:23:10 -07:00
|
|
|
|
virtual webrtc::RtpCodecParameters ToCodecParameters() const;
|
|
|
|
|
|
|
2023-05-31 12:35:47 +00:00
|
|
|
|
// The codec represent an actual media codec, and not a resiliency codec.
|
|
|
|
|
|
bool IsMediaCodec() const;
|
|
|
|
|
|
// The codec represent a resiliency codec such as RED, RTX or FEC variants.
|
|
|
|
|
|
bool IsResiliencyCodec() const;
|
|
|
|
|
|
ResiliencyType GetResiliencyType() const;
|
|
|
|
|
|
|
|
|
|
|
|
// Validates a VideoCodec's payload type, dimensions and bitrates etc. If they
|
|
|
|
|
|
// don't make sense (such as max < min bitrate), and error is logged and
|
|
|
|
|
|
// ValidateCodecFormat returns false.
|
|
|
|
|
|
bool ValidateCodecFormat() const;
|
|
|
|
|
|
|
|
|
|
|
|
std::string ToString() const;
|
|
|
|
|
|
|
Make webrtc 50 KB smaller by not inlining Codec.
The Codec class is a big class and objects of the Codec class are passed
around by value. That means that inlined operations would be duplicated
at many places, in particular inside STL.
By not inlining Codec methods, webrtc shrinks by 50 KB in
a Linux x64 clang build.
Total change: -54147 bytes
==========================
+2810 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/codec.cc - (gained 2920, lost 110)
-1003 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/codec.h - (gained 0, lost 1003)
-1129 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/sctp/sctpdataengine.cc - (gained 1660, lost 2789)
-1190 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/rtpdataengine.cc - (gained 1408, lost 2598)
-1747 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/session/media/mediasession.cc - (gained 803, lost 2550)
-2141 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/webrtc/webrtcvideoengine.cc - (gained 1679, lost 3820)
-2250 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/app/webrtc/webrtcsdp.cc - (gained 1224, lost 3474)
-2927 - Source: /usr/include/c++/4.8/bits/stl_vector.h - (gained 0, lost 2927)
-3729 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/webrtc/webrtcvideoengine2.cc - (gained 10925, lost 14654)
-6369 - Source: /usr/include/c++/4.8/bits/vector.tcc - (gained 0, lost 6369)
-10582 - Source: /usr/include/c++/4.8/bits/stl_heap.h - (gained 0, lost 10582)
-19324 - Source: /usr/include/c++/4.8/bits/stl_algo.h - (gained 743, lost 20067)
BUG=
R=juberti@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/40729005
Cr-Commit-Position: refs/heads/master@{#8436}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8436 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-19 17:55:18 +00:00
|
|
|
|
Codec& operator=(const Codec& c);
|
2016-11-07 10:14:36 -08:00
|
|
|
|
Codec& operator=(Codec&& c);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
Make webrtc 50 KB smaller by not inlining Codec.
The Codec class is a big class and objects of the Codec class are passed
around by value. That means that inlined operations would be duplicated
at many places, in particular inside STL.
By not inlining Codec methods, webrtc shrinks by 50 KB in
a Linux x64 clang build.
Total change: -54147 bytes
==========================
+2810 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/codec.cc - (gained 2920, lost 110)
-1003 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/codec.h - (gained 0, lost 1003)
-1129 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/sctp/sctpdataengine.cc - (gained 1660, lost 2789)
-1190 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/base/rtpdataengine.cc - (gained 1408, lost 2598)
-1747 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/session/media/mediasession.cc - (gained 803, lost 2550)
-2141 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/webrtc/webrtcvideoengine.cc - (gained 1679, lost 3820)
-2250 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/app/webrtc/webrtcsdp.cc - (gained 1224, lost 3474)
-2927 - Source: /usr/include/c++/4.8/bits/stl_vector.h - (gained 0, lost 2927)
-3729 - Source: /home/bratell/src/chromium/src/third_party/libjingle/source/talk/media/webrtc/webrtcvideoengine2.cc - (gained 10925, lost 14654)
-6369 - Source: /usr/include/c++/4.8/bits/vector.tcc - (gained 0, lost 6369)
-10582 - Source: /usr/include/c++/4.8/bits/stl_heap.h - (gained 0, lost 10582)
-19324 - Source: /usr/include/c++/4.8/bits/stl_algo.h - (gained 743, lost 20067)
BUG=
R=juberti@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/40729005
Cr-Commit-Position: refs/heads/master@{#8436}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8436 4adac7df-926f-26a2-2b94-8c16560cd09d
2015-02-19 17:55:18 +00:00
|
|
|
|
bool operator==(const Codec& c) const;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
|
bool operator!=(const Codec& c) const { return !(*this == c); }
|
2016-12-08 01:50:48 -08:00
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
// Creates an empty codec.
|
2023-05-31 12:35:47 +00:00
|
|
|
|
explicit Codec(Type type);
|
|
|
|
|
|
// Creates a codec with the given parameters.
|
|
|
|
|
|
Codec(Type type, int id, const std::string& name, int clockrate);
|
|
|
|
|
|
Codec(Type type,
|
|
|
|
|
|
int id,
|
|
|
|
|
|
const std::string& name,
|
|
|
|
|
|
int clockrate,
|
|
|
|
|
|
size_t channels);
|
2016-12-06 05:36:03 -08:00
|
|
|
|
|
2023-06-20 17:12:57 +00:00
|
|
|
|
explicit Codec(const webrtc::SdpAudioFormat& c);
|
2023-06-04 23:22:36 +00:00
|
|
|
|
explicit Codec(const webrtc::SdpVideoFormat& c);
|
2023-06-14 11:22:38 +00:00
|
|
|
|
|
2023-06-04 23:22:36 +00:00
|
|
|
|
friend Codec CreateAudioCodec(int id,
|
|
|
|
|
|
const std::string& name,
|
|
|
|
|
|
int clockrate,
|
|
|
|
|
|
size_t channels);
|
2023-06-20 17:12:57 +00:00
|
|
|
|
friend Codec CreateAudioCodec(const webrtc::SdpAudioFormat& c);
|
2023-06-04 23:22:36 +00:00
|
|
|
|
friend Codec CreateAudioRtxCodec(int rtx_payload_type,
|
|
|
|
|
|
int associated_payload_type);
|
|
|
|
|
|
friend Codec CreateVideoCodec(int id, const std::string& name);
|
|
|
|
|
|
friend Codec CreateVideoCodec(const webrtc::SdpVideoFormat& c);
|
|
|
|
|
|
friend Codec CreateVideoRtxCodec(int rtx_payload_type,
|
|
|
|
|
|
int associated_payload_type);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2023-06-04 23:22:36 +00:00
|
|
|
|
// TODO(webrtc:15214): Compatibility names, to be migrated away and removed.
|
|
|
|
|
|
using VideoCodec = Codec;
|
|
|
|
|
|
using AudioCodec = Codec;
|
|
|
|
|
|
|
|
|
|
|
|
Codec CreateAudioCodec(int id,
|
|
|
|
|
|
const std::string& name,
|
|
|
|
|
|
int clockrate,
|
|
|
|
|
|
size_t channels);
|
2023-06-20 17:12:57 +00:00
|
|
|
|
Codec CreateAudioCodec(const webrtc::SdpAudioFormat& c);
|
2023-06-04 23:22:36 +00:00
|
|
|
|
Codec CreateAudioRtxCodec(int rtx_payload_type, int associated_payload_type);
|
|
|
|
|
|
Codec CreateVideoCodec(const std::string& name);
|
|
|
|
|
|
Codec CreateVideoCodec(int id, const std::string& name);
|
|
|
|
|
|
Codec CreateVideoCodec(const webrtc::SdpVideoFormat& c);
|
|
|
|
|
|
Codec CreateVideoRtxCodec(int rtx_payload_type, int associated_payload_type);
|
2023-05-31 12:35:47 +00:00
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
|
// Get the codec setting associated with `payload_type`. If there
|
2016-11-11 04:00:16 -08:00
|
|
|
|
// is no codec associated with that payload type it returns nullptr.
|
2015-03-16 04:14:34 +00:00
|
|
|
|
template <class Codec>
|
2016-11-11 04:00:16 -08:00
|
|
|
|
const Codec* FindCodecById(const std::vector<Codec>& codecs, int payload_type) {
|
2015-03-16 04:14:34 +00:00
|
|
|
|
for (const auto& codec : codecs) {
|
2016-11-11 04:00:16 -08:00
|
|
|
|
if (codec.id == payload_type)
|
|
|
|
|
|
return &codec;
|
2015-03-16 04:14:34 +00:00
|
|
|
|
}
|
2016-11-11 04:00:16 -08:00
|
|
|
|
return nullptr;
|
2015-03-16 04:14:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-24 13:40:02 +02:00
|
|
|
|
bool HasLntf(const Codec& codec);
|
2016-02-04 04:12:24 -08:00
|
|
|
|
bool HasNack(const Codec& codec);
|
|
|
|
|
|
bool HasRemb(const Codec& codec);
|
2018-04-04 16:33:49 +02:00
|
|
|
|
bool HasRrtr(const Codec& codec);
|
2016-02-04 04:12:24 -08:00
|
|
|
|
bool HasTransportCc(const Codec& codec);
|
2023-09-20 12:22:39 +02:00
|
|
|
|
|
2021-07-26 13:24:57 +02:00
|
|
|
|
// Returns the first codec in `supported_codecs` that matches `codec`, or
|
2016-11-12 09:53:04 -08:00
|
|
|
|
// nullptr if no codec matches.
|
|
|
|
|
|
const VideoCodec* FindMatchingCodec(
|
|
|
|
|
|
const std::vector<VideoCodec>& supported_codecs,
|
|
|
|
|
|
const VideoCodec& codec);
|
2015-04-21 20:24:50 +08:00
|
|
|
|
|
2023-09-20 12:22:39 +02:00
|
|
|
|
// Returns all codecs in `supported_codecs` that matches `codec`.
|
|
|
|
|
|
std::vector<const VideoCodec*> FindAllMatchingCodecs(
|
|
|
|
|
|
const std::vector<VideoCodec>& supported_codecs,
|
|
|
|
|
|
const VideoCodec& codec);
|
|
|
|
|
|
|
2020-03-29 22:17:00 +02:00
|
|
|
|
RTC_EXPORT void AddH264ConstrainedBaselineProfileToSupportedFormats(
|
|
|
|
|
|
std::vector<webrtc::SdpVideoFormat>* supported_formats);
|
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
|
} // namespace cricket
|
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
|
#endif // MEDIA_BASE_CODEC_H_
|