Skip to content

Commit

Permalink
Auto merge of #27530 - jdm:media, r=Manishearth
Browse files Browse the repository at this point in the history
Fix crashes on video playback in UWP

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #27529 and fix #27526
- [x] These changes do not require tests because there's no way to test UWP right now.
  • Loading branch information
bors-servo committed Aug 6, 2020
2 parents 0573e9c + 5de6074 commit 776b564
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 27 deletions.
6 changes: 3 additions & 3 deletions components/script/dom/mediasession.rs
Expand Up @@ -20,7 +20,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::htmlmediaelement::HTMLMediaElement;
use crate::dom::mediametadata::MediaMetadata;
use crate::dom::window::Window;
use crate::realms::{AlreadyInRealm, InRealm};
use crate::realms::{enter_realm, InRealm};
use dom_struct::dom_struct;
use embedder_traits::MediaMetadata as EmbedderMediaMetadata;
use embedder_traits::MediaSessionEvent;
Expand Down Expand Up @@ -80,8 +80,8 @@ impl MediaSession {
if let Some(media) = self.media_instance.get() {
match action {
MediaSessionActionType::Play => {
let in_realm_proof = AlreadyInRealm::assert(&self.global());
media.Play(InRealm::Already(&in_realm_proof));
let realm = enter_realm(self);
media.Play(InRealm::Entered(&realm));
},
MediaSessionActionType::Pause => {
media.Pause();
Expand Down
2 changes: 2 additions & 0 deletions support/hololens/ServoApp/BrowserPage.cpp
Expand Up @@ -81,6 +81,8 @@ void BrowserPage::BindServoEvents() {
urlTextbox().GotFocus(std::bind(&BrowserPage::OnURLFocused, this, _1));
servoView().OnMediaSessionMetadata(
[=](hstring title, hstring artist, hstring album) {});
servoView().OnMediaSessionPosition(
[=](double duration, double position, double rate) {});
servoView().OnMediaSessionPlaybackStateChange([=](const auto &, int state) {
if (state == Servo::MediaSessionPlaybackState::None) {
mediaControls().Visibility(Visibility::Collapsed);
Expand Down
6 changes: 5 additions & 1 deletion support/hololens/ServoApp/ServoApp.vcxproj
Expand Up @@ -87,6 +87,8 @@
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(ProjectDir)\..\..\..\target\aarch64-uwp-windows-msvc\debug\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(ProjectDir)\..\..\..\target\x86_64-uwp-windows-msvc\debug\</AdditionalIncludeDirectories>
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">stdcpplatest</LanguageStandard>
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">OneCore.lib;WindowsApp.lib;%(AdditionalDependencies);simpleservo.dll.lib</AdditionalDependencies>
Expand All @@ -105,6 +107,8 @@
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(ProjectDir)\..\..\..\target\aarch64-uwp-windows-msvc\release</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);$(ProjectDir)\..\..\..\target\x86_64-uwp-windows-msvc\release</AdditionalIncludeDirectories>
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">stdcpplatest</LanguageStandard>
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Release|x64'">stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">OneCore.lib;WindowsApp.lib;%(AdditionalDependencies);simpleservo.dll.lib</AdditionalDependencies>
Expand Down Expand Up @@ -1010,4 +1014,4 @@
<Error Condition="!Exists('..\packages\ANGLE.WindowsStore.Servo.2.1.19\build\native\ANGLE.WindowsStore.Servo.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ANGLE.WindowsStore.Servo.2.1.19\build\native\ANGLE.WindowsStore.Servo.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.UI.Xaml.2.4.2\build\native\Microsoft.UI.Xaml.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.UI.Xaml.2.4.2\build\native\Microsoft.UI.Xaml.targets'))" />
</Target>
</Project>
</Project>
55 changes: 32 additions & 23 deletions support/hololens/ServoApp/ServoControl/Servo.cpp
Expand Up @@ -99,6 +99,12 @@ const char *get_clipboard_contents() {
return nullptr;
}

void on_media_session_set_position_state(double duration, double position,
double playback_rate) {
return sServo->Delegate().OnServoMediaSessionPosition(duration, position,
playback_rate);
}

void on_media_session_metadata(const char *title, const char *album,
const char *artist) {
return sServo->Delegate().OnServoMediaSessionMetadata(
Expand Down Expand Up @@ -296,29 +302,32 @@ Servo::Servo(std::optional<hstring> initUrl, hstring args, GLsizei width,
std::to_string(GetLastError()));
}

capi::CHostCallbacks c;
c.on_load_started = &on_load_started;
c.on_load_ended = &on_load_ended;
c.on_title_changed = &on_title_changed;
c.on_url_changed = &on_url_changed;
c.on_history_changed = &on_history_changed;
c.on_animating_changed = &on_animating_changed;
c.on_shutdown_complete = &on_shutdown_complete;
c.on_allow_navigation = &on_allow_navigation;
c.on_ime_show = &on_ime_show;
c.on_ime_hide = &on_ime_hide;
c.get_clipboard_contents = &get_clipboard_contents;
c.set_clipboard_contents = &set_clipboard_contents;
c.on_media_session_metadata = &on_media_session_metadata;
c.on_media_session_playback_state_change =
&on_media_session_playback_state_change;
c.prompt_alert = &prompt_alert;
c.prompt_ok_cancel = &prompt_ok_cancel;
c.prompt_yes_no = &prompt_yes_no;
c.prompt_input = &prompt_input;
c.on_devtools_started = &on_devtools_started;
c.show_context_menu = &show_context_menu;
c.on_log_output = &on_log_output;
capi::CHostCallbacks c = capi::CHostCallbacks{
.on_load_started = &on_load_started,
.on_load_ended = &on_load_ended,
.on_title_changed = &on_title_changed,
.on_allow_navigation = &on_allow_navigation,
.on_url_changed = &on_url_changed,
.on_history_changed = &on_history_changed,
.on_animating_changed = &on_animating_changed,
.on_shutdown_complete = &on_shutdown_complete,
.on_ime_show = &on_ime_show,
.on_ime_hide = &on_ime_hide,
.get_clipboard_contents = &get_clipboard_contents,
.set_clipboard_contents = &set_clipboard_contents,
.on_media_session_metadata = &on_media_session_metadata,
.on_media_session_playback_state_change =
&on_media_session_playback_state_change,
.on_media_session_set_position_state =
&on_media_session_set_position_state,
.prompt_alert = &prompt_alert,
.prompt_ok_cancel = &prompt_ok_cancel,
.prompt_yes_no = &prompt_yes_no,
.prompt_input = &prompt_input,
.on_devtools_started = &on_devtools_started,
.show_context_menu = &show_context_menu,
.on_log_output = &on_log_output,
};

capi::register_panic_handler(&on_panic);

Expand Down
1 change: 1 addition & 0 deletions support/hololens/ServoApp/ServoControl/Servo.h
Expand Up @@ -124,6 +124,7 @@ class ServoDelegate {
virtual void OnServoIMEHide() = 0;
virtual void OnServoDevtoolsStarted(bool, const unsigned int, hstring) = 0;
virtual void OnServoMediaSessionMetadata(hstring, hstring, hstring) = 0;
virtual void OnServoMediaSessionPosition(double, double, double) = 0;
virtual void OnServoMediaSessionPlaybackStateChange(int) = 0;
virtual void OnServoPromptAlert(hstring, bool) = 0;
virtual void OnServoShowContextMenu(std::optional<hstring>,
Expand Down
6 changes: 6 additions & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.cpp
Expand Up @@ -548,6 +548,12 @@ void ServoControl::OnServoIMEShow(hstring text, int32_t x, int32_t y,
});
}

void ServoControl::OnServoMediaSessionPosition(double duration, double position,
double playback_rate) {
RunOnUIThread(
[=] { mOnMediaSessionPositionEvent(duration, position, playback_rate); });
}

void ServoControl::OnServoMediaSessionMetadata(hstring title, hstring artist,
hstring album) {
RunOnUIThread([=] { mOnMediaSessionMetadataEvent(title, artist, album); });
Expand Down
10 changes: 10 additions & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.h
Expand Up @@ -151,6 +151,14 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
mOnCaptureGesturesEndedEvent.remove(token);
}

winrt::event_token
OnMediaSessionPosition(MediaSessionPositionDelegate const &handler) {
return mOnMediaSessionPositionEvent.add(handler);
};
void OnMediaSessionPosition(winrt::event_token const &token) noexcept {
mOnMediaSessionPositionEvent.remove(token);
}

winrt::event_token
OnMediaSessionMetadata(MediaSessionMetadataDelegate const &handler) {
return mOnMediaSessionMetadataEvent.add(handler);
Expand Down Expand Up @@ -187,6 +195,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
virtual void OnServoMediaSessionMetadata(winrt::hstring, winrt::hstring,
winrt::hstring);
virtual void OnServoMediaSessionPlaybackStateChange(int);
virtual void OnServoMediaSessionPosition(double, double, double);
virtual void OnServoPromptAlert(winrt::hstring, bool);
virtual void OnServoShowContextMenu(std::optional<winrt::hstring>,
std::vector<winrt::hstring>);
Expand All @@ -210,6 +219,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
winrt::event<EventDelegate> mOnCaptureGesturesStartedEvent;
winrt::event<EventDelegate> mOnCaptureGesturesEndedEvent;
winrt::event<MediaSessionMetadataDelegate> mOnMediaSessionMetadataEvent;
winrt::event<MediaSessionPositionDelegate> mOnMediaSessionPositionEvent;
winrt::event<Windows::Foundation::EventHandler<int>>
mOnMediaSessionPlaybackStateChangeEvent;

Expand Down
2 changes: 2 additions & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.idl
Expand Up @@ -3,6 +3,7 @@ namespace ServoApp {
delegate void EventDelegate();
delegate void HistoryChangedDelegate(Boolean back, Boolean forward);
delegate void MediaSessionMetadataDelegate(String title, String artist, String album);
delegate void MediaSessionPositionDelegate(Double duration, Double position, Double rate);
delegate void DevtoolsStatusChangedDelegate(DevtoolsStatus status, UInt32 port, String token);

enum DevtoolsStatus {
Expand Down Expand Up @@ -42,6 +43,7 @@ namespace ServoApp {
event Windows.Foundation.EventHandler<String> OnServoPanic;
event Windows.Foundation.EventHandler<String> OnURLChanged;
event MediaSessionMetadataDelegate OnMediaSessionMetadata;
event MediaSessionPositionDelegate OnMediaSessionPosition;
event Windows.Foundation.EventHandler<int> OnMediaSessionPlaybackStateChange;
Windows.Foundation.Collections.IVector<Pref> Preferences { get; };
Pref GetPref(String key);
Expand Down

0 comments on commit 776b564

Please sign in to comment.