Bug 1271566 - VideoTrackList::RemoveTrack/AddTrack should also update selected index. r=jesup r=pehrsons

MozReview-Commit-ID: Bb4iPGbb9KW

--HG--
extra : transplant_source : %0A%10%5B%26J%93%0E%2C%FD%86%CE%AC%C8%132V%27%F1m8
This commit is contained in:
ctai 2016-05-10 16:28:24 +08:00
Родитель 7e0671d483
Коммит 56e1b21cb5
3 изменённых файлов: 40 добавлений и 1 удалений

Просмотреть файл

@ -45,7 +45,9 @@ public:
void AddTrack(MediaTrack* aTrack);
void RemoveTrack(const RefPtr<MediaTrack>& aTrack);
// In remove track case, the VideoTrackList::mSelectedIndex should be updated
// due to mTracks changed. No need to take care this in add track case.
virtual void RemoveTrack(const RefPtr<MediaTrack>& aTrack);
void RemoveTracks();

Просмотреть файл

@ -23,6 +23,41 @@ VideoTrackList::operator[](uint32_t aIndex)
return track->AsVideoTrack();
}
void
VideoTrackList::RemoveTrack(const RefPtr<MediaTrack>& aTrack)
{
// we need to find the video track before |MediaTrackList::RemoveTrack|. Or
// mSelectedIndex will not be valid. The check of mSelectedIndex == -1
// need to be done after RemoveTrack. Also the call of
// |MediaTrackList::RemoveTrack| is necessary even when mSelectedIndex = -1.
bool found;
VideoTrack* videoTrack = IndexedGetter(mSelectedIndex, found);
MediaTrackList::RemoveTrack(aTrack);
if (mSelectedIndex == -1) {
// There was no selected track and we don't select another track on removal.
return;
}
MOZ_ASSERT(found, "When mSelectedIndex is set it should point to a track");
MOZ_ASSERT(videoTrack, "The mSelectedIndex should be set to video track only");
// Let the caller of RemoveTrack deal with choosing the new selected track if
// it removes the currently-selected track.
if (aTrack == videoTrack) {
mSelectedIndex = -1;
return;
}
// The removed track was not the selected track and there is a
// currently-selected video track. We need to find the new location of the
// selected track.
for (size_t ix = 0; ix < mTracks.Length(); ix++) {
if (mTracks[ix] == videoTrack) {
mSelectedIndex = ix;
return;
}
}
}
void
VideoTrackList::EmptyTracks()
{

Просмотреть файл

@ -28,6 +28,8 @@ public:
VideoTrack* operator[](uint32_t aIndex);
void RemoveTrack(const RefPtr<MediaTrack>& aTrack) override;
void EmptyTracks() override;
// WebIDL