tor-browser

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

HLSDecoder.h (2804B)


      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 #ifndef HLSDecoder_h_
      8 #define HLSDecoder_h_
      9 
     10 #include "MediaDecoder.h"
     11 #include "mozilla/java/GeckoHLSResourceWrapperWrappers.h"
     12 
     13 namespace mozilla {
     14 
     15 class HLSResourceCallbacksSupport;
     16 
     17 class HLSDecoder final : public MediaDecoder {
     18 public:
     19  static RefPtr<HLSDecoder> Create(MediaDecoderInit& aInit);
     20 
     21  // Returns true if the HLS backend is pref'ed on.
     22  static bool IsEnabled();
     23 
     24  // Returns true if aContainerType is an HLS type that we think we can render
     25  // with the a platform decoder backend.
     26  // If provided, codecs are checked for support.
     27  static bool IsSupportedType(const MediaContainerType& aContainerType);
     28 
     29  nsresult Load(nsIChannel* aChannel);
     30 
     31  // MediaDecoder interface.
     32  void Play() override;
     33 
     34  void Pause() override;
     35 
     36  void AddSizeOfResources(ResourceSizes* aSizes) override;
     37  already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override;
     38  bool HadCrossOriginRedirects() override;
     39  bool IsTransportSeekable() override { return true; }
     40  void Suspend() override;
     41  void Resume() override;
     42  void Shutdown() override;
     43 
     44  // Called as data arrives on the underlying HLS player. Main thread only.
     45  void NotifyDataArrived();
     46 
     47  // Called when Exoplayer start to load media. Main thread only.
     48  void NotifyLoad(nsCString aMediaUrl);
     49 
     50  bool IsHLSDecoder() const override { return true; }
     51 
     52 private:
     53  friend class HLSResourceCallbacksSupport;
     54 
     55  explicit HLSDecoder(MediaDecoderInit& aInit);
     56  ~HLSDecoder();
     57  MediaDecoderStateMachineBase* CreateStateMachine(
     58      bool aDisableExternalEngine) override;
     59 
     60  bool CanPlayThroughImpl() final {
     61    // TODO: We don't know how to estimate 'canplaythrough' for this decoder.
     62    // For now we just return true for 'autoplay' can work.
     63    return true;
     64  }
     65 
     66  void UpdateCurrentPrincipal(nsIURI* aMediaUri);
     67  already_AddRefed<nsIPrincipal> GetContentPrincipal(nsIURI* aMediaUri);
     68  void RecordMediaUsage(nsIURI* aMediaUri);
     69 
     70  static size_t sAllocatedInstances;  // Access only in the main thread.
     71 
     72  nsCOMPtr<nsIChannel> mChannel;
     73  nsCOMPtr<nsIURI> mURI;
     74  java::GeckoHLSResourceWrapper::GlobalRef mHLSResourceWrapper;
     75  java::GeckoHLSResourceWrapper::Callbacks::GlobalRef mJavaCallbacks;
     76  RefPtr<HLSResourceCallbacksSupport> mCallbackSupport;
     77  nsCOMPtr<nsIPrincipal> mContentPrincipal;
     78  // There can be multiple media files loaded for one HLS content. Use this flag
     79  // to ensure we only record once per content.
     80  bool mUsageRecorded;
     81 };
     82 
     83 }  // namespace mozilla
     84 
     85 #endif /* HLSDecoder_h_ */