1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
* Copyright 2025 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef PC_CODEC_VENDOR_H_
#define PC_CODEC_VENDOR_H_
#include <utility>
#include <vector>
#include "api/field_trials_view.h"
#include "api/rtc_error.h"
#include "api/rtp_transceiver_direction.h"
#include "call/payload_type.h"
#include "media/base/codec.h"
#include "media/base/codec_list.h"
#include "media/base/media_engine.h"
#include "pc/media_options.h"
#include "pc/session_description.h"
#include "pc/typed_codec_vendor.h"
namespace webrtc {
// This class contains the functions required to compute the list of codecs
// for SDP offer/answer. It is exposed to MediaSessionDescriptionFactory
// for the construction of offers and answers.
// TODO: bugs.webrtc.org/360058654 - complete the architectural changes
// The list of things to be done:
// - Make as much as possible private.
// - Split object usage into four objects: sender/receiver/audio/video.
// - Remove audio/video from the call names, merge code where possible.
// - Make the class instances owned by transceivers, so that codec
// lists can differ per transceiver.
// For cleanliness:
// - Thread guard
class CodecVendor {
public:
CodecVendor(MediaEngineInterface* media_engine,
bool rtx_enabled,
const FieldTrialsView& trials);
public:
RTCErrorOr<std::vector<Codec>> GetNegotiatedCodecsForOffer(
const MediaDescriptionOptions& media_description_options,
const MediaSessionOptions& session_options,
const ContentInfo* current_content,
PayloadTypeSuggester& pt_suggester);
RTCErrorOr<Codecs> GetNegotiatedCodecsForAnswer(
const MediaDescriptionOptions& media_description_options,
const MediaSessionOptions& session_options,
RtpTransceiverDirection offer_rtd,
RtpTransceiverDirection answer_rtd,
const ContentInfo* current_content,
std::vector<Codec> codecs_from_offer,
PayloadTypeSuggester& pt_suggester);
// Function exposed for issues.webrtc.org/412904801
// Modify the video codecs to return on subsequent GetNegotiated* calls.
// The input is a vector of pairs of codecs.
// For each pair, the first element is the codec to be replaced,
// and the second element is the codec to replace it with.
void ModifyVideoCodecs(std::vector<std::pair<Codec, Codec>> changes);
// Functions exposed for testing
void set_audio_codecs(const CodecList& send_codecs,
const CodecList& recv_codecs);
void set_audio_codecs(const std::vector<Codec>& send_codecs,
const std::vector<Codec>& recv_codecs) {
set_audio_codecs(CodecList::CreateFromTrustedData(send_codecs),
CodecList::CreateFromTrustedData(recv_codecs));
}
void set_video_codecs(const CodecList& send_codecs,
const CodecList& recv_codecs);
void set_video_codecs(const std::vector<Codec>& send_codecs,
const std::vector<Codec>& recv_codecs) {
set_video_codecs(CodecList::CreateFromTrustedData(send_codecs),
CodecList::CreateFromTrustedData(recv_codecs));
}
CodecList audio_sendrecv_codecs() const;
const CodecList& audio_send_codecs() const;
const CodecList& audio_recv_codecs() const;
CodecList video_sendrecv_codecs() const;
const CodecList& video_send_codecs() const;
const CodecList& video_recv_codecs() const;
private:
CodecList GetAudioCodecsForOffer(
const RtpTransceiverDirection& direction) const;
CodecList GetAudioCodecsForAnswer(
const RtpTransceiverDirection& offer,
const RtpTransceiverDirection& answer) const;
CodecList GetVideoCodecsForOffer(
const RtpTransceiverDirection& direction) const;
CodecList GetVideoCodecsForAnswer(
const RtpTransceiverDirection& offer,
const RtpTransceiverDirection& answer) const;
CodecList all_video_codecs() const;
CodecList all_audio_codecs() const;
TypedCodecVendor audio_send_codecs_;
TypedCodecVendor audio_recv_codecs_;
TypedCodecVendor video_send_codecs_;
TypedCodecVendor video_recv_codecs_;
};
// A class to assist in looking up data for a codec mapping.
// Pure virtual to allow implementations that depend on things that
// codec_vendor.h should not depend on.
// Pointers returned are not stable, and should not be stored.
class CodecLookupHelper {
public:
virtual ~CodecLookupHelper() = default;
virtual PayloadTypeSuggester* PayloadTypeSuggester() = 0;
// Look up the codec vendor to use, depending on context.
// This call may get additional arguments in the future, to aid
// in selection of the correct context.
virtual CodecVendor* GetCodecVendor() = 0;
};
} // namespace webrtc
// Re-export symbols from the webrtc namespace for backwards compatibility.
// TODO(bugs.webrtc.org/4222596): Remove once all references are updated.
#ifdef WEBRTC_ALLOW_DEPRECATED_NAMESPACES
namespace cricket {
using ::webrtc::CodecLookupHelper;
using ::webrtc::CodecVendor;
} // namespace cricket
#endif // WEBRTC_ALLOW_DEPRECATED_NAMESPACES
#endif // PC_CODEC_VENDOR_H_
|