summaryrefslogtreecommitdiff
path: root/src/media.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-10-06 13:27:31 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-10-06 13:27:31 +0300
commit403d8fc06fda157b134f96328f98b9305509b5a3 (patch)
treea7ac4dc92dfcaa9fafddb65377a1d8a8cf61cccd /src/media.c
parent3ed9a627712bf6223e521e1f63a113404fea824a (diff)
Updating media content
Making it possible for media to be partially updated, for streaming. Also fixed a problem with multiple concurrent audio players started on a single media item.
Diffstat (limited to 'src/media.c')
-rw-r--r--src/media.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/media.c b/src/media.c
index ad0682b1..b72ec32c 100644
--- a/src/media.c
+++ b/src/media.c
@@ -140,21 +140,41 @@ void clear_Media(iMedia *d) {
140} 140}
141 141
142void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBlock *data, 142void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBlock *data,
143 iBool allowHide) { 143 int flags) {
144 if (!mime || !data) { 144 const iBool isPartial = (flags & partialData_MediaFlag) != 0;
145 iMediaId existing = findLinkImage_Media(d, linkId); 145 const iBool allowHide = (flags & allowHide_MediaFlag) != 0;
146 if (existing) { 146 const iBool isDeleting = (!mime || !data);
147 iMediaId existing = findLinkImage_Media(d, linkId);
148 if (existing) {
149 if (isDeleting) {
147 iGmImage *img; 150 iGmImage *img;
148 take_PtrArray(&d->images, existing - 1, (void **) &img); 151 take_PtrArray(&d->images, existing - 1, (void **) &img);
149 delete_GmImage(img); 152 delete_GmImage(img);
150 } 153 }
151 else if ((existing = findLinkAudio_Media(d, linkId)) != 0) { 154 else {
152 iGmAudio *audio; 155 iAssert(isDeleting); /* images cannot be modified once set */
156 }
157 }
158 else if ((existing = findLinkAudio_Media(d, linkId)) != 0) {
159 iGmAudio *audio;
160 if (isDeleting) {
153 take_PtrArray(&d->audio, existing - 1, (void **) &audio); 161 take_PtrArray(&d->audio, existing - 1, (void **) &audio);
154 delete_GmAudio(audio); 162 delete_GmAudio(audio);
155 } 163 }
164 else {
165 audio = at_PtrArray(&d->audio, existing - 1);
166 iAssert(equal_String(&audio->props.mime, mime)); /* MIME cannot change */
167 updateSourceData_Player(audio->player, data, append_PlayerUpdate);
168 if (!isStarted_Player(audio->player)) {
169 /* Maybe the previous updates didn't have enough data. */
170 start_Player(audio->player);
171 }
172 if (!isPartial) {
173 updateSourceData_Player(audio->player, NULL, complete_PlayerUpdate);
174 }
175 }
156 } 176 }
157 else { 177 else if (!isDeleting) {
158 if (startsWith_String(mime, "image/")) { 178 if (startsWith_String(mime, "image/")) {
159 /* Copy the image to a texture. */ 179 /* Copy the image to a texture. */
160 /* TODO: Resize down to min(maximum texture size, window size). */ 180 /* TODO: Resize down to min(maximum texture size, window size). */
@@ -171,13 +191,14 @@ void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBloc
171 } 191 }
172 else if (startsWith_String(mime, "audio/")) { 192 else if (startsWith_String(mime, "audio/")) {
173 iGmAudio *audio = new_GmAudio(); 193 iGmAudio *audio = new_GmAudio();
174 audio->props.linkId = linkId; 194 audio->props.linkId = linkId; /* TODO: use a hash? */
175 audio->props.isPermanent = !allowHide; 195 audio->props.isPermanent = !allowHide;
176 set_String(&audio->props.mime, mime); 196 set_String(&audio->props.mime, mime);
177 /* TODO: What about update/complete, for streaming? */
178 updateSourceData_Player(audio->player, data, replace_PlayerUpdate); 197 updateSourceData_Player(audio->player, data, replace_PlayerUpdate);
198 if (!isPartial) {
199 updateSourceData_Player(audio->player, NULL, complete_PlayerUpdate);
200 }
179 pushBack_PtrArray(&d->audio, audio); 201 pushBack_PtrArray(&d->audio, audio);
180
181 /* TEST: Start playing right away. */ 202 /* TEST: Start playing right away. */
182 start_Player(audio->player); 203 start_Player(audio->player);
183 } 204 }