@@ -200,13 +200,13 @@ MediaPlayer::SourceId MediaPlayer::setSource(
200
200
const avsCommon::utils::AudioFormat* audioFormat,
201
201
const SourceConfig& config) {
202
202
ACSDK_DEBUG9 (LX (" setSourceCalled" ).d (" name" , RequiresShutdown::name ()).d (" sourceType" , " AttachmentReader" ));
203
- std::promise<MediaPlayer::SourceId> promise ;
204
- auto future = promise. get_future ();
205
- std::function<gboolean ()> callback = [this , &reader, & promise, &config, audioFormat]() {
206
- handleSetAttachmentReaderSource (std::move (reader), config, & promise, audioFormat);
203
+ auto promise = std::make_shared<std:: promise<MediaPlayer::SourceId>>() ;
204
+ auto future = promise-> get_future ();
205
+ std::function<gboolean ()> callback = [this , &reader, promise, &config, audioFormat]() {
206
+ handleSetAttachmentReaderSource (std::move (reader), config, promise. get () , audioFormat);
207
207
return false ;
208
208
};
209
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
209
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
210
210
auto sourceId = future.get ();
211
211
// Assume that the Attachment is fully buffered - not ideal, revisit if needed. Should be fine for file streams
212
212
// and resources.
@@ -223,13 +223,13 @@ MediaPlayer::SourceId MediaPlayer::setSource(
223
223
avsCommon::utils::MediaType format) {
224
224
ACSDK_DEBUG9 (
225
225
LX (" setSourceCalled" ).d (" name" , RequiresShutdown::name ()).d (" sourceType" , " istream" ).d (" format" , format));
226
- std::promise<MediaPlayer::SourceId> promise ;
227
- auto future = promise. get_future ();
228
- std::function<gboolean ()> callback = [this , &stream, repeat, &config, & promise]() {
229
- handleSetIStreamSource (stream, repeat, config, & promise);
226
+ auto promise = std::make_shared<std:: promise<MediaPlayer::SourceId>>() ;
227
+ auto future = promise-> get_future ();
228
+ std::function<gboolean ()> callback = [this , &stream, repeat, &config, promise]() {
229
+ handleSetIStreamSource (stream, repeat, config, promise. get () );
230
230
return false ;
231
231
};
232
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
232
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
233
233
auto sourceId = future.get ();
234
234
// Assume that the Attachment is fully buffered - not ideal, revisit if needed. Should be fine for file streams
235
235
// and resources.
@@ -246,13 +246,13 @@ MediaPlayer::SourceId MediaPlayer::setSource(
246
246
bool repeat,
247
247
const PlaybackContext& playbackContext) {
248
248
ACSDK_DEBUG9 (LX (" setSourceForUrlCalled" ).d (" name" , RequiresShutdown::name ()).sensitive (" url" , url));
249
- std::promise<MediaPlayer::SourceId> promise ;
250
- auto future = promise. get_future ();
251
- std::function<gboolean ()> callback = [this , url, offset, &config, & promise, repeat]() {
252
- handleSetUrlSource (url, offset, config, & promise, repeat);
249
+ auto promise = std::make_shared<std:: promise<MediaPlayer::SourceId>>() ;
250
+ auto future = promise-> get_future ();
251
+ std::function<gboolean ()> callback = [this , url, offset, &config, promise, repeat]() {
252
+ handleSetUrlSource (url, offset, config, promise. get () , repeat);
253
253
return false ;
254
254
};
255
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
255
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
256
256
return future.get ();
257
257
}
258
258
return ERROR_SOURCE_ID;
@@ -281,71 +281,71 @@ bool MediaPlayer::play(MediaPlayer::SourceId id) {
281
281
282
282
m_source->preprocess ();
283
283
284
- std::promise<bool > promise ;
285
- auto future = promise. get_future ();
286
- std::function<gboolean ()> callback = [this , id, & promise]() {
287
- handlePlay (id, & promise);
284
+ auto promise = std::make_shared<std:: promise<bool >>() ;
285
+ auto future = promise-> get_future ();
286
+ std::function<gboolean ()> callback = [this , id, promise]() {
287
+ handlePlay (id, promise. get () );
288
288
return false ;
289
289
};
290
290
291
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
291
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
292
292
return future.get ();
293
293
}
294
294
return false ;
295
295
}
296
296
297
297
bool MediaPlayer::stop (MediaPlayer::SourceId id) {
298
298
ACSDK_DEBUG9 (LX (" stopCalled" ).d (" name" , RequiresShutdown::name ()));
299
- std::promise<bool > promise ;
300
- auto future = promise. get_future ();
301
- std::function<gboolean ()> callback = [this , id, & promise]() {
302
- handleStop (id, & promise);
299
+ auto promise = std::make_shared<std:: promise<bool >>() ;
300
+ auto future = promise-> get_future ();
301
+ std::function<gboolean ()> callback = [this , id, promise]() {
302
+ handleStop (id, promise. get () );
303
303
return false ;
304
304
};
305
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
305
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
306
306
return future.get ();
307
307
}
308
308
return false ;
309
309
}
310
310
311
311
bool MediaPlayer::pause (MediaPlayer::SourceId id) {
312
312
ACSDK_DEBUG9 (LX (" pausedCalled" ).d (" name" , RequiresShutdown::name ()));
313
- std::promise<bool > promise ;
314
- auto future = promise. get_future ();
315
- std::function<gboolean ()> callback = [this , id, & promise]() {
316
- handlePause (id, & promise);
313
+ auto promise = std::make_shared<std:: promise<bool >>() ;
314
+ auto future = promise-> get_future ();
315
+ std::function<gboolean ()> callback = [this , id, promise]() {
316
+ handlePause (id, promise. get () );
317
317
return false ;
318
318
};
319
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
319
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
320
320
return future.get ();
321
321
}
322
322
return false ;
323
323
}
324
324
325
325
bool MediaPlayer::resume (MediaPlayer::SourceId id) {
326
326
ACSDK_DEBUG9 (LX (" resumeCalled" ).d (" name" , RequiresShutdown::name ()));
327
- std::promise<bool > promise ;
328
- auto future = promise. get_future ();
329
- std::function<gboolean ()> callback = [this , id, & promise]() {
330
- handleResume (id, & promise);
327
+ auto promise = std::make_shared<std:: promise<bool >>() ;
328
+ auto future = promise-> get_future ();
329
+ std::function<gboolean ()> callback = [this , id, promise]() {
330
+ handleResume (id, promise. get () );
331
331
return false ;
332
332
};
333
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
333
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
334
334
return future.get ();
335
335
}
336
336
return false ;
337
337
}
338
338
339
339
std::chrono::milliseconds MediaPlayer::getOffset (MediaPlayer::SourceId id) {
340
340
ACSDK_DEBUG9 (LX (" getOffsetCalled" ).d (" name" , RequiresShutdown::name ()));
341
- std::promise<std::chrono::milliseconds> promise ;
342
- auto future = promise. get_future ();
343
- std::function<gboolean ()> callback = [this , id, & promise]() {
344
- handleGetOffset (id, & promise);
341
+ auto promise = std::make_shared<std:: promise<std::chrono::milliseconds>>() ;
342
+ auto future = promise-> get_future ();
343
+ std::function<gboolean ()> callback = [this , id, promise]() {
344
+ handleGetOffset (id, promise. get () );
345
345
return false ;
346
346
};
347
347
348
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
348
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
349
349
return future.get ();
350
350
}
351
351
return MEDIA_PLAYER_INVALID_OFFSET;
@@ -363,14 +363,14 @@ void MediaPlayer::addObserver(std::shared_ptr<MediaPlayerObserverInterface> obse
363
363
}
364
364
365
365
ACSDK_DEBUG9 (LX (" addObserverCalled" ).d (" name" , RequiresShutdown::name ()));
366
- std::promise<void > promise ;
367
- auto future = promise. get_future ();
368
- std::function<gboolean ()> callback = [this , & promise, &observer]() {
369
- handleAddObserver (& promise, observer);
366
+ auto promise = std::make_shared<std:: promise<void >>() ;
367
+ auto future = promise-> get_future ();
368
+ std::function<gboolean ()> callback = [this , promise, &observer]() {
369
+ handleAddObserver (promise. get () , observer);
370
370
return false ;
371
371
};
372
372
373
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
373
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
374
374
future.wait ();
375
375
}
376
376
}
@@ -382,27 +382,27 @@ void MediaPlayer::removeObserver(std::shared_ptr<MediaPlayerObserverInterface> o
382
382
}
383
383
384
384
ACSDK_DEBUG9 (LX (" removeObserverCalled" ).d (" name" , RequiresShutdown::name ()));
385
- std::promise<void > promise ;
386
- auto future = promise. get_future ();
387
- std::function<gboolean ()> callback = [this , & promise, &observer]() {
388
- handleRemoveObserver (& promise, observer);
385
+ auto promise = std::make_shared<std:: promise<void >>() ;
386
+ auto future = promise-> get_future ();
387
+ std::function<gboolean ()> callback = [this , promise, &observer]() {
388
+ handleRemoveObserver (promise. get () , observer);
389
389
return false ;
390
390
};
391
391
392
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
392
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
393
393
future.wait ();
394
394
}
395
395
}
396
396
397
397
bool MediaPlayer::setVolume (int8_t volume) {
398
398
ACSDK_DEBUG9 (LX (" setVolumeCalled" ).d (" name" , RequiresShutdown::name ()));
399
- std::promise<bool > promise ;
400
- auto future = promise. get_future ();
401
- std::function<gboolean ()> callback = [this , & promise, volume]() {
402
- handleSetVolume (& promise, volume);
399
+ auto promise = std::make_shared<std:: promise<bool >>() ;
400
+ auto future = promise-> get_future ();
401
+ std::function<gboolean ()> callback = [this , promise, volume]() {
402
+ handleSetVolume (promise. get () , volume);
403
403
return false ;
404
404
};
405
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
405
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
406
406
return future.get ();
407
407
}
408
408
return false ;
@@ -455,13 +455,13 @@ void MediaPlayer::handleSetVolume(std::promise<bool>* promise, int8_t volume) {
455
455
456
456
bool MediaPlayer::setMute (bool mute) {
457
457
ACSDK_DEBUG9 (LX (" setMuteCalled" ).d (" name" , RequiresShutdown::name ()));
458
- std::promise<bool > promise ;
459
- auto future = promise. get_future ();
460
- std::function<gboolean ()> callback = [this , & promise, mute]() {
461
- handleSetMute (& promise, mute);
458
+ auto promise = std::make_shared<std:: promise<bool >>() ;
459
+ auto future = promise-> get_future ();
460
+ std::function<gboolean ()> callback = [this , promise, mute]() {
461
+ handleSetMute (promise. get () , mute);
462
462
return false ;
463
463
};
464
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
464
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
465
465
return future.get ();
466
466
}
467
467
return false ;
@@ -483,13 +483,13 @@ void MediaPlayer::handleSetMute(std::promise<bool>* promise, bool mute) {
483
483
484
484
bool MediaPlayer::getSpeakerSettings (SpeakerInterface::SpeakerSettings* settings) {
485
485
ACSDK_DEBUG9 (LX (" getSpeakerSettingsCalled" ).d (" name" , RequiresShutdown::name ()));
486
- std::promise<bool > promise ;
487
- auto future = promise. get_future ();
488
- std::function<gboolean ()> callback = [this , & promise, settings]() {
489
- handleGetSpeakerSettings (& promise, settings);
486
+ auto promise = std::make_shared<std:: promise<bool >>() ;
487
+ auto future = promise-> get_future ();
488
+ std::function<gboolean ()> callback = [this , promise, settings]() {
489
+ handleGetSpeakerSettings (promise. get () , settings);
490
490
return false ;
491
491
};
492
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
492
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
493
493
return future.get ();
494
494
}
495
495
return false ;
@@ -924,13 +924,16 @@ bool MediaPlayer::seek() {
924
924
return seekSuccessful;
925
925
}
926
926
927
- guint MediaPlayer::queueCallback (const std::function<gboolean()>* callback) {
927
+ guint MediaPlayer::queueCallback (std::function<gboolean()>&& callback) {
928
928
if (isShutdown ()) {
929
929
return UNQUEUED_CALLBACK;
930
930
}
931
931
auto source = g_idle_source_new ();
932
932
g_source_set_callback (
933
- source, reinterpret_cast <GSourceFunc>(&onCallback), const_cast <std::function<gboolean ()>*>(callback), nullptr );
933
+ source, reinterpret_cast <GSourceFunc>(&onCallback), new std::function<gboolean ()>(std::move (callback)),
934
+ [](gpointer data) {
935
+ delete reinterpret_cast <std::function<gboolean ()>*>(data);
936
+ });
934
937
auto sourceId = g_source_attach (source, m_workerContext);
935
938
g_source_unref (source);
936
939
return sourceId;
@@ -996,13 +999,13 @@ gboolean MediaPlayer::onCallback(const std::function<gboolean()>* callback) {
996
999
void MediaPlayer::onPadAdded (GstElement* decoder, GstPad* pad, gpointer pointer) {
997
1000
auto mediaPlayer = static_cast <MediaPlayer*>(pointer);
998
1001
ACSDK_DEBUG9 (LX (" onPadAddedCalled" ).d (" name" , mediaPlayer->name ()));
999
- std::promise<void > promise ;
1000
- auto future = promise. get_future ();
1001
- std::function<gboolean ()> callback = [mediaPlayer, & promise, decoder, pad]() {
1002
- mediaPlayer->handlePadAdded (& promise, decoder, pad);
1002
+ auto promise = std::make_shared<std:: promise<void >>() ;
1003
+ auto future = promise-> get_future ();
1004
+ std::function<gboolean ()> callback = [mediaPlayer, promise, decoder, pad]() {
1005
+ mediaPlayer->handlePadAdded (promise. get () , decoder, pad);
1003
1006
return false ;
1004
1007
};
1005
- if (mediaPlayer->queueCallback (& callback) != UNQUEUED_CALLBACK) {
1008
+ if (mediaPlayer->queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
1006
1009
future.wait ();
1007
1010
}
1008
1011
}
@@ -1932,9 +1935,9 @@ void MediaPlayer::setEqualizerBandLevels(EqualizerBandLevelMap bandLevelMap) {
1932
1935
if (!m_equalizerEnabled) {
1933
1936
return ;
1934
1937
}
1935
- std::promise<void > promise ;
1936
- auto future = promise. get_future ();
1937
- std::function<gboolean ()> callback = [this , & promise, bandLevelMap]() {
1938
+ auto promise = std::make_shared<std:: promise<void >>() ;
1939
+ auto future = promise-> get_future ();
1940
+ std::function<gboolean ()> callback = [this , promise, bandLevelMap]() {
1938
1941
auto it = bandLevelMap.find (EqualizerBand::BASS);
1939
1942
if (bandLevelMap.end () != it) {
1940
1943
g_object_set (
@@ -1959,10 +1962,10 @@ void MediaPlayer::setEqualizerBandLevels(EqualizerBandLevelMap bandLevelMap) {
1959
1962
static_cast <gdouble>(clampEqualizerLevel (it->second )),
1960
1963
NULL );
1961
1964
}
1962
- promise. set_value ();
1965
+ promise-> set_value ();
1963
1966
return false ;
1964
1967
};
1965
- if (queueCallback (& callback) != UNQUEUED_CALLBACK) {
1968
+ if (queueCallback (std::move ( callback) ) != UNQUEUED_CALLBACK) {
1966
1969
future.get ();
1967
1970
}
1968
1971
}
0 commit comments