| 1 | /* |
| 2 | * Copyright (C) 2018 Metrological Group B.V. |
| 3 | * Author: Thibault Saunier <tsaunier@igalia.com> |
| 4 | * Author: Alejandro G. Castro <alex@igalia.com> |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * aint with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | |
| 24 | #if ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER) |
| 25 | #include "GStreamerAudioCapturer.h" |
| 26 | |
| 27 | #include "LibWebRTCAudioFormat.h" |
| 28 | |
| 29 | #include <gst/app/gstappsink.h> |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | GStreamerAudioCapturer::GStreamerAudioCapturer(GStreamerCaptureDevice device) |
| 34 | : GStreamerCapturer(device, adoptGRef(gst_caps_new_simple("audio/x-raw" , "rate" , G_TYPE_INT, LibWebRTCAudioFormat::sampleRate, nullptr))) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | GStreamerAudioCapturer::GStreamerAudioCapturer() |
| 39 | : GStreamerCapturer("appsrc" , adoptGRef(gst_caps_new_simple("audio/x-raw" , "rate" , G_TYPE_INT, LibWebRTCAudioFormat::sampleRate, nullptr))) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | GstElement* GStreamerAudioCapturer::createConverter() |
| 44 | { |
| 45 | auto converter = gst_parse_bin_from_description("audioconvert ! audioresample" , TRUE, nullptr); |
| 46 | |
| 47 | ASSERT(converter); |
| 48 | |
| 49 | return converter; |
| 50 | } |
| 51 | |
| 52 | bool GStreamerAudioCapturer::setSampleRate(int sampleRate) |
| 53 | { |
| 54 | |
| 55 | if (sampleRate <= 0) { |
| 56 | GST_INFO_OBJECT(m_pipeline.get(), "Not forcing sample rate" ); |
| 57 | |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | GST_INFO_OBJECT(m_pipeline.get(), "Setting SampleRate %d" , sampleRate); |
| 62 | m_caps = adoptGRef(gst_caps_new_simple("audio/x-raw" , "rate" , G_TYPE_INT, sampleRate, nullptr)); |
| 63 | |
| 64 | if (!m_capsfilter.get()) |
| 65 | return false; |
| 66 | |
| 67 | g_object_set(m_capsfilter.get(), "caps" , m_caps.get(), nullptr); |
| 68 | |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | } // namespace WebCore |
| 73 | |
| 74 | #endif // ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER) |
| 75 | |