Blame dom/media/platforms/PDMFactory.h

Packit f0b94e
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Packit f0b94e
/* vim:set ts=2 sw=2 sts=2 et cindent: */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
#if !defined(PDMFactory_h_)
Packit f0b94e
#define PDMFactory_h_
Packit f0b94e
Packit f0b94e
#include "PlatformDecoderModule.h"
Packit f0b94e
#include "mozilla/StaticMutex.h"
Packit f0b94e
Packit f0b94e
class CDMProxy;
Packit f0b94e
Packit f0b94e
namespace mozilla {
Packit f0b94e
Packit f0b94e
class DecoderDoctorDiagnostics;
Packit f0b94e
class PDMFactoryImpl;
Packit f0b94e
template <class T>
Packit f0b94e
class StaticAutoPtr;
Packit f0b94e
Packit f0b94e
class PDMFactory final {
Packit f0b94e
 public:
Packit f0b94e
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PDMFactory)
Packit f0b94e
Packit f0b94e
  PDMFactory();
Packit f0b94e
Packit f0b94e
  // Factory method that creates the appropriate PlatformDecoderModule for
Packit f0b94e
  // the platform we're running on. Caller is responsible for deleting this
Packit f0b94e
  // instance. It's expected that there will be multiple
Packit f0b94e
  // PlatformDecoderModules alive at the same time.
Packit f0b94e
  // This is called on the decode task queue.
Packit f0b94e
  already_AddRefed<MediaDataDecoder> CreateDecoder(
Packit f0b94e
      const CreateDecoderParams& aParams);
Packit f0b94e
Packit f0b94e
  bool SupportsMimeType(const nsACString& aMimeType,
Packit f0b94e
                        DecoderDoctorDiagnostics* aDiagnostics) const;
Packit f0b94e
  bool Supports(const TrackInfo& aTrackInfo,
Packit f0b94e
                DecoderDoctorDiagnostics* aDiagnostics) const;
Packit f0b94e
Packit f0b94e
  // Creates a PlatformDecoderModule that uses a CDMProxy to decrypt or
Packit f0b94e
  // decrypt-and-decode EME encrypted content. If the CDM only decrypts and
Packit f0b94e
  // does not decode, we create a PDM and use that to create MediaDataDecoders
Packit f0b94e
  // that we use on on aTaskQueue to decode the decrypted stream.
Packit f0b94e
  // This is called on the decode task queue.
Packit f0b94e
  void SetCDMProxy(CDMProxy* aProxy);
Packit f0b94e
Packit f0b94e
  static void EnsureInit();
Packit f0b94e
Packit f0b94e
  static constexpr int kYUV400 = 0;
Packit f0b94e
  static constexpr int kYUV420 = 1;
Packit f0b94e
  static constexpr int kYUV422 = 2;
Packit f0b94e
  static constexpr int kYUV444 = 3;
Packit f0b94e
Packit f0b94e
 private:
Packit f0b94e
  virtual ~PDMFactory();
Packit f0b94e
  void CreatePDMs();
Packit f0b94e
  void CreateNullPDM();
Packit f0b94e
  // Startup the provided PDM and add it to our list if successful.
Packit f0b94e
  bool StartupPDM(PlatformDecoderModule* aPDM, bool aInsertAtBeginning = false);
Packit f0b94e
  // Returns the first PDM in our list supporting the mimetype.
Packit f0b94e
  already_AddRefed<PlatformDecoderModule> GetDecoder(
Packit f0b94e
      const TrackInfo& aTrackInfo,
Packit f0b94e
      DecoderDoctorDiagnostics* aDiagnostics) const;
Packit f0b94e
Packit f0b94e
  already_AddRefed<MediaDataDecoder> CreateDecoderWithPDM(
Packit f0b94e
      PlatformDecoderModule* aPDM, const CreateDecoderParams& aParams);
Packit f0b94e
Packit f0b94e
  nsTArray<RefPtr<PlatformDecoderModule>> mCurrentPDMs;
Packit f0b94e
  RefPtr<PlatformDecoderModule> mEMEPDM;
Packit f0b94e
  RefPtr<PlatformDecoderModule> mNullPDM;
Packit f0b94e
Packit f0b94e
  bool mWMFFailedToLoad = false;
Packit f0b94e
  bool mFFmpegFailedToLoad = false;
Packit f0b94e
  bool mGMPPDMFailedToStartup = false;
Packit f0b94e
Packit f0b94e
  template <class T>
Packit f0b94e
  friend class StaticAutoPtr;
Packit f0b94e
  static StaticAutoPtr<PDMFactoryImpl> sInstance;
Packit f0b94e
  static StaticMutex sMonitor;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
}  // namespace mozilla
Packit f0b94e
Packit f0b94e
#endif /* PDMFactory_h_ */