rtp_receiver.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright 2015 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. // This file contains classes that implement RtpReceiverInterface.
  11. // An RtpReceiver associates a MediaStreamTrackInterface with an underlying
  12. // transport (provided by cricket::VoiceChannel/cricket::VideoChannel)
  13. #ifndef PC_RTP_RECEIVER_H_
  14. #define PC_RTP_RECEIVER_H_
  15. #include <stdint.h>
  16. #include <string>
  17. #include <vector>
  18. #include "absl/types/optional.h"
  19. #include "api/crypto/frame_decryptor_interface.h"
  20. #include "api/media_stream_interface.h"
  21. #include "api/media_types.h"
  22. #include "api/rtp_parameters.h"
  23. #include "api/rtp_receiver_interface.h"
  24. #include "api/scoped_refptr.h"
  25. #include "api/video/video_frame.h"
  26. #include "api/video/video_sink_interface.h"
  27. #include "api/video/video_source_interface.h"
  28. #include "media/base/media_channel.h"
  29. #include "media/base/video_broadcaster.h"
  30. #include "pc/video_track_source.h"
  31. #include "rtc_base/ref_counted_object.h"
  32. #include "rtc_base/thread.h"
  33. namespace webrtc {
  34. // Internal class used by PeerConnection.
  35. class RtpReceiverInternal : public RtpReceiverInterface {
  36. public:
  37. // Stops receiving. The track may be reactivated.
  38. virtual void Stop() = 0;
  39. // Stops the receiver permanently.
  40. // Causes the associated track to enter kEnded state. Cannot be reversed.
  41. virtual void StopAndEndTrack() = 0;
  42. // Sets the underlying MediaEngine channel associated with this RtpSender.
  43. // A VoiceMediaChannel should be used for audio RtpSenders and
  44. // a VideoMediaChannel should be used for video RtpSenders.
  45. // Must call SetMediaChannel(nullptr) before the media channel is destroyed.
  46. virtual void SetMediaChannel(cricket::MediaChannel* media_channel) = 0;
  47. // Configures the RtpReceiver with the underlying media channel, with the
  48. // given SSRC as the stream identifier.
  49. virtual void SetupMediaChannel(uint32_t ssrc) = 0;
  50. // Configures the RtpReceiver with the underlying media channel to receive an
  51. // unsignaled receive stream.
  52. virtual void SetupUnsignaledMediaChannel() = 0;
  53. virtual void set_transport(
  54. rtc::scoped_refptr<DtlsTransportInterface> dtls_transport) = 0;
  55. // This SSRC is used as an identifier for the receiver between the API layer
  56. // and the WebRtcVideoEngine, WebRtcVoiceEngine layer.
  57. virtual uint32_t ssrc() const = 0;
  58. // Call this to notify the RtpReceiver when the first packet has been received
  59. // on the corresponding channel.
  60. virtual void NotifyFirstPacketReceived() = 0;
  61. // Set the associated remote media streams for this receiver. The remote track
  62. // will be removed from any streams that are no longer present and added to
  63. // any new streams.
  64. virtual void set_stream_ids(std::vector<std::string> stream_ids) = 0;
  65. // TODO(https://crbug.com/webrtc/9480): Remove SetStreams() in favor of
  66. // set_stream_ids() as soon as downstream projects are no longer dependent on
  67. // stream objects.
  68. virtual void SetStreams(
  69. const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) = 0;
  70. // Returns an ID that changes if the attached track changes, but
  71. // otherwise remains constant. Used to generate IDs for stats.
  72. // The special value zero means that no track is attached.
  73. virtual int AttachmentId() const = 0;
  74. protected:
  75. static int GenerateUniqueId();
  76. static std::vector<rtc::scoped_refptr<MediaStreamInterface>>
  77. CreateStreamsFromIds(std::vector<std::string> stream_ids);
  78. static void MaybeAttachFrameDecryptorToMediaChannel(
  79. const absl::optional<uint32_t>& ssrc,
  80. rtc::Thread* worker_thread,
  81. rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor,
  82. cricket::MediaChannel* media_channel,
  83. bool stopped);
  84. };
  85. } // namespace webrtc
  86. #endif // PC_RTP_RECEIVER_H_