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

media / renderers / win / media_engine_extension.h [blame]

// Copyright 2020 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_RENDERERS_WIN_MEDIA_ENGINE_EXTENSION_H_
#define MEDIA_RENDERERS_WIN_MEDIA_ENGINE_EXTENSION_H_

#include <mfapi.h>
#include <mfmediaengine.h>
#include <wrl.h>

#include "base/synchronization/lock.h"

namespace media {

// Implement IMFMediaEngineExtension to load media source into the
// IMFMediaEngine. See details from:
// https://docs.microsoft.com/en-us/windows/win32/api/mfmediaengine/nn-mfmediaengine-imfmediaengineextension.
//
class MediaEngineExtension
    : public Microsoft::WRL::RuntimeClass<
          Microsoft::WRL::RuntimeClassFlags<
              Microsoft::WRL::RuntimeClassType::ClassicCom>,
          IMFMediaEngineExtension> {
 public:
  MediaEngineExtension();
  ~MediaEngineExtension() override;

  HRESULT RuntimeClassInitialize();

  // IMFMediaEngineExtension
  IFACEMETHODIMP CanPlayType(BOOL is_audio_only,
                             BSTR mime_type,
                             MF_MEDIA_ENGINE_CANPLAY* result) override;
  IFACEMETHODIMP BeginCreateObject(BSTR url_bstr,
                                   IMFByteStream* byte_stream,
                                   MF_OBJECT_TYPE type,
                                   IUnknown** cancel_cookie,
                                   IMFAsyncCallback* callback,
                                   IUnknown* state) override;
  IFACEMETHODIMP CancelObjectCreation(IUnknown* cancel_cookie) override;
  IFACEMETHODIMP EndCreateObject(IMFAsyncResult* result,
                                 IUnknown** ret_obj) override;

  HRESULT SetMediaSource(IUnknown* mf_media_source);
  void Shutdown();

 private:
  bool pending_create_object_ = false;

  // Need a lock to ensure thread safe operation between IMFMediaEngineExtension
  // method calls from MFMediaEngine threadpool thread and
  // SetMediaSource/Shutdown from MediaFoundationRenderer calling thread.
  base::Lock lock_;
  bool has_shutdown_ GUARDED_BY(lock_) = false;
  Microsoft::WRL::ComPtr<IUnknown> mf_media_source_ GUARDED_BY(lock_);
};

}  // namespace media

#endif  // MEDIA_RENDERERS_WIN_MEDIA_ENGINE_EXTENSION_H_