Files
platform-external-webrtc/api/setremotedescriptionobserverinterface.h
Henrik Boström 6c7ec32bd6 SetRemoteDescriptionObserverInterface added.
The new observer replaced SetSessionDescriptionObserver for
SetRemoteDescription. Unlike SetSessionDescriptionObserver,
SetRemoteDescriptionObserverInterface is invoked synchronously so
that the you can rely on the state of the PeerConnection to represent
the result of the SetRemoteDescription call in the callback.

The new observer succeeds or fails with an RTCError.

This deprecates the need for PeerConnectionObserver::OnAdd/RemoveTrack
and SetSessionDescriptionObserver, with the benefit that all media
object changes can be processed in a single callback by the application
in a synchronous callback. This will help Chromium keep objects in-sync
across layers and threads in a non-racy and straight-forward way, see
design doc (Proposal 2):
https://docs.google.com/a/google.com/document/d/1-cDDC82mgU5zrHacfFz720p3xwRtuBkOPSRchh07Ho0/edit?usp=sharing

An adapter for SetSessionDescriptionObserver is added to allow calling
the old SetRemoteDescription signature and get the old behavior
(OnSuccess/OnFailure callback in a Post) until third parties switch.

Bug: webrtc:8473
Change-Id: I3d4eb60da6dd34615f2c9f384aeaf4634e648c99
Reviewed-on: https://webrtc-review.googlesource.com/17523
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Peter Thatcher <pthatcher@webrtc.org>
Reviewed-by: Guido Urdaneta <guidou@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20841}
2017-11-22 19:30:34 +00:00

70 lines
2.4 KiB
C++

/*
* 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.
*/
#ifndef API_SETREMOTEDESCRIPTIONOBSERVERINTERFACE_H_
#define API_SETREMOTEDESCRIPTIONOBSERVERINTERFACE_H_
#include <utility>
#include <vector>
#include "api/jsep.h"
#include "api/mediastreaminterface.h"
#include "api/rtcerror.h"
#include "api/rtpreceiverinterface.h"
#include "rtc_base/bind.h"
#include "rtc_base/messagehandler.h"
#include "rtc_base/refcount.h"
#include "rtc_base/refcountedobject.h"
#include "rtc_base/scoped_ref_ptr.h"
#include "rtc_base/thread.h"
namespace webrtc {
// An observer for PeerConnectionInterface::SetRemoteDescription(). The
// callback is invoked such that the state of the peer connection can be
// examined to accurately reflect the effects of the SetRemoteDescription
// operation.
class SetRemoteDescriptionObserverInterface : public rtc::RefCountInterface {
public:
// On success, |error.ok()| is true.
virtual void OnSetRemoteDescriptionComplete(RTCError error) = 0;
};
// Upon completion, posts a task to execute the callback of the
// SetSessionDescriptionObserver asynchronously on the same thread. At this
// point, the state of the peer connection might no longer reflect the effects
// of the SetRemoteDescription operation, as the peer connection could have been
// modified during the post.
// TODO(hbos): Remove this class once we remove the version of
// PeerConnectionInterface::SetRemoteDescription() that takes a
// SetSessionDescriptionObserver as an argument.
class SetRemoteDescriptionObserverAdapter
: public rtc::RefCountedObject<SetRemoteDescriptionObserverInterface>,
public rtc::MessageHandler {
public:
SetRemoteDescriptionObserverAdapter(
rtc::scoped_refptr<SetSessionDescriptionObserver> wrapper);
// SetRemoteDescriptionObserverInterface implementation.
void OnSetRemoteDescriptionComplete(RTCError error) override;
// rtc::MessageHandler implementation.
void OnMessage(rtc::Message* msg) override;
private:
class MessageData;
rtc::scoped_refptr<SetSessionDescriptionObserver> wrapper_;
};
} // namespace webrtc
#endif // API_SETREMOTEDESCRIPTIONOBSERVERINTERFACE_H_