2020-02-20 15:04:12 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef WIDGET_WINDOWS_WINDOWSSTMCPROVIDER_H_
|
|
|
|
#define WIDGET_WINDOWS_WINDOWSSTMCPROVIDER_H_
|
|
|
|
|
|
|
|
#ifndef __MINGW32__
|
|
|
|
|
|
|
|
# include <functional>
|
|
|
|
# include <Windows.Media.h>
|
|
|
|
# include <wrl.h>
|
|
|
|
|
2020-06-19 03:21:21 +03:00
|
|
|
# include "mozilla/dom/FetchImageHelper.h"
|
2020-06-19 03:21:02 +03:00
|
|
|
# include "mozilla/dom/MediaController.h"
|
|
|
|
# include "mozilla/dom/MediaControlKeySource.h"
|
2020-06-19 03:21:21 +03:00
|
|
|
# include "mozilla/UniquePtr.h"
|
2020-02-20 15:04:12 +03:00
|
|
|
|
|
|
|
using ISMTC = ABI::Windows::Media::ISystemMediaTransportControls;
|
|
|
|
using SMTCProperty = ABI::Windows::Media::SystemMediaTransportControlsProperty;
|
2020-06-19 03:20:23 +03:00
|
|
|
using ISMTCDisplayUpdater =
|
2020-02-20 15:04:12 +03:00
|
|
|
ABI::Windows::Media::ISystemMediaTransportControlsDisplayUpdater;
|
|
|
|
|
2020-06-30 01:55:17 +03:00
|
|
|
using ABI::Windows::Foundation::IAsyncOperation;
|
2020-06-19 03:21:13 +03:00
|
|
|
using ABI::Windows::Storage::Streams::IDataWriter;
|
|
|
|
using ABI::Windows::Storage::Streams::IRandomAccessStream;
|
|
|
|
using ABI::Windows::Storage::Streams::IRandomAccessStreamReference;
|
|
|
|
using Microsoft::WRL::ComPtr;
|
|
|
|
|
2020-06-09 05:59:57 +03:00
|
|
|
class WindowsSMTCProvider final : public mozilla::dom::MediaControlKeySource {
|
2020-06-19 03:21:13 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WindowsSMTCProvider, override)
|
2020-02-20 15:04:12 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
WindowsSMTCProvider();
|
|
|
|
|
|
|
|
bool IsOpened() const override;
|
|
|
|
bool Open() override;
|
|
|
|
void Close() override;
|
|
|
|
|
2020-03-17 03:03:55 +03:00
|
|
|
void SetPlaybackState(
|
|
|
|
mozilla::dom::MediaSessionPlaybackState aState) override;
|
2020-02-20 15:04:12 +03:00
|
|
|
|
2020-03-17 04:23:43 +03:00
|
|
|
void SetMediaMetadata(
|
|
|
|
const mozilla::dom::MediaMetadataBase& aMetadata) override;
|
|
|
|
|
2020-08-18 21:28:19 +03:00
|
|
|
void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) override;
|
2020-06-09 05:23:35 +03:00
|
|
|
|
2020-02-20 15:04:12 +03:00
|
|
|
private:
|
|
|
|
~WindowsSMTCProvider();
|
|
|
|
void UnregisterEvents();
|
|
|
|
bool RegisterEvents();
|
|
|
|
|
2020-08-18 21:28:19 +03:00
|
|
|
void OnButtonPressed(mozilla::dom::MediaControlKey aKey) const;
|
|
|
|
// Enable the SMTC interface
|
|
|
|
bool EnableControl(bool aEnabled) const;
|
|
|
|
// Sets the play, pause, next, previous buttons on the SMTC interface by
|
|
|
|
// mSupportedKeys
|
|
|
|
bool UpdateButtons() const;
|
|
|
|
bool IsKeySupported(mozilla::dom::MediaControlKey aKey) const;
|
|
|
|
bool EnableKey(mozilla::dom::MediaControlKey aKey, bool aEnable) const;
|
2020-06-19 03:20:52 +03:00
|
|
|
|
2020-08-18 21:28:19 +03:00
|
|
|
bool InitDisplayAndControls();
|
2020-06-19 03:20:42 +03:00
|
|
|
|
|
|
|
// Sets the Metadata for the currently playing media and sets the playback
|
2020-06-19 03:21:00 +03:00
|
|
|
// type to "MUSIC"
|
2022-05-06 16:36:20 +03:00
|
|
|
bool SetMusicMetadata(const nsString& aArtist, const nsString& aTitle);
|
2020-06-19 03:20:42 +03:00
|
|
|
|
2020-06-19 03:21:13 +03:00
|
|
|
// Sets one of the artwork to the SMTC interface asynchronously
|
|
|
|
void LoadThumbnail(const nsTArray<mozilla::dom::MediaImage>& aArtwork);
|
2020-06-19 03:21:23 +03:00
|
|
|
// Stores the image at index aIndex of the mArtwork to the Thumbnail
|
|
|
|
// asynchronously
|
|
|
|
void LoadImageAtIndex(const size_t aIndex);
|
2020-06-19 03:21:13 +03:00
|
|
|
// Stores the raw binary data of an image to mImageStream and set it to the
|
|
|
|
// Thumbnail asynchronously
|
|
|
|
void LoadImage(const char* aImageData, uint32_t aDataSize);
|
|
|
|
// Sets the Thumbnail to the image stored in mImageStream
|
2020-06-30 01:55:15 +03:00
|
|
|
bool SetThumbnail(const nsAString& aUrl);
|
2020-06-19 03:21:21 +03:00
|
|
|
void ClearThumbnail();
|
2020-06-19 03:20:42 +03:00
|
|
|
|
2020-09-16 19:06:09 +03:00
|
|
|
bool UpdateThumbnail(const nsAString& aUrl);
|
2020-06-30 01:55:17 +03:00
|
|
|
void CancelPendingStoreAsyncOperation() const;
|
|
|
|
|
2020-10-07 12:23:08 +03:00
|
|
|
void ClearMetadata();
|
|
|
|
|
2020-02-20 15:04:12 +03:00
|
|
|
bool mInitialized = false;
|
2020-08-18 21:28:19 +03:00
|
|
|
|
|
|
|
// A bit table indicating what keys are enabled
|
|
|
|
uint32_t mSupportedKeys = 0;
|
|
|
|
|
2020-06-19 03:21:13 +03:00
|
|
|
ComPtr<ISMTC> mControls;
|
|
|
|
ComPtr<ISMTCDisplayUpdater> mDisplay;
|
|
|
|
|
|
|
|
// Use mImageDataWriter to write the binary data of image into mImageStream
|
|
|
|
// and refer the image by mImageStreamReference and then set it to the SMTC
|
|
|
|
// interface
|
|
|
|
ComPtr<IDataWriter> mImageDataWriter;
|
|
|
|
ComPtr<IRandomAccessStream> mImageStream;
|
|
|
|
ComPtr<IRandomAccessStreamReference> mImageStreamReference;
|
2020-06-30 01:55:17 +03:00
|
|
|
ComPtr<IAsyncOperation<unsigned int>> mStoreAsyncOperation;
|
|
|
|
|
|
|
|
// mThumbnailUrl is the url of the current Thumbnail
|
|
|
|
// mProcessingUrl is the url that is being processed. The process starts from
|
|
|
|
// fetching an image from the url and then storing the fetched image to the
|
|
|
|
// mImageStream. If mProcessingUrl is not empty, it means there is an image is
|
|
|
|
// in processing
|
|
|
|
// mThumbnailUrl and mProcessingUrl won't be set at the same time and they can
|
|
|
|
// only be touched on main thread
|
|
|
|
nsString mThumbnailUrl;
|
|
|
|
nsString mProcessingUrl;
|
2020-06-19 03:21:21 +03:00
|
|
|
|
2020-06-19 03:21:23 +03:00
|
|
|
// mArtwork can only be used in main thread in case of data racing
|
|
|
|
CopyableTArray<mozilla::dom::MediaImage> mArtwork;
|
Bug 1649970 - Correct the index for fetching next available image r=alwu
Suppose the current artwork is <img A, img B, img C> and Firefox is
currently fetching img B, whose index is 1 in the artwork. If the
artwork is updated to <img D, img B> before img B is fetched, then
Firefox will skip fetching a new image since img B is also an acceptable
choice in the new artwork. However, if Firefox fails to fetch img B, in
the current implementation, a new image at (previous index + 1) would be
fetched, as a fallback plan. In the above case, the index is 2, which is
out of the bound of the new artwork.
Instead of caching the previous index of an image in the artwork and
using the the previous index plus 1 as the index of the next available
image, the index of the next available image should be reset every time
when artwork is updated
Differential Revision: https://phabricator.services.mozilla.com/D81960
2020-07-06 20:53:28 +03:00
|
|
|
size_t mNextImageIndex;
|
2020-06-19 03:21:23 +03:00
|
|
|
|
2020-06-19 03:21:21 +03:00
|
|
|
mozilla::UniquePtr<mozilla::dom::FetchImageHelper> mImageFetcher;
|
|
|
|
mozilla::MozPromiseRequestHolder<mozilla::dom::ImagePromise>
|
|
|
|
mImageFetchRequest;
|
2020-06-19 03:21:13 +03:00
|
|
|
|
2020-02-20 15:04:12 +03:00
|
|
|
HWND mWindow; // handle to the invisible window
|
|
|
|
|
|
|
|
// EventRegistrationTokens are used to have a handle on a callback (to remove
|
|
|
|
// it again)
|
|
|
|
EventRegistrationToken mButtonPressedToken;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __MINGW32__
|
|
|
|
#endif // WIDGET_WINDOWS_WINDOWSSTMCPROVIDER_H_
|