Giter VIP home page Giter VIP logo

docker-webrtc-sample's Introduction

GStreamer 上で WebRTC を動作させるサンプル

GStreamer 上で WebRTC を動作させるためのサンプルプログラムになります。

フォルダ 備考
data クライアントとして使用する HTML
signaling シグナリングサーバのサンプル
webrtc-sample WebRTC のサンプル

以下のページで簡単な説明がありますので、参照してください。
https://www.gclue.jp/2022/07/gstreamer-webrtc.html

ビルド

以下のコマンドを実行することで、GStreamer の環境ごと作成します。

$ docker-compose build

実行

以下のコマンドを実行することで、シグナリングサーバと WebRTC のサンプルプログラムを実行します。

$ docker-compose up

上記コマンドの起動後に、Chrome ブラウザで、以下の URL を開くことで、WebRTC に接続されます。

http://{DOCKERのIPアドレス}:9449

配信する映像・音声の変更

webrtc-sample/gst-webrtc-sample/src/gst-webrtc-main.cc のソースコードを変更することで、配信する映像・音声を変更することができます。

webrtcbin に格納する映像・音声を変更することで、切り替えることができます。

void WebRTCMain::startPipeline()
{
  stopPipeline();

  // webrtcbin エレメント名前は固定にしておく必要があります
  // webrtcbin name=webrtcbin を変更する場合には、呼び出している箇所も全て変更する必要があります。
  std::string bin = "webrtcbin name=webrtcbin bundle-policy=max-bundle latency=100 stun-server=stun://stun.l.google.com:19302 \
        videotestsrc is-live=true \
         ! videoconvert \
         ! queue \
         ! vp8enc target-bitrate=10240000 deadline=1 \
         ! rtpvp8pay \
         ! application/x-rtp,media=video,encoding-name=VP8,payload=96 \
         ! webrtcbin. \
        audiotestsrc is-live=true \
         ! audioconvert \
         ! audioresample \
         ! queue \
         ! opusenc \
         ! rtpopuspay \
         ! application/x-rtp,media=audio,encoding-name=OPUS,payload=97 \
         ! webrtcbin. ";

  mPipeline = new WebRTCPipeline();
  mPipeline->setListener(this);
  mPipeline->startPipeline(bin);
}

以下のように videotestsrc から v4l2src に変更することで、映像を Web カメラに変更することができます。

void WebRTCMain::startPipeline()
{
  stopPipeline();

  // webrtcbin エレメント名前は固定にしておく必要があります
  // webrtcbin name=webrtcbin を変更する場合には、呼び出している箇所も全て変更する必要があります。
  std::string bin = "webrtcbin name=webrtcbin bundle-policy=max-bundle latency=100 stun-server=stun://stun.l.google.com:19302 \
        v4l2src device=/dev/video0 \
         ! image/jpeg,width=1280,height=720,framerate=30/1 \
         ! jpegdec \
         ! videoconvert \
         ! queue \
         ! vp8enc target-bitrate=10240000 deadline=1 \
         ! rtpvp8pay \
         ! application/x-rtp,media=video,encoding-name=VP8,payload=96 \
         ! webrtcbin. \
        audiotestsrc is-live=true \
         ! audioconvert \
         ! audioresample \
         ! queue \
         ! opusenc \
         ! rtpopuspay \
         ! application/x-rtp,media=audio,encoding-name=OPUS,payload=97 \
         ! webrtcbin. ";

  mPipeline = new WebRTCPipeline();
  mPipeline->setListener(this);
  mPipeline->startPipeline(bin);
}

docker-webrtc-sample's People

Contributors

nobuo-kobayashi avatar

Stargazers

 avatar  avatar Moshi Turner avatar Mohammad Amin Mehralian avatar  avatar 엘련(Jisu Kim) avatar  avatar

Watchers

 avatar

Forkers

goga1992

docker-webrtc-sample's Issues

how to modify if we want to distribute video to multiple client

Thank you for your code.

I am newbie to webrtc.

Can you advice how we can distribute video to multiple people like below?

We want to distribute encoded video to many webrtc client on chrome browser.
We don't want to add webrtcbin pipeline as more webrtc client is connected. This means that we want to build one to many system with only one encoding pipeline.

Thank you.

docker起動後、ChromeブラウザでURLにアクセスしても映像が表示されない。

本gitを試させてもらっている者です。

gitのREADME.mdをもとに環境構築をして映像データの出力まで確認しようとしたのですが、
以下のように、データチャネルが作成されないといったエラーが出ており、映像が表示されないようでした。
以下は、どういうケースで起きるエラーがご教示いただけないでしょうか?

実行環境: Ubuntu 18.04 LTS (デスクトップ環境作成済)
試した手順:
0 リモートデスクトップ接続でログイン後、ターミナル起動
① git clone https://github.com/nobuo-kobayashi/docker-webrtc-sample.git
② cd docker-webrtc-sample
③ docker-compose build
④ docker-compose up
⑤ 上記後、http://<DockerのIP>:9449 にアクセス

Creating signaling ... done
Creating webrtc ... done
Attaching to signaling, webrtc
signaling | Listening on port 9449...
webrtc | > GET / HTTP/1.1
webrtc | > Soup-Debug-Timestamp: 1658968364
webrtc | > Soup-Debug: SoupSession 1 (0x55729336b100), SoupMessage 1 (0x55729336f0b0), SoupSocket 1 (0x5572930974d0)
webrtc | > Host: 127.0.0.1:9449
webrtc | > Upgrade: websocket
webrtc | > Connection: Upgrade
webrtc | > Sec-WebSocket-Key: ny2gO+6el17rV9hM8nNNAg==
webrtc | > Sec-WebSocket-Version: 13
webrtc | > Origin: localhost
webrtc | > Sec-WebSocket-Protocol:
webrtc | > Accept-Encoding: gzip, deflate
webrtc | > User-Agent: gst-webrtc-sample
webrtc |
webrtc | < HTTP/1.1 101 Switching Protocols
webrtc | < Soup-Debug-Timestamp: 1658968364
webrtc | < Soup-Debug: SoupMessage 1 (0x55729336f0b0)
webrtc | < Upgrade: websocket
webrtc | < Connection: Upgrade
webrtc | < Sec-WebSocket-Accept: kU/xTqH5kAChtFgQus6pGwR2mMo=
webrtc |
signaling | ws connect...

signaling | ws connect...
webrtc |
**webrtc | ** (gst-webrtc-sample:1): CRITICAL : 09:33:15.841: gst_webrtc_bin_create_data_channel: assertion 'webrtc->priv->is_closed != TRUE' failed
webrtc | Could not create data channel, is usrsctp available?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.