16 #ifndef ALEXA_CLIENT_SDK_MEDIAPLAYER_GSTREAMERMEDIAPLAYER_INCLUDE_MEDIAPLAYER_MEDIAPLAYER_H_ 17 #define ALEXA_CLIENT_SDK_MEDIAPLAYER_GSTREAMERMEDIAPLAYER_INCLUDE_MEDIAPLAYER_MEDIAPLAYER_H_ 28 #include <unordered_set> 32 #include <gst/app/gstappsrc.h> 33 #include <gst/base/gstbasesink.h> 34 #include <gst/controller/gsttimedvaluecontrolsource.h> 51 namespace mediaPlayer {
53 typedef std::vector<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface::TagKeyValueType>
VectorOfTags;
67 ,
public std::enable_shared_from_this<MediaPlayer> {
78 static std::shared_ptr<MediaPlayer>
create(
79 std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> contentFetcherFactory =
81 bool enableEqualizer =
false,
83 bool enableLiveMode =
false);
92 std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> attachmentReader,
98 std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> attachmentReader,
99 std::chrono::milliseconds offsetAdjustment,
106 std::chrono::milliseconds offset = std::chrono::milliseconds::zero(),
113 std::shared_ptr<std::istream> stream,
130 void addObserver(std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface> observer)
override;
131 void removeObserver(std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface> observer)
override;
137 bool setMute(
bool mute)
override;
143 void setAppSrc(GstAppSrc* appSrc)
override;
145 void setDecoder(GstElement* decoder)
override;
148 guint
queueCallback(
const std::function<gboolean()>* callback)
override;
184 struct AudioPipeline {
192 GstElement* decodedQueue;
195 GstElement* converter;
204 GstElement* resample;
210 GstElement* equalizer;
213 GstElement* audioSink;
216 GstElement* pipeline;
222 decodedQueue{
nullptr},
230 pipeline{
nullptr} {};
242 std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> contentFetcherFactory,
243 bool enableEqualizer,
245 bool enableLiveMode);
272 static gboolean onCallback(
const std::function<gboolean()>* callback);
280 bool setupPipeline();
288 void tearDownTransientPipelineElements(
bool notifyStop);
293 void resetPipeline();
305 static void onPadAdded(GstElement* src, GstPad* pad, gpointer mediaPlayer);
314 void handlePadAdded(std::promise<void>* promise, GstElement* src, GstPad* pad);
326 static gboolean onBusMessage(GstBus* bus, GstMessage* msg, gpointer mediaPlayer);
335 gboolean handleBusMessage(GstMessage*
message);
343 std::unique_ptr<const VectorOfTags> collectTags(GstMessage* message);
350 void sendStreamTagsToObserver(std::unique_ptr<const VectorOfTags> vectorOfTags);
361 void handleSetAttachmentReaderSource(
362 std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> reader,
364 std::promise<SourceId>* promise,
366 bool repeat =
false);
377 void handleSetUrlSource(
379 std::chrono::milliseconds offset,
381 std::promise<SourceId>* promise,
392 void handleSetIStreamSource(
393 std::shared_ptr<std::istream> stream,
396 std::promise<SourceId>* promise);
403 void handleSetVolumeInternal(gdouble gstVolume);
411 void handleSetVolume(std::promise<bool>* promise, int8_t volume);
419 void handleAdjustVolume(std::promise<bool>* promise, int8_t delta);
427 void handleSetMute(std::promise<bool>* promise,
bool mute);
435 void handleGetSpeakerSettings(
436 std::promise<bool>* promise,
446 void handlePlay(
SourceId id, std::promise<bool>* promise);
455 void handleStop(
SourceId id, std::promise<bool>* promise);
464 void handlePause(
SourceId id, std::promise<bool>* promise);
473 void handleResume(
SourceId id, std::promise<bool>* promise);
481 void handleGetOffset(
SourceId id, std::promise<std::chrono::milliseconds>* promise);
488 std::chrono::milliseconds handleGetOffsetImmediately(
SourceId id);
504 void handleAddObserver(
505 std::promise<void>* promise,
506 std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface> observer);
514 void handleRemoveObserver(
515 std::promise<void>* promise,
516 std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface> observer);
521 void sendPlaybackStarted();
526 void sendPlaybackFinished();
531 void sendPlaybackPaused();
536 void sendPlaybackResumed();
541 void sendPlaybackStopped();
549 void sendPlaybackError(
556 void sendBufferingComplete();
561 void sendBufferUnderrun();
566 void sendBufferRefilled();
574 bool queryIsSeekable(
bool* isSeekable);
582 bool queryBufferPercent(gint* percent);
597 bool validateSourceAndId(
SourceId id);
605 static gboolean onErrorCallback(gpointer pointer);
613 static gboolean onWriteCompleteCallback(gpointer pointer);
620 std::chrono::milliseconds getCurrentStreamOffset();
625 void cleanUpSource();
630 int getMinimumBandLevel()
override;
631 int getMaximumBandLevel()
override;
640 int clampEqualizerLevel(
int level);
643 std::mutex m_operationMutex;
646 gdouble m_lastVolume;
652 std::shared_ptr<playlistParser::UrlContentToAttachmentConverter> m_urlConverter;
656 std::shared_ptr<alexaClientSDK::avsCommon::avs::attachment::AttachmentReader> m_parkedReader;
662 std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> m_contentFetcherFactory;
665 bool m_equalizerEnabled;
668 AudioPipeline m_pipeline;
671 GMainLoop* m_mainLoop;
674 std::thread m_mainLoopThread;
680 GMainContext* m_workerContext;
683 bool m_playbackStartedSent;
686 bool m_playbackFinishedSent;
692 bool m_isBufferUnderrun;
695 std::unordered_set<std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface>> m_playerObservers;
698 std::shared_ptr<SourceInterface> m_source;
713 bool m_resumePending;
716 bool m_pauseImmediately;
719 std::chrono::milliseconds m_offsetBeforeTeardown;
722 const bool m_isLiveMode;
725 std::chrono::milliseconds m_offsetAdjustment;
731 #endif // ALEXA_CLIENT_SDK_MEDIAPLAYER_GSTREAMERMEDIAPLAYER_INCLUDE_MEDIAPLAYER_MEDIAPLAYER_H_ const std::string & name() const
std::unordered_map< EqualizerBand, int, avsCommon::utils::functional::EnumClassHash > EqualizerBandLevelMap
A collection of bands with their level values. This is an alias for EqualizerBand to band level (int)...
Definition: EqualizerTypes.h:77
Definition: PlaybackContext.h:35
::std::string string
Definition: gtest-port.h:1097
Definition: RequiresShutdown.h:32
MediaType
Definition: MediaType.h:29
Definition: SpeakerInterface.h:33
Definition: Optional.h:32
Definition: SpeakerInterface.h:42
Class to observe errors that arise from converting a URL to to an Attachment.
Definition: UrlContentToAttachmentConverter.h:44
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
type
Definition: upload.py:443
Audio data type not known.
Class to allow notification when writing to the attachment is complete.
Definition: UrlContentToAttachmentConverter.h:58
tuple message
Definition: gtest_output_test.py:331
Definition: EqualizerInterface.h:27