| 1 | /* |
| 2 | * Copyright (C) 2014 Igalia S.L |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #ifndef AudioSourceProviderGStreamer_h |
| 20 | #define AudioSourceProviderGStreamer_h |
| 21 | |
| 22 | #if ENABLE(WEB_AUDIO) && ENABLE(VIDEO) && USE(GSTREAMER) |
| 23 | |
| 24 | #include "AudioSourceProvider.h" |
| 25 | #include "GRefPtrGStreamer.h" |
| 26 | #include "MainThreadNotifier.h" |
| 27 | #include <gst/gst.h> |
| 28 | #include <wtf/Forward.h> |
| 29 | #include <wtf/Noncopyable.h> |
| 30 | |
| 31 | #if ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) |
| 32 | #include "GStreamerAudioStreamDescription.h" |
| 33 | #include "MediaStreamTrackPrivate.h" |
| 34 | #include "WebAudioSourceProvider.h" |
| 35 | #endif |
| 36 | |
| 37 | typedef struct _GstAdapter GstAdapter; |
| 38 | typedef struct _GstAppSink GstAppSink; |
| 39 | |
| 40 | namespace WebCore { |
| 41 | |
| 42 | #if ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) |
| 43 | class AudioSourceProviderGStreamer final : public WebAudioSourceProvider { |
| 44 | public: |
| 45 | static Ref<AudioSourceProviderGStreamer> create(MediaStreamTrackPrivate& source) |
| 46 | { |
| 47 | return adoptRef(*new AudioSourceProviderGStreamer(source)); |
| 48 | } |
| 49 | AudioSourceProviderGStreamer(MediaStreamTrackPrivate&); |
| 50 | #else |
| 51 | class AudioSourceProviderGStreamer : public AudioSourceProvider { |
| 52 | WTF_MAKE_NONCOPYABLE(AudioSourceProviderGStreamer); |
| 53 | public: |
| 54 | #endif |
| 55 | |
| 56 | AudioSourceProviderGStreamer(); |
| 57 | ~AudioSourceProviderGStreamer(); |
| 58 | |
| 59 | void configureAudioBin(GstElement* audioBin, GstElement* teePredecessor); |
| 60 | |
| 61 | void provideInput(AudioBus*, size_t framesToProcess) override; |
| 62 | void setClient(AudioSourceProviderClient*) override; |
| 63 | const AudioSourceProviderClient* client() const { return m_client; } |
| 64 | |
| 65 | void handleNewDeinterleavePad(GstPad*); |
| 66 | void deinterleavePadsConfigured(); |
| 67 | void handleRemovedDeinterleavePad(GstPad*); |
| 68 | |
| 69 | GstFlowReturn handleAudioBuffer(GstAppSink*); |
| 70 | GstElement* getAudioBin() const { return m_audioSinkBin.get(); } |
| 71 | void clearAdapters(); |
| 72 | |
| 73 | private: |
| 74 | GRefPtr<GstElement> m_pipeline; |
| 75 | enum MainThreadNotification { |
| 76 | DeinterleavePadsConfigured = 1 << 0, |
| 77 | }; |
| 78 | Ref<MainThreadNotifier<MainThreadNotification>> m_notifier; |
| 79 | GRefPtr<GstElement> m_audioSinkBin; |
| 80 | AudioSourceProviderClient* m_client; |
| 81 | int m_deinterleaveSourcePads; |
| 82 | GstAdapter* m_frontLeftAdapter; |
| 83 | GstAdapter* m_frontRightAdapter; |
| 84 | unsigned long m_deinterleavePadAddedHandlerId; |
| 85 | unsigned long m_deinterleaveNoMorePadsHandlerId; |
| 86 | unsigned long m_deinterleavePadRemovedHandlerId; |
| 87 | Lock m_adapterMutex; |
| 88 | }; |
| 89 | |
| 90 | } |
| 91 | #endif // ENABLE(WEB_AUDIO) && ENABLE(VIDEO) && USE(GSTREAMER) |
| 92 | |
| 93 | #endif // AudioSourceProviderGStreamer_h |
| 94 | |