From 97f8640bf3708135462ab8d0e2127423dc98dd0f Mon Sep 17 00:00:00 2001 From: w00848065 Date: Tue, 26 Sep 2023 04:44:10 +0000 Subject: [PATCH] media playing state interface Signed-off-by: w00848065 --- include/capi/cef_media_handler_capi.h | 16 +++++-- include/cef_api_hash.h | 10 ++--- include/cef_media_handler.h | 10 ++++- include/internal/cef_types.h | 27 ++++++++++++ .../browser/alloy/alloy_browser_host_impl.cc | 40 +++++++++++++++++ .../browser/alloy/alloy_browser_host_impl.h | 9 ++++ libcef_dll/cpptoc/media_handler_cpptoc.cc | 44 +++++++++++++------ libcef_dll/ctocpp/media_handler_ctocpp.cc | 36 +++++++++++---- libcef_dll/ctocpp/media_handler_ctocpp.h | 14 +++--- 9 files changed, 169 insertions(+), 37 deletions(-) diff --git a/include/capi/cef_media_handler_capi.h b/include/capi/cef_media_handler_capi.h index d8e192964..df0985fd5 100644 --- a/include/capi/cef_media_handler_capi.h +++ b/include/capi/cef_media_handler_capi.h @@ -33,7 +33,7 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -// $hash=e823f91059dcf96103209e695047899105a83d5d$ +// $hash=95b00c792aeb50ffe1e0b3d733c5874481ccdadf$ // #ifndef CEF_INCLUDE_CAPI_CEF_MEDIA_HANDLER_CAPI_H_ @@ -61,13 +61,21 @@ typedef struct _cef_media_handler_t { /// // Called when the audio state changed. /// - void(CEF_CALLBACK* on_audio_state_changed)(struct _cef_media_handler_t* self, - struct _cef_browser_t* browser, + void(CEF_CALLBACK *on_audio_state_changed)(struct _cef_media_handler_t *self, + struct _cef_browser_t *browser, int audible); + + /// + // Called when the media playing state changed. + /// + void(CEF_CALLBACK *on_media_state_changed)(struct _cef_media_handler_t *self, + struct _cef_browser_t *browser, + cef_media_type_t type, + cef_media_playing_state_t state); } cef_media_handler_t; #ifdef __cplusplus } #endif -#endif // CEF_INCLUDE_CAPI_CEF_MEDIA_HANDLER_CAPI_H_ +#endif // CEF_INCLUDE_CAPI_CEF_MEDIA_HANDLER_CAPI_H_ diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 1dfe43c11..b20da4bbe 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -42,15 +42,15 @@ // way that may cause binary incompatibility with other builds. The universal // hash value will change if any platform is affected whereas the platform hash // values will change only if that particular platform is affected. -#define CEF_API_HASH_UNIVERSAL "9136694da06c3e39438804f09ab4f6169a8e751c" +#define CEF_API_HASH_UNIVERSAL "62092c82461dfa52fa710666add19af22a3714ef" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "2834804fc2e11abb6ac5c3550a6641981c2e748b" +#define CEF_API_HASH_PLATFORM "f8f81dcd278261a5bfb44036da8bbfbaca3d30c7" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "539213150036dbda126130249e711d4bb4f92cd7" +#define CEF_API_HASH_PLATFORM "c727fda5b4a15a5f00b3640e056e74d675479a10" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "8b7ac65714f030a8e55e13d6ada103799cbd158a" +#define CEF_API_HASH_PLATFORM "ae13513366be8d1a1c1eca9415290da124221a51" #elif defined(OS_OHOS) -#define CEF_API_HASH_PLATFORM "8b7ac65714f030a8e55e13d6ada103799cbd158a" +#define CEF_API_HASH_PLATFORM "ae13513366be8d1a1c1eca9415290da124221a51" #endif #ifdef __cplusplus diff --git a/include/cef_media_handler.h b/include/cef_media_handler.h index adb853f74..eebbdf136 100644 --- a/include/cef_media_handler.h +++ b/include/cef_media_handler.h @@ -49,13 +49,21 @@ /*--cef(source=client)--*/ class CefMediaHandler : public virtual CefBaseRefCounted { public: - + typedef cef_media_playing_state_t MediaPlayingState; + typedef cef_media_type_t MediaType; /// // Called when the audio state changed. /// /*--cef()--*/ virtual void OnAudioStateChanged(CefRefPtr browser, bool audible) {} + /// + // Called when the media playing state changed. + /// + /*--cef()--*/ + virtual void OnMediaStateChanged(CefRefPtr browser, + MediaType type, + MediaPlayingState state) {} }; #endif // CEF_INCLUDE_CEF_MEDIA_HANDLER_H_ diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 80c618479..d57d045ff 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -3615,6 +3615,33 @@ typedef struct _cef_autofill_popup_item_t { uint32_t unique_id; } cef_autofill_popup_item_t; +/// +// Media playing state. +/// +typedef enum { + /// + // media is playing + /// + PLAYING, + + /// + // media is paused + /// + PAUSE, + + /// + // media playing reached end of the stream + /// + END_OF_STREAM, +} cef_media_playing_state_t; + +/// +// Media type. +/// +typedef enum { + VIDEO, + AUDIO, +} cef_media_type_t; #ifdef __cplusplus } #endif diff --git a/libcef/browser/alloy/alloy_browser_host_impl.cc b/libcef/browser/alloy/alloy_browser_host_impl.cc index f2177b6bc..3d834caa2 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.cc +++ b/libcef/browser/alloy/alloy_browser_host_impl.cc @@ -1782,6 +1782,46 @@ void AlloyBrowserHostImpl::OnAudioStateChanged(bool audible) { } } +void AlloyBrowserHostImpl::MediaStartedPlaying( + const content::WebContentsObserver::MediaPlayerInfo& video_type, + const content::MediaPlayerId& id) { + LOG(INFO) << "AlloyBrowserHostImpl::MediaStartedPlaying, is_video: " << video_type.has_video; + + start_play_ = true; + cef_media_type_t type = video_type.has_video ? cef_media_type_t::VIDEO : cef_media_type_t::AUDIO; + if (client_.get() && client_->GetMediaHandler().get()) { + client_->GetMediaHandler()->OnMediaStateChanged(this, type, cef_media_playing_state_t::PLAYING); + } +} + +void AlloyBrowserHostImpl::MediaStoppedPlaying( + const content::WebContentsObserver::MediaPlayerInfo& video_type, + const content::MediaPlayerId& id, + content::WebContentsObserver::MediaStoppedReason reason) { + LOG(INFO) << "AlloyBrowserHostImpl::MediaStoppedPlaying, is_video: " << video_type.has_video << " stopped reason: " << static_cast(reason); + + if (!start_play_) { + return; + } + + cef_media_type_t type = video_type.has_video ? cef_media_type_t::VIDEO : cef_media_type_t::AUDIO; + cef_media_playing_state_t state; + + switch(reason) + { + case content::WebContentsObserver::MediaStoppedReason::kReachedEndOfStream: + state = cef_media_playing_state_t::END_OF_STREAM; + break; + case content::WebContentsObserver::MediaStoppedReason::kUnspecified: + state = cef_media_playing_state_t::PAUSE; + break; + } + + if (client_.get() && client_->GetMediaHandler().get()) { + client_->GetMediaHandler()->OnMediaStateChanged(this, type, state); + } +} + void AlloyBrowserHostImpl::OnRecentlyAudibleTimerFired() { audio_capturer_.reset(); } diff --git a/libcef/browser/alloy/alloy_browser_host_impl.h b/libcef/browser/alloy/alloy_browser_host_impl.h index db6b5c89c..201f97c6f 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.h +++ b/libcef/browser/alloy/alloy_browser_host_impl.h @@ -14,6 +14,7 @@ #include "include/cef_browser.h" #include "include/cef_client.h" #include "include/cef_frame.h" +#include "include/internal/cef_types.h" #include "libcef/browser/browser_host_base.h" #include "libcef/browser/browser_info.h" #include "libcef/browser/file_dialog_manager.h" @@ -353,6 +354,12 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase, void DidFinishNavigation( content::NavigationHandle* navigation_handle) override; void OnAudioStateChanged(bool audible) override; + void MediaStartedPlaying(const content::WebContentsObserver::MediaPlayerInfo& video_type, + const content::MediaPlayerId& id) override; + void MediaStoppedPlaying( + const content::WebContentsObserver::MediaPlayerInfo& video_type, + const content::MediaPlayerId& id, + content::WebContentsObserver::MediaStoppedReason reason) override; void AccessibilityEventReceived( const content::AXEventNotificationDetails& content_event_bundle) override; void AccessibilityLocationChangesReceived( @@ -451,6 +458,8 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase, int nweb_id_ = -1; bool is_hidden_ = false; #endif + + bool start_play_ = false; }; #endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_HOST_IMPL_H_ diff --git a/libcef_dll/cpptoc/media_handler_cpptoc.cc b/libcef_dll/cpptoc/media_handler_cpptoc.cc index 3c3fe6e6d..e3ea8ec2b 100644 --- a/libcef_dll/cpptoc/media_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/media_handler_cpptoc.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=2dcdc10f6a076e7300650e5bb427fbec9e42fc7e$ +// $hash=a41d88232e2c9d26dbe56672b58214f97d3a0ff4$ // #include "libcef_dll/cpptoc/media_handler_cpptoc.h" @@ -20,10 +20,8 @@ namespace { // MEMBER FUNCTIONS - Body may be edited by hand. -void CEF_CALLBACK -media_handler_on_audio_state_changed(struct _cef_media_handler_t* self, - cef_browser_t* browser, - int audible) { +void CEF_CALLBACK media_handler_on_audio_state_changed( + struct _cef_media_handler_t *self, cef_browser_t *browser, int audible) { shutdown_checker::AssertNotShutdown(); // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -41,12 +39,33 @@ media_handler_on_audio_state_changed(struct _cef_media_handler_t* self, CefBrowserCToCpp::Wrap(browser), audible ? true : false); } -} // namespace +void CEF_CALLBACK media_handler_on_media_state_changed( + struct _cef_media_handler_t *self, cef_browser_t *browser, + cef_media_type_t type, cef_media_playing_state_t state) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return; + + // Execute + CefMediaHandlerCppToC::Get(self)->OnMediaStateChanged( + CefBrowserCToCpp::Wrap(browser), type, state); +} + +} // namespace // CONSTRUCTOR - Do not edit by hand. CefMediaHandlerCppToC::CefMediaHandlerCppToC() { GetStruct()->on_audio_state_changed = media_handler_on_audio_state_changed; + GetStruct()->on_media_state_changed = media_handler_on_media_state_changed; } // DESTRUCTOR - Do not edit by hand. @@ -56,17 +75,16 @@ CefMediaHandlerCppToC::~CefMediaHandlerCppToC() { } template <> -CefRefPtr CefCppToCRefCounted< - CefMediaHandlerCppToC, - CefMediaHandler, - cef_media_handler_t>::UnwrapDerived(CefWrapperType type, - cef_media_handler_t* s) { +CefRefPtr +CefCppToCRefCounted::UnwrapDerived(CefWrapperType type, + cef_media_handler_t + *s) { NOTREACHED() << "Unexpected class type: " << type; return nullptr; } template <> -CefWrapperType CefCppToCRefCounted::kWrapperType = WT_MEDIA_HANDLER; diff --git a/libcef_dll/ctocpp/media_handler_ctocpp.cc b/libcef_dll/ctocpp/media_handler_ctocpp.cc index 29a65123d..00050eb30 100644 --- a/libcef_dll/ctocpp/media_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/media_handler_ctocpp.cc @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=2722fa796f55add02305722393faeadcaa86bf66$ +// $hash=850f202b8a663fef7c007b504bdc56bae04f785f$ // #include "libcef_dll/ctocpp/media_handler_ctocpp.h" @@ -23,7 +23,7 @@ void CefMediaHandlerCToCpp::OnAudioStateChanged(CefRefPtr browser, bool audible) { shutdown_checker::AssertNotShutdown(); - cef_media_handler_t* _struct = GetStruct(); + cef_media_handler_t *_struct = GetStruct(); if (CEF_MEMBER_MISSING(_struct, on_audio_state_changed)) return; @@ -39,6 +39,28 @@ void CefMediaHandlerCToCpp::OnAudioStateChanged(CefRefPtr browser, audible); } +NO_SANITIZE("cfi-icall") +void CefMediaHandlerCToCpp::OnMediaStateChanged(CefRefPtr browser, + MediaType type, + MediaPlayingState state) { + shutdown_checker::AssertNotShutdown(); + + cef_media_handler_t *_struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, on_media_state_changed)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return; + + // Execute + _struct->on_media_state_changed(_struct, CefBrowserCppToC::Wrap(browser), + type, state); +} + // CONSTRUCTOR - Do not edit by hand. CefMediaHandlerCToCpp::CefMediaHandlerCToCpp() {} @@ -50,17 +72,15 @@ CefMediaHandlerCToCpp::~CefMediaHandlerCToCpp() { } template <> -cef_media_handler_t* -CefCToCppRefCounted::UnwrapDerived(CefWrapperType type, - CefMediaHandler* c) { + CefMediaHandler *c) { NOTREACHED() << "Unexpected class type: " << type; return nullptr; } template <> -CefWrapperType CefCToCppRefCounted::kWrapperType = WT_MEDIA_HANDLER; diff --git a/libcef_dll/ctocpp/media_handler_ctocpp.h b/libcef_dll/ctocpp/media_handler_ctocpp.h index a30076c08..ab3b64314 100644 --- a/libcef_dll/ctocpp/media_handler_ctocpp.h +++ b/libcef_dll/ctocpp/media_handler_ctocpp.h @@ -9,7 +9,7 @@ // implementations. See the translator.README.txt file in the tools directory // for more information. // -// $hash=b3b158709709751c908d88949d4d83081e2ae1f0$ +// $hash=19ab4c6d715b63d1acb26150828c87d08f2b188e$ // #ifndef CEF_LIBCEF_DLL_CTOCPP_MEDIA_HANDLER_CTOCPP_H_ @@ -26,16 +26,18 @@ // Wrap a C structure with a C++ class. // This class may be instantiated and accessed DLL-side only. -class CefMediaHandlerCToCpp : public CefCToCppRefCounted { - public: +class CefMediaHandlerCToCpp + : public CefCToCppRefCounted { +public: CefMediaHandlerCToCpp(); virtual ~CefMediaHandlerCToCpp(); // CefMediaHandler methods. void OnAudioStateChanged(CefRefPtr browser, bool audible) override; + void OnMediaStateChanged(CefRefPtr browser, MediaType type, + MediaPlayingState state) override; }; -#endif // CEF_LIBCEF_DLL_CTOCPP_MEDIA_HANDLER_CTOCPP_H_ +#endif // CEF_LIBCEF_DLL_CTOCPP_MEDIA_HANDLER_CTOCPP_H_ -- Gitee