Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make media tracks aware of their associated track list #22912

Closed
jdm opened this issue Feb 19, 2019 · 14 comments
Closed

Make media tracks aware of their associated track list #22912

jdm opened this issue Feb 19, 2019 · 14 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Feb 19, 2019

Per #22622 (comment) the AudioTrack, VideoTrack, and TextTrack interfaces will need to store a member pointing at the track list object that they are associated with. This will look something like DomRefCell<Option<Dom<AudioTrackList>>> and it will be updated when the track object is added to a list or removed from one.

Code: components/script/dom/audiotrack.rs, components/script/dom/videotrack.rs, components/texttrack.rs
Tests: ./mach test-wpt tests/wpt/web-platform-tests/html/semantics/embedded-content/media-elements/track/track-element/

@jdm
Copy link
Member Author

@jdm jdm commented Jul 12, 2019

@moonlightdrive This might be a good first issue!

@moonlightdrive
Copy link
Contributor

@moonlightdrive moonlightdrive commented Jul 13, 2019

Thanks @jdm! I'll take a look at this one

@sreeise sreeise mentioned this issue Sep 22, 2019
4 of 5 tasks complete
bors-servo added a commit that referenced this issue Oct 2, 2019
Integrates media track selection

<!-- Please describe your changes on the following line: -->
Updates audio/video track selection to use the servo media player track selection methods.

This is technically only a partial fix because only one audio track can be set at a time and servo_media needs to be updated to handle multiple audio tracks. Once/if this goes through I can file follow up issue for that.

I believe this also inadvertently covers at least some of #22912

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #22799 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because -  This probably should have a test case. But I am not aware of a way, at least not from servo, to test that the actual audio or video changed in the underlying player or on screen.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24265)
<!-- Reviewable:end -->
@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Dec 19, 2019

@jdm what changes are still required here? I see that the required member has been defined but without the DomRefCell wrapper

@jdm
Copy link
Member Author

@jdm jdm commented Dec 19, 2019

@kunalmohan I believe we still need the DomRefCell so that the associated track list can be updated when it's added or removed. That's the work that still needs to happen here.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Dec 19, 2019

Okay. I'll start working on this issue.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Dec 20, 2019

I am a bit confused here so I just want to confirm I am thinking in the right direction here. I will have to update the track_list member of struct AudioTrack in this function, right?

pub fn add(&self, track: &AudioTrack) {
self.tracks.borrow_mut().push(Dom::from_ref(track));
}

I don't see any function that removes a track from a tracklist, so what about updating it during removal of track object?

@jdm
Copy link
Member Author

@jdm jdm commented Dec 20, 2019

pub fn clear(&self) {
self.tracks.borrow_mut().clear();
}
removes all tracks from a track list.

Also, as part of this work we should implement the setting behaviour from https://html.spec.whatwg.org/multipage/media.html#dom-videotrack-selected, which is the motivation for this issue.

@jdm
Copy link
Member Author

@jdm jdm commented Dec 20, 2019

And to explicitly answer your question: yes.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Dec 21, 2019

texttracklist.rs does not have a clear() function, but has the following function:

// FIXME(#22314, dlrobertson) allow TextTracks to be
// removed from the TextTrackList.
#[allow(dead_code)]
pub fn remove(&self, idx: usize) {
self.dom_tracks.borrow_mut().remove(idx);
self.upcast::<EventTarget>()
.fire_event(atom!("removetrack"));
}
}

Is there a need for clear() function here or should I proceed with the current code?

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Dec 21, 2019

Also, as part of this work we should implement the setting behaviour from https://html.spec.whatwg.org/multipage/media.html#dom-videotrack-selected, which is the motivation for this issue.

I think the setting behaviour is already implemented here.

pub fn set_selected(&self, idx: usize, value: bool) {
let track = match self.item(idx) {
Some(t) => t,
None => return,
};
// If the chosen tracks selected status is the same as the new status, return early.
if track.selected() == value {
return;
}
let global = &self.global();
let this = Trusted::new(self);
let (source, canceller) = global
.as_window()
.task_manager()
.media_element_task_source_with_canceller();
if let Some(current) = self.selected_index() {
self.tracks.borrow()[current].set_selected(false);
}
track.set_selected(value);
if let Some(media_element) = self.media_element.as_ref() {
media_element.set_video_track(idx, value);
}
let _ = source.queue_with_canceller(
task!(media_track_change: move || {
let this = this.root();
this.upcast::<EventTarget>().fire_event(atom!("change"));
}),
&canceller,
);
}

Or is there something that need to be implemented yet?

Sorry for troubling you with so many questions 😅 . Being a beginner at rust and web-platforms, I am still trying to understand the concepts implemented here.

Thanks for the help 😄

@jdm
Copy link
Member Author

@jdm jdm commented Dec 21, 2019

The setting that I was describing is implemented in

// https://html.spec.whatwg.org/multipage/#dom-videotrack-selected
fn SetSelected(&self, value: bool) {
if let Some(list) = self.track_list.as_ref() {
if let Some(idx) = list.find(self) {
list.set_selected(idx, value);
}
}
self.set_selected(value);
}
. This would not match the specification if the video track list was cleared, and then some JS invoked the selected setter on a video track that was cleared. Does that make sense?

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Dec 22, 2019

Yeah, that makes sense. So, on clearing a tracklist member I have updated the track_list member of each associated track to None. I think that should solve it.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Dec 22, 2019

texttracklist.rs does not have a clear() function, but has the following function:

// FIXME(#22314, dlrobertson) allow TextTracks to be
// removed from the TextTrackList.
#[allow(dead_code)]
pub fn remove(&self, idx: usize) {
self.dom_tracks.borrow_mut().remove(idx);
self.upcast::<EventTarget>()
.fire_event(atom!("removetrack"));
}
}

Is there a need for clear() function here or should I proceed with the current code?

What about this?

@jdm
Copy link
Member Author

@jdm jdm commented Dec 22, 2019

The remove method isn't used yet, but it would be nice to add the same support for updating the removed track's associated list.

bors-servo added a commit that referenced this issue Jan 3, 2020
Add `track_list` member to AudioTrack, VideoTrack, TextTrack structs

Add member to the track structs pointing at their associated tracklist
and update it when the track is added or removed from a tracklist.

r?@jdm

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #22912  (GitHub issue number if applicable)

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bors-servo bors-servo closed this in d47f0ad Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.