webrtc_m130/pc/rtp_transceiver.cc

846 lines
30 KiB
C++
Raw Permalink Normal View History

/*
* Copyright 2017 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.
*/
#include "pc/rtp_transceiver.h"
#include <stdint.h>
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include <algorithm>
#include <cstddef>
#include <functional>
#include <iterator>
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "absl/algorithm/container.h"
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "api/audio_codecs/audio_codec_pair_id.h"
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include "api/audio_options.h"
#include "api/crypto/crypto_options.h"
#include "api/field_trials_view.h"
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include "api/jsep.h"
#include "api/media_types.h"
#include "api/rtc_error.h"
#include "api/rtp_parameters.h"
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include "api/rtp_receiver_interface.h"
#include "api/rtp_sender_interface.h"
#include "api/rtp_transceiver_direction.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include "api/task_queue/pending_task_safety_flag.h"
#include "api/task_queue/task_queue_base.h"
#include "api/video/video_bitrate_allocator_factory.h"
#include "api/video_codecs/scalability_mode.h"
#include "media/base/codec.h"
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
#include "media/base/codec_comparators.h"
#include "media/base/media_channel.h"
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include "media/base/media_config.h"
Reland "Don't create channel_manager++ when media_engine is not set" This reverts commit c6c02efb56b24df04ed9ab61252c14c7bddcca93. Reason for revert: Test now passes (and channel manager is gone) Original change's description: > Revert "Don't create channel_manager when media_engine is not set" > > This reverts commit c48ad732d6eb69f14dd6d44f801d62997cef2c2f. > > Reason for revert: breaks downstream project > > Original change's description: > > Don't create channel_manager when media_engine is not set > > > > Also remove a bunch of functions in ChannelManager that were just > > forwarding to MediaEngineInterface. > > > > Bug: webrtc:13931 > > Change-Id: Ia38591fd22c665cace16d032f5c1e384e413cded > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261304 > > Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#36801} > > Bug: webrtc:13931 > Change-Id: I1e260a2489547bd9483b50e043c28d2805b0fa5a > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261660 > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Owners-Override: Artem Titov <titovartem@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#36811} Bug: webrtc:13931 Change-Id: I7b5b45b46095c18d489b6a9fe4c625971d6b3da6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261661 Reviewed-by: Henrik Boström <hbos@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36976}
2022-05-23 14:57:47 +00:00
#include "media/base/media_engine.h"
#include "pc/channel.h"
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include "pc/channel_interface.h"
#include "pc/connection_context.h"
#include "pc/rtp_media_utils.h"
Reland "Run IWYU on some files I intend to work on" This reverts commit fe34363ca0ff9d79d7d0943a98ae3a5198e61f75. Reason for revert: Downstream error fixed. Original change's description: > Revert "Run IWYU on some files I intend to work on" > > This reverts commit 827da15f1408a399ed15ce5c9726b6af772fb71a. > > Reason for revert: Breaks downstream project > > Original change's description: > > Run IWYU on some files I intend to work on > > > > and files that broke when I fixed the first set. > > > > Bug: webrtc:42226242 > > Change-Id: I321cd63537ab3002098c7bdecd889a6fc5a1eb25 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353421 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > > Auto-Submit: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#42429} > > Bug: webrtc:42226242 > Change-Id: I6b18dced08669c6741c6a51768fbb8b9072c6e82 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353580 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Cr-Commit-Position: refs/heads/main@{#42430} Bug: webrtc:42226242 Change-Id: I8ba51da47ea34d6bbf868e5ebc0037c6cffec8ba Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353660 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42437}
2024-06-04 21:29:14 +00:00
#include "pc/rtp_receiver.h"
#include "pc/rtp_receiver_proxy.h"
#include "pc/rtp_sender.h"
#include "pc/rtp_sender_proxy.h"
#include "pc/rtp_transport_internal.h"
#include "pc/session_description.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/thread.h"
namespace webrtc {
namespace {
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
bool HasAnyMediaCodec(const std::vector<RtpCodecCapability>& codecs) {
return absl::c_any_of(codecs, [](const RtpCodecCapability& codec) {
return codec.IsMediaCodec();
});
}
RTCError VerifyCodecPreferences(
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
const std::vector<RtpCodecCapability>& codecs,
const std::vector<cricket::Codec>& send_codecs,
const std::vector<cricket::Codec>& recv_codecs) {
// `codec_capabilities` is the union of `send_codecs` and `recv_codecs`.
std::vector<cricket::Codec> codec_capabilities;
codec_capabilities.reserve(send_codecs.size() + recv_codecs.size());
codec_capabilities.insert(codec_capabilities.end(), send_codecs.begin(),
send_codecs.end());
codec_capabilities.insert(codec_capabilities.end(), recv_codecs.begin(),
recv_codecs.end());
// If a media codec is not recognized from `codec_capabilities`, throw
// InvalidModificationError.
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
if (!absl::c_all_of(codecs, [&codec_capabilities](
const RtpCodecCapability& codec) {
return !codec.IsMediaCodec() ||
absl::c_any_of(codec_capabilities,
[&codec](const cricket::Codec& codec_capability) {
return IsSameRtpCodec(codec_capability, codec);
});
})) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
"Invalid codec preferences: Missing codec from codec "
"capabilities.");
}
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
// If `codecs` only contains entries for RTX, RED, FEC or Comfort Noise, throw
// InvalidModificationError.
if (!HasAnyMediaCodec(codecs)) {
LOG_AND_RETURN_ERROR(
RTCErrorType::INVALID_MODIFICATION,
"Invalid codec preferences: codec list must have a non "
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
"RTX, RED, FEC or Comfort Noise entry.");
}
return RTCError::OK();
}
TaskQueueBase* GetCurrentTaskQueueOrThread() {
TaskQueueBase* current = TaskQueueBase::Current();
if (!current)
current = rtc::ThreadManager::Instance()->CurrentThread();
return current;
}
} // namespace
RtpTransceiver::RtpTransceiver(cricket::MediaType media_type,
ConnectionContext* context)
: thread_(GetCurrentTaskQueueOrThread()),
unified_plan_(false),
media_type_(media_type),
context_(context) {
RTC_DCHECK(media_type == cricket::MEDIA_TYPE_AUDIO ||
media_type == cricket::MEDIA_TYPE_VIDEO);
RTC_DCHECK(context_);
}
RtpTransceiver::RtpTransceiver(
rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender,
rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
receiver,
ConnectionContext* context,
std::vector<RtpHeaderExtensionCapability> header_extensions_to_negotiate,
std::function<void()> on_negotiation_needed)
: thread_(GetCurrentTaskQueueOrThread()),
unified_plan_(true),
media_type_(sender->media_type()),
context_(context),
header_extensions_to_negotiate_(
std::move(header_extensions_to_negotiate)),
on_negotiation_needed_(std::move(on_negotiation_needed)) {
RTC_DCHECK(context_);
RTC_DCHECK(media_type_ == cricket::MEDIA_TYPE_AUDIO ||
media_type_ == cricket::MEDIA_TYPE_VIDEO);
RTC_DCHECK_EQ(sender->media_type(), receiver->media_type());
sender->internal()->SetSendCodecs(
sender->media_type() == cricket::MEDIA_TYPE_VIDEO
? media_engine()->video().send_codecs(false)
: media_engine()->voice().send_codecs());
senders_.push_back(sender);
receivers_.push_back(receiver);
// Set default header extensions depending on whether simulcast/SVC is used.
RtpParameters parameters = sender->internal()->GetParametersInternal();
bool uses_simulcast = parameters.encodings.size() > 1;
bool uses_svc = !parameters.encodings.empty() &&
parameters.encodings[0].scalability_mode.has_value() &&
parameters.encodings[0].scalability_mode !=
ScalabilityModeToString(ScalabilityMode::kL1T1);
if (uses_simulcast || uses_svc) {
// Enable DD and VLA extensions, can be deactivated by the API.
// Skip this if the GFD extension was enabled via field trial
// for backward compability reasons.
bool uses_gfd =
absl::c_find_if(
header_extensions_to_negotiate_,
[](const RtpHeaderExtensionCapability& ext) {
return ext.uri == RtpExtension::kGenericFrameDescriptorUri00 &&
ext.direction != webrtc::RtpTransceiverDirection::kStopped;
}) != header_extensions_to_negotiate_.end();
if (!uses_gfd) {
for (RtpHeaderExtensionCapability& ext :
header_extensions_to_negotiate_) {
if (ext.uri == RtpExtension::kVideoLayersAllocationUri ||
ext.uri == RtpExtension::kDependencyDescriptorUri) {
ext.direction = RtpTransceiverDirection::kSendRecv;
}
}
}
}
}
RtpTransceiver::~RtpTransceiver() {
// TODO(tommi): On Android, when running PeerConnectionClientTest (e.g.
// PeerConnectionClientTest#testCameraSwitch), the instance doesn't get
// deleted on `thread_`. See if we can fix that.
if (!stopped_) {
RTC_DCHECK_RUN_ON(thread_);
StopInternal();
}
RTC_CHECK(!channel_) << "Missing call to ClearChannel?";
}
RTCError RtpTransceiver::CreateChannel(
absl::string_view mid,
Call* call_ptr,
const cricket::MediaConfig& media_config,
bool srtp_required,
CryptoOptions crypto_options,
const cricket::AudioOptions& audio_options,
const cricket::VideoOptions& video_options,
VideoBitrateAllocatorFactory* video_bitrate_allocator_factory,
std::function<RtpTransportInternal*(absl::string_view)> transport_lookup) {
RTC_DCHECK_RUN_ON(thread_);
RTC_DCHECK(!channel());
if (!media_engine()) {
// TODO(hta): Must be a better way
return RTCError(RTCErrorType::INTERNAL_ERROR,
"No media engine for mid=" + std::string(mid));
}
std::unique_ptr<cricket::ChannelInterface> new_channel;
if (media_type() == cricket::MEDIA_TYPE_AUDIO) {
// TODO(bugs.webrtc.org/11992): CreateVideoChannel internally switches to
// the worker thread. We shouldn't be using the `call_ptr_` hack here but
// simply be on the worker thread and use `call_` (update upstream code).
RTC_DCHECK(call_ptr);
// TODO(bugs.webrtc.org/11992): Remove this workaround after updates in
// PeerConnection and add the expectation that we're already on the right
// thread.
context()->worker_thread()->BlockingCall([&] {
RTC_DCHECK_RUN_ON(context()->worker_thread());
Reland "Use two MediaChannels for 2 directions." This reverts commit 18c869bc36b342cd4a79947067e52a93a04a7808. Reason for revert: Added a field trial that allows landing the code without affecting performance in prod. This CL also incorporates subsequent CLs that also had to be reverted. Original change's description: > Revert "Use two MediaChannels for 2 directions." > > This reverts commit 8981a6fac3d665beac4a58b9453e6c39988a024f. > > Reason for revert: Quality regression detected. > > Original change's description: > > Use two MediaChannels for 2 directions. > > > > This CL separates the two directions of MediaChannel into two separate objects that do not couple with each other. > > > > The notable API change is that receiver local SSRC now has to be set explicitly - before, it was done implicitly when the send-side MediaChannel had a stream added to it. > > > > Bug: webrtc:13931 > > Change-Id: I83c2e3c8e79f89872d5adda1bc2899f7049748b3 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288400 > > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39340} > > No-Try: true > Bug: webrtc:13931 > Change-Id: I791997ad9eff75c3ac9cd2e4bbacf5bc6c3a3a79 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/295663 > Commit-Queue: Harald Alvestrand <hta@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39445} Bug: webrtc:13931 Change-Id: I1318910a685188e2b846c9040e1efc04c2c894ac Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/296080 Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Per Kjellander <perkj@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39494}
2023-03-07 10:10:03 +00:00
AudioCodecPairId codec_pair_id = AudioCodecPairId::Create();
std::unique_ptr<cricket::VoiceMediaSendChannelInterface>
media_send_channel = media_engine()->voice().CreateSendChannel(
call_ptr, media_config, audio_options, crypto_options,
codec_pair_id);
std::unique_ptr<cricket::VoiceMediaReceiveChannelInterface>
media_receive_channel = media_engine()->voice().CreateReceiveChannel(
call_ptr, media_config, audio_options, crypto_options,
codec_pair_id);
// Note that this is safe because both sending and
// receiving channels will be deleted at the same time.
media_send_channel->SetSsrcListChangedCallback(
[receive_channel =
media_receive_channel.get()](const std::set<uint32_t>& choices) {
receive_channel->ChooseReceiverReportSsrc(choices);
});
new_channel = std::make_unique<cricket::VoiceChannel>(
context()->worker_thread(), context()->network_thread(),
context()->signaling_thread(), std::move(media_send_channel),
std::move(media_receive_channel), mid, srtp_required, crypto_options,
context()->ssrc_generator());
});
} else {
RTC_DCHECK_EQ(cricket::MEDIA_TYPE_VIDEO, media_type());
// TODO(bugs.webrtc.org/11992): CreateVideoChannel internally switches to
// the worker thread. We shouldn't be using the `call_ptr_` hack here but
// simply be on the worker thread and use `call_` (update upstream code).
context()->worker_thread()->BlockingCall([&] {
RTC_DCHECK_RUN_ON(context()->worker_thread());
std::unique_ptr<cricket::VideoMediaSendChannelInterface>
media_send_channel = media_engine()->video().CreateSendChannel(
call_ptr, media_config, video_options, crypto_options,
video_bitrate_allocator_factory);
std::unique_ptr<cricket::VideoMediaReceiveChannelInterface>
media_receive_channel = media_engine()->video().CreateReceiveChannel(
call_ptr, media_config, video_options, crypto_options);
// Note that this is safe because both sending and
// receiving channels will be deleted at the same time.
media_send_channel->SetSsrcListChangedCallback(
[receive_channel =
media_receive_channel.get()](const std::set<uint32_t>& choices) {
receive_channel->ChooseReceiverReportSsrc(choices);
});
new_channel = std::make_unique<cricket::VideoChannel>(
context()->worker_thread(), context()->network_thread(),
context()->signaling_thread(), std::move(media_send_channel),
std::move(media_receive_channel), mid, srtp_required, crypto_options,
context()->ssrc_generator());
});
}
SetChannel(std::move(new_channel), transport_lookup);
return RTCError::OK();
}
void RtpTransceiver::SetChannel(
std::unique_ptr<cricket::ChannelInterface> channel,
std::function<RtpTransportInternal*(const std::string&)> transport_lookup) {
RTC_DCHECK_RUN_ON(thread_);
RTC_DCHECK(channel);
RTC_DCHECK(transport_lookup);
RTC_DCHECK(!channel_);
// Cannot set a channel on a stopped transceiver.
if (stopped_) {
return;
}
Add utility to count the number of blocking thread invokes. This is useful to understand how often we block in certain parts of the api and track improvements/regressions. There are two macros, both are only active for RTC_DCHECK_IS_ON builds: * RTC_LOG_THREAD_BLOCK_COUNT() Example: void MyClass::MyFunction() { RTC_LOG_THREAD_BLOCK_COUNT(); thread_->Invoke<void>([this](){ DoStuff(); }); } When executing this function during a test, the output could be: (my_file.cc:2): Blocking MyFunction: total=1 (actual=1, would=0) The words 'actual' and 'would' reflect whether an actual thread switch was made, or if in the case of a test using the same thread for more than one role (e.g. signaling, worker, network are all the same thread) that an actual thread switch did not occur but it would have occurred in the case of having dedicated threads. The 'total' count is the sum. * RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(x) Example: void MyClass::MyFunction() { RTC_LOG_THREAD_BLOCK_COUNT(); thread_->Invoke<void>([this](){ DoStuff(); }); thread_->Invoke<void>([this](){ MoreStuff(); }); RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(1); } When a function is known to have blocking calls and we want to not regress from the currently known number of blocking calls, we can use this macro to state that at a certain point in a function, below where RTC_LOG_THREAD_BLOCK_COUNT() is called, there must have occurred no more than |x| (total) blocking calls. If more occur, a DCHECK will hit and print out what the actual number of calls was: # Fatal error in: my_file.cc, line 5 # last system error: 60 # Check failed: blocked_call_count_printer.GetTotalBlockedCallCount() <= 1 (2 vs. 1) Bug: webrtc:12649 Change-Id: Ibac4f85f00b89680601dba54a651eac95a0f45d3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213782 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33632}
2021-04-07 10:08:28 +02:00
RTC_LOG_THREAD_BLOCK_COUNT();
RTC_DCHECK_EQ(media_type(), channel->media_type());
signaling_thread_safety_ = PendingTaskSafetyFlag::Create();
channel_ = std::move(channel);
// An alternative to this, could be to require SetChannel to be called
// on the network thread. The channel object operates for the most part
// on the network thread, as part of its initialization being on the network
// thread is required, so setting a channel object as part of the construction
// (without thread hopping) might be the more efficient thing to do than
// how SetChannel works today.
// Similarly, if the channel() accessor is limited to the network thread, that
// helps with keeping the channel implementation requirements being met and
// avoids synchronization for accessing the pointer or network related state.
context()->network_thread()->BlockingCall([&]() {
channel_->SetRtpTransport(transport_lookup(channel_->mid()));
channel_->SetFirstPacketReceivedCallback(
[thread = thread_, flag = signaling_thread_safety_, this]() mutable {
thread->PostTask(
SafeTask(std::move(flag), [this]() { OnFirstPacketReceived(); }));
});
channel_->SetFirstPacketSentCallback(
[thread = thread_, flag = signaling_thread_safety_, this]() mutable {
thread->PostTask(
SafeTask(std::move(flag), [this]() { OnFirstPacketSent(); }));
});
});
PushNewMediaChannel();
RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(2);
}
void RtpTransceiver::ClearChannel() {
RTC_DCHECK_RUN_ON(thread_);
if (!channel_) {
return;
}
RTC_LOG_THREAD_BLOCK_COUNT();
signaling_thread_safety_->SetNotAlive();
signaling_thread_safety_ = nullptr;
context()->network_thread()->BlockingCall([&]() {
channel_->SetFirstPacketReceivedCallback(nullptr);
channel_->SetFirstPacketSentCallback(nullptr);
channel_->SetRtpTransport(nullptr);
});
RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(1);
DeleteChannel();
RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(2);
}
void RtpTransceiver::PushNewMediaChannel() {
RTC_DCHECK(channel_);
if (senders_.empty() && receivers_.empty()) {
return;
}
context()->worker_thread()->BlockingCall([&]() {
// Push down the new media_channel.
auto* media_send_channel = channel_->media_send_channel();
for (const auto& sender : senders_) {
sender->internal()->SetMediaChannel(media_send_channel);
}
auto* media_receive_channel = channel_->media_receive_channel();
for (const auto& receiver : receivers_) {
receiver->internal()->SetMediaChannel(media_receive_channel);
}
});
}
void RtpTransceiver::DeleteChannel() {
RTC_DCHECK(channel_);
// Ensure that channel_ is not reachable via transceiver, but is deleted
// only after clearing the references in senders_ and receivers_.
context()->worker_thread()->BlockingCall([&]() {
auto channel_to_delete = std::move(channel_);
// Clear the media channel reference from senders and receivers.
for (const auto& sender : senders_) {
sender->internal()->SetMediaChannel(nullptr);
}
for (const auto& receiver : receivers_) {
receiver->internal()->SetMediaChannel(nullptr);
}
// The channel is destroyed here, on the worker thread as it needs to
// be.
channel_to_delete.reset();
});
}
void RtpTransceiver::AddSender(
rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender) {
RTC_DCHECK_RUN_ON(thread_);
RTC_DCHECK(!stopped_);
RTC_DCHECK(!unified_plan_);
RTC_DCHECK(sender);
RTC_DCHECK_EQ(media_type(), sender->media_type());
RTC_DCHECK(!absl::c_linear_search(senders_, sender));
std::vector<cricket::Codec> send_codecs =
media_type() == cricket::MEDIA_TYPE_VIDEO
? media_engine()->video().send_codecs(false)
: media_engine()->voice().send_codecs();
sender->internal()->SetSendCodecs(send_codecs);
senders_.push_back(sender);
}
bool RtpTransceiver::RemoveSender(RtpSenderInterface* sender) {
RTC_DCHECK(!unified_plan_);
if (sender) {
RTC_DCHECK_EQ(media_type(), sender->media_type());
}
auto it = absl::c_find(senders_, sender);
if (it == senders_.end()) {
return false;
}
(*it)->internal()->Stop();
senders_.erase(it);
return true;
}
void RtpTransceiver::AddReceiver(
rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
receiver) {
RTC_DCHECK_RUN_ON(thread_);
RTC_DCHECK(!stopped_);
RTC_DCHECK(!unified_plan_);
RTC_DCHECK(receiver);
RTC_DCHECK_EQ(media_type(), receiver->media_type());
RTC_DCHECK(!absl::c_linear_search(receivers_, receiver));
receivers_.push_back(receiver);
}
bool RtpTransceiver::RemoveReceiver(RtpReceiverInterface* receiver) {
RTC_DCHECK_RUN_ON(thread_);
RTC_DCHECK(!unified_plan_);
if (receiver) {
RTC_DCHECK_EQ(media_type(), receiver->media_type());
}
auto it = absl::c_find(receivers_, receiver);
if (it == receivers_.end()) {
return false;
}
(*it)->internal()->Stop();
context()->worker_thread()->BlockingCall([&]() {
// `Stop()` will clear the receiver's pointer to the media channel.
(*it)->internal()->SetMediaChannel(nullptr);
});
receivers_.erase(it);
return true;
}
rtc::scoped_refptr<RtpSenderInternal> RtpTransceiver::sender_internal() const {
RTC_DCHECK(unified_plan_);
RTC_CHECK_EQ(1u, senders_.size());
return rtc::scoped_refptr<RtpSenderInternal>(senders_[0]->internal());
}
rtc::scoped_refptr<RtpReceiverInternal> RtpTransceiver::receiver_internal()
const {
RTC_DCHECK(unified_plan_);
RTC_CHECK_EQ(1u, receivers_.size());
return rtc::scoped_refptr<RtpReceiverInternal>(receivers_[0]->internal());
}
cricket::MediaType RtpTransceiver::media_type() const {
return media_type_;
}
std::optional<std::string> RtpTransceiver::mid() const {
return mid_;
}
void RtpTransceiver::OnFirstPacketReceived() {
for (const auto& receiver : receivers_) {
receiver->internal()->NotifyFirstPacketReceived();
}
}
void RtpTransceiver::OnFirstPacketSent() {
for (const auto& sender : senders_) {
sender->internal()->NotifyFirstPacketSent();
}
}
rtc::scoped_refptr<RtpSenderInterface> RtpTransceiver::sender() const {
RTC_DCHECK(unified_plan_);
RTC_CHECK_EQ(1u, senders_.size());
return senders_[0];
}
rtc::scoped_refptr<RtpReceiverInterface> RtpTransceiver::receiver() const {
RTC_DCHECK(unified_plan_);
RTC_CHECK_EQ(1u, receivers_.size());
return receivers_[0];
}
void RtpTransceiver::set_current_direction(RtpTransceiverDirection direction) {
RTC_LOG(LS_INFO) << "Changing transceiver (MID=" << mid_.value_or("<not set>")
<< ") current direction from "
<< (current_direction_ ? RtpTransceiverDirectionToString(
*current_direction_)
: "<not set>")
<< " to " << RtpTransceiverDirectionToString(direction)
<< ".";
current_direction_ = direction;
if (RtpTransceiverDirectionHasSend(*current_direction_)) {
has_ever_been_used_to_send_ = true;
}
}
void RtpTransceiver::set_fired_direction(
std::optional<RtpTransceiverDirection> direction) {
fired_direction_ = direction;
}
bool RtpTransceiver::stopped() const {
RTC_DCHECK_RUN_ON(thread_);
return stopped_;
}
bool RtpTransceiver::stopping() const {
RTC_DCHECK_RUN_ON(thread_);
return stopping_;
}
RtpTransceiverDirection RtpTransceiver::direction() const {
if (unified_plan_ && stopping())
return RtpTransceiverDirection::kStopped;
return direction_;
}
RTCError RtpTransceiver::SetDirectionWithError(
RtpTransceiverDirection new_direction) {
if (unified_plan_ && stopping()) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_STATE,
"Cannot set direction on a stopping transceiver.");
}
if (new_direction == direction_)
return RTCError::OK();
if (new_direction == RtpTransceiverDirection::kStopped) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
"The set direction 'stopped' is invalid.");
}
direction_ = new_direction;
on_negotiation_needed_();
return RTCError::OK();
}
std::optional<RtpTransceiverDirection> RtpTransceiver::current_direction()
const {
if (unified_plan_ && stopped())
return RtpTransceiverDirection::kStopped;
return current_direction_;
}
std::optional<RtpTransceiverDirection> RtpTransceiver::fired_direction() const {
return fired_direction_;
}
void RtpTransceiver::StopSendingAndReceiving() {
// 1. Let sender be transceiver.[[Sender]].
// 2. Let receiver be transceiver.[[Receiver]].
//
// 3. Stop sending media with sender.
//
RTC_DCHECK_RUN_ON(thread_);
// 4. Send an RTCP BYE for each RTP stream that was being sent by sender, as
// specified in [RFC3550].
for (const auto& sender : senders_)
sender->internal()->Stop();
// Signal to receiver sources that we're stopping.
for (const auto& receiver : receivers_)
receiver->internal()->Stop();
context()->worker_thread()->BlockingCall([&]() {
// 5 Stop receiving media with receiver.
for (const auto& receiver : receivers_)
receiver->internal()->SetMediaChannel(nullptr);
});
stopping_ = true;
direction_ = RtpTransceiverDirection::kInactive;
}
RTCError RtpTransceiver::StopStandard() {
RTC_DCHECK_RUN_ON(thread_);
// If we're on Plan B, do what Stop() used to do there.
if (!unified_plan_) {
StopInternal();
return RTCError::OK();
}
// 1. Let transceiver be the RTCRtpTransceiver object on which the method is
// invoked.
//
// 2. Let connection be the RTCPeerConnection object associated with
// transceiver.
//
// 3. If connection.[[IsClosed]] is true, throw an InvalidStateError.
if (is_pc_closed_) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_STATE,
"PeerConnection is closed.");
}
// 4. If transceiver.[[Stopping]] is true, abort these steps.
if (stopping_)
return RTCError::OK();
// 5. Stop sending and receiving given transceiver, and update the
// negotiation-needed flag for connection.
StopSendingAndReceiving();
on_negotiation_needed_();
return RTCError::OK();
}
void RtpTransceiver::StopInternal() {
RTC_DCHECK_RUN_ON(thread_);
StopTransceiverProcedure();
}
void RtpTransceiver::StopTransceiverProcedure() {
RTC_DCHECK_RUN_ON(thread_);
// As specified in the "Stop the RTCRtpTransceiver" procedure
// 1. If transceiver.[[Stopping]] is false, stop sending and receiving given
// transceiver.
if (!stopping_)
StopSendingAndReceiving();
// 2. Set transceiver.[[Stopped]] to true.
stopped_ = true;
// Signal the updated change to the senders.
for (const auto& sender : senders_)
sender->internal()->SetTransceiverAsStopped();
// 3. Set transceiver.[[Receptive]] to false.
// 4. Set transceiver.[[CurrentDirection]] to null.
current_direction_ = std::nullopt;
}
RTCError RtpTransceiver::SetCodecPreferences(
rtc::ArrayView<RtpCodecCapability> codec_capabilities) {
RTC_DCHECK(unified_plan_);
// 3. If codecs is an empty list, set transceiver's [[PreferredCodecs]] slot
// to codecs and abort these steps.
if (codec_capabilities.empty()) {
codec_preferences_.clear();
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
sendrecv_codec_preferences_.clear();
sendonly_codec_preferences_.clear();
recvonly_codec_preferences_.clear();
return RTCError::OK();
}
// 4. Remove any duplicate values in codecs.
std::vector<RtpCodecCapability> codecs;
absl::c_remove_copy_if(codec_capabilities, std::back_inserter(codecs),
[&codecs](const RtpCodecCapability& codec) {
return absl::c_linear_search(codecs, codec);
});
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
// TODO(https://crbug.com/webrtc/391530822): Move logic in
// MediaSessionDescriptionFactory to this level.
return UpdateCodecPreferencesCaches(codecs);
}
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
RTCError RtpTransceiver::UpdateCodecPreferencesCaches(
const std::vector<RtpCodecCapability>& codecs) {
// Get codec capabilities from media engine.
std::vector<cricket::Codec> send_codecs, recv_codecs;
if (media_type_ == cricket::MEDIA_TYPE_AUDIO) {
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
send_codecs = media_engine()->voice().send_codecs();
recv_codecs = media_engine()->voice().recv_codecs();
Revert "Reland "Reland "Reland "Distinguish between send and receive codecs"""" This reverts commit 184ea66aed43161f05d80fbb74183a2efccca352. Reason for revert: Breaks downstream projects. TBR=steveanton@webrtc.org Original change's description: > Reland "Reland "Reland "Distinguish between send and receive codecs""" > > This reverts commit a104ceb0ceec0f95e199e6d6704f41ec88a51fc5. > > Reason for revert: Keep logic as is. > > Original change's description: > > Revert "Reland "Reland "Distinguish between send and receive codecs""" > > > > This reverts commit 9bac68c0cc4444b852416396f0e0f31ea66a9cfe. > > > > Reason for revert: Breaks perf test on iOS. > > > > Original change's description: > > > Reland "Reland "Distinguish between send and receive codecs"" > > > > > > This reverts commit 00a30873c415d717af8dcdf21c2df7fd4b6d1ed2. > > > > > > Reason for revert: Flaky test in Chromium fixed. > > > > > > Original change's description: > > > > Revert "Reland "Distinguish between send and receive codecs"" > > > > > > > > This reverts commit 133bf2bd28596aab5c7684e0ea3da99b1fece77f. > > > > > > > > Reason for revert: Breaks Chromium import due to flaky test in Chromium. > > > > > > > > Original change's description: > > > > > Reland "Distinguish between send and receive codecs" > > > > > > > > > > This reverts commit e57b266a20334e47f105a0bd777190ec8c6562e8. > > > > > > > > > > Reason for revert: Fixed negotiation of send-only clients. > > > > > > > > > > Original change's description: > > > > > > Revert "Distinguish between send and receive codecs" > > > > > > > > > > > > This reverts commit c0f25cf762a6946666c812f7a3df3f0a7f98b38d. > > > > > > > > > > > > Reason for revert: breaks negotiation with send-only clients > > > > > > > > > > > > (webrtc_video_engine.cc:985): SetRecvParameters called with unsupported video codec: VideoCodec[96:H264] > > > > > > (peer_connection.cc:6043): Failed to set local video description recv parameters. (INVALID_PARAMETER) > > > > > > (peer_connection.cc:2591): Failed to set local offer sdp: Failed to set local video description recv parameters. > > > > > > > > > > > > Original change's description: > > > > > > > Distinguish between send and receive codecs > > > > > > > > > > > > > > Even though send and receive codecs may be the same, they might have > > > > > > > different support in HW. Distinguish between send and receive codecs > > > > > > > to be able to keep track of which codecs have HW support. > > > > > > > > > > > > > > Bug: chromium:1029737 > > > > > > > Change-Id: Id119560becadfe0aaf861c892a6485f1c2eb378d > > > > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165763 > > > > > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > > > > Cr-Commit-Position: refs/heads/master@{#30284} > > > > > > > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > > > > > > > Change-Id: Iacb7059436b2313b52577b65f164ee363c4816aa > > > > > > No-Presubmit: true > > > > > > No-Tree-Checks: true > > > > > > No-Try: true > > > > > > Bug: chromium:1029737 > > > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166420 > > > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > > > Commit-Queue: Steve Anton <steveanton@webrtc.org> > > > > > > Cr-Commit-Position: refs/heads/master@{#30292} > > > > > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > > > > > > > > > > Bug: chromium:1029737 > > > > > Change-Id: I287efcfdcd1c9a3f2c410aeec8fe26a84204d1fd > > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166604 > > > > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > > > Cr-Commit-Position: refs/heads/master@{#30348} > > > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > > > Change-Id: I9f8731309749e07ce7e651e1550ecfabddb1735f > > > > No-Presubmit: true > > > > No-Tree-Checks: true > > > > No-Try: true > > > > Bug: chromium:1029737 > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167205 > > > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > > Cr-Commit-Position: refs/heads/master@{#30360} > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > Change-Id: I1cc2d83bd884f10685503a9c31288f96c935d6a3 > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Bug: chromium:1029737 > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167206 > > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > Cr-Commit-Position: refs/heads/master@{#30367} > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > Change-Id: I0a9b0b58922ce7c558b3d31b64cc12086b2a6a55 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:1029737 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167364 > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#30373} > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > Bug: chromium:1029737 > Change-Id: Id381cb6d8e03b0fca941e392978362af6fdab0b6 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167531 > Reviewed-by: Johannes Kron <kron@webrtc.org> > Reviewed-by: Steve Anton <steveanton@webrtc.org> > Commit-Queue: Johannes Kron <kron@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#30415} TBR=steveanton@webrtc.org,kron@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1029737 Change-Id: Ice25339e7dfb9fc75049bd207d097b0910bd4446 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168341 Commit-Queue: Johannes Kron <kron@webrtc.org> Reviewed-by: Johannes Kron <kron@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30484}
2020-02-07 14:23:45 +00:00
} else if (media_type_ == cricket::MEDIA_TYPE_VIDEO) {
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
send_codecs = media_engine()->video().send_codecs();
recv_codecs = media_engine()->video().recv_codecs(context()->use_rtx());
Reland "Reland "Reland "Distinguish between send and receive codecs""" This reverts commit a104ceb0ceec0f95e199e6d6704f41ec88a51fc5. Reason for revert: Keep logic as is. Original change's description: > Revert "Reland "Reland "Distinguish between send and receive codecs""" > > This reverts commit 9bac68c0cc4444b852416396f0e0f31ea66a9cfe. > > Reason for revert: Breaks perf test on iOS. > > Original change's description: > > Reland "Reland "Distinguish between send and receive codecs"" > > > > This reverts commit 00a30873c415d717af8dcdf21c2df7fd4b6d1ed2. > > > > Reason for revert: Flaky test in Chromium fixed. > > > > Original change's description: > > > Revert "Reland "Distinguish between send and receive codecs"" > > > > > > This reverts commit 133bf2bd28596aab5c7684e0ea3da99b1fece77f. > > > > > > Reason for revert: Breaks Chromium import due to flaky test in Chromium. > > > > > > Original change's description: > > > > Reland "Distinguish between send and receive codecs" > > > > > > > > This reverts commit e57b266a20334e47f105a0bd777190ec8c6562e8. > > > > > > > > Reason for revert: Fixed negotiation of send-only clients. > > > > > > > > Original change's description: > > > > > Revert "Distinguish between send and receive codecs" > > > > > > > > > > This reverts commit c0f25cf762a6946666c812f7a3df3f0a7f98b38d. > > > > > > > > > > Reason for revert: breaks negotiation with send-only clients > > > > > > > > > > (webrtc_video_engine.cc:985): SetRecvParameters called with unsupported video codec: VideoCodec[96:H264] > > > > > (peer_connection.cc:6043): Failed to set local video description recv parameters. (INVALID_PARAMETER) > > > > > (peer_connection.cc:2591): Failed to set local offer sdp: Failed to set local video description recv parameters. > > > > > > > > > > Original change's description: > > > > > > Distinguish between send and receive codecs > > > > > > > > > > > > Even though send and receive codecs may be the same, they might have > > > > > > different support in HW. Distinguish between send and receive codecs > > > > > > to be able to keep track of which codecs have HW support. > > > > > > > > > > > > Bug: chromium:1029737 > > > > > > Change-Id: Id119560becadfe0aaf861c892a6485f1c2eb378d > > > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165763 > > > > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > > > Cr-Commit-Position: refs/heads/master@{#30284} > > > > > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > > > > > Change-Id: Iacb7059436b2313b52577b65f164ee363c4816aa > > > > > No-Presubmit: true > > > > > No-Tree-Checks: true > > > > > No-Try: true > > > > > Bug: chromium:1029737 > > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166420 > > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > > Commit-Queue: Steve Anton <steveanton@webrtc.org> > > > > > Cr-Commit-Position: refs/heads/master@{#30292} > > > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > > > > > > > Bug: chromium:1029737 > > > > Change-Id: I287efcfdcd1c9a3f2c410aeec8fe26a84204d1fd > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166604 > > > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > > Cr-Commit-Position: refs/heads/master@{#30348} > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > Change-Id: I9f8731309749e07ce7e651e1550ecfabddb1735f > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Bug: chromium:1029737 > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167205 > > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > Cr-Commit-Position: refs/heads/master@{#30360} > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > Change-Id: I1cc2d83bd884f10685503a9c31288f96c935d6a3 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:1029737 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167206 > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#30367} > > TBR=steveanton@webrtc.org,kron@webrtc.org > > Change-Id: I0a9b0b58922ce7c558b3d31b64cc12086b2a6a55 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: chromium:1029737 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167364 > Commit-Queue: Johannes Kron <kron@webrtc.org> > Reviewed-by: Johannes Kron <kron@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#30373} TBR=steveanton@webrtc.org,kron@webrtc.org Bug: chromium:1029737 Change-Id: Id381cb6d8e03b0fca941e392978362af6fdab0b6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167531 Reviewed-by: Johannes Kron <kron@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Commit-Queue: Johannes Kron <kron@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30415}
2020-01-29 12:43:36 +01:00
}
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
RTCError error = VerifyCodecPreferences(codecs, send_codecs, recv_codecs);
if (!error.ok()) {
return error;
}
codec_preferences_ = codecs;
// Update the filtered views of `codec_preferences_` so that we don't have
// to query codec capabilities when calling filtered_codec_preferences() or
// every time the direction changes.
sendrecv_codec_preferences_.clear();
sendonly_codec_preferences_.clear();
recvonly_codec_preferences_.clear();
for (const RtpCodecCapability& codec : codec_preferences_) {
if (!codec.IsMediaCodec()) {
// Non-media codecs don't need to be filtered at this level.
sendrecv_codec_preferences_.push_back(codec);
sendonly_codec_preferences_.push_back(codec);
recvonly_codec_preferences_.push_back(codec);
continue;
}
// Is this a send codec, receive codec or both?
bool is_send_codec =
absl::c_any_of(send_codecs, [&codec](const cricket::Codec& send_codec) {
return IsSameRtpCodecIgnoringLevel(send_codec, codec);
});
bool is_recv_codec =
absl::c_any_of(recv_codecs, [&codec](const cricket::Codec& recv_codec) {
return IsSameRtpCodecIgnoringLevel(recv_codec, codec);
});
// The codec being neither for sending or receving is not possible because
// of prior validation by VerifyCodecPreferences().
RTC_CHECK(is_send_codec || is_recv_codec);
if (is_send_codec && is_recv_codec) {
sendrecv_codec_preferences_.push_back(codec);
}
if (is_send_codec) {
sendonly_codec_preferences_.push_back(codec);
}
if (is_recv_codec) {
recvonly_codec_preferences_.push_back(codec);
}
}
// If filtering results in an empty list this is the same as not having any
// preferences.
if (!HasAnyMediaCodec(sendrecv_codec_preferences_)) {
sendrecv_codec_preferences_.clear();
}
if (!HasAnyMediaCodec(sendonly_codec_preferences_)) {
sendonly_codec_preferences_.clear();
}
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
if (!HasAnyMediaCodec(recvonly_codec_preferences_)) {
recvonly_codec_preferences_.clear();
}
return RTCError::OK();
}
Revert "Reland "Reland "Reland "Distinguish between send and receive codecs"""" This reverts commit 184ea66aed43161f05d80fbb74183a2efccca352. Reason for revert: Breaks downstream projects. TBR=steveanton@webrtc.org Original change's description: > Reland "Reland "Reland "Distinguish between send and receive codecs""" > > This reverts commit a104ceb0ceec0f95e199e6d6704f41ec88a51fc5. > > Reason for revert: Keep logic as is. > > Original change's description: > > Revert "Reland "Reland "Distinguish between send and receive codecs""" > > > > This reverts commit 9bac68c0cc4444b852416396f0e0f31ea66a9cfe. > > > > Reason for revert: Breaks perf test on iOS. > > > > Original change's description: > > > Reland "Reland "Distinguish between send and receive codecs"" > > > > > > This reverts commit 00a30873c415d717af8dcdf21c2df7fd4b6d1ed2. > > > > > > Reason for revert: Flaky test in Chromium fixed. > > > > > > Original change's description: > > > > Revert "Reland "Distinguish between send and receive codecs"" > > > > > > > > This reverts commit 133bf2bd28596aab5c7684e0ea3da99b1fece77f. > > > > > > > > Reason for revert: Breaks Chromium import due to flaky test in Chromium. > > > > > > > > Original change's description: > > > > > Reland "Distinguish between send and receive codecs" > > > > > > > > > > This reverts commit e57b266a20334e47f105a0bd777190ec8c6562e8. > > > > > > > > > > Reason for revert: Fixed negotiation of send-only clients. > > > > > > > > > > Original change's description: > > > > > > Revert "Distinguish between send and receive codecs" > > > > > > > > > > > > This reverts commit c0f25cf762a6946666c812f7a3df3f0a7f98b38d. > > > > > > > > > > > > Reason for revert: breaks negotiation with send-only clients > > > > > > > > > > > > (webrtc_video_engine.cc:985): SetRecvParameters called with unsupported video codec: VideoCodec[96:H264] > > > > > > (peer_connection.cc:6043): Failed to set local video description recv parameters. (INVALID_PARAMETER) > > > > > > (peer_connection.cc:2591): Failed to set local offer sdp: Failed to set local video description recv parameters. > > > > > > > > > > > > Original change's description: > > > > > > > Distinguish between send and receive codecs > > > > > > > > > > > > > > Even though send and receive codecs may be the same, they might have > > > > > > > different support in HW. Distinguish between send and receive codecs > > > > > > > to be able to keep track of which codecs have HW support. > > > > > > > > > > > > > > Bug: chromium:1029737 > > > > > > > Change-Id: Id119560becadfe0aaf861c892a6485f1c2eb378d > > > > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165763 > > > > > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > > > > Cr-Commit-Position: refs/heads/master@{#30284} > > > > > > > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > > > > > > > Change-Id: Iacb7059436b2313b52577b65f164ee363c4816aa > > > > > > No-Presubmit: true > > > > > > No-Tree-Checks: true > > > > > > No-Try: true > > > > > > Bug: chromium:1029737 > > > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166420 > > > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > > > Commit-Queue: Steve Anton <steveanton@webrtc.org> > > > > > > Cr-Commit-Position: refs/heads/master@{#30292} > > > > > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > > > > > > > > > > Bug: chromium:1029737 > > > > > Change-Id: I287efcfdcd1c9a3f2c410aeec8fe26a84204d1fd > > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166604 > > > > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > > > Cr-Commit-Position: refs/heads/master@{#30348} > > > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > > > Change-Id: I9f8731309749e07ce7e651e1550ecfabddb1735f > > > > No-Presubmit: true > > > > No-Tree-Checks: true > > > > No-Try: true > > > > Bug: chromium:1029737 > > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167205 > > > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > > Cr-Commit-Position: refs/heads/master@{#30360} > > > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > > > Change-Id: I1cc2d83bd884f10685503a9c31288f96c935d6a3 > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Bug: chromium:1029737 > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167206 > > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > > Cr-Commit-Position: refs/heads/master@{#30367} > > > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > > Change-Id: I0a9b0b58922ce7c558b3d31b64cc12086b2a6a55 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:1029737 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167364 > > Commit-Queue: Johannes Kron <kron@webrtc.org> > > Reviewed-by: Johannes Kron <kron@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#30373} > > TBR=steveanton@webrtc.org,kron@webrtc.org > > > Bug: chromium:1029737 > Change-Id: Id381cb6d8e03b0fca941e392978362af6fdab0b6 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167531 > Reviewed-by: Johannes Kron <kron@webrtc.org> > Reviewed-by: Steve Anton <steveanton@webrtc.org> > Commit-Queue: Johannes Kron <kron@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#30415} TBR=steveanton@webrtc.org,kron@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: chromium:1029737 Change-Id: Ice25339e7dfb9fc75049bd207d097b0910bd4446 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168341 Commit-Queue: Johannes Kron <kron@webrtc.org> Reviewed-by: Johannes Kron <kron@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30484}
2020-02-07 14:23:45 +00:00
Add unidirectional codec support ("offer to send" use case). This CL implements allowing sendonly codecs in setCodecPreferences(), i.e. this spec PR: https://github.com/w3c/webrtc-pc/pull/3018. It also makes the setCodecPreferences() ignore level IDs in the filtering algorithm (but not in the sCP method call) as per this spec PR: https://github.com/w3c/webrtc-pc/pull/3023. In short, before this CL, setCodecPreferences() threw an exception if a codec was preferred that is not present in receiver codec capabilities. After this CL, setCodecPreferences() allows you to prefer codecs that are *either* in the sender capabilities *or* the receiver capabilities. - This allows you to "offer to send", i.e. prefer sendonly codecs on a sendonly transceiver. - The filtering on direction is handled by RtpTransceiver::filtered_codec_preferences() which is called during SDP offer/answer (sdp_offer_answer.cc). Also as per spec changes, if this filtering results in not having any codecs to offer or answer then this results in not having any codec preferences as opposed to throwing an exception (old behavior). - Two old peer_connection_media_unittest.cc tests are updated to reflect the API failing less. This CL adds both unit tests (rtp_transceiver_unittest.cc) and full stack integration tests (peer_connection_encodings_integrationtest.cc). It also makes us pass the following Web Platform Tests in Chrome: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/h265-level-id.https.html Bug: chromium:381407888 Change-Id: I98a5ad1acccb56db0538e4d47975b8a725102c33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374520 Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43788}
2025-01-22 15:13:37 +01:00
std::vector<RtpCodecCapability> RtpTransceiver::codec_preferences() const {
return codec_preferences_;
}
std::vector<RtpCodecCapability> RtpTransceiver::filtered_codec_preferences()
const {
switch (direction_) {
case RtpTransceiverDirection::kSendRecv:
case RtpTransceiverDirection::kInactive:
case RtpTransceiverDirection::kStopped:
return sendrecv_codec_preferences_;
case RtpTransceiverDirection::kSendOnly:
return sendonly_codec_preferences_;
case RtpTransceiverDirection::kRecvOnly:
return recvonly_codec_preferences_;
}
return codec_preferences_;
}
std::vector<RtpHeaderExtensionCapability>
RtpTransceiver::GetHeaderExtensionsToNegotiate() const {
return header_extensions_to_negotiate_;
}
std::vector<RtpHeaderExtensionCapability>
RtpTransceiver::GetNegotiatedHeaderExtensions() const {
RTC_DCHECK_RUN_ON(thread_);
std::vector<RtpHeaderExtensionCapability> result;
result.reserve(header_extensions_to_negotiate_.size());
for (const auto& ext : header_extensions_to_negotiate_) {
auto negotiated = absl::c_find_if(negotiated_header_extensions_,
[&ext](const RtpExtension& negotiated) {
return negotiated.uri == ext.uri;
});
RtpHeaderExtensionCapability capability(ext.uri);
// TODO(bugs.webrtc.org/7477): extend when header extensions support
// direction.
capability.direction = negotiated != negotiated_header_extensions_.end()
? RtpTransceiverDirection::kSendRecv
: RtpTransceiverDirection::kStopped;
result.push_back(capability);
}
return result;
}
// Helper function to determine mandatory-to-negotiate extensions.
// See https://www.rfc-editor.org/rfc/rfc8834#name-header-extensions
// and https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
// Since BUNDLE is offered by default, MID is mandatory and can not be turned
// off via this API.
bool IsMandatoryHeaderExtension(const std::string& uri) {
return uri == RtpExtension::kMidUri;
}
RTCError RtpTransceiver::SetHeaderExtensionsToNegotiate(
rtc::ArrayView<const RtpHeaderExtensionCapability> header_extensions) {
// https://w3c.github.io/webrtc-extensions/#dom-rtcrtptransceiver-setheaderextensionstonegotiate
if (header_extensions.size() != header_extensions_to_negotiate_.size()) {
return RTCError(RTCErrorType::INVALID_MODIFICATION,
"Size of extensions to negotiate does not match.");
}
// For each index i of extensions, run the following steps: ...
for (size_t i = 0; i < header_extensions.size(); i++) {
const auto& extension = header_extensions[i];
if (extension.uri != header_extensions_to_negotiate_[i].uri) {
return RTCError(RTCErrorType::INVALID_MODIFICATION,
"Reordering extensions is not allowed.");
}
if (IsMandatoryHeaderExtension(extension.uri) &&
extension.direction != RtpTransceiverDirection::kSendRecv) {
return RTCError(RTCErrorType::INVALID_MODIFICATION,
"Attempted to stop a mandatory extension.");
}
// TODO(bugs.webrtc.org/7477): Currently there are no recvonly extensions so
// this can not be checked: "When there exists header extension capabilities
// that have directions other than kSendRecv, restrict extension.direction
// as to not exceed that capability."
}
// Apply mutation after error checking.
for (size_t i = 0; i < header_extensions.size(); i++) {
header_extensions_to_negotiate_[i].direction =
header_extensions[i].direction;
}
return RTCError::OK();
}
void RtpTransceiver::OnNegotiationUpdate(
SdpType sdp_type,
const cricket::MediaContentDescription* content) {
RTC_DCHECK_RUN_ON(thread_);
RTC_DCHECK(content);
if (sdp_type == SdpType::kAnswer)
negotiated_header_extensions_ = content->rtp_header_extensions();
}
void RtpTransceiver::SetPeerConnectionClosed() {
is_pc_closed_ = true;
}
} // namespace webrtc