summaryrefslogtreecommitdiff
path: root/src/media.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-24 22:11:11 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-24 22:11:11 +0200
commit5268fb9f7e1bca4b0fc496ff115c253aea724e49 (patch)
tree8023f45f3538f7966c2f75674a4b14fb4778e79c /src/media.c
parent9421f64ee86e6aec26e05a45bcfc65edd895a8a8 (diff)
Fixed threading issues and data races
The most serious problem was that GmRequest's response body was being accessed while the TlsRequest thread was modifying it. Now the response must always be locked before accessing elsewhere. There were also inefficient data updates in the media players.
Diffstat (limited to 'src/media.c')
-rw-r--r--src/media.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/media.c b/src/media.c
index cd3dfb82..8bd635a5 100644
--- a/src/media.c
+++ b/src/media.c
@@ -154,12 +154,13 @@ void clear_Media(iMedia *d) {
154 clear_PtrArray(&d->audio); 154 clear_PtrArray(&d->audio);
155} 155}
156 156
157void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBlock *data, 157iBool setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBlock *data,
158 int flags) { 158 int flags) {
159 const iBool isPartial = (flags & partialData_MediaFlag) != 0; 159 const iBool isPartial = (flags & partialData_MediaFlag) != 0;
160 const iBool allowHide = (flags & allowHide_MediaFlag) != 0; 160 const iBool allowHide = (flags & allowHide_MediaFlag) != 0;
161 const iBool isDeleting = (!mime || !data); 161 const iBool isDeleting = (!mime || !data);
162 iMediaId existing = findLinkImage_Media(d, linkId); 162 iMediaId existing = findLinkImage_Media(d, linkId);
163 iBool isNew = iFalse;
163 if (existing) { 164 if (existing) {
164 iGmImage *img; 165 iGmImage *img;
165 if (isDeleting) { 166 if (isDeleting) {
@@ -205,6 +206,7 @@ void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBloc
205 if (!isPartial) { 206 if (!isPartial) {
206 makeTexture_GmImage(img); 207 makeTexture_GmImage(img);
207 } 208 }
209 isNew = iTrue;
208 } 210 }
209 else if (startsWith_String(mime, "audio/")) { 211 else if (startsWith_String(mime, "audio/")) {
210 iGmAudio *audio = new_GmAudio(); 212 iGmAudio *audio = new_GmAudio();
@@ -219,8 +221,10 @@ void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBloc
219 /* Start playing right away. */ 221 /* Start playing right away. */
220 start_Player(audio->player); 222 start_Player(audio->player);
221 postCommandf_App("media.player.started player:%p", audio->player); 223 postCommandf_App("media.player.started player:%p", audio->player);
224 isNew = iTrue;
222 } 225 }
223 } 226 }
227 return isNew;
224} 228}
225 229
226iMediaId findLinkImage_Media(const iMedia *d, iGmLinkId linkId) { 230iMediaId findLinkImage_Media(const iMedia *d, iGmLinkId linkId) {