How do I programatically add fields to the Media module's field tables? I use the Media (ver, 2) module to manage a library of media assets.  It allows reuse of the same media in several nodes and keeps track of media use.

When reusing media (e.g.) images, I want to be able to add different captions (and maybe other metadata) to each use of the same image. I.e.: When I use the same image attached to two different nodes, I want to set the caption for each instance.

There is a great tutorial “How to Add Captions to Images in Drupal” about adding captions – but its approach is to add the caption to the image entity itself. This means that the same caption must be repeated whenever the image is reused.  I want an unique caption for each use instance.

I’ve noticed that version 2 (7.x-2.0-alpha4) of the Media  module manage some metadata (e.g. field_media_description) about each media instance use in the two tables {field_data_field_media} and {field_revision_field_media}. I’ve tried to use the already existing field field_media_description for the caption. This works, and almost does what I want.

However, I want the caption field to be a textarea (not a textfield), and I prefer not to overload some existing field with new functionality (maybe breaking the initial intent for this existing field) - so I want to add another field (field_media_caption) to these tables.

I’ve been digging about the Media module for days, trying to figure out how to add my own fields to these tables, and have not been able to figure it out.

So:
How do I programatically add additional metadata fields to the Media module's field tables?

I will also accept an alternative solution that allows me to use a different module to manage a library of reusable images and add captions fields per use-instance.
There is a sandbox module I helped with, Media Wrapper, which solves this problem by managing media via a field collection. This has the advantage of making it possible to associate any fields you like with a media file, including captions. And the metadata is all per-use rather than per-file.

As it is a sandbox module, it's not as polished as we would like but it does a reasonable job of solving this problem.

To use it, once installed you create a field collection with your media field and meta data and then configure it via field settings of the field collection to say how each field is to be used (for alt text, title, caption etc).