AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
BaseStreamSource.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_MEDIAPLAYER_GSTREAMERMEDIAPLAYER_INCLUDE_MEDIAPLAYER_BASESTREAMSOURCE_H_
17 #define ALEXA_CLIENT_SDK_MEDIAPLAYER_GSTREAMERMEDIAPLAYER_INCLUDE_MEDIAPLAYER_BASESTREAMSOURCE_H_
18 
19 #include <memory>
20 #include <mutex>
21 #include <unordered_set>
22 
23 #include <gst/gst.h>
24 #include <gst/app/gstappsrc.h>
25 
27 
29 
30 namespace alexaClientSDK {
31 namespace mediaPlayer {
32 
34 public:
41  BaseStreamSource(PipelineInterface* pipeline, const std::string& className);
42 
43  ~BaseStreamSource() override;
44 
47  bool hasAdditionalData() override;
48  bool handleEndOfStream() override;
49  void preprocess() override;
50  void addObserver(std::shared_ptr<SourceObserverInterface> observer) override;
51  void removeObserver(std::shared_ptr<SourceObserverInterface> observer) override;
53 
54 protected:
64  bool init(const avsCommon::utils::AudioFormat* audioFormat = nullptr);
65 
71  virtual bool isOpen() = 0;
72 
76  virtual void close() = 0;
77 
83  virtual gboolean handleReadData() = 0;
84 
90  virtual gboolean handleSeekData(guint64 offset) = 0;
91 
97  GstAppSrc* getAppSrc() const;
98 
102  void signalEndOfData();
103 
108 
113 
118 
123  void clearOnReadDataHandler();
124 
129 
130 private:
138  static void onNeedData(GstElement* pipeline, guint size, gpointer source);
139 
145  gboolean handleNeedData();
146 
153  static void onEnoughData(GstElement* pipeline, gpointer source);
154 
160  gboolean handleEnoughData();
161 
162  static gboolean onSeekData(GstElement* pipeline, guint64 offset, gpointer source);
163 
170  static gboolean onReadData(gpointer source);
171 
173  PipelineInterface* m_pipeline;
174 
176  guint m_sourceId;
177 
179  bool m_hasReadData;
180 
182  guint m_sourceRetryCount;
183 
185  const std::function<gboolean()> m_handleNeedDataFunction;
186 
188  const std::function<gboolean()> m_handleEnoughDataFunction;
189 
191  guint m_needDataHandlerId;
192 
194  guint m_enoughDataHandlerId;
195 
197  guint m_seekDataHandlerId;
198 
200  std::mutex m_callbackIdMutex;
201 
203  guint m_needDataCallbackId;
204 
206  guint m_enoughDataCallbackId;
207 
209  std::mutex m_observersMutex;
210 
212  std::unordered_set<std::shared_ptr<SourceObserverInterface>> m_observers;
213 };
214 
215 } // namespace mediaPlayer
216 } // namespace alexaClientSDK
217 
218 #endif // ALEXA_CLIENT_SDK_MEDIAPLAYER_GSTREAMERMEDIAPLAYER_INCLUDE_MEDIAPLAYER_BASESTREAMSOURCE_H_
Definition: BaseStreamSource.h:33
::std::string string
Definition: gtest-port.h:1097
Definition: SourceInterface.h:30
bool init(const avsCommon::utils::AudioFormat *audioFormat=nullptr)
BaseStreamSource(PipelineInterface *pipeline, const std::string &className)
void addObserver(std::shared_ptr< SourceObserverInterface > observer) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
virtual gboolean handleSeekData(guint64 offset)=0
Definition: PipelineInterface.h:33
void removeObserver(std::shared_ptr< SourceObserverInterface > observer) override

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0