diff options
Diffstat (limited to 'src/media.c')
-rw-r--r-- | src/media.c | 41 |
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 | ||
142 | void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBlock *data, | 142 | void 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 | } |