Asterisk - The Open Source Telephony Project GIT-master-f36a736
media_cache.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2015, Digium, Inc.
5 *
6 * Matt Jordan <mjordan@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*!
20 * \file
21 * \brief An in-memory media cache
22 */
23
24#ifndef _ASTERISK_MEDIA_CACHE_H
25#define _ASTERISK_MEDIA_CACHE_H
26
27#if defined(__cplusplus) || defined(c_plusplus)
28extern "C" {
29#endif
30
31struct ast_variable;
32
33/*!
34 * \brief Check if an item exists in the cache
35 *
36 * \param uri The unique URI for the media item
37 *
38 * \retval 0 uri does not exist in cache
39 * \retval 1 uri does exist in cache
40 */
41int ast_media_cache_exists(const char *uri);
42
43/*!
44 * \brief Retrieve an item from the cache
45 *
46 * \param uri The unique URI for the media item
47 * \param preferred_file_name The preferred name for the file storing the
48 * media once it is retrieved. Can be NULL.
49 * \param file_path Buffer to store the full path to the media in the
50 * cache
51 * \param len The length of the buffer pointed to by \c file_path
52 *
53 * \retval 0 The item was retrieved successfully
54 * \retval -1 The item could not be retrieved
55 *
56 * Example Usage:
57 * \code
58 * char media[PATH_MAX];
59 * int res;
60 *
61 * res = ast_media_cache_retrieve("http://localhost/foo.wav", NULL,
62 * media, sizeof(media));
63 * \endcode
64 *
65 * \details
66 * Retrieving an item will cause the \ref bucket Bucket backend associated
67 * with the URI scheme in \c uri to be queried. If the Bucket backend
68 * does not require an update, the cached information is used to find the
69 * file associated with \c uri, and \c file_path is populated with the
70 * location of the media file associated with \c uri.
71 *
72 * If the item is not in the cache, the item will be retrieved using the
73 * \ref bucket backend. When this occurs, if \c preferred_file_name is given,
74 * it will be used as the destination file for the retrieval. When retrieval
75 * of the media from the backend is complete, \c file_path is then populated
76 * as before.
77 */
78int ast_media_cache_retrieve(const char *uri, const char *preferred_file_name,
79 char *file_path, size_t len);
80
81/*!
82 * \brief Retrieve metadata from an item in the cache
83 *
84 * \param uri The unique URI for the media item
85 * \param key The key of the metadata to retrieve
86 * \param value Buffer to store the value in
87 * \param len The length of the buffer pointed to by \c value
88 *
89 * \retval 0 The metadata was retrieved successfully
90 * \retval -1 The metadata could not be retrieved
91 *
92 * Example Usage:
93 * \code
94 *
95 * int res;
96 * char file_size[32];
97 *
98 * res = ast_media_cache_retrieve_metadata("http://localhost/foo.wav", "size",
99 * file_size, sizeof(file_size));
100 * \endcode
101 */
102int ast_media_cache_retrieve_metadata(const char *uri, const char *key,
103 char *value, size_t len);
104
105/*!
106 * \brief Create/update a cached media item
107 *
108 * \param uri The unique URI for the media item to store in the cache
109 * \param file_path Full path to the media file to be cached
110 * \param metadata Metadata to store with the cached item
111 *
112 * \retval 0 The item was cached
113 * \retval -1 An error occurred when creating/updating the item
114 *
115 * Example Usage:
116 * \code
117 * int res;
118 *
119 * res = ast_media_cache_create_or_update("http://localhost/foo.wav",
120 * "/tmp/foo.wav", NULL);
121 * \endcode
122 *
123 * \note This method will overwrite whatever has been provided by the
124 * \ref bucket backend.
125 *
126 * \details
127 * While \ref ast_media_cache_retrieve is used to retrieve media from
128 * some \ref bucket provider, this method allows for overwriting what
129 * is provided by a backend with some local media. This is useful for
130 * reconstructing or otherwise associating local media with a remote
131 * URI, deferring updating of the media from the backend to some later
132 * retrieval.
133 */
134int ast_media_cache_create_or_update(const char *uri, const char *file_path,
135 struct ast_variable *metadata);
136
137/*!
138 * \brief Remove an item from the media cache
139 *
140 * \param uri The unique URI for the media item to store in the cache
141 *
142 * \retval 0 success
143 * \retval -1 error
144 *
145 * Example Usage:
146 * \code
147 * int res;
148 *
149 * res = ast_media_cache_delete("http://localhost/foo.wav");
150 * \endcode
151 *
152 * \details
153 * This removes an item completely from the media cache. Any files local
154 * on disk associated with the item are deleted as well.
155 *
156 * \note It is up to the \ref bucket implementation whether or not this
157 * affects any non-local storage
158 */
159int ast_media_cache_delete(const char *uri);
160
161/*!
162 * \brief Initialize the media cache
163 *
164 * \note This should only be called once, during Asterisk initialization
165 *
166 * \retval 0 success
167 * \retval -1 error
168 */
169int ast_media_cache_init(void);
170
171#if defined(__cplusplus) || defined(c_plusplus)
172}
173#endif
174
175#endif /* _ASTERISK_MEDIA_CACHE_H */
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ast_media_cache_init(void)
Initialize the media cache.
Definition: media_cache.c:671
int ast_media_cache_retrieve(const char *uri, const char *preferred_file_name, char *file_path, size_t len)
Retrieve an item from the cache.
Definition: media_cache.c:157
int ast_media_cache_create_or_update(const char *uri, const char *file_path, struct ast_variable *metadata)
Create/update a cached media item.
Definition: media_cache.c:268
int ast_media_cache_delete(const char *uri)
Remove an item from the media cache.
Definition: media_cache.c:347
int ast_media_cache_exists(const char *uri)
Check if an item exists in the cache.
Definition: media_cache.c:53
int ast_media_cache_retrieve_metadata(const char *uri, const char *key, char *value, size_t len)
Retrieve metadata from an item in the cache.
Definition: media_cache.c:241
Structure for variables, used for configurations and for channel variables.
int value
Definition: syslog.c:37