blob: 4e0a40672cc7e0a17a641bc549db09a98846e731 [file] [log] [blame]
deadbeefe814a0d2017-02-25 18:15:09 -08001/*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef ORTC_ORTCRTPRECEIVERADAPTER_H_
12#define ORTC_ORTCRTPRECEIVERADAPTER_H_
deadbeefe814a0d2017-02-25 18:15:09 -080013
14#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/ortc/ortcrtpreceiverinterface.h"
17#include "api/rtcerror.h"
18#include "api/rtpparameters.h"
19#include "ortc/rtptransportcontrolleradapter.h"
20#include "pc/rtpreceiver.h"
21#include "rtc_base/constructormagic.h"
22#include "rtc_base/sigslot.h"
23#include "rtc_base/thread.h"
deadbeefe814a0d2017-02-25 18:15:09 -080024
25namespace webrtc {
26
27// Implementation of OrtcRtpReceiverInterface that works with
28// RtpTransportAdapter, and wraps a VideoRtpReceiver/AudioRtpReceiver that's
29// normally used with the PeerConnection.
30//
31// TODO(deadbeef): When BaseChannel is split apart into separate
32// "RtpReceiver"/"RtpTransceiver"/"RtpReceiver"/"RtpReceiver" objects, this
33// adapter object can be removed.
34class OrtcRtpReceiverAdapter : public OrtcRtpReceiverInterface {
35 public:
36 // Wraps |wrapped_receiver| in a proxy that will safely call methods on the
37 // correct thread.
38 static std::unique_ptr<OrtcRtpReceiverInterface> CreateProxy(
39 std::unique_ptr<OrtcRtpReceiverAdapter> wrapped_receiver);
40
41 // Should only be called by RtpTransportControllerAdapter.
42 OrtcRtpReceiverAdapter(
43 cricket::MediaType kind,
44 RtpTransportInterface* transport,
45 RtpTransportControllerAdapter* rtp_transport_controller);
46 ~OrtcRtpReceiverAdapter() override;
47
48 // OrtcRtpReceiverInterface implementation.
49 rtc::scoped_refptr<MediaStreamTrackInterface> GetTrack() const override;
50
51 RTCError SetTransport(RtpTransportInterface* transport) override;
52 RtpTransportInterface* GetTransport() const override;
53
54 RTCError Receive(const RtpParameters& parameters) override;
55 RtpParameters GetParameters() const override;
56
57 cricket::MediaType GetKind() const override;
58
59 // Used so that the RtpTransportControllerAdapter knows when it can
60 // deallocate resources allocated for this object.
61 sigslot::signal0<> SignalDestroyed;
62
63 private:
64 void MaybeRecreateInternalReceiver();
65
66 cricket::MediaType kind_;
67 RtpTransportInterface* transport_;
68 RtpTransportControllerAdapter* rtp_transport_controller_;
69 // Scoped refptr due to ref-counted interface, but we should be the only
70 // reference holder.
71 rtc::scoped_refptr<RtpReceiverInternal> internal_receiver_;
72 RtpParameters last_applied_parameters_;
73
74 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(OrtcRtpReceiverAdapter);
75};
76
77} // namespace webrtc
78
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#endif // ORTC_ORTCRTPRECEIVERADAPTER_H_