Create an Obj-C wrapper of the RtpReceiverObserverInterface.
Create the RTCRtpReceiverDelegate which is a wrapper over webrtc::RtpReceiverObserverInterface. The callback will be called whenever the first rtp packet is received. Related CL: https://codereview.webrtc.org/2531333003/ BUG=webrtc:6742 Review-Url: https://codereview.webrtc.org/2641923003 Cr-Commit-Position: refs/heads/master@{#16501}
This commit is contained in:
@ -14,6 +14,20 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class RtpReceiverDelegateAdapter : public RtpReceiverObserverInterface {
|
||||
public:
|
||||
RtpReceiverDelegateAdapter(RTCRtpReceiver* receiver);
|
||||
|
||||
void OnFirstPacketReceived(cricket::MediaType media_type) override;
|
||||
|
||||
private:
|
||||
__weak RTCRtpReceiver* receiver_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@interface RTCRtpReceiver ()
|
||||
|
||||
@property(nonatomic, readonly)
|
||||
@ -24,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
(rtc::scoped_refptr<webrtc::RtpReceiverInterface>)nativeRtpReceiver
|
||||
NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
+ (RTCRtpMediaType)mediaTypeForNativeMediaType:(cricket::MediaType)nativeMediaType;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@ -17,10 +17,31 @@
|
||||
|
||||
#include "webrtc/api/mediastreaminterface.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
RtpReceiverDelegateAdapter::RtpReceiverDelegateAdapter(
|
||||
RTCRtpReceiver *receiver) {
|
||||
RTC_CHECK(receiver);
|
||||
receiver_ = receiver;
|
||||
}
|
||||
|
||||
void RtpReceiverDelegateAdapter::OnFirstPacketReceived(
|
||||
cricket::MediaType media_type) {
|
||||
RTCRtpMediaType packet_media_type =
|
||||
[RTCRtpReceiver mediaTypeForNativeMediaType:media_type];
|
||||
RTCRtpReceiver *receiver = receiver_;
|
||||
[receiver.delegate rtpReceiver:receiver didReceiveFirstPacketForMediaType:packet_media_type];
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@implementation RTCRtpReceiver {
|
||||
rtc::scoped_refptr<webrtc::RtpReceiverInterface> _nativeRtpReceiver;
|
||||
std::unique_ptr<webrtc::RtpReceiverDelegateAdapter> _observer;
|
||||
}
|
||||
|
||||
@synthesize delegate = _delegate;
|
||||
|
||||
- (NSString *)receiverId {
|
||||
return [NSString stringForStdString:_nativeRtpReceiver->id()];
|
||||
}
|
||||
@ -81,8 +102,22 @@
|
||||
_nativeRtpReceiver = nativeRtpReceiver;
|
||||
RTCLogInfo(
|
||||
@"RTCRtpReceiver(%p): created receiver: %@", self, self.description);
|
||||
_observer.reset(new webrtc::RtpReceiverDelegateAdapter(self));
|
||||
_nativeRtpReceiver->SetObserver(_observer.get());
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (RTCRtpMediaType)mediaTypeForNativeMediaType:
|
||||
(cricket::MediaType)nativeMediaType {
|
||||
switch (nativeMediaType) {
|
||||
case cricket::MEDIA_TYPE_AUDIO:
|
||||
return RTCRtpMediaTypeAudio;
|
||||
case cricket::MEDIA_TYPE_VIDEO:
|
||||
return RTCRtpMediaTypeVideo;
|
||||
case cricket::MEDIA_TYPE_DATA:
|
||||
return RTCRtpMediaTypeData;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -16,6 +16,35 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/** Represents the media type of the RtpReceiver. */
|
||||
typedef NS_ENUM(NSInteger, RTCRtpMediaType) {
|
||||
RTCRtpMediaTypeAudio,
|
||||
RTCRtpMediaTypeVideo,
|
||||
RTCRtpMediaTypeData,
|
||||
};
|
||||
|
||||
@class RTCRtpReceiver;
|
||||
|
||||
RTC_EXPORT
|
||||
@protocol RTCRtpReceiverDelegate <NSObject>
|
||||
|
||||
/** Called when the first RTP packet is received.
|
||||
*
|
||||
* Note: Currently if there are multiple RtpReceivers of the same media type,
|
||||
* they will all call OnFirstPacketReceived at once.
|
||||
*
|
||||
* For example, if we create three audio receivers, A/B/C, they will listen to
|
||||
* the same signal from the underneath network layer. Whenever the first audio packet
|
||||
* is received, the underneath signal will be fired. All the receivers A/B/C will be
|
||||
* notified and the callback of the receiver's delegate will be called.
|
||||
*
|
||||
* The process is the same for video receivers.
|
||||
*/
|
||||
- (void)rtpReceiver:(RTCRtpReceiver *)rtpReceiver
|
||||
didReceiveFirstPacketForMediaType:(RTCRtpMediaType)mediaType;
|
||||
|
||||
@end
|
||||
|
||||
RTC_EXPORT
|
||||
@protocol RTCRtpReceiver <NSObject>
|
||||
|
||||
@ -38,6 +67,9 @@ RTC_EXPORT
|
||||
*/
|
||||
@property(nonatomic, readonly) RTCMediaStreamTrack *track;
|
||||
|
||||
/** The delegate for this RtpReceiver. */
|
||||
@property(nonatomic, weak) id<RTCRtpReceiverDelegate> delegate;
|
||||
|
||||
@end
|
||||
|
||||
RTC_EXPORT
|
||||
|
||||
Reference in New Issue
Block a user