tor-browser

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

MediaDataDecoderProxy.cpp (4824B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      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 "MediaDataDecoderProxy.h"
      8 
      9 namespace mozilla {
     10 
     11 RefPtr<MediaDataDecoder::InitPromise> MediaDataDecoderProxy::Init() {
     12  MOZ_ASSERT(!mIsShutdown);
     13 
     14  if (!mProxyThread || mProxyThread->IsOnCurrentThread()) {
     15    return mProxyDecoder->Init();
     16  }
     17  return InvokeAsync(mProxyThread, __func__, [self = RefPtr{this}] {
     18    return self->mProxyDecoder->Init();
     19  });
     20 }
     21 
     22 RefPtr<MediaDataDecoder::DecodePromise> MediaDataDecoderProxy::Decode(
     23    MediaRawData* aSample) {
     24  MOZ_ASSERT(!mIsShutdown);
     25 
     26  if (!mProxyThread || mProxyThread->IsOnCurrentThread()) {
     27    return mProxyDecoder->Decode(aSample);
     28  }
     29  RefPtr<MediaRawData> sample = aSample;
     30  return InvokeAsync(mProxyThread, __func__, [self = RefPtr{this}, sample] {
     31    return self->mProxyDecoder->Decode(sample);
     32  });
     33 }
     34 
     35 bool MediaDataDecoderProxy::CanDecodeBatch() const {
     36  return mProxyDecoder->CanDecodeBatch();
     37 }
     38 
     39 RefPtr<MediaDataDecoder::DecodePromise> MediaDataDecoderProxy::DecodeBatch(
     40    nsTArray<RefPtr<MediaRawData>>&& aSamples) {
     41  MOZ_ASSERT(!mIsShutdown);
     42  if (!mProxyThread || mProxyThread->IsOnCurrentThread()) {
     43    return mProxyDecoder->DecodeBatch(std::move(aSamples));
     44  }
     45  return InvokeAsync(
     46      mProxyThread, __func__,
     47      [self = RefPtr{this}, samples = std::move(aSamples)]() mutable {
     48        return self->mProxyDecoder->DecodeBatch(std::move(samples));
     49      });
     50 }
     51 
     52 RefPtr<MediaDataDecoder::FlushPromise> MediaDataDecoderProxy::Flush() {
     53  MOZ_ASSERT(!mIsShutdown);
     54 
     55  if (!mProxyThread || mProxyThread->IsOnCurrentThread()) {
     56    return mProxyDecoder->Flush();
     57  }
     58  return InvokeAsync(mProxyThread, __func__, [self = RefPtr{this}] {
     59    return self->mProxyDecoder->Flush();
     60  });
     61 }
     62 
     63 RefPtr<MediaDataDecoder::DecodePromise> MediaDataDecoderProxy::Drain() {
     64  MOZ_ASSERT(!mIsShutdown);
     65 
     66  if (!mProxyThread || mProxyThread->IsOnCurrentThread()) {
     67    return mProxyDecoder->Drain();
     68  }
     69  return InvokeAsync(mProxyThread, __func__, [self = RefPtr{this}] {
     70    return self->mProxyDecoder->Drain();
     71  });
     72 }
     73 
     74 RefPtr<ShutdownPromise> MediaDataDecoderProxy::Shutdown() {
     75  MOZ_ASSERT(!mIsShutdown);
     76 
     77 #if defined(DEBUG)
     78  mIsShutdown = true;
     79 #endif
     80 
     81  if (!mProxyThread || mProxyThread->IsOnCurrentThread()) {
     82    return mProxyDecoder->Shutdown();
     83  }
     84  // We chain another promise to ensure that the proxied decoder gets destructed
     85  // on the proxy thread.
     86  return InvokeAsync(mProxyThread, __func__, [self = RefPtr{this}] {
     87    RefPtr<ShutdownPromise> p = self->mProxyDecoder->Shutdown()->Then(
     88        self->mProxyThread, __func__,
     89        [self](const ShutdownPromise::ResolveOrRejectValue& aResult) {
     90          self->mProxyDecoder = nullptr;
     91          return ShutdownPromise::CreateAndResolveOrReject(aResult, __func__);
     92        });
     93    return p;
     94  });
     95 }
     96 
     97 nsCString MediaDataDecoderProxy::GetDescriptionName() const {
     98  MOZ_ASSERT(!mIsShutdown);
     99 
    100  return mProxyDecoder->GetDescriptionName();
    101 }
    102 
    103 nsCString MediaDataDecoderProxy::GetProcessName() const {
    104  MOZ_ASSERT(!mIsShutdown);
    105 
    106  return mProxyDecoder->GetProcessName();
    107 }
    108 
    109 nsCString MediaDataDecoderProxy::GetCodecName() const {
    110  MOZ_ASSERT(!mIsShutdown);
    111 
    112  return mProxyDecoder->GetCodecName();
    113 }
    114 
    115 bool MediaDataDecoderProxy::IsHardwareAccelerated(
    116    nsACString& aFailureReason) const {
    117  MOZ_ASSERT(!mIsShutdown);
    118 
    119  return mProxyDecoder->IsHardwareAccelerated(aFailureReason);
    120 }
    121 
    122 void MediaDataDecoderProxy::SetSeekThreshold(const media::TimeUnit& aTime) {
    123  MOZ_ASSERT(!mIsShutdown);
    124 
    125  if (!mProxyThread || mProxyThread->IsOnCurrentThread()) {
    126    mProxyDecoder->SetSeekThreshold(aTime);
    127    return;
    128  }
    129  media::TimeUnit time = aTime;
    130  mProxyThread->Dispatch(NS_NewRunnableFunction(
    131      "MediaDataDecoderProxy::SetSeekThreshold", [self = RefPtr{this}, time] {
    132        self->mProxyDecoder->SetSeekThreshold(time);
    133      }));
    134 }
    135 
    136 bool MediaDataDecoderProxy::SupportDecoderRecycling() const {
    137  MOZ_ASSERT(!mIsShutdown);
    138 
    139  return mProxyDecoder->SupportDecoderRecycling();
    140 }
    141 
    142 bool MediaDataDecoderProxy::ShouldDecoderAlwaysBeRecycled() const {
    143  MOZ_ASSERT(!mIsShutdown);
    144 
    145  return mProxyDecoder->ShouldDecoderAlwaysBeRecycled();
    146 }
    147 
    148 MediaDataDecoder::ConversionRequired MediaDataDecoderProxy::NeedsConversion()
    149    const {
    150  MOZ_ASSERT(!mIsShutdown);
    151 
    152  return mProxyDecoder->NeedsConversion();
    153 }
    154 
    155 Maybe<MediaDataDecoder::PropertyValue> MediaDataDecoderProxy::GetDecodeProperty(
    156    MediaDataDecoder::PropertyName aName) const {
    157  MOZ_ASSERT(!mIsShutdown);
    158 
    159  return mProxyDecoder->GetDecodeProperty(aName);
    160 }
    161 
    162 }  // namespace mozilla