decoder: h264: simplify and optimize reference frame store updates.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 6 May 2014 13:28:29 +0000 (15:28 +0200)
committerXiang, Haihao <haihao.xiang@intel.com>
Mon, 16 Jun 2014 03:53:35 +0000 (11:53 +0800)
commitd2e843eed7fa31d86e196fb0e07b9cd3c377c969
treeb9ef0a71077b6c986651c9f6ef87d51bea4d2833
parenta35d3c2d8f006d4b019881a23ad57819eeb7d62e
decoder: h264: simplify and optimize reference frame store updates.

Simplify and optimize the update process of the reference frame store.
Use less iterations to look up existing objects. Use a cache to store
the free'd slots.

Prerequisite: the reference_objects[] array was previously arranged in
a way that the element at index i is exactly the object_surface that
corresponds to the VA surface identified by the VAPictureH264.picture_id
located at index i in the ReferenceFrames[] array.

Theory of operations:

1. Obsolete entries are removed first, i.e. entries in the internal DPB
   that no longer have a match in the supplied ReferenceFrames[] array.
   That obsolete entry index is stored in a local cache: free_slots[].

2. This cache is completed with entries considered as "invalid" or "not
   present", sequentially while traversing the frame store for obsolete
   entries. At the end of this removal process, the free_slots[] array
   represents all possible indices in there that could be re-used for
   new reference frames to track.

3. The list of ReferenceFrames[] objects is traversed for new entries
   that are not already in the frame store. If an entry needs to be
   added, it is placed at the index obtained from the next free_slots[]
   element. There is no need to traverse the frame store array again,
   the next available slot can be known from that free_slots[] cache.

v2: dropped the superfluous "found" variable [Yakui]
v3: renamed "free_slots" array to "free_refs", which now holds
  GenFrameStore entries

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
(cherry picked from commit 70ecad1264255123df99b472891e8ee90399013c)
src/i965_decoder_utils.c