Tracking: Make image accessor own what it needs

Previously image accessor was sharing array pointer for tracks access.
Now it is possible to pass a temporary array valid only during the
initialization process.

Should be no functional changes.
This commit is contained in:
Sergey Sharybin 2020-11-30 15:55:52 +01:00
parent 13ce25d24c
commit 0f30edc20c
2 changed files with 16 additions and 1 deletions

View File

@ -1021,7 +1021,10 @@ TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR
memcpy(accessor->clips, clips, num_clips * sizeof(MovieClip *));
accessor->num_clips = num_clips;
accessor->tracks = tracks;
accessor->tracks = MEM_malloc_arrayN(
num_tracks, sizeof(MovieTrackingTrack *), "image accessor tracks");
memcpy(accessor->tracks, tracks, num_tracks * sizeof(MovieTrackingTrack *));
accessor->num_tracks = num_tracks;
accessor->libmv_accessor = libmv_FrameAccessorNew((libmv_FrameAccessorUserData *)accessor,
@ -1040,5 +1043,6 @@ void tracking_image_accessor_destroy(TrackingImageAccessor *accessor)
IMB_moviecache_free(accessor->cache);
libmv_FrameAccessorDestroy(accessor->libmv_accessor);
BLI_spin_end(&accessor->cache_lock);
MEM_freeN(accessor->tracks);
MEM_freeN(accessor);
}

View File

@ -132,14 +132,25 @@ struct libmv_FrameAccessor;
#define MAX_ACCESSOR_CLIP 64
typedef struct TrackingImageAccessor {
struct MovieCache *cache;
struct MovieClip *clips[MAX_ACCESSOR_CLIP];
int num_clips;
/* Array of tracks which are being tracked.
* Points to actual track from the `MovieClip` (or multiple of them).
* This accessor owns the array, but not the tracks themselves. */
struct MovieTrackingTrack **tracks;
int num_tracks;
struct libmv_FrameAccessor *libmv_accessor;
SpinLock cache_lock;
} TrackingImageAccessor;
/* Clips are used to access images of an actual footage.
* Tracks are used to access masks associated with the tracks.
*
* NOTE: Both clips and tracks arrays are copied into the image accessor. It means that the caller
* is allowed to pass temporary arrays which are only valid during initialization. */
TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR_CLIP],
int num_clips,
MovieTrackingTrack **tracks,