Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Prev Previous commit
Next Next commit
[[ Player ]] Reduce property changes performed when setting enabledTr…
…acks

This patch reduces the work done by platform players when setting the
enabledTracks property by only changing the enabled state of tracks
added or removed from the enabledTracks.

This is useful for some player implementations (e.g. Windows
MediaFoundation) which need to reload the media source when enabling or
disabling tracks.
  • Loading branch information
Ian Macphail committed May 15, 2020
commit d304877c284bd641cb8a5cf5190128d295d088e1
44 changes: 25 additions & 19 deletions engine/src/player-platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,28 +1870,34 @@ void MCPlayer::setenabledtracks(uindex_t p_count, uint32_t *p_tracks_id)
{
uindex_t t_track_count;
MCPlatformCountPlayerTracks(m_platform_player, t_track_count);
for(uindex_t i = 0; i < t_track_count; i++)

// convert array of track ids to boolean array of enabled states
MCAutoArray<bool> t_new_enabled;
/* UNCHECKED */ t_new_enabled.New(t_track_count);
for (uindex_t i = 0; i < p_count; i++)
{
bool t_enabled;
t_enabled = false;
MCPlatformSetPlayerTrackProperty(m_platform_player, i, kMCPlatformPlayerTrackPropertyEnabled, kMCPlatformPropertyTypeBool, &t_enabled);
}

for (uindex_t i = 0; i < t_track_count; i++)
{
// If the list of enabledtracks we set contains 0 (empty), just skip it
if (p_tracks_id[i] == 0)
continue;

uindex_t t_index;
if (!MCPlatformFindPlayerTrackWithId(m_platform_player, p_tracks_id[i], t_index))
return;

bool t_enabled;
t_enabled = true;
MCPlatformSetPlayerTrackProperty(m_platform_player, t_index, kMCPlatformPlayerTrackPropertyEnabled, kMCPlatformPropertyTypeBool, &t_enabled);
}


uindex_t t_index;
if (!MCPlatformFindPlayerTrackWithId(m_platform_player, p_tracks_id[i], t_index))
return;

t_new_enabled[t_index] = true;
}

for (uindex_t i = 0; i < t_track_count; i++)
{
bool t_enabled;
MCPlatformGetPlayerTrackProperty(m_platform_player, i, kMCPlatformPlayerTrackPropertyEnabled, kMCPlatformPropertyTypeBool, &t_enabled);

if (t_enabled != t_new_enabled[i])
{
t_enabled = t_new_enabled[i];
MCPlatformSetPlayerTrackProperty(m_platform_player, i, kMCPlatformPlayerTrackPropertyEnabled, kMCPlatformPropertyTypeBool, &t_enabled);
}
}

MCRectangle t_movie_rect;
MCPlatformGetPlayerProperty(m_platform_player, kMCPlatformPlayerPropertyMovieRect, kMCPlatformPropertyTypeRectangle, &t_movie_rect);
MCRectangle trect = resize(t_movie_rect);
Expand Down