tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RemoteTrackSource.cpp (3642B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "RemoteTrackSource.h"
      8 
      9 #include "MediaStreamError.h"
     10 #include "MediaTrackGraph.h"
     11 #include "RTCRtpReceiver.h"
     12 
     13 namespace mozilla {
     14 
     15 NS_IMPL_ADDREF_INHERITED(RemoteTrackSource, dom::MediaStreamTrackSource)
     16 NS_IMPL_RELEASE_INHERITED(RemoteTrackSource, dom::MediaStreamTrackSource)
     17 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoteTrackSource)
     18 NS_INTERFACE_MAP_END_INHERITING(dom::MediaStreamTrackSource)
     19 NS_IMPL_CYCLE_COLLECTION_CLASS(RemoteTrackSource)
     20 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(RemoteTrackSource,
     21                                                dom::MediaStreamTrackSource)
     22  tmp->Destroy();
     23  NS_IMPL_CYCLE_COLLECTION_UNLINK(mReceiver)
     24 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     25 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(RemoteTrackSource,
     26                                                  dom::MediaStreamTrackSource)
     27  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReceiver)
     28 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     29 
     30 RemoteTrackSource::RemoteTrackSource(SourceMediaTrack* aStream,
     31                                     dom::RTCRtpReceiver* aReceiver,
     32                                     nsIPrincipal* aPrincipal,
     33                                     const nsString& aLabel,
     34                                     TrackingId aTrackingId)
     35    : dom::MediaStreamTrackSource(aPrincipal, aLabel, std::move(aTrackingId)),
     36      mStream(aStream),
     37      mReceiver(aReceiver) {}
     38 
     39 RemoteTrackSource::~RemoteTrackSource() { Destroy(); }
     40 
     41 void RemoteTrackSource::Destroy() {
     42  if (mStream) {
     43    if (mReceiver && mStream->mType == MediaSegment::VIDEO) {
     44      mReceivingSizeOnEnded = mReceiver->ReceivingSize().orElse(
     45          [] { return Some(gfx::IntSize{0, 0}); });
     46    }
     47    MOZ_ASSERT(!mStream->IsDestroyed());
     48    mStream->End();
     49    mStream->Destroy();
     50    mStream = nullptr;
     51 
     52    GetMainThreadSerialEventTarget()->Dispatch(NewRunnableMethod(
     53        "RemoteTrackSource::ForceEnded", this, &RemoteTrackSource::ForceEnded));
     54  }
     55 }
     56 
     57 void RemoteTrackSource::GetSettings(dom::MediaTrackSettings& aSettings) {
     58  if (mReceivingSizeOnEnded) {
     59    aSettings.mWidth.Construct(mReceivingSizeOnEnded->width);
     60    aSettings.mHeight.Construct(mReceivingSizeOnEnded->height);
     61    return;
     62  }
     63 
     64  if (mStream && mStream->mType == MediaSegment::VIDEO) {
     65    const gfx::IntSize size = mReceiver->ReceivingSize().valueOrFrom(
     66        [] { return gfx::IntSize{0, 0}; });
     67    aSettings.mWidth.Construct(size.width);
     68    aSettings.mHeight.Construct(size.height);
     69  }
     70 }
     71 
     72 auto RemoteTrackSource::ApplyConstraints(
     73    const dom::MediaTrackConstraints& aConstraints, dom::CallerType aCallerType)
     74    -> RefPtr<ApplyConstraintsPromise> {
     75  return ApplyConstraintsPromise::CreateAndReject(
     76      MakeRefPtr<MediaMgrError>(
     77          dom::MediaStreamError::Name::OverconstrainedError, ""),
     78      __func__);
     79 }
     80 
     81 void RemoteTrackSource::SetPrincipal(nsIPrincipal* aPrincipal) {
     82  mPrincipal = aPrincipal;
     83  PrincipalChanged();
     84 }
     85 
     86 void RemoteTrackSource::SetMuted(bool aMuted) { MutedChanged(aMuted); }
     87 
     88 void RemoteTrackSource::ForceEnded() { OverrideEnded(); }
     89 
     90 SourceMediaTrack* RemoteTrackSource::Stream() const { return mStream; }
     91 
     92 const dom::RTCStatsTimestampMaker* RemoteTrackSource::GetTimestampMaker()
     93    const {
     94  if (!mReceiver) {
     95    return nullptr;
     96  }
     97  return mReceiver->GetTimestampMaker();
     98 }
     99 
    100 }  // namespace mozilla