Add RtcpTransceiver::Stop to allow non-blocking destruction

As downside it disallows to destroy RtcpTransceiver on the TaskQueue
without prio call to the Stop function

BUG: webrtc:8239
Change-Id: I236b9aff7a0746044dd764c619174cc5ac03d27f
Reviewed-on: https://webrtc-review.googlesource.com/98120
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24587}
This commit is contained in:
Danil Chapovalov
2018-09-05 16:46:40 +02:00
committed by Commit Bot
parent 389d2261c3
commit f0076d31f8
4 changed files with 90 additions and 64 deletions

View File

@ -20,7 +20,6 @@
#include "rtc_base/constructormagic.h"
#include "rtc_base/copyonwritebuffer.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/weak_ptr.h"
namespace webrtc {
//
@ -30,8 +29,18 @@ namespace webrtc {
class RtcpTransceiver : public RtcpFeedbackSenderInterface {
public:
explicit RtcpTransceiver(const RtcpTransceiverConfig& config);
// Blocks unless Stop was called.
// TODO(danilchap): Change destructor to never block by breaking assumption
// callbacks are not used after destruction.
~RtcpTransceiver() override;
// Start asynchronious destruction of the RtcpTransceiver.
// It is safe to call destructor right after Stop exits.
// No other methods can be called.
// Note that observers provided in constructor or registered with AddObserver
// still might be used by the transceiver until |on_destroyed| runs.
void Stop(std::unique_ptr<rtc::QueuedTask> on_destroyed);
// Registers observer to be notified about incoming rtcp packets.
// Calls to observer will be done on the |config.task_queue|.
void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc,
@ -80,12 +89,6 @@ class RtcpTransceiver : public RtcpFeedbackSenderInterface {
private:
rtc::TaskQueue* const task_queue_;
std::unique_ptr<RtcpTransceiverImpl> rtcp_transceiver_;
rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_;
// TaskQueue, and thus tasks posted to it, may outlive this.
// Thus when Posting task class always pass copy of the weak_ptr to access
// the RtcpTransceiver and never guarantee it still will be alive when task
// runs.
rtc::WeakPtr<RtcpTransceiverImpl> ptr_;
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiver);
};