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}
62 lines
2.1 KiB
C++
62 lines
2.1 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.
|
|
*/
|
|
|
|
#include "api/setremotedescriptionobserverinterface.h"
|
|
|
|
#include <string>
|
|
|
|
namespace webrtc {
|
|
|
|
// The message keeps the observer alive through reference counting.
|
|
class SetRemoteDescriptionObserverAdapter::MessageData
|
|
: public rtc::MessageData {
|
|
public:
|
|
static MessageData* Create(
|
|
rtc::scoped_refptr<SetRemoteDescriptionObserverAdapter> observer,
|
|
RTCError error) {
|
|
return new MessageData(std::move(observer), std::move(error));
|
|
}
|
|
|
|
const RTCError& error() const { return error_; }
|
|
|
|
private:
|
|
MessageData(rtc::scoped_refptr<SetRemoteDescriptionObserverAdapter> observer,
|
|
RTCError error)
|
|
: observer_(std::move(observer)), error_(std::move(error)) {}
|
|
|
|
rtc::scoped_refptr<SetRemoteDescriptionObserverAdapter> observer_;
|
|
RTCError error_;
|
|
};
|
|
|
|
SetRemoteDescriptionObserverAdapter::SetRemoteDescriptionObserverAdapter(
|
|
rtc::scoped_refptr<SetSessionDescriptionObserver> wrapper)
|
|
: wrapper_(std::move(wrapper)) {}
|
|
|
|
void SetRemoteDescriptionObserverAdapter::OnSetRemoteDescriptionComplete(
|
|
RTCError error) {
|
|
// MessageData keeps a reference to |this|, ensuring it is not deleted until
|
|
// OnMessage().
|
|
rtc::Thread::Current()->Post(RTC_FROM_HERE, this, 0,
|
|
MessageData::Create(this, std::move(error)));
|
|
}
|
|
|
|
void SetRemoteDescriptionObserverAdapter::OnMessage(rtc::Message* msg) {
|
|
MessageData* message = static_cast<MessageData*>(msg->pdata);
|
|
if (message->error().ok())
|
|
wrapper_->OnSuccess();
|
|
else
|
|
wrapper_->OnFailure(message->error().message());
|
|
// Delete the message data, this may delete |this|. Don't use member variables
|
|
// after this line.
|
|
delete message;
|
|
}
|
|
|
|
} // namespace webrtc
|