summaryrefslogtreecommitdiff
path: root/src/media.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/media.c')
-rw-r--r--src/media.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/media.c b/src/media.c
index 1313b7da..eb4a8311 100644
--- a/src/media.c
+++ b/src/media.c
@@ -24,6 +24,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
24#include "gmdocument.h" 24#include "gmdocument.h"
25#include "gmrequest.h" 25#include "gmrequest.h"
26#include "ui/window.h" 26#include "ui/window.h"
27#include "ui/paint.h" /* size_SDLTexture */
27#include "audio/player.h" 28#include "audio/player.h"
28#include "app.h" 29#include "app.h"
29#include "stb_image.h" 30#include "stb_image.h"
@@ -261,6 +262,31 @@ void clear_Media(iMedia *d) {
261 clear_PtrArray(&d->downloads); 262 clear_PtrArray(&d->downloads);
262} 263}
263 264
265size_t memorySize_Media(const iMedia *d) {
266 size_t memSize = 0;
267 iConstForEach(PtrArray, i, &d->images) {
268 const iGmImage *img = i.ptr;
269 if (img->texture) {
270 const iInt2 texSize = size_SDLTexture(img->texture);
271 memSize += 4 * texSize.x * texSize.y; /* RGBA */
272 }
273 else {
274 memSize += size_Block(&img->partialData);
275 }
276 }
277 iConstForEach(PtrArray, a, &d->audio) {
278 const iGmAudio *audio = a.ptr;
279 if (audio->player) {
280 memSize += sourceDataSize_Player(audio->player);
281 }
282 }
283 iConstForEach(PtrArray, n, &d->downloads) {
284 const iGmDownload *down = n.ptr;
285 memSize += down->numBytes;
286 }
287 return memSize;
288}
289
264iBool setDownloadUrl_Media(iMedia *d, iGmLinkId linkId, const iString *url) { 290iBool setDownloadUrl_Media(iMedia *d, iGmLinkId linkId, const iString *url) {
265 iGmDownload *dl = NULL; 291 iGmDownload *dl = NULL;
266 iMediaId existing = findLinkDownload_Media(d, linkId); 292 iMediaId existing = findLinkDownload_Media(d, linkId);
@@ -464,6 +490,15 @@ iPlayer *audioPlayer_Media(const iMedia *d, iMediaId audioId) {
464 return NULL; 490 return NULL;
465} 491}
466 492
493void pauseAllPlayers_Media(const iMedia *d, iBool setPaused) {
494 for (size_t i = 0; i < size_PtrArray(&d->audio); ++i) {
495 const iGmAudio *audio = constAt_PtrArray(&d->audio, i);
496 if (audio->player) {
497 setPaused_Player(audio->player, setPaused);
498 }
499 }
500}
501
467iBool downloadInfo_Media(const iMedia *d, iMediaId downloadId, iGmMediaInfo *info_out) { 502iBool downloadInfo_Media(const iMedia *d, iMediaId downloadId, iGmMediaInfo *info_out) {
468 if (downloadId > 0 && downloadId <= size_PtrArray(&d->downloads)) { 503 if (downloadId > 0 && downloadId <= size_PtrArray(&d->downloads)) {
469 const iGmDownload *dl = constAt_PtrArray(&d->downloads, downloadId - 1); 504 const iGmDownload *dl = constAt_PtrArray(&d->downloads, downloadId - 1);