Commit Graph

4 Commits

Author SHA1 Message Date
Joshua Colp 72a897c534 media_cache: Demote warning to debug as it may occur often.
The file playback system will now query the media cache and then
the old file functionality. Under normal conditions this will result
in the cache failing to retrieve a file causing a warning message
to get output each time a file is played back.

This change demotes this warning to a debug message.

Change-Id: Ib72246ba300b5cce32774bfb3c26634bfb708624
2016-03-25 10:22:36 -05:00
Matt Jordan 791b4c9f81 main/media_cache: Provide an extension on the local file associated with a URI
This patch does the following:

First, it addresses file extension handling in the media cache. The media core
in Asterisk is a bit interesting in that it wants:
 * A file to have an extension on it. That extension is used to associate the
   file with a defined format module.
 * The filename passed to the core to not have an extension on it. This allows
   the core to match the available file formats with the format a channel
   is capable of handling.

Unfortunately, this makes the current implementation a bit lacking in the media
cache. By default, we do not store the extension of a retrieved URI on the
local file that is created. As a result, the media core does not know what
format the file is, and the file is ignored. Modifying the file outside of the
media core is bad, as we would not be able to update the internal
ast_bucket_file's path.

At the same time, we do not want to pass the extension out in the file_path
parameter in ast_media_cache_retrieve. This parameter is intended to be fed
into the media core; if we passed the extension, all callers would have to
strip it off.

Thus, this patch does the following:
* If there is an extension specified in the URL, we append it to the local
  file name (if a preferred file name isn't specified), and we store that
  in the local file path.
* The extension, however, is stripped off of the file_path parameter passed
  back out of ast_media_cache_retrieve.

Second, this patch causes stale items to be completely removed from the system.
Prior to this patch, sound files could be orphaned due to the bucket
referencing the file being deleted, but the file itself not being removed. This
is now addressed by explicitly calling ast_bucket_file_delete on the
bucket_file when it is deemed to be stale. Note that this only happen when we
know we will attempt to retrieve the resource again.

Finally, this patch changes the AO2 container holding media items to just use
a regular mutex. The usage for this container already assumed it was a plain
mutex, and - given that retrieval of an item can cause it to be replaced in
the container - a mutex makes more sense than a read/write lock.

Change-Id: I51667fff86ae8d2e4a663555dfa85b11e935fe0f
2016-03-23 11:46:39 -03:00
Matt Jordan ef82190804 media cache: Add CLI commands
This patch adds five CLI commands for the media cache:
 * 'media cache show all' - display a summary of all items in the media
   cache.
 * 'media cache show <uri>' - display detailed information about a
   single item in the media cache.
 * 'media cache delete <uri>' - remove an item from the media cache, and
   inform the bucket backend for the URI scheme to remove the item as
   well.
 * 'media cache refresh <uri>' - refresh a URI. If the item does not
   exist in the media cache, the bucket backend will pull down the media
   associated with the URI and create the item in the cache.
 * 'media cache create <uri>' - create an item in the media cache from
   some local media storage. Note that the bucket backend for the URI
   scheme must still permit the item creation.

Change-Id: Id1c5707a3b8e2d96b56e4691a46a936cd171f4ae
2015-07-12 20:44:16 -05:00
Matthew Jordan 3ea0d38396 media cache: Add a core API and facade for a backend agnostic media cache
This patch adds a new API to the Asterisk core that acts as a media
cache. The core API itself is mostly a thin wrapper around some bucket
API provided implementation that itself acts as the mechanism of
retrieval for media. The media cache API in the core provides the
following:
 * A very thin in-memory cache of the active bucket_file items. Unlike a
   more traditional cache, it provides no expiration mechanisms. Most
   queries that hit the in-memory cache will also call into the bucket
   implementations as well. The bucket implementations are responsible
   for determining whether or not the active record is active and valid.
   This makes sense for the most likely implementation of a media cache
   backend, i.e., HTTP. The HTTP layer itself is the actual arbiter of
   whether or not a record is truly active; as such, the in-memory cache
   in the core has to defer to it.
 * The ability to create new items in the media cache from local
   resources. This allows for re-creation of items in the cache on
   restart.
 * Synchronization of items in the media cache to the AstDB. This
   also includes various pieces of important metadata.

The API provides sufficient access that higher level APIs, such as the
file or app APIs, do not have to worry about the semantics of the bucket
APIs when needing to playback a resource.

In addition, this patch provides unit tests for the media cache API. The
unit tests use a fake bucket backend to verify correctness.

Change-Id: I11227abbf14d8929eeb140ddd101dd5c3820391e
2015-07-12 20:44:16 -05:00