国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

gstreamer中使用webrtc實(shí)現(xiàn)音視頻對(duì)講

這篇具有很好參考價(jià)值的文章主要介紹了gstreamer中使用webrtc實(shí)現(xiàn)音視頻對(duì)講。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

gstreamer官方源代碼中有一個(gè)基于webrtc插件實(shí)現(xiàn)音視頻通話的開源項(xiàng)目,下面介紹在Ubuntu系統(tǒng)中如何搭建環(huán)境并使用。

一、環(huán)境搭建

1.安裝依賴庫

這里省略gstreamer安裝,直接安裝使用webrtcbin插件使用的相關(guān)庫,參考官網(wǎng)。系統(tǒng)版本建議高于ubuntu18.04。
首先安裝如下相關(guān)依賴庫。

sudo apt-get install -y gstreamer1.0-tools gstreamer1.0-nice gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-plugins-good libgstreamer1.0-dev git libglib2.0-dev libgstreamer-plugins-bad1.0-dev libsoup2.4-dev libjson-glib-dev

gstreamer項(xiàng)目編譯官方建議使用meson和ninja。參考官方。

sudo apt-get install meson ninja-build

如果想使用虛擬環(huán)境編譯運(yùn)行,官方推薦使用hotdoc,安裝使用參考官方網(wǎng)頁。

我這里使用的系統(tǒng)是Ubuntu22.04,gst版本為1.20。
libnice gstreamer,webrtc,音視頻,gstreamer

2.編譯運(yùn)行

gst-webrtc開源項(xiàng)目在gst官方源碼gst-examples目錄下。下載對(duì)應(yīng)版本壓縮包,或者直接git克隆。

cd /path/gst-examples
meson build

環(huán)境沒問題會(huì)顯示

The Meson build system
Version: 1.2.1
Source dir: /home/cht/gst/gst-examples
Build dir: /home/cht/gst/gst-examples/reconfigure
Build type: native build
Project name: gst-examples
Project version: 1.19.2
C compiler for the host machine: cc (gcc 11.4.0 "cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0")
C linker for the host machine: cc ld.bfd 2.38
Host machine cpu family: x86_64
Host machine cpu: x86_64
Library m found: YES
Found pkg-config: /usr/bin/pkg-config (0.29.2)
Run-time dependency glib-2.0 found: YES 2.72.4
Run-time dependency gio-2.0 found: YES 2.72.4
Run-time dependency gobject-2.0 found: YES 2.72.4
Run-time dependency gmodule-2.0 found: YES 2.72.4
Run-time dependency gstreamer-1.0 found: YES 1.20.3
Run-time dependency gstreamer-play-1.0 found: YES 1.20.3
Run-time dependency gstreamer-tag-1.0 found: YES 1.20.1
Run-time dependency gstreamer-webrtc-1.0 found: YES 1.20.3
Run-time dependency gstreamer-sdp-1.0 found: YES 1.20.1
Run-time dependency gstreamer-rtp-1.0 found: YES 1.20.1
Dependency gstreamer-play-1.0 found: YES 1.20.3 (cached)
Found CMake: /usr/bin/cmake (3.22.1)
Run-time dependency gtk+-3.0 found: NO (tried pkgconfig and cmake)
Run-time dependency x11 found: YES 1.7.5
Dependency gstreamer-sdp-1.0 found: YES 1.20.1 (cached)
Run-time dependency libsoup-2.4 found: YES 2.74.2
Run-time dependency json-glib-1.0 found: YES 1.6.6
Program openssl found: YES (/usr/bin/openssl)
Program generate_cert.sh found: YES (/home/cht/gst/gst-examples/webrtc/signalling/generate_cert.sh)
Program configure_test_check.py found: YES (/usr/bin/python3 /home/cht/gst/gst-examples/webrtc/check/configure_test_check.py)
WARNING: You should add the boolean check kwarg to the run_command call.
         It currently defaults to false,
         but it will default to true in future releases of meson.
         See also: https://github.com/mesonbuild/meson/issues/9300
Build targets in project: 7
Found ninja-1.11.1.git.kitware.jobserver-1 at /home/cht/.local/bin/ninja
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.

會(huì)檢查編譯前相關(guān)依賴環(huán)境是否準(zhǔn)備完畢??梢钥吹絯ebrtc項(xiàng)目只更新到了1.19。如果是使用低版本gst 1.18 meson ninja編譯后運(yùn)行可能會(huì)提示缺少liblice相關(guān)插件庫。需要下載https://gitlab.freedesktop.org/libnice/libnice庫手動(dòng)編譯。還是使用meson和ninja。編譯完成 將libgstnice.so插件庫make install到系統(tǒng)默認(rèn)的gstreamer插件路徑/lib/x86_64-linux-gnu/gstreamer-1.0下。

meson成功直接編譯然后運(yùn)行

ninja -C build
cd gst-examples/build/webrtc/sendrecv/gst
./webrtc-sendrecv --peer-id=xxxx

peer-id由https://webrtc.nirbheek.in網(wǎng)頁生成的一個(gè)隨機(jī)數(shù)字。網(wǎng)頁如下圖
libnice gstreamer,webrtc,音視頻,gstreamer
運(yùn)行webrtc-sendrecv使用peer-id需要遠(yuǎn)程提供,使用our-id可以讓遠(yuǎn)程來主動(dòng)連接。
運(yùn)行成功后網(wǎng)頁端顯示,另一端推流的圖像為gst中videotestsrc產(chǎn)生,為了方便演示,還疊加了一個(gè)秒表計(jì)時(shí)器timeoverlay。音頻在聲卡類型不清楚的情況下可以使用autoaudiosrc來采集。

libnice gstreamer,webrtc,音視頻,gstreamer

網(wǎng)頁這邊默認(rèn)推流的為電腦自帶的攝像頭采集的視頻和麥克風(fēng)采集的音頻。Ubuntu顯示畫面如下
libnice gstreamer,webrtc,音視頻,gstreamer
這樣在gstreamer中使用webrtcbin插件簡(jiǎn)易的音視頻p2p對(duì)講實(shí)現(xiàn)。

二、gstreamer采集和播放的源碼分析

1.采集

這里就不分析webrtc的流程了。
采集部分在start_pipeline中

libnice gstreamer,webrtc,音視頻,gstreamer

這里對(duì)比原項(xiàng)目有所改動(dòng),原項(xiàng)目使用的vp8軟編碼方式以及audiotestsrc產(chǎn)生的噪聲,由于很多平臺(tái)都支持h264硬編碼所以改了編碼方式,例如瑞芯微平臺(tái)使用的mpph264enc。需要添加一個(gè)宏定義

#define RTP_CAPS_H264 "application/x-rtp,media=video,encoding-name=H264,payload="

2.播放

static void
handle_media_stream (GstPad * pad, GstElement * pipe, const char *convert_name,   const char *sink_name)
{
  GstPad *qpad;
  GstElement *q, *conv, *resample, *sink;
  GstPadLinkReturn ret;

  gst_println ("Trying to handle stream with %s ! %s", convert_name, sink_name);

  q = gst_element_factory_make ("queue", NULL);
  g_assert_nonnull (q);
  conv = gst_element_factory_make (convert_name, NULL);
  g_assert_nonnull (conv);
  sink = gst_element_factory_make (sink_name, NULL);
  g_assert_nonnull (sink);

  if (g_strcmp0 (convert_name, "audioconvert") == 0) {
    /* Might also need to resample, so add it just in case.
     * Will be a no-op if it's not required. */
    resample = gst_element_factory_make ("audioresample", NULL);
    g_assert_nonnull (resample);
    gst_bin_add_many (GST_BIN (pipe), q, conv, resample, sink, NULL);
    gst_element_sync_state_with_parent (q);
    gst_element_sync_state_with_parent (conv);
    gst_element_sync_state_with_parent (resample);
    gst_element_sync_state_with_parent (sink);
    gst_element_link_many (q, conv, resample, sink, NULL);
  } else {
    gst_bin_add_many (GST_BIN (pipe), q, conv, sink, NULL);
    gst_element_sync_state_with_parent (q);
    gst_element_sync_state_with_parent (conv);
    gst_element_sync_state_with_parent (sink);
    gst_element_link_many (q, conv, sink, NULL);
  }

  qpad = gst_element_get_static_pad (q, "sink");
  ret = gst_pad_link (pad, qpad);
  g_assert_cmphex (ret, ==, GST_PAD_LINK_OK);

}

static void
on_incoming_decodebin_stream (GstElement * decodebin, GstPad * pad,
    GstElement * pipe)
{
  GstCaps *caps;
  const gchar *name;

  if (!gst_pad_has_current_caps (pad)) {
    gst_printerr ("Pad '%s' has no caps, can't do anything, ignoring\n",
       GST_PAD_NAME (pad));
    return;
  }
  caps = gst_pad_get_current_caps (pad);
  name = gst_structure_get_name (gst_caps_get_structure (caps, 0));

  if (g_str_has_prefix (name, "video")) {
	 handle_media_stream (pad, pipe, "videoconvert", "waylandsink");
	  //    handle_media_stream (pad, pipe, "videoconvert", "autovideosink");
  } else if (g_str_has_prefix (name, "audio")) {
    handle_media_stream (pad, pipe, "audioconvert", "autoaudiosink");
  } else {
    gst_printerr ("Unknown pad %s, ignoring", GST_PAD_NAME (pad));
  }

}

static void

on_incoming_stream (GstElement * webrtc, GstPad * pad, GstElement * pipe)

{
  GstElement *decodebin;
  GstPad *sinkpad;
  if (GST_PAD_DIRECTION (pad) != GST_PAD_SRC)
    return;

  decodebin = gst_element_factory_make ("decodebin", NULL);
  g_signal_connect (decodebin, "pad-added",
      G_CALLBACK (on_incoming_decodebin_stream), pipe);
  gst_bin_add (GST_BIN (pipe), decodebin);
  gst_element_sync_state_with_parent (decodebin);

  sinkpad = gst_element_get_static_pad (decodebin, "sink");

  gst_pad_link (pad, sinkpad);
  gst_object_unref (sinkpad);

}


可以看出視頻解碼使用的decodebin,對(duì)于音頻管道建立if (g_strcmp0 (convert_name, “audioconvert”) == 0)對(duì)比使用了重采樣,因?yàn)閷?duì)遠(yuǎn)程傳輸而來的音頻格式在通用處理。

總結(jié)

完成。文章來源地址http://www.zghlxwxcb.cn/news/detail-847263.html

到了這里,關(guān)于gstreamer中使用webrtc實(shí)現(xiàn)音視頻對(duì)講的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【音視頻】國標(biāo)雙向?qū)χv方案

    【音視頻】國標(biāo)雙向?qū)χv方案

    目錄 國標(biāo)語音對(duì)講-正統(tǒng)方案 特殊方案:私有協(xié)議等 結(jié)合zlm的使用? 語音廣播流程? 實(shí)時(shí)點(diǎn)播? 參考資料 a)? 實(shí)時(shí)音視頻點(diǎn)播 ?b) 語音廣播功能 ? 參考資料中的“大華及其它” 描述的最為清晰 。 ? ? 語音對(duì)講的的整體流程為: 先拉流播放設(shè)備的視頻; 使用WebRTC推送語音流

    2024年02月13日
    瀏覽(32)
  • 【音視頻】國際雙向?qū)χv方案

    【音視頻】國際雙向?qū)χv方案

    目錄 國標(biāo)語音對(duì)講-正統(tǒng)方案 特殊方案:私有協(xié)議等 結(jié)合zlm的使用? 語音廣播流程? 實(shí)時(shí)點(diǎn)播? 參考資料 a)? 實(shí)時(shí)音視頻點(diǎn)播 ?b) 語音廣播功能 ? 參考資料中的“大華及其它” 描述的最為清晰 。 ? ? 語音對(duì)講的的整體流程為: 先拉流播放設(shè)備的視頻; 使用WebRTC推送語音流

    2023年04月24日
    瀏覽(26)
  • 【復(fù)】基于 WebRTC 的音視頻在線監(jiān)考模塊的設(shè)計(jì)與實(shí)現(xiàn)(下)

    【復(fù)】基于 WebRTC 的音視頻在線監(jiān)考模塊的設(shè)計(jì)與實(shí)現(xiàn)(下)

    在上一篇博文 【復(fù)】基于 WebRTC 的音視頻在線監(jiān)考模塊的設(shè)計(jì)與實(shí)現(xiàn)(上) 中,主要介紹了關(guān)于 WebRTC 的基本理論,那么這篇文章我們將進(jìn)入實(shí)戰(zhàn)階段,通過 WebRTC 框架,去實(shí)現(xiàn) P2P 通話,以及延伸到一對(duì)多的音視頻通話,從而實(shí)現(xiàn)在線監(jiān)考功能; ? 在開發(fā) Web 時(shí),WebRTC 標(biāo)準(zhǔn)

    2024年02月01日
    瀏覽(29)
  • WebRTC簡(jiǎn)介及實(shí)戰(zhàn)應(yīng)用 — 從0到1實(shí)現(xiàn)實(shí)時(shí)音視頻聊天等功能

    WebRTC簡(jiǎn)介及實(shí)戰(zhàn)應(yīng)用 — 從0到1實(shí)現(xiàn)實(shí)時(shí)音視頻聊天等功能

    WebRTC 是由一家名為 Gobal IP Solutions,簡(jiǎn)稱 GIPS 的瑞典公司開發(fā)的。Google 在 2011 年收購了 GIPS,并將其源代碼開源。然后又與 IETF 和 W3C 的相關(guān)標(biāo)準(zhǔn)機(jī)構(gòu)合作,以確保行業(yè)達(dá)成共識(shí)。其中: Web Real-Time Communications (WEBRTC) W3C 組織:定義瀏覽器 API。 Real-Time Communication in Web-browsers (

    2024年03月19日
    瀏覽(31)
  • 基于webrtc的音視頻通話,實(shí)現(xiàn)相機(jī)流識(shí)別人臉的功能

    這幾天研究了一下webRTC的基礎(chǔ)能力,在此基礎(chǔ)之上能實(shí)現(xiàn)的視頻通話,互動(dòng)等更多實(shí)用功能。項(xiàng)目中使用的是阿里的rtc,我研究的是聲網(wǎng)的是否符合功能,后續(xù)會(huì)總結(jié)和記錄一下應(yīng)用到的幾個(gè)功能實(shí)現(xiàn)方法。 今天要記錄的功能是項(xiàng)目流識(shí)別人臉的功能,其實(shí)類似功能很常見了

    2024年04月28日
    瀏覽(27)
  • SRS OBS利用RTMP協(xié)議實(shí)現(xiàn)音視頻推拉流;WebRTC 屏幕直播分享工具

    SRS OBS利用RTMP協(xié)議實(shí)現(xiàn)音視頻推拉流;WebRTC 屏幕直播分享工具

    參考:https://ossrs.net/lts/zh-cn/docs/v5/doc/getting-started 1)docker直接運(yùn)行SRS服務(wù): 運(yùn)行起來后可以http://localhost:8080/ 看到服務(wù)基本信息: 2) OBS 推流 在設(shè)置里設(shè)置直播地址: 然后回到首頁點(diǎn)擊開始直播 3)點(diǎn)擊http://localhost:8080/ 可以網(wǎng)頁查看流視頻 SRS低延遲啟動(dòng)(暫時(shí)測(cè)試下來延遲

    2024年04月13日
    瀏覽(21)
  • 【音視頻處理】基礎(chǔ)框架介紹,F(xiàn)Fmpeg、GStreamer、OpenCV、OpenGL

    【音視頻處理】基礎(chǔ)框架介紹,F(xiàn)Fmpeg、GStreamer、OpenCV、OpenGL

    大家好,歡迎來到停止重構(gòu)的頻道。? 本期我們介紹 音視頻處理的基礎(chǔ)框架 。 包括FFmpeg、GStreamer、OpenCV、OpenGL 。 我們按這樣的分類介紹 : 1、編解碼處理:FFmpeg、GStreamer 2、圖像分析:OpenCV 3、復(fù)雜圖像生成:OpenGL 首先是編解碼處理的基礎(chǔ)框架,這類基礎(chǔ)框架的 應(yīng)用場(chǎng)景

    2024年02月08日
    瀏覽(49)
  • WebRTC音視頻通話(二)簡(jiǎn)單音視頻通話

    WebRTC音視頻通話(二)簡(jiǎn)單音視頻通話

    本篇不詳細(xì)介紹websocket,只針對(duì)websocket整合rtc。 webrtc是P2P通信,也就是實(shí)際交流的 只有兩個(gè)人 ,而要建立通信,這兩個(gè)人需要 交換一些信息來保證通信安全 。而且, webrtc必須通過ssh加密 ,也就是使用https協(xié)議、wss協(xié)議。 借用一幅圖 1.1 創(chuàng)建端點(diǎn)的解析 以下解析不包括we

    2023年04月09日
    瀏覽(29)
  • Linphone3.5.2 ARM RV1109音視頻對(duì)講開發(fā)記錄

    說明 這是一份事后記錄,主要記錄的幾個(gè)核心關(guān)鍵點(diǎn),有可能很多細(xì)節(jié)沒有記上,主要是方便后面自己再找回來! 版本 3.5.2 一些原因選的是這樣一個(gè)舊的版本! 新的開發(fā)最好選新一些的版本吧, 像 4.5, 4.2, 3.8 這一類的! 因?yàn)橹皼]有開發(fā)過Linphone的應(yīng)用,所以對(duì)整個(gè)框架不了

    2024年02月07日
    瀏覽(19)
  • WebRTC音視頻通話-WebRTC視頻自定義RTCVideoCapturer相機(jī)

    WebRTC音視頻通話-WebRTC視頻自定義RTCVideoCapturer相機(jī)

    WebRTC音視頻通話-WebRTC視頻自定義RTCVideoCapturer相機(jī) 在之前已經(jīng)實(shí)現(xiàn)了WebRTC調(diào)用ossrs服務(wù),實(shí)現(xiàn)直播視頻通話功能。但是在使用過程中,RTCCameraVideoCapturer類提供的方法不能修改及調(diào)節(jié)相機(jī)的燈光等設(shè)置,那就需要自定義RTCVideoCapturer自行采集畫面了。 iOS端WebRTC調(diào)用ossrs相關(guān),實(shí)現(xiàn)

    2024年02月12日
    瀏覽(29)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包