1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63

media / cdm / fuchsia / fuchsia_cdm_factory.h [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CDM_FUCHSIA_FUCHSIA_CDM_FACTORY_H_
#define MEDIA_CDM_FUCHSIA_FUCHSIA_CDM_FACTORY_H_

#include <stdint.h>

#include <memory>

#include "base/containers/flat_map.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "media/base/cdm_factory.h"
#include "media/base/content_decryption_module.h"
#include "media/base/key_systems.h"
#include "media/base/media_export.h"
#include "media/cdm/fuchsia/fuchsia_cdm_provider.h"

namespace media {

class MEDIA_EXPORT FuchsiaCdmFactory final : public CdmFactory {
 public:
  // |interface_provider| and |key_systems| must outlive this class.
  FuchsiaCdmFactory(std::unique_ptr<FuchsiaCdmProvider> provider,
                    KeySystems* key_systems);

  FuchsiaCdmFactory(const FuchsiaCdmFactory&) = delete;
  FuchsiaCdmFactory& operator=(const FuchsiaCdmFactory&) = delete;

  ~FuchsiaCdmFactory() override;

  // CdmFactory implementation.
  void Create(const CdmConfig& cdm_config,
              const SessionMessageCB& session_message_cb,
              const SessionClosedCB& session_closed_cb,
              const SessionKeysChangeCB& session_keys_change_cb,
              const SessionExpirationUpdateCB& session_expiration_update_cb,
              CdmCreatedCB cdm_created_cb) override;

 private:
  void OnCdmReady(uint32_t creation_id,
                  CdmCreatedCB cdm_created_cb,
                  bool success,
                  CreateCdmStatus status);

  std::unique_ptr<FuchsiaCdmProvider> cdm_provider_;
  uint32_t creation_id_ = 0;

  // Map between creation id and pending cdms
  base::flat_map<uint32_t, scoped_refptr<ContentDecryptionModule>>
      pending_cdms_;

  // Non-owned
  raw_ptr<KeySystems> key_systems_;

  base::WeakPtrFactory<FuchsiaCdmFactory> weak_factory_{this};
};

}  // namespace media

#endif  // MEDIA_CDM_FUCHSIA_FUCHSIA_CDM_FACTORY_H_