media_engine_notify_impl.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_RENDERERS_WIN_MEDIA_ENGINE_NOTIFY_IMPL_H_
  5. #define MEDIA_RENDERERS_WIN_MEDIA_ENGINE_NOTIFY_IMPL_H_
  6. #include <mfmediaengine.h>
  7. #include <wrl.h>
  8. #include "base/callback.h"
  9. #include "base/synchronization/lock.h"
  10. #include "media/base/buffering_state.h"
  11. #include "media/base/pipeline_status.h"
  12. namespace media {
  13. // Implements IMFMediaEngineNotify required by IMFMediaEngine
  14. // (https://docs.microsoft.com/en-us/windows/win32/api/mfmediaengine/nn-mfmediaengine-imfmediaengine).
  15. //
  16. class MediaEngineNotifyImpl
  17. : public Microsoft::WRL::RuntimeClass<
  18. Microsoft::WRL::RuntimeClassFlags<
  19. Microsoft::WRL::RuntimeClassType::ClassicCom>,
  20. IMFMediaEngineNotify> {
  21. public:
  22. MediaEngineNotifyImpl();
  23. ~MediaEngineNotifyImpl() override;
  24. using ErrorCB = base::RepeatingCallback<void(PipelineStatus, HRESULT)>;
  25. using EndedCB = base::RepeatingClosure;
  26. using FormatChangeCB = base::RepeatingClosure;
  27. using LoadedDataCB = base::RepeatingClosure;
  28. using PlayingCB = base::RepeatingClosure;
  29. using WaitingCB = base::RepeatingClosure;
  30. using TimeUpdateCB = base::RepeatingClosure;
  31. HRESULT RuntimeClassInitialize(ErrorCB error_cb,
  32. EndedCB ended_cb,
  33. FormatChangeCB format_change_cb,
  34. LoadedDataCB loaded_data_cb,
  35. PlayingCB playing_cb,
  36. WaitingCB waiting_cb,
  37. TimeUpdateCB time_update_cb);
  38. // IMFMediaEngineNotify implementation.
  39. IFACEMETHODIMP EventNotify(DWORD event_code,
  40. DWORD_PTR param1,
  41. DWORD param2) override;
  42. void Shutdown();
  43. private:
  44. // Callbacks are called on the MF threadpool thread and the creator of this
  45. // object must make sure the callbacks are safe to be called on that thread,
  46. // e.g. using BindToCurrentLoop().
  47. ErrorCB error_cb_;
  48. EndedCB ended_cb_;
  49. FormatChangeCB format_change_cb_;
  50. LoadedDataCB loaded_data_cb_;
  51. PlayingCB playing_cb_;
  52. WaitingCB waiting_cb_;
  53. TimeUpdateCB time_update_cb_;
  54. // EventNotify is invoked from MF threadpool thread where the callbacks are
  55. // called.
  56. // Shutdown is invoked from media stack thread. When this object is shutting
  57. // down, callbacks should not be called.
  58. base::Lock lock_;
  59. bool has_shutdown_ GUARDED_BY(lock_) = false;
  60. };
  61. } // namespace media
  62. #endif // MEDIA_RENDERERS_WIN_MEDIA_ENGINE_NOTIFY_IMPL_H_