├── .dockerignore
├── .gitattributes
├── .gitignore
├── .vscode
├── c_cpp_properties.json
├── settings.json
└── tasks.json
├── Dockerfile.build
├── LICENSE.md
├── LICENSE
├── LICENSE.Raspberry_UserLand_Software
├── LICENSE.WebRTC
├── LICENSE.WebRTC_THIRD_PARTY
├── LICENSE.avahi
├── LICENSE.libwebsockets
├── LICENSE.rpi-webrtc-streamer
├── OWNERS.WebRTC
└── PATENTS.WebRTC
├── README.md
├── README_TelegramBot.md
├── README_audio.md
├── README_building.md
├── README_motion.md
├── README_rws_setup.md
├── etc
└── template
│ ├── media_config.conf
│ ├── motion_config.conf
│ ├── telegramBot.conf
│ └── webrtc_streamer.conf
├── lib
└── libwebsockets-3.1.0.zip
├── misc
├── .clang-format
├── AndroidApp_ClinetCerts.patch
├── icons8-raspberry-pi-520.png
├── motion_detection_example.avi
├── telegram-icon-6264.png
├── telegram_botfather.png
├── webrtc_arm_build_args.gn
├── webrtc_armv6_build_args.gn
├── webrtc_streamer_architecture.png
└── webrtc_x64_build_args.gn
├── mk
├── config_libwebsockets.sh
├── cross_arm_build.mk
├── cross_mmal.mk
├── libavahi_arm.mk
├── libwebsocket_arm_build.mk
├── libwebsocket_native_gcc.mk
├── native_gcc.mk
├── validate_variables.mk
└── webrtc_library_gn.py
├── scripts
└── rws.service
├── src
├── Makefile
├── app_channel.cc
├── app_channel.h
├── app_clientinfo.cc
├── app_clientinfo.h
├── app_ws_client.cc
├── app_ws_client.h
├── compat
│ ├── optionsfile.cc
│ ├── optionsfile.h
│ ├── status.cc
│ ├── status_payload_printer.cc
│ └── statusor.cc
├── config_defs.h
├── config_media.cc
├── config_media.h
├── config_motion.cc
├── config_motion.h
├── config_streamer.cc
├── config_streamer.h
├── def
│ ├── config_media.def
│ ├── config_motion.def
│ └── config_streamer.def
├── direct_socket.cc
├── direct_socket.h
├── file_log_sink.cc
├── file_log_sink.h
├── file_writer_handle.cc
├── file_writer_handle.h
├── frame_queue.cc
├── frame_queue.h
├── log_rotating_stream.cc
├── log_rotating_stream.h
├── main.cc
├── mdns_publish.c
├── mdns_publish.h
├── mmal_common.h
├── mmal_still.c
├── mmal_still.h
├── mmal_still_capture.cc
├── mmal_still_capture.h
├── mmal_util.c
├── mmal_video.c
├── mmal_video.h
├── mmal_video_reset.c
├── mmal_wrapper.cc
├── mmal_wrapper.h
├── raspi_decoder.cc
├── raspi_decoder.h
├── raspi_decoder_dummy.cc
├── raspi_decoder_dummy.h
├── raspi_encoder.cc
├── raspi_encoder.h
├── raspi_encoder_impl.cc
├── raspi_encoder_impl.h
├── raspi_httpnoti.cc
├── raspi_httpnoti.h
├── raspi_motion.cc
├── raspi_motion.h
├── raspi_motionblob.cc
├── raspi_motionblob.h
├── raspi_motionblobid.h
├── raspi_motionfile.cc
├── raspi_motionfile.h
├── raspi_motionvector.cc
├── raspi_motionvector.h
├── raspi_quality_config.cc
├── raspi_quality_config.h
├── raspicamcontrol.c
├── raspicamcontrol.h
├── raspicli.c
├── raspicli.h
├── raspipreview.c
├── raspipreview.h
├── session_config.cc
├── session_config.h
├── streamer.cc
├── streamer.h
├── streamer_signaling.cc
├── streamer_signaling.h
├── utils.cc
├── utils.h
├── utils_pc_config.cc
├── utils_pc_config.h
├── utils_pc_strings.cc
├── utils_pc_strings.h
├── utils_url.h
├── websocket_handler.h
├── websocket_server.cc
├── websocket_server.h
├── websocket_server_callback.cc
├── websocket_server_internal.h
├── websocket_server_util.c
├── wstreamer_types.cc
└── wstreamer_types.h
├── tools
├── ffmpeg_armv6
├── ffmpeg_neon
└── telegramBot.py
└── web-root
└── np2
├── css
└── main.css
├── images
└── webrtc-icon-192x192.png
├── index.html
└── js
├── config_media.mjs
├── config_params.mjs
├── constants.mjs
├── peerconnection_client.mjs
├── snackbar.mjs
├── streamer_connection_rws.mjs
├── streamer_controller.mjs
└── streamer_transaction.mjs
/.dockerignore:
--------------------------------------------------------------------------------
1 | backup/*
2 | imv_examples/*
3 | lib/libsockets
4 | tools/*
5 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | web-root/* linguist-vendored
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.o
3 | *.dwo
4 |
5 | # Precompiled Headers
6 | *.gch
7 | *.pch
8 | ipch
9 |
10 | # Compiled Static libraries
11 | *.a
12 | *.lib
13 |
14 | # Executables
15 | webrtc-streamer
16 | lib/libwebsockets/
17 |
18 | # Configuration
19 | etc/app_channel.conf
20 | etc/webrtc-streamer.conf
21 |
22 | # Tempoary backup
23 | backup
24 | src/OLD
25 | imv_examples
26 | src/.vscode
27 | .ccls-cache
28 |
--------------------------------------------------------------------------------
/.vscode/c_cpp_properties.json:
--------------------------------------------------------------------------------
1 | {
2 | "configurations": [
3 | {
4 | "name": "Linux",
5 | "cStandard": "c11",
6 | "cppStandard": "c++17",
7 | "intelliSenseMode": "gcc-x64",
8 | "compileCommands": "${workspaceFolder}/compile_commands.json",
9 | "compilerPath": "/opt/rpi_rootfs/tools/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++"
10 | }
11 | ],
12 | "version": 4
13 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "files.exclude": {
3 | "**/.ccls-cache/**": true,
4 | "**/.DS_Store": false,
5 | "**/*.dwo": true,
6 | "**/*.o": true,
7 | "**/webrtc/out/**": true,
8 | "${workspaceFolder}/backup/**": true,
9 | "${workspaceFolder}/log/**": true,
10 | "${workspaceFolder}/src/OLD/**": true
11 | },
12 | "C_Cpp.clang_format_path": "/usr/bin/clang-format-9",
13 | "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4 }",
14 | "git.ignoreLimitWarning": true,
15 | "C_Cpp.default.cppStandard": "c++17",
16 | "C_Cpp.default.cStandard": "c11",
17 | "files.associations": {
18 | "*.tcc": "cpp",
19 | "string": "cpp"
20 | },
21 | "C_Cpp.default.compileCommands": "${workspaceFolder}/compile_commands.json",
22 | "editor.formatOnSave": true,
23 | "C_Cpp.default.intelliSenseMode": "gcc-x64",
24 | "search.exclude": {
25 | "**/webrtc/**/*.c": true,
26 | "**/webrtc/**/*.cc": true
27 | },
28 | "files.watcherExclude": {
29 | "**/webrtc/src/**.cc": true
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "shell",
8 | "label": "Builing with make",
9 | "command": "make",
10 | "args": [
11 | "all",
12 | ],
13 | "options": {
14 | "cwd": "${workspaceRoot}/src"
15 | },
16 | "problemMatcher": [
17 | "$gcc"
18 | ],
19 | "group": {
20 | "kind": "build",
21 | "isDefault": true
22 | }
23 | },
24 | {
25 | "type": "shell",
26 | "label": "Clean with make",
27 | "command": "make",
28 | "args": [
29 | "clean",
30 | ],
31 | "options": {
32 | "cwd": "${workspaceRoot}/src"
33 | },
34 | "problemMatcher": [
35 | "$gcc"
36 | ],
37 | "group": {
38 | "kind": "build",
39 | "isDefault": true
40 | }
41 | }
42 | ]
43 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | #### WebRTC
2 |
3 | Refer to LICENSE.WebRTC, PATERNS.WebRTC, OWNERS.WebRTC in LICENSE directory
4 |
5 | #### H.264 bitstream
6 |
7 | Refer to LICENSE_h264bitstream in LICENSE directory
8 |
9 | #### rpi-webrtc-streamer
10 |
11 | Refer to LICENSE_rpi-webrtc-streamer in LICENSE directory
--------------------------------------------------------------------------------
/LICENSE/LICENSE.Raspberry_UserLand_Software:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012, Broadcom Europe Ltd
2 | Copyright (c) 2015, Raspberry Pi (Trading) Ltd
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above copyright
10 | notice, this list of conditions and the following disclaimer in the
11 | documentation and/or other materials provided with the distribution.
12 | * Neither the name of the copyright holder nor the
13 | names of its contributors may be used to endorse or promote products
14 | derived from this software without specific prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE/LICENSE.WebRTC:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011, The WebRTC project authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in
12 | the documentation and/or other materials provided with the
13 | distribution.
14 |
15 | * Neither the name of Google nor the names of its contributors may
16 | be used to endorse or promote products derived from this software
17 | without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/LICENSE/LICENSE.rpi-webrtc-streamer:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016, Lyu,KeunChang rpi-webrtc-streamer
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of the copyright holder nor the
15 | names of its contributors may be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 |
--------------------------------------------------------------------------------
/LICENSE/OWNERS.WebRTC:
--------------------------------------------------------------------------------
1 | henrika@webrtc.org
2 | kwiberg@webrtc.org
3 | mflodman@webrtc.org
4 | niklas.enbom@webrtc.org
5 | tina.legrand@webrtc.org
6 | tommi@webrtc.org
7 |
8 | per-file *.isolate=kjellander@webrtc.org
9 |
10 | # These are for the common case of adding or renaming files. If you're doing
11 | # structural changes, please get a review from a reviewer in this file.
12 | per-file *.gyp=*
13 | per-file *.gypi=*
14 |
15 | per-file BUILD.gn=kjellander@webrtc.org
16 |
17 | per-file *video*.h=pbos@webrtc.org
18 |
--------------------------------------------------------------------------------
/LICENSE/PATENTS.WebRTC:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the WebRTC code package.
5 |
6 | Google hereby grants to you a perpetual, worldwide, non-exclusive,
7 | no-charge, irrevocable (except as stated in this section) patent
8 | license to make, have made, use, offer to sell, sell, import,
9 | transfer, and otherwise run, modify and propagate the contents of this
10 | implementation of the WebRTC code package, where such license applies
11 | only to those patent claims, both currently owned by Google and
12 | acquired in the future, licensable by Google that are necessarily
13 | infringed by this implementation of the WebRTC code package. This
14 | grant does not include claims that would be infringed only as a
15 | consequence of further modification of this implementation. If you or
16 | your agent or exclusive licensee institute or order or agree to the
17 | institution of patent litigation against any entity (including a
18 | cross-claim or counterclaim in a lawsuit) alleging that this
19 | implementation of the WebRTC code package or any code incorporated
20 | within this implementation of the WebRTC code package constitutes
21 | direct or contributory patent infringement, or inducement of patent
22 | infringement, then any patent rights granted to you under this License
23 | for this implementation of the WebRTC code package shall terminate as
24 | of the date such litigation is filed.
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # WebRTC streamer for Raspberry PI
3 |
4 | ## General
5 | Notice: This is a work in progress,
6 |
7 | This repo's objective is providing something like Web Cam server on the most popular Raspberry PI hardware. By integrating [WebRTC](https://webrtc.org/native-code/) and Raspberry PI, we can stream the Raspberry camera feed to browser or native client which talks WebRTC.
8 |
9 | Generally, the components of WebRTC service are classified into Signaling Server and WebRTC client. However, RWS(Rpi-WebRTC-Streamer) is built to operate on one piece of Raspberry PI hardware and includes some of Signaling Server functionality. In other words, the Browser or Client supporting WebRTC directly connects to RWS and receives WebRTC streaming service.
10 |
11 | ### Streaming camera feed
12 | To get the camera feed from Raspberry PI, i.e. H.264 video stream, RWS use MMAL(Multi-Media Abstraction Layer) library can be found on [ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland). it provides lower level API to multi-media components running on Broadcom VideoCore. For convenience, this streamer directly integrated [raspivid](https://github.com/raspberrypi/userland/tree/master/host_applications/linux/apps/raspicam)
13 | with encoding parameter changing in H.264 stream and passing video frame through WebRTC native code package.
14 |
15 | ### Motion Detection
16 | Motion Detection feature provided by Rpi-WebRTC-Streamer uses Inline Motion Vector which is generated during video encoding. And use this to get the approximate Motion Detection function while using minimal CPU resources.
17 |
18 | Please refer to [README_motion document](../master/README_motion.md).
19 |
20 | ### Messenger Notification
21 | The motion detection event message can be transmitted to the user through the telegram messenger. It can send motion detection message and detected video clip to Telegram Messenger client so that it can be used as a private security bot.
22 | For more information, Please refer to [README_TelegramBot document](../master/README_TelegramBot.md).
23 |
24 |
25 | ## Rpi WebRTC Streamer
26 | ### Demo Video
27 |
28 |
30 |
31 | ## Hardware Requirement
32 | ### Raspberry PI
33 | - Raspberry PI 2/3
34 | - Raspberry Pi Zero/Zero W (ZeroW tested)
35 |
36 | ### Video Camera
37 | - RPI Camera board V1/V2
38 | - Arducam 5 Megapixels 1080p Sensor OV5647 Mini Camera Video Module
39 |
40 | ### Audio hardware
41 | Please refer to the [README_audio.md](https://github.com/kclyu/rpi-webrtc-streamer/blob/master/README_audio.md)
42 |
43 | ## Running RWS on Raspberry PI
44 | Please refer to [README_rws_setup.md document](../master/README_rws_setup.md).
45 |
46 | ## Download Docker image for Testing
47 | In Raspberry PI, you can run the image directly after the pull from the docker hub as shown below.
48 |
49 | ```
50 | docker pull kclyu/rpi-webrtc-streamer
51 | docker container run --device=/dev/vcsm --device=/dev/vchiq --net=host --mount type=bind,source=/var/run/dbus,target=/var/run/dbus --rm -d kclyu/rpi-webrtc-streamer # note1
52 | ```
53 | _Note1: docker image is currently for armv7l (Raspberry PI2 and above)._
54 | ## Download Deb package for Testing
55 | To download RWS deb package, please refer to the following URL. RWS is currently in development and testing, so please use it with consideration.
56 |
57 | Please refer to [Rpi-Webrtc-Streamer-deb Repo](https://github.com/kclyu/rpi-webrtc-streamer-deb).
58 |
59 | ## Cross Compile on Ubuntu Linux
60 |
61 | Please refer to [README_building.md document](../master/README_building.md).
62 |
--------------------------------------------------------------------------------
/README_audio.md:
--------------------------------------------------------------------------------
1 |
2 | # Raspberry PI Audio Setup for RWS
3 |
4 | ## General
5 | In RWS, PulseAudio is disabled and uses ALSA. To use audio, use a USB audio dongle or USB microphone that has been confirmed to work with Raspberry PI. This document is based on the device whose operation has been verified and will be added if any device operation is confirmed.
6 |
7 | ## Want to buy Audio Device?
8 | The Raspberry PI forum audio articles have a large number of posts , but there are not many latest updates of USB audio device for new hardware. One thing I would like to ask you first is to try to purchase a audio device that has been confirmed to be a hardware device that runs on Raspberry PI before purchasing a device for Audio Setup.
9 |
10 | For example, USB 3.0 hub (power hub) or dongle does not work with Raspberry PI and some USB 2.0 dongle may or may not work.
11 |
12 | See [USB Sound Cards](http://elinux.org/RPi_VerifiedPeripherals#USB_Sound_Cards), which is confirmed to work with Raspberry PI).
13 |
14 | ## Audio Device Setup
15 | The linux audio part of the WebRTC native code package first searches all available audio device lists in the OS. However, the audio device you want to use should be set to search first.
16 |
17 | #### 1. Disable raspberry audio
18 | ```
19 | sudo vi /boot/config.txt
20 | #dtparam=audio=on ## comment out
21 | ```
22 | #### 2. Reorder USB audio device index
23 | ```
24 | sudo vi /lib/modprobe.d/aliases.conf
25 | #options snd-usb-audio index=-2 # comment out
26 | ```
27 | #### 3. change asoundrc
28 | ```
29 | vi ~/.asoundrc
30 | defaults.pcm.card 0;
31 | defaults.ctl.card 0;
32 | ```
33 |
34 |
35 | ## USB audio dongle
36 | An example of using USB audio dongle is [A presence robot with Chromium, WebRTC, Raspberry Pi 3 and EasyRTC](https://planb.nicecupoftea.org/2016/10/24/a-presence-robot-with-chromium-webrtc-raspberry-pi-3-and-easyrtc/)
37 |
38 | ## Working Audio Device List for WebRTC audio
39 | - USB microphone - Cosy USB microphone MK1343UB
40 |
41 | ## Do you have any working configuration on Audio?
42 | It is not easy to buy as many hardware as possible for the test, and there is not really much time to test it. If you have successfully set up your audio with your Raspberry PI and have verified audio transmission from RWS, please share it. I think it will help a lot of others.
43 |
44 | Please add the comment to the issue as shown below.
45 |
46 | - Device Type: (USB dongle | USB microphone | Raspberry PI audio hat | etc)
47 | - Device Name: (Device Model)
48 | - Command Output:
49 | - lsusb
50 | - cat / proc / asound / cards
51 |
52 |
53 | ## Testing Required
54 |
55 | - Raspberry PI Audio Hat
56 | - USB audio dongle
57 |
58 |
59 | ## Audio Setup - Version History
60 |
61 | * 2017/05/21 : Initial Version
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/etc/template/media_config.conf:
--------------------------------------------------------------------------------
1 | max_bitrate=3500000
2 | # specify screen resolution ratio ( true: using 4:3, false: using 16:9)
3 | resolution_4_3_enable=true
4 |
5 | # The roi value consists of 4 values, and each value is x,y,width,height
6 | # video_roi=x,y,width,height
7 | # Each value is set to a value normalized to a value of 0.0 ~ 1.0 for the size of
8 | # the video resolution. The width and height values must have a size of 0.2
9 | # (at least 20% of the total) or more. If this config does not in use,
10 | # delete the video_roi setting value and use as the default value.
11 | #
12 | # video_roi=0,0,0,1.0,1.0
13 | #
14 |
15 | # rotate video , valid value is [0|90|180|270]
16 | video_rotation=0
17 | video_hflip=false
18 | video_vflip=false
19 | # specify using dynamic resolution changing based on the bandwidth estimation
20 | # (If set to true, dynamic resolution feature is enabled; if set to false,
21 | # fixed_resolution will be used.)
22 | use_dynamic_video_resolution=true
23 | use_dynamic_video_fps=true
24 | fixed_video_resolution=640x480
25 | fixed_video_fps=30
26 | # list of 4:3 ratio screen resolution
27 | video_resolution_list_4_3=320x240,400x300,512x384,640x480,1024x768,1152x864,1296x972,1640x1232
28 | # list of 16:9 ratio screen resolution
29 | video_resolution_list_16_9=384x216,512x288,640x360,768x432,896x504,1024x576,1152x648,1280x720,1408x864,1920x1080
30 | # enable/disable below audio processing feature
31 | # when set to true, audio related features are enabled.
32 | # After enable, each feature can be set to enable/disable.
33 | # when set to false, all audio features are ignored.
34 | audio_processing_enable=false
35 | # echo cancelllation
36 | audio_echo_cancellaton=true
37 | audio_auto_gain_control=true
38 | audio_high_passfilter=true
39 | audio_noise_suppression=true
40 | audio_experimental_agc=false
41 | audio_experimental_ns=false
42 | # sharpness (-100 to 100)
43 | video_sharpness=0
44 | # contrast (-100 to 100)
45 | video_contrast=0
46 | # brightness (0 to 100)
47 | video_brightness=50
48 | # saturation (-100 to 100)
49 | video_saturation=0
50 | # exposure compensation (-10 to 10)
51 | video_ev=0
52 | video_exposure_mode=auto
53 | video_flicker_mode=auto
54 | video_awb_mode=auto
55 | video_drc_mode=high
56 | video_enable_annotate_text=false
57 | video_annotate_text_size_ratio=3
58 | video_annotate_text=%Y-%m-%d.%X
59 |
--------------------------------------------------------------------------------
/etc/template/motion_config.conf:
--------------------------------------------------------------------------------
1 | motion_detection_enable=false
2 | motion_width=1024
3 | motion_height=768
4 | motion_fps=30
5 | motion_bitrate=3500
6 | motion_clear_percent=5
7 | motion_annotate_text=Raspi Motion %Y-%m-%d.%X
8 | motion_clear_wait_period=5000
9 | motion_directory=/home/pi/Videos
10 | motion_file_prefix=motion
11 | motion_file_size_limit=6000
12 | motion_save_imv_file=false
13 | blob_cancel_threshold=1
14 | blob_tracking_threshold=10
15 | motion_file_total_size_limit=2000
16 |
--------------------------------------------------------------------------------
/etc/template/telegramBot.conf:
--------------------------------------------------------------------------------
1 | # auth_token : Auth_token generated from Telegram BotFather
2 | auth_token: xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3 |
4 | # the directory where Rpi-WebRTC-Streamer stores h.264 files
5 | motion_h264_path: /home/pi/Videos
6 |
7 | # Set the interval to invoke process to check for new files added.
8 | checking_interval: 5
9 |
10 | # the file to store the telegram chat_id to use when sending the message.
11 | # the below example is default value
12 | #
13 | chat_id_filename: /opt/rws/etc/run/telegrambot.pickle
14 |
15 | # specify the location of the file to store the admin id.
16 | #
17 | admin_list_filename: /opt/rws/etc/run/telegrambotadmin.pickle
18 |
19 | # specifies whether the h.264 file generated by rws is converted to an mp4 file
20 | # and included in the telegram message. if you set the default value to true
21 | # and set it to false, only the name of the newly created file will be transferred
22 | # to the message without the mp4 file.
23 | # default value is true
24 | mp4_upload_enable: true
25 |
26 | # specifies the system command to use when converting to mp4 file.
27 | # the specified command string must have $input_file and $output_file,
28 | # and it is a template to replace internally.
29 | #
30 | # there are two ffmpeg_neon and ffmpeg_armv6 files in the tools directory,
31 | # and ffmpeg_neon should be used on pi2 or higher hardware.
32 | # and ffmpeg_armv6 should be used on ZeroW or PI1
33 | #
34 | #converting_command: '/opt/rws/tools/ffmpeg_armv6 -y -i $input_file $output_file'
35 | #
36 | # When you convert h.264 video to mp4, the size will be smaller than h.264 original
37 | # file and it is advantageous when you send the file to Messenger like Telegram or
38 | # upload it to Cloud Storage like GoogleDrive
39 | #
40 | # However, conversion to mp4 is very slow on hardware such as PI 1 or PI Zero W
41 | # with an ARMv6 family of CPUs, so it can hardly be used.
42 | # In this case, you should use '-vcodec copy' to convert the file to a level
43 | # that simply changes the container, as shown below.
44 | #
45 | converting_command: '/opt/rws/tools/ffmpeg_armv6 -y -vcodec copy -i $input_file $output_file'
46 |
47 | #
48 | # When telegram message upload, specify the value of upload timeout seconds.
49 | # If network upload is slow, you should increase the timeout value.
50 | upload_timeout: 120
51 |
52 | # Keep the message waiting for a period of time after transmission.
53 | # No new messages are sent during this period.
54 | # The default value is 120.
55 | # When set to 0, new motion detection messages will continue to be transmitted
56 | # without waiting time.
57 | noti_cooling_period: 120
58 |
59 |
60 | # Always disable sound alert when sending messages.
61 | # The Telegram Client receives new messages but without a sound alert.
62 | #
63 | sound_alerts_in_schedule: False
64 |
65 | # specifies the hour of day
66 | noti_schedule_hour: '[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]'
67 | # specifies the day of week. 0 is Monday, ... 6 is Sunday
68 | noti_schedule_day: '[0,1,2,3,4,5,6]'
69 |
--------------------------------------------------------------------------------
/etc/template/webrtc_streamer.conf:
--------------------------------------------------------------------------------
1 | websocket_enable=true
2 | websocket_port=8889
3 | media_config=etc/media_config.conf
4 | motion_config=etc/motion_config.conf
5 | direct_socket_enable=true
6 | direct_socket_port=8888
7 | disable_log_buffering=false
8 | web_root=/opt/rws/web-root
9 | libwebsocket_debug=false
10 | rws_ws_url=/rws/ws
11 |
12 | #
13 | # Using audio is disabled by default. To use audio, set audio_enable = true.
14 | # video is enabled by default.
15 | audio_enable=false
16 | video_enable=true
17 |
18 | #
19 | # The settings related to ice_server are separated by urls,
20 | # as shown below. If you only use stun, you only need to set urls.
21 | #
22 | # * : default value
23 | # ice_transports_type= none | relay | nohost | *all
24 | # bundle_policy= *balanced | max-bundle | max-compat
25 | # rtcp_mux_policy= *require | negotiate
26 | #
27 | # ice_server_urls_?=stun:stun.l.google.com:19302
28 | # ice_server_username_?=
29 | # ice_server_password_?=
30 | # ice_server_hostname_?=
31 | # ice_server_tls_cert_policy_?= secure or insecure
32 | # ice_server_tls_alpn_protocols_?= # List of protocols to be used in the TLS ALPN extension.
33 | # ice_server_tls_elliptic_curves_?= # List of elliptic curves to be used in the TLS elliptic curves extension.
34 | #
35 | ice_server_urls_0=stun:stun.l.google.com:19302,stun:stun1.l.google.com:19302,stun:stun2.l.google.com:19302,stun:stun3.l.google.com:19302,stun:stun4.l.google.com:19302
36 |
--------------------------------------------------------------------------------
/lib/libwebsockets-3.1.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kclyu/rpi-webrtc-streamer/e109e418aa9023009b3b59c95eec2de4721125be/lib/libwebsockets-3.1.0.zip
--------------------------------------------------------------------------------
/misc/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Cpp
3 | # BasedOnStyle: Google
4 | AccessModifierOffset: -1
5 | AlignAfterOpenBracket: Align
6 | AlignConsecutiveMacros: false
7 | AlignConsecutiveAssignments: false
8 | AlignConsecutiveDeclarations: false
9 | AlignEscapedNewlines: Left
10 | AlignOperands: true
11 | AlignTrailingComments: true
12 | AllowAllArgumentsOnNextLine: true
13 | AllowAllConstructorInitializersOnNextLine: true
14 | AllowAllParametersOfDeclarationOnNextLine: true
15 | AllowShortBlocksOnASingleLine: false
16 | AllowShortCaseLabelsOnASingleLine: false
17 | AllowShortFunctionsOnASingleLine: All
18 | AllowShortLambdasOnASingleLine: All
19 | AllowShortIfStatementsOnASingleLine: WithoutElse
20 | AllowShortLoopsOnASingleLine: true
21 | AlwaysBreakAfterDefinitionReturnType: None
22 | AlwaysBreakAfterReturnType: None
23 | AlwaysBreakBeforeMultilineStrings: true
24 | AlwaysBreakTemplateDeclarations: Yes
25 | BinPackArguments: true
26 | BinPackParameters: true
27 | BraceWrapping:
28 | AfterCaseLabel: false
29 | AfterClass: false
30 | AfterControlStatement: false
31 | AfterEnum: false
32 | AfterFunction: false
33 | AfterNamespace: false
34 | AfterObjCDeclaration: false
35 | AfterStruct: false
36 | AfterUnion: false
37 | AfterExternBlock: false
38 | BeforeCatch: false
39 | BeforeElse: false
40 | IndentBraces: false
41 | SplitEmptyFunction: true
42 | SplitEmptyRecord: true
43 | SplitEmptyNamespace: true
44 | BreakBeforeBinaryOperators: None
45 | BreakBeforeBraces: Attach
46 | BreakBeforeInheritanceComma: false
47 | BreakInheritanceList: BeforeColon
48 | BreakBeforeTernaryOperators: true
49 | BreakConstructorInitializersBeforeComma: false
50 | BreakConstructorInitializers: BeforeColon
51 | BreakAfterJavaFieldAnnotations: false
52 | BreakStringLiterals: true
53 | ColumnLimit: 80
54 | CommentPragmas: '^ IWYU pragma:'
55 | CompactNamespaces: false
56 | ConstructorInitializerAllOnOneLineOrOnePerLine: true
57 | ConstructorInitializerIndentWidth: 4
58 | ContinuationIndentWidth: 4
59 | Cpp11BracedListStyle: true
60 | DerivePointerAlignment: true
61 | DisableFormat: false
62 | ExperimentalAutoDetectBinPacking: false
63 | FixNamespaceComments: true
64 | ForEachMacros:
65 | - foreach
66 | - Q_FOREACH
67 | - BOOST_FOREACH
68 | IncludeBlocks: Regroup
69 | IncludeCategories:
70 | - Regex: '^'
71 | Priority: 2
72 | - Regex: '^<.*\.h>'
73 | Priority: 1
74 | - Regex: '^<.*'
75 | Priority: 2
76 | - Regex: '.*'
77 | Priority: 3
78 | IncludeIsMainRegex: '([-_](test|unittest))?$'
79 | IndentCaseLabels: true
80 | IndentPPDirectives: None
81 | IndentWidth: 4
82 | IndentWrappedFunctionNames: false
83 | JavaScriptQuotes: Leave
84 | JavaScriptWrapImports: true
85 | KeepEmptyLinesAtTheStartOfBlocks: false
86 | MacroBlockBegin: ''
87 | MacroBlockEnd: ''
88 | MaxEmptyLinesToKeep: 1
89 | NamespaceIndentation: None
90 | ObjCBinPackProtocolList: Never
91 | ObjCBlockIndentWidth: 2
92 | ObjCSpaceAfterProperty: false
93 | ObjCSpaceBeforeProtocolList: true
94 | PenaltyBreakAssignment: 2
95 | PenaltyBreakBeforeFirstCallParameter: 1
96 | PenaltyBreakComment: 300
97 | PenaltyBreakFirstLessLess: 120
98 | PenaltyBreakString: 1000
99 | PenaltyBreakTemplateDeclaration: 10
100 | PenaltyExcessCharacter: 1000000
101 | PenaltyReturnTypeOnItsOwnLine: 200
102 | PointerAlignment: Left
103 | RawStringFormats:
104 | - Language: Cpp
105 | Delimiters:
106 | - cc
107 | - CC
108 | - cpp
109 | - Cpp
110 | - CPP
111 | - 'c++'
112 | - 'C++'
113 | CanonicalDelimiter: ''
114 | BasedOnStyle: google
115 | - Language: TextProto
116 | Delimiters:
117 | - pb
118 | - PB
119 | - proto
120 | - PROTO
121 | EnclosingFunctions:
122 | - EqualsProto
123 | - EquivToProto
124 | - PARSE_PARTIAL_TEXT_PROTO
125 | - PARSE_TEST_PROTO
126 | - PARSE_TEXT_PROTO
127 | - ParseTextOrDie
128 | - ParseTextProtoOrDie
129 | CanonicalDelimiter: ''
130 | BasedOnStyle: google
131 | ReflowComments: true
132 | SortIncludes: true
133 | SortUsingDeclarations: true
134 | SpaceAfterCStyleCast: false
135 | SpaceAfterLogicalNot: false
136 | SpaceAfterTemplateKeyword: true
137 | SpaceBeforeAssignmentOperators: true
138 | SpaceBeforeCpp11BracedList: false
139 | SpaceBeforeCtorInitializerColon: true
140 | SpaceBeforeInheritanceColon: true
141 | SpaceBeforeParens: ControlStatements
142 | SpaceBeforeRangeBasedForLoopColon: true
143 | SpaceInEmptyParentheses: false
144 | SpacesBeforeTrailingComments: 2
145 | SpacesInAngles: false
146 | SpacesInContainerLiterals: true
147 | SpacesInCStyleCastParentheses: false
148 | SpacesInParentheses: false
149 | SpacesInSquareBrackets: false
150 | Standard: Cpp11
151 | StatementMacros:
152 | - Q_UNUSED
153 | - QT_REQUIRE_VERSION
154 | TabWidth: 4
155 | UseTab: Never
156 | ...
157 |
158 |
--------------------------------------------------------------------------------
/misc/icons8-raspberry-pi-520.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kclyu/rpi-webrtc-streamer/e109e418aa9023009b3b59c95eec2de4721125be/misc/icons8-raspberry-pi-520.png
--------------------------------------------------------------------------------
/misc/motion_detection_example.avi:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kclyu/rpi-webrtc-streamer/e109e418aa9023009b3b59c95eec2de4721125be/misc/motion_detection_example.avi
--------------------------------------------------------------------------------
/misc/telegram-icon-6264.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kclyu/rpi-webrtc-streamer/e109e418aa9023009b3b59c95eec2de4721125be/misc/telegram-icon-6264.png
--------------------------------------------------------------------------------
/misc/telegram_botfather.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kclyu/rpi-webrtc-streamer/e109e418aa9023009b3b59c95eec2de4721125be/misc/telegram_botfather.png
--------------------------------------------------------------------------------
/misc/webrtc_arm_build_args.gn:
--------------------------------------------------------------------------------
1 | # Build arguments go here. Examples:
2 | # is_component_build = true
3 | # is_debug = false
4 | # See "gn args --list" for available build arguments.
5 |
6 | #
7 | #
8 | # The following two flags are used for debugging.
9 | #
10 | #is_official_build=false
11 | #is_debug=true
12 |
13 | # For package building, we need to chage is_official_build to true and is_debug to false.
14 | #
15 | is_official_build=true
16 | is_debug=false
17 |
18 | is_component_build=false
19 | enable_iterator_debugging=false
20 |
21 | host_toolchain="//build/toolchain/linux:arm"
22 | is_clang=false
23 | use_sysroot=true
24 | target_sysroot="/opt/rpi_rootfs/rootfs"
25 | gold_path = "/opt/rpi_rootfs/tools/arm-linux-gnueabihf/bin"
26 |
27 | # target CPU optimization for PI2
28 | target_os="linux"
29 | target_cpu="arm"
30 | arm_arch="armv7-a"
31 | arm_fpu="neon"
32 | arm_float_abi="hard"
33 | arm_use_neon=true
34 | arm_tune="cortex-a7"
35 | rtc_build_with_neon=true
36 |
37 | #
38 | # build option for third party package of WebRTC native code
39 | rtc_use_pipewire=false
40 | libyuv_disable_jpeg=true
41 | use_system_libjpeg=true
42 | # disabled
43 | libcxx_natvis_include=false
44 | libyuv_include_tests=false
45 | rtc_enable_protobuf=false
46 |
47 | #
48 | # codec config options
49 | rtc_use_h264=true
50 | rtc_include_pulse_audio=false
51 | # do not use libaom(AV1 codec)
52 | enable_libaom=false
53 |
54 | #
55 | # WebRTC native package code build options which related to
56 | # target system envirionment
57 | #
58 | rtc_use_x11=false
59 | rtc_use_gtk=false
60 | use_ozone=true
61 | use_aura=false
62 | use_partition_alloc=false
63 | use_allocator_shim=false
64 | use_custom_libcxx=false
65 | is_chrome_branded=true
66 | rtc_include_tests=false
67 | treat_warnings_as_errors=false
68 |
69 |
--------------------------------------------------------------------------------
/misc/webrtc_armv6_build_args.gn:
--------------------------------------------------------------------------------
1 | # Build arguments go here. Examples:
2 | # is_component_build = true
3 | # is_debug = false
4 | # See "gn args --list" for available build arguments.
5 |
6 | #
7 | #
8 | # The following two flags are used for debugging.
9 | #
10 | #is_official_build=false
11 | #is_debug=true
12 |
13 | # For package building, we need to chage is_official_build to true and is_debug to false.
14 | #
15 | is_official_build=true
16 | is_debug=false
17 |
18 | is_component_build=false
19 | enable_iterator_debugging=false
20 |
21 | host_toolchain="//build/toolchain/linux:arm"
22 | is_clang=false
23 | use_sysroot=true
24 | target_sysroot="/opt/rpi_rootfs/rootfs"
25 | gold_path = "/opt/rpi_rootfs/tools/arm-linux-gnueabihf/bin"
26 |
27 | # taget CPU optimization for PI ZeroW
28 | target_os="linux"
29 | target_cpu="arm"
30 | arm_version=6
31 | arm_arch="armv6"
32 | arm_float_abi="hard"
33 | arm_use_neon=false
34 | arm_use_thumb=false
35 | arm_fpu="vfp"
36 | arm_optionally_use_neon=false
37 | arm_tune="arm1176jz-s"
38 | rtc_build_with_neon=false
39 |
40 | #
41 | # build option for third party package of WebRTC native code
42 | rtc_use_pipewire=false
43 | libyuv_disable_jpeg=true
44 | use_system_libjpeg=true
45 | # disabled
46 | libcxx_natvis_include=false
47 | libyuv_include_tests=false
48 | rtc_enable_protobuf=false
49 | ffmpeg_use_atomics_fallback=false
50 |
51 | #
52 | # codec config options
53 | rtc_use_h264=true
54 | rtc_include_pulse_audio=false
55 | rtc_libvpx_build_vp9=false
56 | # do not use libaom(AV1 codec)
57 | enable_libaom=false
58 |
59 | #
60 | # WebRTC native package code build options which related to
61 | # target system envirionment
62 | #
63 | rtc_use_x11=false
64 | rtc_use_gtk=false
65 | use_ozone=true
66 | use_aura=false
67 | use_partition_alloc=false
68 | use_allocator_shim=false
69 | use_custom_libcxx=false
70 | is_chrome_branded=true
71 | rtc_include_tests=false
72 | treat_warnings_as_errors=false
73 |
74 |
--------------------------------------------------------------------------------
/misc/webrtc_streamer_architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kclyu/rpi-webrtc-streamer/e109e418aa9023009b3b59c95eec2de4721125be/misc/webrtc_streamer_architecture.png
--------------------------------------------------------------------------------
/misc/webrtc_x64_build_args.gn:
--------------------------------------------------------------------------------
1 | # Build arguments go here. Examples:
2 | # is_component_build = true
3 | # is_debug = false
4 | # See "gn args --list" for available build arguments.
5 |
6 | #is_official_build=true
7 | #is_debug=false # Relese Version
8 | is_component_build=false
9 | enable_iterator_debugging=false
10 |
11 | host_toolchain="//build/toolchain/linux:x64"
12 | target_os="linux"
13 | is_clang=false
14 | use_sysroot=false
15 |
16 | #
17 | #
18 | use_ozone=true
19 | is_desktop_linux=false
20 |
21 | #
22 | #
23 | is_chrome_branded=true
24 | rtc_use_h264=true
25 | use_openh264=true
26 | rtc_libvpx_build_vp9=false # do not build VP9
27 | rtc_include_tests=false
28 | rtc_include_pulse_audio=false
29 | rtc_enable_protobuf=false
30 | treat_warnings_as_errors=false
31 |
32 |
--------------------------------------------------------------------------------
/mk/config_libwebsockets.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # this script will accept RPI_ROOTFS path a argument
3 | # e.g: ./config_libwebsocket.sh /opt/rpi_rootfs
4 | # if argument does not exist, the default rpi_rootfs path will be used
5 | if [ "$#" -lt 1 ]; then
6 | RPI_ROOTFS_CMAKE=${HOME}/Workspace/rpi_rootfs/PI.cmake
7 | else
8 | RPI_ROOTFS_CMAKE=$1/PI.cmake
9 | fi
10 |
11 | RWS_LIBRARY_DIR=../lib
12 |
13 | LIBWEBSOCKETS_BASENAME=libwebsockets-3.1.0
14 | LIBWEBSOCKET_DIR=${RWS_LIBRARY_DIR}/libwebsockets
15 | LIBWEBSOCKET_BUILD_DIR=${RWS_LIBRARY_DIR}/libwebsockets/arm_build
16 | LIBWEBSOCKETS_LIBRARY=${LIBWEBSOCKET_BUILD_DIR}/lib/libwebsockets.a
17 |
18 | ##
19 | ## Check whether rpi_rootfs repo exist
20 | if [ ! -e ${RPI_ROOTFS_CMAKE} ]
21 | then
22 | echo "rpi_rootfs does not exists"
23 | echo "You need to configure rpi_rootfs repo to build"
24 | echo "Please check https://github.com/kclyu/rpi_rootfs"
25 | exit -1
26 | fi
27 |
28 | if [ -e ${RWS_LIBRARY_DIR}/${LIBWEBSOCKETS_BASENAME}.zip ]
29 | then
30 | # checking libwebsockets library build directory exist
31 | if [ ! -d ${LIBWEBSOCKET_DIR} ]
32 | then
33 | echo "extracting libwebsocket library in lib"
34 | cd ${RWS_LIBRARY_DIR} && unzip ${LIBWEBSOCKETS_BASENAME}.zip && \
35 | mv ${LIBWEBSOCKETS_BASENAME} ${LIBWEBSOCKET_DIR}
36 | fi
37 |
38 | # checking libwebsockets library archive file
39 | if [ ! -f ${LIBWEBSOCKETS_LIBRARY} ]
40 | then
41 | echo "start building libwebsockets library"
42 | mkdir -p ${LIBWEBSOCKET_BUILD_DIR}
43 | cd ${LIBWEBSOCKET_BUILD_DIR} && \
44 | cmake .. -DCMAKE_TOOLCHAIN_FILE=${RPI_ROOTFS_CMAKE} \
45 | -DCMAKE_BUILD_TYPE=Debug -DLWS_WITH_SSL=OFF -DLWS_WITH_SHARED=OFF \
46 | -DLWS_WITH_LIBEV=0 && make
47 | else
48 | echo "libwebsockets.a already exist"
49 | fi
50 | else
51 | echo "Zipfile ${RWS_LIBRARY_DIR}/${LIBWEBSOCKETS_BASENAME}.zip not found"
52 | fi
53 | exit 0
54 |
55 |
--------------------------------------------------------------------------------
/mk/cross_arm_build.mk:
--------------------------------------------------------------------------------
1 |
2 | ifdef RPI_ROOTFS
3 | SYSROOT=$(RPI_ROOTFS)/rootfs
4 | else
5 | SYSROOT=/opt/rpi_rootfs/rootfs
6 | endif
7 |
8 | # validate sysroot path
9 | ifeq ("$(wildcard $(SYSROOT))","")
10 | $(error sysroot is is not configurd, please configure the sysroot/rootfs in Rpi_RootFS)
11 | endif
12 |
13 | CC=arm-linux-gnueabihf-gcc
14 | CXX=arm-linux-gnueabihf-g++
15 | AR=arm-linux-gnueabihf-ar
16 | LD=arm-linux-gnueabihf-ld
17 | AS=arm-linux-gnueabihf-as
18 | RANLIB=arm-linux-gnueabihf-ranlib
19 |
20 | #
21 | # WebRTC source tree and object directory
22 | #
23 | ifndef WEBRTC_ROOT
24 | WEBRTC_ROOT=$(HOME)/Workspace/webrtc
25 | endif
26 |
27 | WEBRTC_OUTPUT=out/$(TARGET_ARCH_BUILD)
28 | WEBRTC_LIBPATH=$(WEBRTC_ROOT)/src/$(WEBRTC_COUTPUT)
29 |
30 | ## WebRTC library build script
31 | # GN Build
32 | WEBRTC_NINJA_EXTACTOR=../mk/webrtc_library_gn.py $(WEBRTC_ROOT) $(WEBRTC_OUTPUT)
33 |
34 | WEBRTC_CFLAGS=$(shell $(WEBRTC_NINJA_EXTACTOR) cflags)
35 | WEBRTC_CCFLAGS=$(shell $(WEBRTC_NINJA_EXTACTOR) ccflags)
36 | WEBRTC_DEFINES=$(shell $(WEBRTC_NINJA_EXTACTOR) defines)
37 |
38 | WEBRTC_FLAGS_INCLUDES = -I$(WEBRTC_ROOT)/src
39 | WEBRTC_FLAGS_INCLUDES += $(shell $(WEBRTC_NINJA_EXTACTOR) includes)
40 |
41 | WEBRTC_BUILD_LIBS=$(shell $(WEBRTC_NINJA_EXTACTOR) libs)
42 | WEBRTC_SYSLIBS = $(shell $(WEBRTC_NINJA_EXTACTOR) syslibs)
43 | WEBRTC_LDFLAGS = $(shell $(WEBRTC_NINJA_EXTACTOR) ldflags)
44 |
45 | ifdef VERBOSE
46 | $(info WEBRTC_CFLAGS is "$(WEBRTC_CFLAGS)")
47 | $(info WEBRTC_CCFLAGS is "$(WEBRTC_CCFLAGS)")
48 | $(info WEBRTC_FLAGS_INCLUDES is "$(WEBRTC_FLAGS_INCLUDES)")
49 | $(info WEBRTC_SYSLIBS is "$(WEBRTC_SYSLIBS)")
50 | $(info WEBRTC_LDFLAGS is "$(WEBRTC_LDFLAGS)")
51 | $(info WEBRTC_BUILD_LIBS is "$(WEBRTC_BUILD_LIBS)")
52 | endif
53 |
54 |
55 |
--------------------------------------------------------------------------------
/mk/cross_mmal.mk:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # Variables for MMAL(raspivid) compilation
4 | #
5 | PI_INCLUDE=$(SYSROOT)/opt/vc/include
6 | MMAL_CFLAGS+=-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX \
7 | -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE \
8 | -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 \
9 | -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX \
10 | -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM
11 |
12 | MMAL_INCLUDES+=-I$(PI_INCLUDE)/interface/vcos/pthreads \
13 | -I$(PI_INCLUDE)/interface/vmcs_host/linux \
14 | -I$(PI_INCLUDE)/interface/vmcs_host \
15 | -I$(PI_INCLUDE)/interface/vchiq_arm \
16 | -I$(PI_INCLUDE) -I$(PI_INCLUDE)/interface/mmal
17 |
18 | MMAL_LDFLAGS+=-Wl,--no-as-needed -L$(SYSROOT)/opt/vc/lib/ -lmmal_core -lmmal \
19 | -lmmal_util -lvcos -lbcm_host -lmmal_vc_client -lmmal_components \
20 | -lvchiq_arm
21 |
22 |
--------------------------------------------------------------------------------
/mk/libavahi_arm.mk:
--------------------------------------------------------------------------------
1 | #
2 | # Avahi library compiler and linker flags definiton
3 | #
4 | AVAHI_INCLUDES=-I$(SYSROOT)/usr/include
5 |
6 | # LD FLAGS
7 | AVAHI_LIBS=-L$(SYSROOT)/usr/lib -lavahi-client -lavahi-common
8 |
--------------------------------------------------------------------------------
/mk/libwebsocket_arm_build.mk:
--------------------------------------------------------------------------------
1 | #
2 | # libwebsocket compiler and linker definiton
3 | #
4 | #
5 | LIBWEBSOCKETS_ROOT=$(HOME)/Workspace/rpi-webrtc-streamer/lib/libwebsockets
6 |
7 | # CC FLAGS
8 | LWS_C_FLAGS=-Wall -fvisibility=hidden -pthread
9 | LWS_INCLUDES=-I$(LIBWEBSOCKETS_ROOT)/arm_build \
10 | -I$(LIBWEBSOCKETS_ROOT)/arm_build/include \
11 | -I$(LIBWEBSOCKETS_ROOT)
12 |
13 | # LD FLAGS
14 | LWS_LIBS=$(LIBWEBSOCKETS_ROOT)/arm_build/lib/libwebsockets.a
15 | LWS_SYS_LIBS=-lz -lssl -lcrypto -lm
16 |
--------------------------------------------------------------------------------
/mk/libwebsocket_native_gcc.mk:
--------------------------------------------------------------------------------
1 | #
2 | # libwebsocket compiler and linker definiton
3 | #
4 | #
5 | LIBWEBSOCKETS_ROOT=$(HOME)/Workspace/rpi-webrtc-streamer/lib/libwebsockets
6 |
7 |
8 | # CC FLAGS
9 | #LWS_C_FLAGS=-Wall -Werror -fvisibility=hidden -pthread
10 | LWS_C_FLAGS=-Wall -fvisibility=hidden -pthread
11 | LWS_INCLUDES=-I$(LIBWEBSOCKETS_ROOT)/linux_build
12 |
13 | # LD FLAGS
14 | LWS_LIBS=$(LIBWEBSOCKETS_ROOT)/linux_build/lib/libwebsockets.a
15 | LWS_SYS_LIBS=-lz -lssl -lcrypto -lm
16 |
--------------------------------------------------------------------------------
/mk/native_gcc.mk:
--------------------------------------------------------------------------------
1 | #
2 | # WebRTC source tree and object directory
3 | #
4 | WEBRTC_ROOT=$(HOME)/Workspace/webrtc
5 | WEBRTC_OUTPUT=x64_build
6 | WEBRTC_LIBPATH=$(WEBRTC_ROOT)/src/$(WEBRTC_COUTPUT)
7 |
8 | ## WebRTC library build script
9 | # GN Build
10 | WEBRTC_NINJA_EXTACTOR=./scripts/webrtc_library_gn.py $(WEBRTC_ROOT) $(WEBRTC_OUTPUT)
11 |
12 | WEBRTC_CFLAGS=$(shell $(WEBRTC_NINJA_EXTACTOR) cflags)
13 | WEBRTC_CCFLAGS=$(shell $(WEBRTC_NINJA_EXTACTOR) ccflags)
14 | WEBRTC_DEFINES=$(shell $(WEBRTC_NINJA_EXTACTOR) defines)
15 |
16 | WEBRTC_FLAGS_INCLUDES = -I$(WEBRTC_ROOT)/src
17 | WEBRTC_FLAGS_INCLUDES += $(shell $(WEBRTC_NINJA_EXTACTOR) includes)
18 |
19 | WEBRTC_BUILD_LIBS=$(shell $(WEBRTC_NINJA_EXTACTOR) libs)
20 | WEBRTC_SYSLIBS = $(shell $(WEBRTC_NINJA_EXTACTOR) syslibs)
21 | WEBRTC_LDFLAGS = $(shell $(WEBRTC_NINJA_EXTACTOR) ldflags)
22 |
23 | ifdef VERBOSE
24 | $(info WEBRTC_CFLAGS is "$(WEBRTC_CFLAGS)")
25 | $(info WEBRTC_CCFLAGS is "$(WEBRTC_CCFLAGS)")
26 | $(info WEBRTC_FLAGS_INCLUDES is "$(WEBRTC_FLAGS_INCLUDES)")
27 | $(info WEBRTC_SYSLIBS is "$(WEBRTC_SYSLIBS)")
28 | $(info WEBRTC_LDFLAGS is "$(WEBRTC_LDFLAGS)")
29 | $(info WEBRTC_BUILD_LIBS is "$(WEBRTC_BUILD_LIBS)")
30 | endif
31 |
--------------------------------------------------------------------------------
/mk/validate_variables.mk:
--------------------------------------------------------------------------------
1 | #
2 | # ARCH can only be used in either arm or armv6.
3 | # arm : above armv6
4 | # armv6 : armv6 (raspberry pi zero)
5 | ARCH=arm
6 | ifeq ($(ARCH),arm)
7 | TARGET_ARCH_BUILD=arm_build
8 | else ifeq ($(ARCH),armv6)
9 | TARGET_ARCH_BUILD=armv6_build
10 | else
11 | $(error Unknown ARCH $(ARCH) type argument)
12 | endif
13 |
14 | #
15 | # Checking RPI_ROOTFS variable
16 | #
17 | ifndef RPI_ROOTFS
18 | # default RPI_ROOTFS variable
19 | RPI_ROOTFS=/opt/rpi_rootfs
20 | endif
21 | ifeq ("$(wildcard $(RPI_ROOTFS))","")
22 | define RPI_ROOTFS_ERROR_MESG
23 | Rpi_RootFS is not configured, please configure rpi_rootfs
24 | You need to configure rpi_rootfs repo to build,Please check https://github.com/kclyu/rpi_rootfs
25 | endef
26 | $(error $(RPI_ROOTFS_ERROR_MESG))
27 | endif
28 |
29 | #
30 | # Checking WEBRTC_ROOT variable
31 | #
32 | ifndef WEBRTC_ROOT
33 | # default WEBRTC_ROOT variable
34 | WEBRTC_ROOT=$(HOME)/Workspace/webrtc
35 | endif
36 | ifeq ("$(wildcard $(WEBRTC_ROOT)/src)","")
37 | define WEBRTC_ROOT_ERROR_MESG
38 | WebRTC native source code package is not configured, please configure it before try RWS building
39 | endef
40 | $(error $(WEBRTC_ROOT_ERROR_MESG))
41 | endif
42 |
43 |
--------------------------------------------------------------------------------
/scripts/rws.service:
--------------------------------------------------------------------------------
1 | [Unit]
2 | Description=Rpi WebRTC Streamer
3 | After=syslog.target
4 |
5 | [Service]
6 | Type=simple
7 | PIDFile=/var/run/webrtc-streamer.pid
8 | ExecStart=/opt/rws/webrtc-streamer --log /opt/rws/log
9 | StandardOutput=journal
10 | StandardError=journal
11 | Restart=always
12 | RestartSec=5
13 |
14 | [Install]
15 | WantedBy=multi-user.target
16 |
--------------------------------------------------------------------------------
/src/Makefile:
--------------------------------------------------------------------------------
1 |
2 | # including make scripts supports RWS building
3 | include ../mk/validate_variables.mk # validating required variable to build
4 | include ../mk/cross_arm_build.mk
5 | include ../mk/cross_mmal.mk
6 | include ../mk/libwebsocket_arm_build.mk
7 | include ../mk/libavahi_arm.mk
8 |
9 | #
10 | # including compat as source directory
11 | #
12 | RWS_INSTALL_DIR=\"/opt/rws\"
13 | RWS_VERSION=\"$(shell git describe --abbrev=16 --dirty --always --tags)\"
14 | WEBRTC_GIT=$(shell (cd $(WEBRTC_ROOT)/src/; git describe --abbrev=16 --dirty --always --tags))
15 | WEBRTC_CRPOSITION=$(shell (cd $(WEBRTC_ROOT)/src/;\
16 | git log -1 | gawk 'match($$0,/Cr-Commit-Position/){print $$0}' | sed 's/ //g'))
17 |
18 | CCFLAGS += -DINSTALL_DIR=$(RWS_INSTALL_DIR) $(LWS_C_FLAGS) $(WEBRTC_CCFLAGS)
19 | CFLAGS += -DINSTALL_DIR=$(RWS_INSTALL_DIR) $(WEBRTC_CFLAGS)
20 |
21 | INCLUDES += $(LWS_INCLUDES) $(WEBRTC_DEFINES) $(WEBRTC_FLAGS_INCLUDES) \
22 | $(H264BITSTREAM_INCLUDES) $(MMAL_INCLUDES) $(AVAHI_INCLUDES) \
23 | -I$(SYSROOT)/usr/include/arm-linux-gnueabihf
24 |
25 | # adding abseil-cpp include path in this makefile
26 | INCLUDES += -I$(WEBRTC_ROOT)/src/third_party/abseil-cpp/
27 |
28 | # for Raspbian Strech
29 | BUILD_LIBS += $(WEBRTC_BUILD_LIBS) $(LWS_LIBS) $(AVAHI_LIBS)
30 | SYSLIBS += $(LWS_SYS_LIBS) $(WEBRTC_SYSLIBS)
31 | LDFLAGS += $(WEBRTC_LDFLAGS) $(MMAL_LDFLAGS)
32 |
33 | # Adding Version Information
34 | CCFLAGS += -D__RWS_VERSION__=$(RWS_VERSION) \
35 | -D__WEBRTC_VERSION__="\"$(WEBRTC_GIT),$(WEBRTC_CRPOSITION)\""
36 |
37 | #
38 | # Debugging purpose only
39 | #
40 | ifdef VERBOSE
41 | $(info LWS_C_FLAGS is "$(LWS_C_FLAGS)")
42 | $(info WEBRTC_CCFLAGS is "$(WEBRTC_CCFLAGS)")
43 | $(info MMAL_CFLAGS is "$(MMAL_CFLAGS)")
44 | $(info RWS_INSTALL_DIR is "$(RWS_INSTALL_DIR)")
45 | $(info CFLAGS is "$(CFLAGS)")
46 | $(info CCFLAGS is "$(CCFLAGS)")
47 | $(info INCLUDES is "$(INCLUDES)")
48 | $(info SYSLIBS is "$(SYSLIBS)")
49 | $(info LDFLAGS is "$(LDFLAGS)")
50 | $(info BUILD_LIBS is "$(BUILD_LIBS)")
51 | endif
52 |
53 | #
54 | # Raspberry PI testing host
55 | ifndef RPI_HOST_URL
56 | RPI_HOST_URL=pi@10.0.0.11:~/Workspace/client
57 | endif
58 |
59 | # TARGET
60 | #
61 | TARGET = ../webrtc-streamer
62 | TARGET_LWS_LIBS = $(LWS_LIBS)
63 |
64 | #
65 | # source from WebRTC native library for compat
66 | #
67 | COMPAT.CC = compat/optionsfile.cc compat/status.cc compat/status_payload_printer.cc \
68 | compat/statusor.cc
69 | #
70 | # source & object list definition
71 | #
72 | SOURCES.CC = websocket_server.cc websocket_server_callback.cc app_clientinfo.cc \
73 | app_channel.cc direct_socket.cc raspi_decoder_dummy.cc raspi_decoder.cc \
74 | raspi_encoder.cc raspi_encoder_impl.cc mmal_wrapper.cc utils.cc main.cc \
75 | streamer_signaling.cc streamer.cc raspi_quality_config.cc app_ws_client.cc \
76 | file_log_sink.cc raspi_motion.cc raspi_motionvector.cc config_streamer.cc \
77 | raspi_motionblob.cc raspi_motionfile.cc config_media.cc config_motion.cc \
78 | utils_pc_config.cc utils_pc_strings.cc session_config.cc frame_queue.cc \
79 | file_writer_handle.cc log_rotating_stream.cc wstreamer_types.cc mmal_still_capture.cc \
80 |
81 | SOURCES.C = websocket_server_util.c mmal_video.c mmal_video_reset.c mmal_util.c \
82 | raspicli.c raspicamcontrol.c mmal_still.c raspipreview.c mdns_publish.c
83 |
84 | OBJECTS.CC = $(SOURCES.CC:.cc=.o) $(COMPAT.CC:.cc=.o)
85 | OBJECTS.C = $(SOURCES.C:.c=.o)
86 | OBJECTS = $(OBJECTS.CC) $(OBJECTS.C)
87 |
88 | all: $(TARGET_LWS_LIBS) $(TARGET)
89 |
90 | #
91 | # Makefile rules...
92 | #
93 | .c.o : $(OBJECTS.C)
94 | $(CC) -I. $(CFLAGS) $(INCLUDES) $(MMAL_CFLAGS) -D__MMAL_ENCODER_DEBUG__ -c $< -o $@
95 |
96 | .cc.o : $(OBJECTS.CC)
97 | $(CXX) -I. $(CFLAGS) $(CCFLAGS) $(MMAL_CFLAGS) $(INCLUDES) -c $< -o $@
98 |
99 | $(TARGET): $(OBJECTS)
100 | $(CXX) $(LDFLAGS) -o $(TARGET) -Wl,--start-group $(OBJECTS) $(BUILD_LIBS) -Wl,--end-group $(SYSLIBS)
101 |
102 | clean:
103 | rm -f *.o *.dwo compat/*.o compat/*.dwo $(TARGET)
104 |
105 | distclean: clean
106 | rm -fr ../lib/libwebsockets
107 |
108 | $(TARGET_LWS_LIBS) :
109 | ../mk/config_libwebsockets.sh $(RPI_ROOTFS)
110 |
111 | #
112 | # helper rules
113 | #
114 | rcp: $(TARGET)
115 | rsync -v -u -r --stats $(TARGET) *.cc *.h *.dwo compat $(RPI_HOST_URL)
116 |
117 | rcp_full: $(TARGET)
118 | rsync -v -u -r --stats $(TARGET) ../LICENSE ../tools ../etc ../etc/template ../web-root \
119 | ../scripts $(RPI_HOST_URL)
120 |
121 | web: $(TARGET)
122 | rsync -v -u -r -L --stats ../web-root $(RPI_HOST_URL)
123 |
124 | #
125 | # You need to install clang-format-9
126 | format:
127 | find . -maxdepth 2 -iname \*.h -o -iname \*.cc -o -iname \*.c \
128 | | xargs clang-format-9 -style=file -i -fallback-style=none
129 |
130 | #
131 | # You need to configure ccls and bear(2.4.3 >= version) to generate compile_commands.json
132 | ccls:
133 | make clean
134 | bear --use-cc arm-linux-gnueabihf-gcc --use-c++ arm-linux-gnueabihf-g++ make
135 | rm -f ../compile_commands.json
136 | mv compile_commands.json ../
137 |
138 |
--------------------------------------------------------------------------------
/src/app_channel.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017, rpi-webrtc-streamer Lyu,KeunChang
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of the copyright holder nor the
15 | names of its contributors may be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #include "app_channel.h"
31 |
32 | #include
33 |
34 | #include
35 | #include
36 |
37 | #include "absl/strings/str_format.h"
38 | #include "config_media.h"
39 | #include "utils.h"
40 | #include "websocket_server.h"
41 |
42 | namespace {
43 |
44 | constexpr char kDefaultHttpWebMount[] = "/";
45 | constexpr char kMotionFileLink[] = "motion";
46 | constexpr char kStillFileLink[] = "still";
47 |
48 | } // namespace
49 |
50 | ////////////////////////////////////////////////////////////////////////////////
51 | //
52 | // Application Channel
53 | //
54 | ////////////////////////////////////////////////////////////////////////////////
55 | AppChannel::AppChannel() : is_inited_(false) {}
56 |
57 | bool AppChannel::AppInitialize(StreamerProxy* proxy,
58 | ConfigStreamer& config_streamer,
59 | ConfigMotion& config_motion) {
60 | std::string websocket_url_path;
61 | std::string http_mount_origin;
62 | int port_num;
63 |
64 | // LibWebSocket debug log
65 | if (config_streamer.GetLwsDebugEnable()) {
66 | RTC_LOG(INFO) << "enabling debug logging message of websocket library";
67 | LogLevel(LibWebSocketServer::DEBUG_LEVEL_ALL);
68 | };
69 |
70 | // need to initialize the motion mount after WebRoot initialization.
71 | http_mount_origin = config_streamer.GetWebRootPath();
72 | RTC_LOG(INFO) << "Using http file mapping : " << http_mount_origin;
73 | AddHttpWebMount(kDefaultHttpWebMount, http_mount_origin);
74 |
75 | if (config_motion.GetDetectionEnable()) {
76 | std::string motion_file_link =
77 | absl::StrFormat("%s/%s", http_mount_origin, kMotionFileLink);
78 | utils::DeleteFile(motion_file_link);
79 | utils::SymLink(config_motion.GetDirectory(), motion_file_link);
80 | RTC_LOG(INFO) << "Using motion video mapping : "
81 | << config_motion.GetDirectory()
82 | << ", link: " << motion_file_link;
83 | }
84 | if (ConfigMediaSingleton::Instance()->GetStillEnable()) {
85 | std::string still_file_link =
86 | absl::StrFormat("%s/%s", http_mount_origin, kStillFileLink);
87 | utils::DeleteFile(still_file_link);
88 | utils::SymLink(ConfigMediaSingleton::Instance()->GetStillDirectory(),
89 | still_file_link);
90 | RTC_LOG(INFO) << "Using still image mapping : "
91 | << ConfigMediaSingleton::Instance()->GetStillDirectory()
92 | << ", link: " << still_file_link;
93 | }
94 |
95 | port_num = config_streamer.GetWebSocketPort();
96 | RTC_LOG(INFO) << "WebSocket port num : " << port_num;
97 | if (Init(port_num) == false) return false;
98 |
99 | ws_client_.reset(new AppWsClient(proxy));
100 |
101 | websocket_url_path = config_streamer.GetRwsWsUrlPath();
102 | RTC_LOG(INFO) << "Using RWS WS client url : " << websocket_url_path;
103 | ws_client_->RegisterWebSocketMessage(this);
104 | ws_client_->RegisterConfigStreamer(&config_streamer);
105 | AddWebSocketHandler(websocket_url_path, SINGLE_INSTANCE, ws_client_.get());
106 |
107 | is_inited_ = true;
108 | return true;
109 | }
110 |
111 | AppChannel::~AppChannel() {}
112 |
--------------------------------------------------------------------------------
/src/app_channel.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017, rpi-webrtc-streamer Lyu,KeunChang
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of the copyright holder nor the
15 | names of its contributors may be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #ifndef APP_CHANNEL_H_
31 | #define APP_CHANNEL_H_
32 |
33 | #include
34 | #include
35 |
36 | #include "app_ws_client.h"
37 | #include "config_motion.h"
38 | #include "config_streamer.h"
39 | #include "websocket_server.h"
40 |
41 | class AppChannel : public LibWebSocketServer {
42 | public:
43 | explicit AppChannel();
44 | ~AppChannel();
45 | bool AppInitialize(StreamerProxy* proxy, ConfigStreamer& config_streamer,
46 | ConfigMotion& config_motion);
47 |
48 | private:
49 | bool is_inited_;
50 | std::unique_ptr ws_client_;
51 | };
52 |
53 | #endif // APP_CHANNEL_H_
54 |
--------------------------------------------------------------------------------
/src/app_clientinfo.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017, rpi-webrtc-streamer Lyu,KeunChang
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of the copyright holder nor the
15 | names of its contributors may be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #include "app_clientinfo.h"
31 |
32 | #include
33 | #include
34 | #include
35 |
36 | #include
37 | #include
38 |
39 | #include "rtc_base/checks.h"
40 | #include "rtc_base/logging.h"
41 |
42 | namespace {
43 |
44 | const uint32_t kClientIDLength = 8;
45 | const uint32_t kRoomIDLength = 9;
46 | const uint32_t kMaxClientID = 99999999;
47 | const uint32_t kMaxRoomID = 999999999;
48 | const uint64_t kWaitTimeout = 1000;
49 |
50 | } // namespace
51 |
52 | ////////////////////////////////////////////////////////////////////////////////
53 | //
54 | // AppClientInfo
55 | //
56 | ////////////////////////////////////////////////////////////////////////////////
57 | AppClientInfo::AppClientInfo() : state_(ClientState::CLIENT_DISCONNECTED) {}
58 |
59 | bool AppClientInfo::Register(int sockid, int room_id, int client_id) {
60 | webrtc::MutexLock lock(&mutex_);
61 | RTC_LOG(LS_VERBOSE) << __FUNCTION__ << "WS id: " << sockid << ", Roomid "
62 | << room_id << ",Client id: " << client_id;
63 | RTC_DCHECK(sockid > 0 && room_id > 0 && client_id > 0)
64 | << "id must be greater then 0";
65 | switch (state_) {
66 | case ClientState::CLIENT_REGISTERED:
67 | if (room_id_ == room_id && client_id_ == client_id) {
68 | RTC_LOG(LS_WARNING) << "Doing register second times";
69 | return true;
70 | }
71 | return false; // already registered by another client
72 | // All other state can be changed to CONNECTED
73 | case ClientState::CLIENT_DISCONNECTED:
74 | room_id_ = room_id;
75 | client_id_ = client_id;
76 | break;
77 | default:
78 | break;
79 | }
80 | sockid_ = sockid;
81 |
82 | // this type of request generated by testing page of browser
83 | if (room_id_ != 0 || client_id_ != 0) {
84 | RTC_LOG(LS_WARNING)
85 | << "internal id (room,client) does not cleared correctly"
86 | << " or, invalid/unknown state transition";
87 | }
88 | room_id_ = room_id;
89 | client_id_ = client_id;
90 |
91 | state_ = CLIENT_REGISTERED;
92 | return true;
93 | }
94 |
95 | bool AppClientInfo::Disconnect(int sockid) {
96 | webrtc::MutexLock lock(&mutex_);
97 | RTC_LOG(INFO) << __FUNCTION__ << ": sockid id " << sockid;
98 | if (sockid_ != sockid) {
99 | RTC_LOG(INFO) << "sockid does not match.";
100 | return false;
101 | };
102 | switch (state_) {
103 | case ClientState::CLIENT_REGISTERED:
104 | state_ = ClientState::CLIENT_DISCONNECTED;
105 | return true;
106 | default:
107 | break;
108 | }
109 | return true;
110 | }
111 |
112 | bool AppClientInfo::GetSockId(int client_id, int& sockid) {
113 | RTC_LOG(LS_VERBOSE) << __FUNCTION__ << ":Client id: " << client_id;
114 | RTC_DCHECK(client_id_ == client_id);
115 | if (client_id_ == client_id) {
116 | sockid = sockid_;
117 | return true;
118 | }
119 | return false;
120 | }
121 |
122 | bool AppClientInfo::IsRegistered(int sockid) {
123 | return state_ == ClientState::CLIENT_REGISTERED && sockid_ == sockid;
124 | }
125 |
126 | void AppClientInfo::Reset() {
127 | RTC_LOG(LS_VERBOSE) << __FUNCTION__;
128 | client_id_ = room_id_ = sockid_ = 0;
129 | state_ = CLIENT_DISCONNECTED;
130 | }
131 |
--------------------------------------------------------------------------------
/src/app_clientinfo.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017, rpi-webrtc-streamer Lyu,KeunChang
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of the copyright holder nor the
15 | names of its contributors may be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 |
29 | #ifndef APP_CLIENTINFO_H_
30 | #define APP_CLIENTINFO_H_
31 |
32 | #include
33 | #include
34 | #include
35 |
36 | #include "rtc_base/checks.h"
37 | #include "rtc_base/strings/json.h"
38 | #include "rtc_base/synchronization/mutex.h"
39 |
40 | // AppClient does not have room concept and only one clinet connection..
41 | // so room_id and client_id will be held within AppClientInfo
42 | class AppClientInfo {
43 | enum ClientState {
44 | CLIENT_DISCONNECTED = 0,
45 | CLIENT_REGISTERED,
46 | CLIENT_DISCONNECT_WAIT
47 | };
48 |
49 | public:
50 | explicit AppClientInfo();
51 | ~AppClientInfo(){};
52 |
53 | bool Register(int sockid, int room_id, int client_id);
54 | bool Disconnect(int sockid);
55 | bool GetSockId(int client_id, int& sockid);
56 | bool IsRegistered(int sockid);
57 | void Reset();
58 |
59 | private:
60 | webrtc::Mutex mutex_;
61 | // Status transition
62 | ClientState state_;
63 | int client_id_;
64 | int room_id_;
65 | int sockid_;
66 | };
67 |
68 | #endif // APP_CLIENTINFO_H_
69 |
--------------------------------------------------------------------------------
/src/app_ws_client.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017, rpi-webrtc-streamer Lyu,KeunChang
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | * Neither the name of the copyright holder nor the
15 | names of its contributors may be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #ifndef APP_WS_CLIENT_H_
31 | #define APP_WS_CLIENT_H_
32 |
33 | #include
34 | #include
35 |
36 | #include "api/media_stream_interface.h"
37 | #include "api/peer_connection_interface.h"
38 | #include "app_clientinfo.h"
39 | #include "compat/optionsfile.h"
40 | #include "config_media.h"
41 | #include "config_streamer.h"
42 | #include "rtc_base/message_handler.h"
43 | #include "session_config.h"
44 | #include "streamer_signaling.h"
45 | #include "utils.h"
46 | #include "websocket_server.h"
47 |
48 | class AppWsClient : public rtc::MessageHandler,
49 | public WebSocketHandler,
50 | public SignalingChannelHelper {
51 | public:
52 | enum EventType { EventNotice, EventError };
53 |
54 | explicit AppWsClient(StreamerProxy* proxy);
55 | ~AppWsClient();
56 |
57 | // register WebSocket Server for SendMessage
58 | void RegisterWebSocketMessage(WebSocketMessage* server_instance);
59 | void RegisterConfigStreamer(ConfigStreamer* config_streamer);
60 |
61 | // WebSocket Handler
62 | void OnConnect(int sockid) override;
63 | bool OnMessage(int sockid, const std::string& message) override;
64 | void OnDisconnect(int sockid) override;
65 | void OnError(int sockid, const std::string& message) override;
66 |
67 | // SignalingInbound interface
68 | bool SendMessageToPeer(const int peer_id,
69 | const std::string& message) override;
70 | void ReportEvent(const int peer_id, bool drop_connection,
71 | const std::string& message) override;
72 |
73 | private:
74 | // message handler interface
75 | void OnMessage(rtc::Message* msg) override;
76 |
77 | void SendResponse(int sockid, bool success, const std::string& type,
78 | const std::string& transaction, const std::string& data,
79 | const std::string& error_mesg);
80 | void SendEvent(int sockid, EventType is_event,
81 | const std::string& event_mesg);
82 |
83 | std::string ws_url_;
84 | AppClientInfo app_client_;
85 | SessionConfig session_config_;
86 | WebSocketMessage* websocket_message_;
87 |
88 | // WebSocket chunked frames
89 | std::string chunked_frames_;
90 | int num_chunked_frames_;
91 | std::string deviceid_;
92 | bool deviceid_inited_;
93 | ConfigMedia* config_media_;
94 | ConfigStreamer* config_streamer_;
95 | };
96 |
97 | #endif // APP_WS_CLIENT_H_
98 |
--------------------------------------------------------------------------------
/src/compat/optionsfile.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 The WebRTC Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef RTC_BASE_OPTIONSFILE_H_
12 | #define RTC_BASE_OPTIONSFILE_H_
13 |
14 | #include