From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/media/webrtc/transport/transportflow.cpp | 74 ++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 dom/media/webrtc/transport/transportflow.cpp (limited to 'dom/media/webrtc/transport/transportflow.cpp') diff --git a/dom/media/webrtc/transport/transportflow.cpp b/dom/media/webrtc/transport/transportflow.cpp new file mode 100644 index 0000000000..8b263c8cfe --- /dev/null +++ b/dom/media/webrtc/transport/transportflow.cpp @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Original author: ekr@rtfm.com +#include + +#include "transportflow.h" +#include "transportlayer.h" + +namespace mozilla { + +NS_IMPL_ISUPPORTS0(TransportFlow) + +// There are some hacks here to allow destruction off of +// the main thread. +TransportFlow::~TransportFlow() { + // Push the destruction onto the STS thread. Note that there + // is still some possibility that someone is accessing this + // object simultaneously, but as long as smart pointer discipline + // is maintained, it shouldn't be possible to access and + // destroy it simultaneously. The conversion to a UniquePtr + // ensures automatic destruction of the queue at exit of + // DestroyFinal. + CheckThread(); + ClearLayers(layers_.get()); +} + +void TransportFlow::DestroyFinal( + UniquePtr> layers) { + ClearLayers(layers.get()); +} + +void TransportFlow::ClearLayers(std::deque* layers) { + while (!layers->empty()) { + delete layers->front(); + layers->pop_front(); + } +} + +void TransportFlow::PushLayer(TransportLayer* layer) { + CheckThread(); + layers_->push_front(layer); + EnsureSameThread(layer); + layer->SetFlowId(id_); +} + +TransportLayer* TransportFlow::GetLayer(const std::string& id) const { + CheckThread(); + + if (layers_) { + for (TransportLayer* layer : *layers_) { + if (layer->id() == id) return layer; + } + } + + return nullptr; +} + +void TransportFlow::EnsureSameThread(TransportLayer* layer) { + // Enforce that if any of the layers have a thread binding, + // they all have the same binding. + if (target_) { + const nsCOMPtr& lthread = layer->GetThread(); + + if (lthread && (lthread != target_)) MOZ_CRASH(); + } else { + target_ = layer->GetThread(); + } +} + +} // namespace mozilla -- cgit v1.2.3