├── .github └── workflows │ └── build.yml ├── .gitignore ├── .vscode └── c_cpp_properties.json ├── COPYING ├── LICENSE ├── README.md ├── build.sh ├── divinus.yaml ├── doc ├── endpoints.md └── overlays.md ├── remote.sh ├── res ├── index.html └── onvif │ ├── badauth.xml │ ├── capabilities.xml │ ├── deviceinfo.xml │ ├── discovery.xml │ ├── mediaprofile.xml │ ├── mediaprofiles.xml │ ├── snapshot.xml │ ├── stream.xml │ ├── systemtime.xml │ └── videosources.xml └── src ├── Makefile ├── app_config.c ├── app_config.h ├── compat.c ├── error.c ├── error.h ├── fmt ├── bitbuf.c ├── bitbuf.h ├── moof.c ├── moof.h ├── moov.c ├── moov.h ├── mp4.c ├── mp4.h ├── nal.c └── nal.h ├── gpio.c ├── gpio.h ├── hal ├── config.c ├── config.h ├── hisi │ ├── quirks.c │ ├── v1_aud.h │ ├── v1_common.h │ ├── v1_config.h │ ├── v1_hal.c │ ├── v1_hal.h │ ├── v1_isp.h │ ├── v1_rgn.h │ ├── v1_snr.h │ ├── v1_sys.h │ ├── v1_vb.h │ ├── v1_venc.h │ ├── v1_vi.h │ ├── v1_vpss.h │ ├── v2_aud.h │ ├── v2_common.h │ ├── v2_config.h │ ├── v2_hal.c │ ├── v2_hal.h │ ├── v2_isp.h │ ├── v2_rgn.h │ ├── v2_snr.h │ ├── v2_sys.h │ ├── v2_vb.h │ ├── v2_venc.h │ ├── v2_vi.h │ ├── v2_vpss.h │ ├── v3_aud.h │ ├── v3_common.h │ ├── v3_config.h │ ├── v3_hal.c │ ├── v3_hal.h │ ├── v3_isp.h │ ├── v3_rgn.h │ ├── v3_snr.h │ ├── v3_sys.h │ ├── v3_vb.h │ ├── v3_venc.h │ ├── v3_vi.h │ ├── v3_vpss.h │ ├── v4_aud.h │ ├── v4_common.h │ ├── v4_config.h │ ├── v4_hal.c │ ├── v4_hal.h │ ├── v4_isp.h │ ├── v4_rgn.h │ ├── v4_snr.h │ ├── v4_sys.h │ ├── v4_vb.h │ ├── v4_venc.h │ ├── v4_vi.h │ └── v4_vpss.h ├── inge │ ├── t31_aud.h │ ├── t31_common.h │ ├── t31_fs.h │ ├── t31_hal.c │ ├── t31_hal.h │ ├── t31_isp.h │ ├── t31_osd.h │ ├── t31_sys.h │ └── t31_venc.h ├── macros.h ├── plus │ ├── ak_aud.h │ ├── ak_common.h │ ├── ak_hal.c │ ├── ak_hal.h │ ├── ak_sys.h │ ├── ak_venc.h │ ├── ak_vi.h │ ├── aw_common.h │ ├── aw_sys.h │ ├── cvi_aud.h │ ├── cvi_common.h │ ├── cvi_config.h │ ├── cvi_hal.c │ ├── cvi_hal.h │ ├── cvi_isp.h │ ├── cvi_rgn.h │ ├── cvi_snr.h │ ├── cvi_sys.h │ ├── cvi_vb.h │ ├── cvi_venc.h │ ├── cvi_vi.h │ ├── cvi_vpss.h │ ├── gm_aud.h │ ├── gm_cap.h │ ├── gm_common.h │ ├── gm_hal.c │ ├── gm_hal.h │ ├── gm_osd.h │ ├── gm_venc.h │ ├── rk_aiq.h │ ├── rk_aud.h │ ├── rk_common.h │ ├── rk_hal.c │ ├── rk_hal.h │ ├── rk_mb.h │ ├── rk_rgn.h │ ├── rk_sys.h │ ├── rk_venc.h │ ├── rk_vi.h │ └── rk_vpss.h ├── star │ ├── i3_aud.h │ ├── i3_common.h │ ├── i3_hal.c │ ├── i3_hal.h │ ├── i3_isp.h │ ├── i3_osd.h │ ├── i3_sys.h │ ├── i3_venc.h │ ├── i3_vi.h │ ├── i6_aud.h │ ├── i6_common.h │ ├── i6_hal.c │ ├── i6_hal.h │ ├── i6_ipu.h │ ├── i6_isp.h │ ├── i6_rgn.h │ ├── i6_snr.h │ ├── i6_sys.h │ ├── i6_venc.h │ ├── i6_vif.h │ ├── i6_vpe.h │ ├── i6c_aud.h │ ├── i6c_common.h │ ├── i6c_hal.c │ ├── i6c_hal.h │ ├── i6c_ipu.h │ ├── i6c_isp.h │ ├── i6c_rgn.h │ ├── i6c_scl.h │ ├── i6c_snr.h │ ├── i6c_sys.h │ ├── i6c_venc.h │ ├── i6c_vif.h │ ├── m6_aud.h │ ├── m6_common.h │ ├── m6_hal.c │ ├── m6_hal.h │ ├── m6_ipu.h │ ├── m6_isp.h │ ├── m6_rgn.h │ ├── m6_scl.h │ ├── m6_snr.h │ ├── m6_sys.h │ ├── m6_venc.h │ └── m6_vif.h ├── support.c ├── support.h ├── symbols.h ├── tools.c ├── tools.h └── types.h ├── http_post.c ├── http_post.h ├── jpeg.c ├── jpeg.h ├── lib ├── miniz │ ├── miniz.c │ ├── miniz.h │ ├── miniz_common.h │ ├── miniz_export.h │ ├── miniz_tdef.c │ ├── miniz_tdef.h │ ├── miniz_tinfl.c │ ├── miniz_tinfl.h │ ├── miniz_zip.c │ └── miniz_zip.h ├── schrift.c ├── schrift.h ├── shine │ ├── bitstream.c │ ├── bitstream.h │ ├── huffman.c │ ├── huffman.h │ ├── l3bitstream.c │ ├── l3bitstream.h │ ├── l3loop.c │ ├── l3loop.h │ ├── l3mdct.c │ ├── l3mdct.h │ ├── l3subband.c │ ├── l3subband.h │ ├── layer3.c │ ├── layer3.h │ ├── mult_mips_gcc.h │ ├── mult_noarch_gcc.h │ ├── mult_sarm_gcc.h │ ├── reservoir.c │ ├── reservoir.h │ ├── tables.c │ ├── tables.h │ └── types.h ├── spng.c ├── spng.h ├── tinysvcmdns.c └── tinysvcmdns.h ├── main.c ├── media.c ├── media.h ├── network.c ├── network.h ├── night.c ├── night.h ├── onvif.c ├── onvif.h ├── record.c ├── record.h ├── region.c ├── region.h ├── rtsp ├── bufpool.h ├── common.h ├── hash.h ├── list.h ├── mime.c ├── mime.h ├── rfc.h ├── rtcp.h ├── rtp.c ├── rtp.h ├── rtsp.c ├── rtsp.h ├── rtsp_server.h └── thread.h ├── server.c ├── server.h ├── stack.c ├── stream.c ├── stream.h ├── text.c ├── text.h ├── watchdog.c └── watchdog.h /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | workflow_dispatch: 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | 18 | - name: Build 19 | run: | 20 | list="arm-glibc arm-musl3 arm-musl4 arm9-musl3 arm9-musl4 arm9-uclibc armhf-glibc armhf-musl armhf-uclibc mips-musl" 21 | for lib in $list; do 22 | sh build.sh $lib 23 | zip $lib divinus* 24 | done 25 | 26 | - name: Upload 27 | if: github.event_name != 'pull_request' 28 | uses: softprops/action-gh-release@v2 29 | with: 30 | tag_name: latest 31 | files: ./*.zip 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode/settings.json 2 | /obj 3 | /.previous 4 | /src/**/*.o 5 | /toolchain 6 | divinus 7 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "arm-glibc", 5 | "includePath": ["${workspaceFolder}/**"], 6 | "defines": ["__arm__", "__ARM_PCS"], 7 | "compilerPath": "toolchain/toolchain.hisilicon-hi3516cv500/bin/arm-openipc-linux-gnueabi-gcc", 8 | "cStandard": "c11" 9 | },{ 10 | "name": "arm-musl3", 11 | "includePath": ["${workspaceFolder}/**"], 12 | "defines": ["__arm__", "__ARM_PCS"], 13 | "compilerPath": "toolchain/toolchain.hisilicon-hi3516av100/bin/arm-openipc-linux-musleabi-gcc", 14 | "cStandard": "c11" 15 | },{ 16 | "name": "arm-musl4", 17 | "includePath": ["${workspaceFolder}/**"], 18 | "defines": ["__arm__", "__ARM_PCS"], 19 | "compilerPath": "toolchain/toolchain.hisilicon-hi3516ev200/bin/arm-openipc-linux-musleabi-gcc", 20 | "cStandard": "c11" 21 | },{ 22 | "name": "arm9-glibc", 23 | "includePath": ["${workspaceFolder}/**"], 24 | "defines": ["__arm__", "__ARM_PCS"], 25 | "compilerPath": "toolchain/arm926t-gcc13-musl-3_0/bin/arm-openipc-linux-musleabi-gcc", 26 | "cStandard": "c11" 27 | },{ 28 | "name": "arm9-musl3", 29 | "includePath": ["${workspaceFolder}/**"], 30 | "defines": ["__arm__", "__ARM_PCS"], 31 | "compilerPath": "toolchain/toolchain.hisilicon-hi3516cv100/bin/arm-openipc-linux-musleabi-gcc", 32 | "cStandard": "c11" 33 | },{ 34 | "name": "arm9-musl4", 35 | "includePath": ["${workspaceFolder}/**"], 36 | "defines": ["__arm__", "__ARM_PCS"], 37 | "compilerPath": "toolchain/toolchain.hisilicon-hi3516cv200/bin/arm-openipc-linux-musleabi-gcc", 38 | "cStandard": "c11" 39 | },{ 40 | "name": "arm9-uclibc", 41 | "includePath": ["${workspaceFolder}/**"], 42 | "defines": ["__arm__", "__ARM_PCS"], 43 | "compilerPath": "toolchain/toolchain.grainmedia-gm8136/bin/arm-openipc-linux-uclibcgnueabi-gcc", 44 | "cStandard": "c11" 45 | },{ 46 | "name": "armhf-glibc", 47 | "includePath": ["${workspaceFolder}/**"], 48 | "defines": ["__arm__", "__ARM_PCS_VFP"], 49 | "compilerPath": "toolchain/toolchain.sigmastar-infinity6e/bin/arm-openipc-linux-gnueabihf-gcc", 50 | "cStandard": "c11" 51 | },{ 52 | "name": "armhf-musl", 53 | "includePath": ["${workspaceFolder}/**"], 54 | "defines": ["__arm__", "__ARM_PCS_VFP"], 55 | "compilerPath": "toolchain/toolchain.sigmastar-infinity6/bin/arm-openipc-linux-musleabihf-gcc", 56 | "cStandard": "c11" 57 | },{ 58 | "name": "armhf-uclibc", 59 | "includePath": ["${workspaceFolder}/**"], 60 | "defines": ["__arm__", "__ARM_PCS_VFP"], 61 | "compilerPath": "toolchain/toolchain.rockchip-rv11xx/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc", 62 | "cStandard": "c11" 63 | },{ 64 | "name": "mips-musl", 65 | "includePath": ["${workspaceFolder}/**"], 66 | "defines": ["__mips__"], 67 | "compilerPath": "toolchain/toolchain.ingenic-t31/bin/mipsel-openipc-linux-musl-gcc", 68 | "cStandard": "c11" 69 | },{ 70 | "name": "riscv64-musl", 71 | "includePath": ["${workspaceFolder}/**"], 72 | "defines": ["__riscv", "__riscv__"], 73 | "compilerPath": "toolchain/riscv64-lp64d--musl--stable-2024.05-1/bin/riscv64-linux-gcc", 74 | "cStandard": "c11" 75 | } 76 | ], 77 | "version": 4 78 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 OpenIPC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | DL="https://github.com/OpenIPC/firmware/releases/download/toolchain" 3 | EXT="tgz" 4 | PRE="linux" 5 | 6 | toolchain() { 7 | if [ ! -e toolchain/$1 ]; then 8 | wget -c -q $DL/$1.$EXT -P $PWD 2>/dev/null || curl -L -s -o $PWD/$1.$EXT $DL/$1.$EXT 9 | mkdir -p toolchain/$1 10 | if [ "$EXT" = "zip" ]; then 11 | unzip $1.$EXT || exit 1 12 | chmod -R +x toolchain/$1/bin 13 | else 14 | tar -xf $1.$EXT -C toolchain/$1 --strip-components=1 || exit 1 15 | fi 16 | rm -f $1.$EXT 17 | fi 18 | make -j $(nproc) -C src CC=$PWD/toolchain/$1/bin/$2-$PRE-gcc OPT="$OPT $3" 19 | } 20 | 21 | if [ "$2" = "debug" ]; then 22 | OPT="-DDEBUG -gdwarf-3" 23 | else 24 | OPT="-Os -s" 25 | fi 26 | 27 | previous=$(cat .previous 2>/dev/null) 28 | if [ "$1" != "$previous" ]; then 29 | echo "$1" > .previous 30 | make -C src clean 31 | fi 32 | 33 | if [ "$1" = "arm-glibc" ] || [ "$1" = "hisi-v4a" ]; then 34 | toolchain toolchain.hisilicon-hi3516cv500 arm -lm 35 | elif [ "$1" = "arm-musl3" ] || [ "$1" = "hisi-v2a" ] || [ "$1" = "hisi-v3a" ]; then 36 | toolchain toolchain.hisilicon-hi3516av100 arm 37 | elif [ "$1" = "arm-musl4" ] || [ "$1" = "hisi-v4" ]; then 38 | toolchain toolchain.hisilicon-hi3516ev200 arm 39 | elif [ "$1" = "arm9-glibc" ] || [ "$1" = "ak39xx" ]; then 40 | DL="https://github.com/Lamobo/Lamobo-D1/raw/master/compiler" 41 | EXT="tar.bz2" 42 | PRE="none-linux-gnueabi" 43 | toolchain arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu arm "-ldl -lm -lpthread -lrt -std=gnu99" 44 | elif [ "$1" = "arm9-musl3" ] || [ "$1" = "hisi-v1" ]; then 45 | toolchain toolchain.hisilicon-hi3516cv100 arm 46 | elif [ "$1" = "arm9-musl4" ] || [ "$1" = "hisi-v2" ] || [ "$1" = "hisi-v3" ]; then 47 | toolchain toolchain.hisilicon-hi3516cv200 arm 48 | elif [ "$1" = "arm9-uclibc" ] || [ "$1" = "gm813x" ]; then 49 | toolchain toolchain.grainmedia-gm8136 arm 50 | elif [ "$1" = "armhf-glibc" ] || [ "$1" = "star6e" ]; then 51 | toolchain toolchain.sigmastar-infinity6e arm -lm 52 | elif [ "$1" = "armhf-musl" ] || [ "$1" = "star6" ]; then 53 | toolchain toolchain.sigmastar-infinity6 arm 54 | elif [ "$1" = "armhf-uclibc" ] || [ "$1" = "rv11xx" ]; then 55 | if [ ! -e toolchain/toolchain.rockchip-rv11xx ]; then 56 | git clone https://github.com/deerpi/arm-rockchip830-linux-uclibcgnueabihf toolchain/toolchain.rockchip-rv11xx 57 | fi 58 | PRE="rockchip830-linux-uclibcgnueabihf" 59 | toolchain toolchain.rockchip-rv11xx arm 60 | elif [ "$1" = "mips-musl" ] || [ "$1" = "inge-t31" ]; then 61 | toolchain toolchain.ingenic-t31 mipsel 62 | elif [ "$1" = "riscv64-musl" ] || [ "$1" = "cvitek" ]; then 63 | DL="https://toolchains.bootlin.com/downloads/releases/toolchains/riscv64-lp64d/tarballs" 64 | EXT="tar.xz" 65 | toolchain riscv64-lp64d--musl--stable-2024.05-1 riscv64 66 | else 67 | echo "Usage: $0 [arm-glibc|arm-musl3|arm-musl4|arm9-glibc|arm9-musl3|arm9-musl4|arm9-uclibc|" 68 | echo " armhf-glibc|armhf-musl|armhf-uclibc|mips-musl|riscv64-musl|ak39xx|cvitek|gm813x|" 69 | echo " hisi-v1|hisi-v2|hisi-v2a|hisi-v3|hisi-v3a|hisi-v4|hisi-v4a|inge-t31|rv11xx|" 70 | echo " star6|star6e] (debug)" 71 | rm -f .previous 72 | fi 73 | -------------------------------------------------------------------------------- /divinus.yaml: -------------------------------------------------------------------------------- 1 | system: 2 | sensor_config: /etc/sensors/imx415.bin 3 | web_port: 80 4 | web_enable_auth: false 5 | web_auth_user: admin 6 | web_auth_pass: 12345 7 | web_enable_static: false 8 | isp_thread_stack_size: 16384 9 | venc_stream_thread_stack_size: 16384 10 | web_server_thread_stack_size: 65536 11 | time_format: "%Y-%m-%d %H:%M:%S" 12 | watchdog: 30 13 | 14 | isp: 15 | mirror: false 16 | flip: false 17 | antiflicker: 60 18 | 19 | osd: 20 | enable: true 21 | 22 | mdns: 23 | enable: false 24 | 25 | onvif: 26 | enable: false 27 | enable_auth: false 28 | auth_user: admin 29 | auth_pass: 12345 30 | 31 | rtsp: 32 | enable: true 33 | enable_auth: false 34 | auth_user: admin 35 | auth_pass: 12345 36 | port: 554 37 | 38 | record: 39 | enable: false 40 | continuous: false 41 | path: /mnt/sdcard/recordings 42 | #filename: "output.mp4" 43 | #segment_duration: 0 44 | #segment_size: 52428800 45 | 46 | stream: 47 | enable: false 48 | udp_srcport: 5600 49 | dest: 50 | - udp://239.255.255.0:5600 51 | 52 | night_mode: 53 | enable: false 54 | ir_sensor_pin: 62 55 | check_interval_s: 10 56 | ir_cut_pin1: 1 57 | ir_cut_pin2: 2 58 | ir_led_pin: 3 59 | pin_switch_delay_us: 150 60 | adc_device: /dev/sar_adc_drv 61 | adc_threshold: 128 62 | 63 | http_post: 64 | enable: false 65 | host: 66 | url: /~example/000000000000/%Y/%m/%d/%H.%M.jpg 67 | width: 640 68 | height: 360 69 | qfactor: 90 70 | interval: 60 71 | login: 72 | password: 73 | 74 | audio: 75 | enable: false 76 | srate: 48000 77 | bitrate: 128 78 | 79 | mp4: 80 | enable: true 81 | codec: H264 82 | mode: CBR 83 | width: 3840 84 | height: 2160 85 | fps: 20 86 | gop: 40 87 | bitrate: 1024 88 | profile: 2 89 | 90 | jpeg: 91 | enable: false 92 | width: 1920 93 | height: 1080 94 | qfactor: 70 95 | 96 | mjpeg: 97 | enable: true 98 | mode: CBR 99 | width: 3840 100 | height: 2160 101 | fps: 20 102 | bitrate: 1024 -------------------------------------------------------------------------------- /doc/overlays.md: -------------------------------------------------------------------------------- 1 | ## Overlays Reference 2 | 3 | ### Usage Example 4 | 5 | Parameters for each region can be passed in one or many calls: 6 | ``` 7 | curl "http://192.168.1.17/api/osd/0?font=comic&size=32.0&text=Frontdoor" 8 | curl http://192.168.1.17/api/osd/0?posy=72 9 | ``` 10 | N.B. Ampersands require the address to be enclosed with double quotes under Windows or to be escaped with a backslash under Unix OSes 11 | 12 | Supported fonts (sourced from /usr/share/fonts/truetype/) can render Unicode characters: 13 | ``` 14 | curl http://192.168.1.17/api/osd/0?text=Entrée 15 | ``` 16 | 17 | The text color is configurable (using a hexadecimal RGB555 representation) and can be made easier to read by applying an outline this way: 18 | ``` 19 | curl http://192.168.1.17/api/osd/1?color=%23FFFF&outl=%238000&thick=1.0 20 | ``` 21 | N.B. Hashtags have to be espaced with %23 in curl URL syntaxes 22 | 23 | Empty strings are used to clear the regions: 24 | ``` 25 | curl http://192.168.1.17/api/osd/1?text= 26 | ``` 27 | 28 | Specifiers starting with a dollar sign are used to represent real-time statistics: 29 | ``` 30 | curl http://192.168.1.17/api/osd/1?text=$B%20C:$C%20M:$M 31 | ``` 32 | N.B. Spaces have to be escaped with %20 in curl URL syntaxes 33 | 34 | Showing the time and customizing the time format is done this way: 35 | ``` 36 | curl http://192.168.1.17/api/time?fmt=%25Y/%25m/%25d%20%25H:%25M:%25S 37 | curl http://192.168.1.17/api/osd/2?text=$t&posy=120 38 | ``` 39 | N.B. Percent signs have to be escaped with %25 in curl URL syntaxes 40 | 41 | UTC date and time can be set using Unix timestamps: 42 | ``` 43 | curl http://192.168.1.17/api/time?ts=1712320920 44 | ``` 45 | 46 | 24- and 32-bit bitmap files (.bmp) can be uploaded to a region using this command: 47 | ``` 48 | curl -F data=@.\Desktop\myimage.bmp http://192.168.1.17/api/osd/3 49 | ``` 50 | N.B. curl already implies "-X POST" when passing a file with "-F" -------------------------------------------------------------------------------- /res/onvif/badauth.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SOAP-ENV:Sender 7 | 8 | 9 | Not Authorized 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/onvif/capabilities.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | http://%s:%d/onvif/analytics_service 8 | false 9 | false 10 | 11 | 12 | http://%s:%d/onvif/device_service 13 | 14 | false 15 | false 16 | false 17 | false 18 | 19 | 20 | true 21 | true 22 | false 23 | false 24 | false 25 | false 26 | 27 | 2 28 | 40 29 | 30 | 31 | 32 | 0 33 | 0 34 | 35 | 36 | false 37 | false 38 | false 39 | false 40 | false 41 | false 42 | false 43 | false 44 | false 45 | true 46 | true 47 | 48 | 49 | 50 | http://%s:%d/onvif/event_service 51 | false 52 | false 53 | false 54 | 55 | 56 | http://%s:%d/onvif/imaging_service 57 | 58 | 59 | http://%s:%d/onvif/media_service 60 | 61 | false 62 | false 63 | false 64 | 65 | 66 | 2 67 | 68 | 69 | 70 | http://%s:%d/onvif/ptz_service 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /res/onvif/deviceinfo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %s 6 | %s 7 | %s 8 | %s 9 | %s 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/onvif/discovery.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %s 5 | %s 6 | http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous 7 | http://schemas.xmlsoap.org/ws/2005/04/discovery/ProbeMatches 8 | 9 | 10 | 11 | 12 | 13 | %s 14 | 15 | dn:NetworkVideoTransmitter 16 | onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/name/%s onvif://www.onvif.org/hardware/Divinus 17 | %s 18 | 1 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /res/onvif/mediaprofile.xml: -------------------------------------------------------------------------------- 1 | 2 | %s 3 | 4 | VideoSourceConfig_%d 5 | 1 6 | VideoSource_1 7 | 8 | 9 | 10 | VideoEncoderConfig_%d 11 | 1 12 | %s 13 | 14 | %d 15 | %d 16 | 17 | 5 18 | 19 | %d 20 | 1 21 | %d 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /res/onvif/mediaprofiles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %s 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/onvif/snapshot.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %s 7 | false 8 | false 9 | PT0S 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/onvif/stream.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %s 7 | false 8 | false 9 | PT0S 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/onvif/systemtime.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | NTP 7 | false 8 | 9 | UTC 10 | 11 | 12 | 13 | %02d 14 | %02d 15 | %02d 16 | 17 | 18 | %d 19 | %02d 20 | %02d 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /res/onvif/videosources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d 8 | 9 | %d 10 | %d 11 | 12 | 13 | 14 | OFF 15 | 0 16 | 17 | 50 18 | 50 19 | 50 20 | 21 | AUTO 22 | 10 23 | 30000 24 | 0 25 | 0 26 | 100 27 | 28 | 29 | AUTO 30 | 1 31 | 0 32 | 0 33 | 34 | 35 | AUTO 36 | 0 37 | 0 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | SRC = $(shell find ./ -name '*.c') 2 | OBJ = ../divinus 3 | 4 | .PHONY: clean divinus 5 | divinus: $(OBJ) 6 | 7 | $(OBJ): $(SRC:%.c=%.o) 8 | $(CC) $^ -rdynamic $(OPT) -o $@ 9 | 10 | %.o: %.c Makefile 11 | $(CC) -c $< $(OPT) -o $@ 12 | 13 | clean: 14 | rm -rf $(SRC:%.c=%.o) $(OBJ) 15 | -------------------------------------------------------------------------------- /src/app_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "hal/config.h" 10 | #include "hal/support.h" 11 | #include "region.h" 12 | 13 | struct AppConfig { 14 | // [system] 15 | char sensor_config[128]; 16 | unsigned short web_port; 17 | char web_whitelist[4][256]; 18 | bool web_enable_auth; 19 | char web_auth_user[32]; 20 | char web_auth_pass[32]; 21 | bool web_enable_static; 22 | unsigned int isp_thread_stack_size; 23 | unsigned int venc_stream_thread_stack_size; 24 | unsigned int web_server_thread_stack_size; 25 | unsigned int watchdog; 26 | 27 | // [night_mode] 28 | bool night_mode_enable; 29 | unsigned int ir_cut_pin1; 30 | unsigned int ir_cut_pin2; 31 | unsigned int ir_led_pin; 32 | unsigned int ir_sensor_pin; 33 | unsigned int check_interval_s; 34 | unsigned int pin_switch_delay_us; 35 | char adc_device[128]; 36 | int adc_threshold; 37 | 38 | // [isp] 39 | bool mirror; 40 | bool flip; 41 | int antiflicker; 42 | 43 | // [osd] 44 | bool osd_enable; 45 | 46 | // [mdns] 47 | bool mdns_enable; 48 | 49 | // [onvif] 50 | bool onvif_enable; 51 | bool onvif_enable_auth; 52 | char onvif_auth_user[32]; 53 | char onvif_auth_pass[32]; 54 | 55 | // [rtsp] 56 | bool rtsp_enable; 57 | bool rtsp_enable_auth; 58 | char rtsp_auth_user[32]; 59 | char rtsp_auth_pass[32]; 60 | int rtsp_port; 61 | 62 | // [record] 63 | bool record_enable; 64 | bool record_continuous; 65 | char record_filename[128]; 66 | char record_path[128]; 67 | int record_segment_duration; 68 | int record_segment_size; 69 | 70 | // [stream] 71 | bool stream_enable; 72 | unsigned short stream_udp_srcport; 73 | char stream_dests[4][256]; 74 | 75 | // [audio] 76 | bool audio_enable; 77 | unsigned int audio_bitrate; 78 | int audio_gain; 79 | unsigned int audio_srate; 80 | 81 | // [mp4] 82 | bool mp4_enable; 83 | bool mp4_codecH265; 84 | unsigned int mp4_mode; 85 | unsigned int mp4_fps; 86 | unsigned int mp4_gop; 87 | unsigned int mp4_width; 88 | unsigned int mp4_height; 89 | unsigned int mp4_profile; 90 | unsigned int mp4_bitrate; 91 | 92 | // [jpeg] 93 | bool jpeg_enable; 94 | unsigned int jpeg_width; 95 | unsigned int jpeg_height; 96 | unsigned int jpeg_qfactor; 97 | 98 | // [mjpeg] 99 | bool mjpeg_enable; 100 | unsigned int mjpeg_mode; 101 | unsigned int mjpeg_fps; 102 | unsigned int mjpeg_width; 103 | unsigned int mjpeg_height; 104 | unsigned int mjpeg_bitrate; 105 | 106 | // [http_post] 107 | bool http_post_enable; 108 | char http_post_host[128]; 109 | char http_post_url[128]; 110 | char http_post_login[128]; 111 | char http_post_password[128]; 112 | unsigned int http_post_width; 113 | unsigned int http_post_height; 114 | unsigned int http_post_qfactor; 115 | unsigned int http_post_interval; 116 | }; 117 | 118 | extern struct AppConfig app_config; 119 | enum ConfigError parse_app_config(void); 120 | void restore_app_config(void); 121 | int save_app_config(void); 122 | -------------------------------------------------------------------------------- /src/compat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #ifndef __UCLIBC__ 8 | void __stdin(void) {} 9 | 10 | #ifndef __GLIBC__ 11 | #include 12 | 13 | struct _stat_ { 14 | char padding[16]; 15 | int st_mode; 16 | }; 17 | 18 | int sTaT(const char *path, struct _stat_ *buf) 19 | { 20 | struct stat st; 21 | int ret = stat(path, &st); 22 | buf->st_mode = st.st_mode; 23 | return ret; 24 | } 25 | #else 26 | #include 27 | #include 28 | 29 | int stat(const char *restrict path, struct stat *restrict buf) 30 | { 31 | return fstatat(AT_FDCWD, path, buf, 0); 32 | } 33 | #endif 34 | #endif 35 | 36 | void __assert(void) {} 37 | void akuio_clean_invalidate_dcache(void) {} 38 | #ifndef __GLIBC__ 39 | void backtrace(void) {} 40 | void backtrace_symbols(void) {} 41 | #endif 42 | void __ctype_b(void) {} 43 | #ifndef __GLIBC__ 44 | void __ctype_b_loc(void) {} 45 | void __ctype_tolower(void) {} 46 | #endif 47 | void _MI_PRINT_GetDebugLevel(void) {} 48 | void __pthread_register_cancel(void) {} 49 | void __pthread_unregister_cancel(void) {} 50 | #ifndef __UCLIBC__ 51 | void _stdlib_mb_cur_max(void) {} 52 | #endif 53 | 54 | float __expf_finite(float x) { return expf(x); } 55 | int __fgetc_unlocked(FILE *stream) { return fgetc(stream); } 56 | double __log_finite(double x) { return log(x); } 57 | 58 | #if !defined(__riscv) && !defined(__riscv__) 59 | void *mmap(void *start, size_t len, int prot, int flags, int fd, uint32_t off) { 60 | return (void*)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12); 61 | } 62 | 63 | void *__mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off) { 64 | return (void*)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12); 65 | } 66 | #if !(defined(__ARM_PCS_VFP) && defined(__UCLIBC__)) 67 | void *mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off) { 68 | return (void*)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12); 69 | } 70 | #endif 71 | #else 72 | void *__mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off) { 73 | return (void*)syscall(SYS_mmap, start, len, prot, flags, fd, off); 74 | } 75 | void *mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off) { 76 | return (void*)syscall(SYS_mmap, start, len, prot, flags, fd, off); 77 | } 78 | #endif -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "hal/support.h" 4 | #include "hal/hisi/v4_sys.h" 5 | 6 | char *errstr(int error); -------------------------------------------------------------------------------- /src/fmt/bitbuf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define chk_err \ 8 | if (err != BUF_OK) { \ 9 | printf( \ 10 | "Error buf: %s %s(...) %s:%d\n", buf_error_to_str(err), \ 11 | __func__, __FILE__, __LINE__); \ 12 | return err; \ 13 | } 14 | #define chk_err_continue \ 15 | if (err != BUF_OK) { \ 16 | printf( \ 17 | "Error buf: %s %s(...) %s:%d\n", buf_error_to_str(err), \ 18 | __func__, __FILE__, __LINE__); \ 19 | continue; \ 20 | } 21 | 22 | enum BufError { 23 | BUF_OK = 0, 24 | BUF_ENDOFBUF_ERROR, 25 | BUF_MALLOC_ERROR, 26 | BUF_INCORRECT 27 | }; 28 | char *buf_error_to_str(const enum BufError err); 29 | 30 | struct BitBuf { 31 | char *buf; 32 | uint32_t size; 33 | uint32_t offset; 34 | }; 35 | 36 | enum BufError put_skip(struct BitBuf *ptr, const uint32_t count); 37 | enum BufError put_to_offset( 38 | struct BitBuf *ptr, const uint32_t offset, const char *data, 39 | const uint32_t size); 40 | enum BufError put(struct BitBuf *ptr, const char *data, const uint32_t size); 41 | enum BufError 42 | put_u8_to_offset(struct BitBuf *ptr, const uint32_t offset, const uint8_t val); 43 | enum BufError put_u8(struct BitBuf *ptr, uint8_t val); 44 | enum BufError put_u16_be_to_offset( 45 | struct BitBuf *ptr, const uint32_t offset, const uint16_t val); 46 | enum BufError put_u16_be(struct BitBuf *ptr, const uint16_t val); 47 | enum BufError put_u16_le_to_offset( 48 | struct BitBuf *ptr, const uint32_t offset, const uint16_t val); 49 | enum BufError put_u16_le(struct BitBuf *ptr, const uint16_t val); 50 | enum BufError put_u32_be_to_offset( 51 | struct BitBuf *ptr, const uint32_t offset, const uint32_t val); 52 | enum BufError put_u32_be(struct BitBuf *ptr, const uint32_t val); 53 | enum BufError put_i32_be(struct BitBuf *ptr, const int32_t val); 54 | enum BufError put_u64_be_to_offset( 55 | struct BitBuf *ptr, const uint32_t offset, const uint64_t val); 56 | enum BufError put_u64_be(struct BitBuf *ptr, const uint64_t val); 57 | enum BufError put_u32_le_to_offset( 58 | struct BitBuf *ptr, const uint32_t offset, const uint32_t val); 59 | enum BufError put_u32_le(struct BitBuf *ptr, const uint32_t val); 60 | enum BufError put_str4_to_offset( 61 | struct BitBuf *ptr, const uint32_t offset, const char str[4]); 62 | enum BufError put_str4(struct BitBuf *ptr, const char str[4]); 63 | enum BufError put_counted_str_to_offset( 64 | struct BitBuf *ptr, const uint32_t offset, const char *str, 65 | const uint32_t len); 66 | enum BufError 67 | put_counted_str(struct BitBuf *ptr, const char *str, const uint32_t len); 68 | -------------------------------------------------------------------------------- /src/fmt/moof.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "bitbuf.h" 4 | 5 | extern uint32_t pos_sequence_number; 6 | extern uint32_t pos_base_data_offset; 7 | extern uint32_t pos_audio_media_decode_time; 8 | extern uint32_t pos_video_media_decode_time; 9 | 10 | struct SampleInfo { 11 | uint32_t duration; 12 | uint32_t size; 13 | uint32_t flags; 14 | }; 15 | 16 | enum BufError 17 | write_mdat(struct BitBuf *ptr, 18 | const char *data_vid, const uint32_t len_vid, 19 | const char *data_aud, const uint32_t len_aud); 20 | enum BufError write_moof( 21 | struct BitBuf *ptr, const uint32_t sequence_number, 22 | const uint64_t base_data_offset, const uint64_t base_media_decode_time, 23 | const uint32_t default_sample_duration, const struct SampleInfo *samples_vid, 24 | const uint32_t samples_vid_len, const struct SampleInfo *samples_aud, 25 | const uint32_t samples_aud_len); 26 | -------------------------------------------------------------------------------- /src/fmt/moov.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "bitbuf.h" 6 | #include "nal.h" 7 | 8 | struct MoovInfo { 9 | char audio_codec; 10 | unsigned short audio_bitrate; 11 | unsigned char audio_channels; 12 | unsigned int audio_samplerate; 13 | char is_h265; 14 | uint8_t profile_idc; 15 | uint8_t level_idc; 16 | char *vps; 17 | uint16_t vps_length; 18 | char *sps; 19 | uint16_t sps_length; 20 | char *pps; 21 | uint16_t pps_length; 22 | uint16_t width; 23 | uint16_t height; 24 | uint32_t horizontal_resolution; 25 | uint32_t vertical_resolution; 26 | uint32_t creation_time; 27 | uint32_t timescale; 28 | }; 29 | 30 | enum BufError write_header(struct BitBuf *ptr, struct MoovInfo *moov_info); 31 | -------------------------------------------------------------------------------- /src/fmt/mp4.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "bitbuf.h" 10 | #include "moof.h" 11 | #include "moov.h" 12 | #include "nal.h" 13 | 14 | #ifndef MIN 15 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 16 | #endif 17 | 18 | extern uint32_t default_sample_size; 19 | 20 | struct Mp4State { 21 | bool header_sent; 22 | 23 | uint32_t sequence_number; 24 | uint64_t base_data_offset; 25 | uint64_t base_media_decode_time; 26 | uint32_t default_sample_duration; 27 | 28 | uint32_t nals_count; 29 | }; 30 | 31 | void mp4_set_config(short width, short height, char framerate, char acodec, 32 | unsigned short bitrate, char channels, unsigned int srate); 33 | 34 | void mp4_set_sps(const char *nal_data, const uint32_t nal_len, char is_h265); 35 | void mp4_set_pps(const char *nal_data, const uint32_t nal_len, char is_h265); 36 | void mp4_set_vps(const char *nal_data, const uint32_t nal_len); 37 | enum BufError mp4_set_slice(const char *nal_data, const uint32_t nal_len, 38 | char is_iframe); 39 | enum BufError mp4_ingest_audio(const char *data, const uint32_t len); 40 | 41 | enum BufError mp4_set_state(struct Mp4State *state); 42 | 43 | enum BufError mp4_get_header(struct BitBuf *ptr); 44 | enum BufError mp4_get_moof(struct BitBuf *ptr); 45 | enum BufError mp4_get_mdat(struct BitBuf *ptr); -------------------------------------------------------------------------------- /src/fmt/nal.c: -------------------------------------------------------------------------------- 1 | #include "nal.h" 2 | 3 | char *nal_type_to_str(const enum NalUnitType nal_type) { 4 | switch (nal_type) { 5 | case NalUnitType_Unspecified: 6 | return "Unspecified"; 7 | case NalUnitType_CodedSliceNonIdr: 8 | return "CodedSliceNonIdr"; 9 | case NalUnitType_CodedSliceDataPartitionA: 10 | return "CodedSliceDataPartitionA"; 11 | case NalUnitType_CodedSliceDataPartitionB: 12 | return "CodedSliceDataPartitionB"; 13 | case NalUnitType_CodedSliceDataPartitionC: 14 | return "CodedSliceDataPartitionC"; 15 | case NalUnitType_CodedSliceIdr: 16 | return "CodedSliceIdr"; 17 | case NalUnitType_SEI: 18 | case NalUnitType_SEI_HEVC: 19 | case NalUnitType_SEI_HEVC_2: 20 | return "SEI"; 21 | case NalUnitType_SPS: 22 | case NalUnitType_SPS_HEVC: 23 | return "SPS"; 24 | case NalUnitType_PPS: 25 | case NalUnitType_PPS_HEVC: 26 | return "PPS"; 27 | case NalUnitType_VPS_HEVC: 28 | return "VPS"; 29 | case NalUnitType_AUD: 30 | case NalUnitType_AUD_HEVC: 31 | return "AUD"; 32 | case NalUnitType_EndOfSequence: 33 | case NalUnitType_EndOfSequence_HEVC: 34 | return "EndOfSequence"; 35 | case NalUnitType_EndOfStream: 36 | case NalUnitType_EndOfStream_HEVC: 37 | return "EndOfStream"; 38 | case NalUnitType_Filler: 39 | case NalUnitType_Filler_HEVC: 40 | return "Filler"; 41 | case NalUnitType_SpsExt: 42 | return "SpsExt"; 43 | case NalUnitType_CodedSliceAux: 44 | return "CodedSliceAux (AVC) / CodedSliceIdr (HEVC)"; 45 | default: 46 | return "Unknown"; 47 | } 48 | } 49 | 50 | void nal_parse_header(struct NAL *nal, const char first_byte) { 51 | nal->forbidden_zero_bit = nal->isH265 ? (first_byte & 0b00000001) : (((first_byte & 0b10000000) >> 7) == 1); 52 | nal->ref_idc = nal->isH265 ? 0 : ((first_byte & 0b01100000) >> 5); 53 | nal->unit_type = nal->isH265 ? ((first_byte & 0b01111110) >> 1) : (first_byte & 0b00011111); 54 | } 55 | 56 | bool nal_chk4(const char *buf, const unsigned int offset) { 57 | if (buf[offset] == 0x00 && buf[offset + 1] == 0x00 && 58 | buf[offset + 2] == 0x01) { 59 | return true; 60 | } 61 | if (buf[offset] == 0x00 && buf[offset + 1] == 0x00 && 62 | buf[offset + 2] == 0x00 && buf[offset + 3] == 0x01) { 63 | return true; 64 | } 65 | return false; 66 | } 67 | 68 | bool nal_chk3(const char *buf, const unsigned int offset) { 69 | if (buf[offset] == 0x00 && buf[offset + 1] == 0x00 && 70 | buf[offset + 2] == 0x01) { 71 | return true; 72 | } 73 | return false; 74 | } -------------------------------------------------------------------------------- /src/fmt/nal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | enum NalUnitType { // Table 7-1 NAL unit type codes 7 | NalUnitType_Unspecified = 0, // Unspecified 8 | NalUnitType_CodedSliceNonIdr = 1, // Coded slice of a non-IDR picture 9 | NalUnitType_CodedSliceDataPartitionA = 2, // Coded slice data partition A 10 | NalUnitType_CodedSliceDataPartitionB = 3, // Coded slice data partition B 11 | NalUnitType_CodedSliceDataPartitionC = 4, // Coded slice data partition C 12 | NalUnitType_CodedSliceIdr = 5, // Coded slice of an IDR picture 13 | NalUnitType_SEI = 6, // Supplemental enhancement information (SEI) 14 | NalUnitType_SPS = 7, // Sequence parameter set 15 | NalUnitType_PPS = 8, // Picture parameter set 16 | NalUnitType_AUD = 9, // Access unit delimiter 17 | NalUnitType_EndOfSequence = 10, // End of sequence 18 | NalUnitType_EndOfStream = 11, // End of stream 19 | NalUnitType_Filler = 12, // Filler data 20 | NalUnitType_SpsExt = 13, // Sequence parameter set extension 21 | // 14..18 // Reserved 22 | NalUnitType_CodedSliceAux = 23 | 19, // Coded slice of an auxiliary coded picture without partitioning 24 | // 20..23 // Reserved 25 | // 24..31 // Unspecified 26 | NalUnitType_VPS_HEVC = 32, 27 | NalUnitType_SPS_HEVC = 33, 28 | NalUnitType_PPS_HEVC = 34, 29 | NalUnitType_AUD_HEVC = 35, 30 | NalUnitType_EndOfSequence_HEVC = 36, 31 | NalUnitType_EndOfStream_HEVC = 37, 32 | NalUnitType_Filler_HEVC = 38, 33 | NalUnitType_SEI_HEVC = 39, 34 | NalUnitType_SEI_HEVC_2 = 40, 35 | }; 36 | 37 | char *nal_type_to_str(const enum NalUnitType nal_type); 38 | 39 | struct NAL { 40 | char isH265; 41 | char *data; 42 | uint64_t data_size; 43 | uint32_t picture_order_count; 44 | 45 | // NAL header 46 | bool forbidden_zero_bit; 47 | uint8_t ref_idc; 48 | uint8_t unit_type_value; 49 | enum NalUnitType unit_type; 50 | }; 51 | 52 | void nal_parse_header(struct NAL *nal, const char first_byte); 53 | bool nal_chk4(const char *buf, const uint32_t offset); 54 | bool nal_chk3(const char *buf, const uint32_t offset); -------------------------------------------------------------------------------- /src/gpio.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) 11 | #include 12 | #include 13 | #else 14 | #include 15 | #endif 16 | 17 | #include "hal/macros.h" 18 | 19 | void gpio_deinit(void); 20 | int gpio_init(void); 21 | int gpio_read(char pin, bool *value); 22 | int gpio_write(char pin, bool value); -------------------------------------------------------------------------------- /src/hal/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "macros.h" 11 | #include "tools.h" 12 | 13 | #define MAX_SECTIONS 16 14 | #define REG_SECTION "^([[:space:]]*\\[(\\w+)\\][[:space:]]|(\\w+):)" 15 | #define REG_PARAM "^[[:space:]]*%s[[:space:]]*[=:][[:space:]]*(.[^;#\n\r]*)" 16 | 17 | struct IniConfig { 18 | char *str; 19 | struct Section { 20 | char name[64]; 21 | int pos; 22 | } sections[MAX_SECTIONS]; 23 | }; 24 | 25 | enum ConfigError { 26 | CONFIG_OK = 0, 27 | CONFIG_SECTION_NOT_FOUND, 28 | CONFIG_PARAM_NOT_FOUND, 29 | CONFIG_PARAM_ISNT_NUMBER, 30 | CONFIG_PARAM_ISNT_FLOAT, 31 | CONFIG_PARAM_ISNT_IN_RANGE, 32 | CONFIG_PARAM_INVALID_FORMAT, 33 | CONFIG_ENUM_INCORRECT_STRING, 34 | CONFIG_REGEX_ERROR, 35 | CONFIG_CANT_OPEN_PROC_CMDLINE, 36 | CONFIG_SENSOR_ISNOT_SUPPORT, 37 | CONFIG_SENSOR_NOT_FOUND, 38 | }; 39 | 40 | bool open_config(struct IniConfig *ini, FILE **file); 41 | enum ConfigError find_sections(struct IniConfig *ini); 42 | enum ConfigError section_pos( 43 | struct IniConfig *ini, const char *section, int *start_pos, int *end_pos); 44 | enum ConfigError parse_param_value( 45 | struct IniConfig *ini, const char *section, const char *param_name, 46 | char *param_value); 47 | enum ConfigError parse_double( 48 | struct IniConfig *ini, const char *section, const char *param_name, 49 | const double min, const double max, double *double_value); 50 | enum ConfigError parse_enum( 51 | struct IniConfig *ini, const char *section, const char *param_name, 52 | void *enum_value, const char *possible_values[], 53 | const int possible_values_count, const int possible_values_offset); 54 | enum ConfigError parse_bool( 55 | struct IniConfig *ini, const char *section, const char *param_name, 56 | bool *bool_value); 57 | enum ConfigError parse_int( 58 | struct IniConfig *ini, const char *section, const char *param_name, 59 | const int min, const int max, int *int_value); 60 | enum ConfigError parse_array( 61 | struct IniConfig *ini, const char *section, const char *param_name, 62 | int *array, const int array_size); 63 | enum ConfigError parse_uint64( 64 | struct IniConfig *ini, const char *section, const char *param_name, 65 | const uint64_t min, const uint64_t max, uint64_t *int_value); 66 | enum ConfigError parse_uint32( 67 | struct IniConfig *ini, const char *section, const char *param_name, 68 | const unsigned int min, const unsigned int max, unsigned int *value); 69 | enum ConfigError parse_list( 70 | struct IniConfig *ini, const char *section, const char *param_name, 71 | const unsigned int max_entries, unsigned int *count, char entries[][256]); 72 | -------------------------------------------------------------------------------- /src/hal/hisi/quirks.c: -------------------------------------------------------------------------------- 1 | #ifdef __arm__ 2 | 3 | void* (*fnIsp_Malloc)(unsigned long); 4 | int (*fnISP_AlgRegisterAcs)(int); 5 | int (*fnISP_AlgRegisterDehaze)(int); 6 | int (*fnISP_AlgRegisterDrc)(int); 7 | int (*fnISP_AlgRegisterLdci)(int); 8 | int (*fnMPI_ISP_IrAutoRunOnce)(int, void*); 9 | 10 | void *isp_malloc(unsigned long size) { 11 | return fnIsp_Malloc(size); 12 | } 13 | int isp_alg_register_acs(int pipeId) { 14 | return fnISP_AlgRegisterAcs(pipeId); 15 | } 16 | int isp_alg_register_dehaze(int pipeId) { 17 | return fnISP_AlgRegisterDehaze(pipeId); 18 | } 19 | int ISP_AlgRegisterDehaze(int pipeId) { 20 | return fnISP_AlgRegisterDehaze(pipeId); 21 | } 22 | int isp_alg_register_drc(int pipeId) { 23 | return fnISP_AlgRegisterDrc(pipeId); 24 | } 25 | int ISP_AlgRegisterDrc(int pipeId) { 26 | return fnISP_AlgRegisterDrc(pipeId); 27 | } 28 | int isp_alg_register_ldci(int pipeId) { 29 | return fnISP_AlgRegisterLdci(pipeId); 30 | } 31 | int ISP_AlgRegisterLdci(int pipeId) { 32 | return fnISP_AlgRegisterLdci(pipeId); 33 | } 34 | int isp_ir_auto_run_once(int pipeId, void *irAttr) { 35 | return fnMPI_ISP_IrAutoRunOnce(pipeId, irAttr); 36 | } 37 | int MPI_ISP_IrAutoRunOnce(int pipeId, void *irAttr) { 38 | return fnMPI_ISP_IrAutoRunOnce(pipeId, irAttr); 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/hal/hisi/v1_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | V1_BAYER_RG, 12 | V1_BAYER_GR, 13 | V1_BAYER_GB, 14 | V1_BAYER_BG, 15 | V1_BAYER_END 16 | } v1_common_bayer; 17 | 18 | typedef enum { 19 | V1_COMPR_NONE, 20 | V1_COMPR_SEG, 21 | V1_COMPR_SEG128, 22 | V1_COMPR_LINE, 23 | V1_COMPR_FRAME, 24 | V1_COMPR_END 25 | } v1_common_compr; 26 | 27 | typedef enum { 28 | V1_PIXFMT_1BPP, 29 | V1_PIXFMT_2BPP, 30 | V1_PIXFMT_4BPP, 31 | V1_PIXFMT_8BPP, 32 | V1_PIXFMT_RGB444, 33 | V1_PIXFMT_ARGB4444, 34 | V1_PIXFMT_RGB555, 35 | V1_PIXFMT_RGB565, 36 | V1_PIXFMT_ARGB1555, 37 | V1_PIXFMT_RGB888, 38 | V1_PIXFMT_ARGB8888, 39 | V1_PIXFMT_RGB888P, 40 | V1_PIXFMT_RGB_BAYER, 41 | V1_PIXFMT_YUV_A422, 42 | V1_PIXFMT_YUV_A444, 43 | V1_PIXFMT_YUV422P, 44 | V1_PIXFMT_YUV420P, 45 | V1_PIXFMT_YUV444P, 46 | V1_PIXFMT_YUV422SP, 47 | V1_PIXFMT_YUV420SP, 48 | V1_PIXFMT_YUV444SP, 49 | V1_PIXFMT_YUV422_UYVY, 50 | V1_PIXFMT_YUV422_YUYV, 51 | V1_PIXFMT_YUV422_VYUY, 52 | V1_PIXFMT_YCbCrP, 53 | V1_PIXFMT_RGB422, 54 | V1_PIXFMT_RGB420, 55 | V1_PIXFMT_END 56 | } v1_common_pixfmt; 57 | 58 | typedef enum { 59 | V1_PREC_8BPP, 60 | V1_PREC_10BPP, 61 | V1_PREC_12BPP, 62 | V1_PREC_14BPP, 63 | V1_PREC_16BPP, 64 | V1_PREC_END 65 | } v1_common_prec; 66 | 67 | typedef enum { 68 | V1_VIDFMT_LINEAR, 69 | V1_VIDFMT_TILE_256X16, 70 | V1_VIDFMT_TILE_64X16, 71 | V1_VIDFMT_END 72 | } v1_common_vidfmt; 73 | 74 | typedef enum { 75 | V1_WDR_NONE, 76 | V1_WDR_BUILTIN, 77 | V1_WDR_QUDRA, 78 | V1_WDR_2TO1_LINE, 79 | V1_WDR_2TO1_FRAME, 80 | V1_WDR_2TO1_FRAME_FULLRATE, 81 | V1_WDR_3TO1_LINE, 82 | V1_WDR_3TO1_FRAME, 83 | V1_WDR_3TO1_FRAME_FULLRATE, 84 | V1_WDR_4TO1_LINE, 85 | V1_WDR_4TO1_FRAME, 86 | V1_WDR_4TO1_FRAME_FULLRATE, 87 | V1_WDR_END 88 | } v1_common_wdr; 89 | 90 | typedef struct { 91 | unsigned int topWidth; 92 | unsigned int bottomWidth; 93 | unsigned int leftWidth; 94 | unsigned int rightWidth; 95 | unsigned int color; 96 | } v1_common_bord; 97 | 98 | typedef struct { 99 | unsigned int width; 100 | unsigned int height; 101 | } v1_common_dim; 102 | 103 | typedef struct { 104 | int x; 105 | int y; 106 | } v1_common_pnt; 107 | 108 | typedef struct { 109 | int x; 110 | int y; 111 | unsigned int width; 112 | unsigned int height; 113 | } v1_common_rect; 114 | -------------------------------------------------------------------------------- /src/hal/hisi/v1_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v1_common.h" 4 | #include "v1_aud.h" 5 | #include "v1_config.h" 6 | #include "v1_isp.h" 7 | #include "v1_rgn.h" 8 | #include "v1_snr.h" 9 | #include "v1_sys.h" 10 | #include "v1_vb.h" 11 | #include "v1_venc.h" 12 | #include "v1_vi.h" 13 | #include "v1_vpss.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | extern char audioOn, keepRunning; 21 | 22 | extern hal_chnstate v1_state[V1_VENC_CHN_NUM]; 23 | extern int (*v1_aud_cb)(hal_audframe*); 24 | extern int (*v1_vid_cb)(char, hal_vidstream*); 25 | 26 | void v1_hal_deinit(void); 27 | int v1_hal_init(void); 28 | 29 | void v1_audio_deinit(void); 30 | int v1_audio_init(int samplerate); 31 | void *v1_audio_thread(void); 32 | 33 | int v1_channel_bind(char index); 34 | int v1_channel_create(char index, short width, short height, char mirror, char flip, char framerate); 35 | int v1_channel_grayscale(char enable); 36 | int v1_channel_unbind(char index); 37 | 38 | void *v1_image_thread(void); 39 | 40 | int v1_pipeline_create(void); 41 | void v1_pipeline_destroy(void); 42 | 43 | int v1_region_create(char handle, hal_rect rect, short opacity); 44 | void v1_region_destroy(char handle); 45 | int v1_region_setbitmap(int handle, hal_bitmap *bitmap); 46 | 47 | void v1_sensor_deconfig(void); 48 | void v1_sensor_deinit(void); 49 | int v1_sensor_init(char *name, char *obj); 50 | 51 | int v1_video_create(char index, hal_vidconfig *config); 52 | int v1_video_destroy(char index); 53 | int v1_video_destroy_all(void); 54 | void v1_video_request_idr(char index); 55 | int v1_video_snapshot_grab(char index, hal_jpegdata *jpeg); 56 | void *v1_video_thread(void); 57 | 58 | int v1_system_calculate_block(short width, short height, v1_common_pixfmt pixFmt, 59 | unsigned int alignWidth); 60 | void v1_system_deinit(void); 61 | int v1_system_init(char *snrConfig); -------------------------------------------------------------------------------- /src/hal/hisi/v1_snr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v1_common.h" 4 | 5 | #define V1_SNR_LANE_NUM 8 6 | #define V1_SNR_WDR_VC_NUM 4 7 | 8 | typedef enum { 9 | V1_SNR_INPUT_MIPI, 10 | V1_SNR_INPUT_SUBLVDS, 11 | V1_SNR_INPUT_LVDS, 12 | V1_SNR_INPUT_HISPI, 13 | V1_SNR_INPUT_CMOS_18V, 14 | V1_SNR_INPUT_CMOS_33V, 15 | V1_SNR_INPUT_BT1120, 16 | V1_SNR_INPUT_BYPASS, 17 | V1_SNR_INPUT_END 18 | } v1_snr_input; 19 | 20 | typedef enum { 21 | V1_SNR_LWDR_NONE, 22 | V1_SNR_LWDR_2F, 23 | V1_SNR_LWDR_3F, 24 | V1_SNR_LWDR_4F, 25 | V1_SNR_LWDR_DOL2F, 26 | V1_SNR_LWDR_DOL3F, 27 | V1_SNR_LWDR_DOL4F, 28 | V1_SNR_LWDR_END 29 | } v1_snr_lwdr; 30 | 31 | typedef struct { 32 | v1_common_dim dest; 33 | v1_snr_lwdr wdr; 34 | int syncSavOn; 35 | v1_common_prec prec; 36 | int dataBeOn; 37 | int syncBeOn; 38 | // Value -1 signifies a lane is disabled 39 | short laneId[V1_SNR_LANE_NUM]; 40 | /* Each lane has two virtual channel, each has four params 41 | If syncSavOn is false: SOF, EOF, SOL, EOL 42 | If syncSavOn is true: invalid sav, invalid eav, valid sav, valid eav */ 43 | unsigned short syncCode[V1_SNR_LANE_NUM * V1_SNR_WDR_VC_NUM * 4]; 44 | } v1_snr_lvds; 45 | 46 | typedef struct { 47 | v1_common_prec prec; 48 | // Value -1 signifies a lane is disabled 49 | short laneId[V1_SNR_LANE_NUM]; 50 | } v1_snr_mipi; 51 | 52 | typedef struct { 53 | void *handle; 54 | 55 | int (*fnInit)(void); 56 | int (*fnRegisterCallback)(void); 57 | int (*fnUnRegisterCallback)(void); 58 | } v1_snr_drv_impl; -------------------------------------------------------------------------------- /src/hal/hisi/v1_vb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v1_common.h" 4 | 5 | typedef struct { 6 | unsigned int count; 7 | struct { 8 | unsigned int blockSize; 9 | unsigned int blockCnt; 10 | char heapName[16]; 11 | } comm[16]; 12 | } v1_vb_pool; 13 | 14 | typedef struct { 15 | void *handle; 16 | 17 | int (*fnConfigPool)(v1_vb_pool *config); 18 | int (*fnExit)(void); 19 | int (*fnInit)(void); 20 | } v1_vb_impl; 21 | 22 | static int v1_vb_load(v1_vb_impl *vb_lib) { 23 | if (!(vb_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) 24 | HAL_ERROR("v1_vb", "Failed to load library!\nError: %s\n", dlerror()); 25 | 26 | if (!(vb_lib->fnConfigPool = (int(*)(v1_vb_pool *config)) 27 | hal_symbol_load("v1_vb", vb_lib->handle, "HI_MPI_VB_SetConf"))) 28 | return EXIT_FAILURE; 29 | 30 | if (!(vb_lib->fnExit = (int(*)(void)) 31 | hal_symbol_load("v1_vb", vb_lib->handle, "HI_MPI_VB_Exit"))) 32 | return EXIT_FAILURE; 33 | 34 | if (!(vb_lib->fnInit = (int(*)(void)) 35 | hal_symbol_load("v1_vb", vb_lib->handle, "HI_MPI_VB_Init"))) 36 | return EXIT_FAILURE; 37 | 38 | return EXIT_SUCCESS; 39 | } 40 | 41 | static void v1_vb_unload(v1_vb_impl *vb_lib) { 42 | if (vb_lib->handle) dlclose(vb_lib->handle); 43 | vb_lib->handle = NULL; 44 | memset(vb_lib, 0, sizeof(*vb_lib)); 45 | } 46 | 47 | inline static unsigned int v1_buffer_calculate_venc(short width, short height, v1_common_pixfmt pixFmt, 48 | unsigned int alignWidth) 49 | { 50 | unsigned int bufSize = CEILING_2_POWER(width, alignWidth) * 51 | CEILING_2_POWER(height, alignWidth) * 52 | (pixFmt == V1_PIXFMT_YUV422SP ? 2 : 1.5); 53 | unsigned int headSize = 16 * height; 54 | if (pixFmt == V1_PIXFMT_YUV422SP) 55 | headSize *= 2; 56 | else if (pixFmt == V1_PIXFMT_YUV420SP) 57 | headSize *= 3; 58 | headSize >>= 1; 59 | return bufSize + headSize; 60 | } -------------------------------------------------------------------------------- /src/hal/hisi/v2_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | V2_BAYER_RG, 12 | V2_BAYER_GR, 13 | V2_BAYER_GB, 14 | V2_BAYER_BG, 15 | V2_BAYER_END 16 | } v2_common_bayer; 17 | 18 | typedef enum { 19 | V2_COMPR_NONE, 20 | V2_COMPR_SEG, 21 | V2_COMPR_SEG128, 22 | V2_COMPR_LINE, 23 | V2_COMPR_FRAME, 24 | V2_COMPR_END 25 | } v2_common_compr; 26 | 27 | typedef enum { 28 | V2_PIXFMT_1BPP, 29 | V2_PIXFMT_2BPP, 30 | V2_PIXFMT_4BPP, 31 | V2_PIXFMT_8BPP, 32 | V2_PIXFMT_RGB444, 33 | V2_PIXFMT_ARGB4444, 34 | V2_PIXFMT_RGB555, 35 | V2_PIXFMT_RGB565, 36 | V2_PIXFMT_ARGB1555, 37 | V2_PIXFMT_RGB888, 38 | V2_PIXFMT_ARGB8888, 39 | V2_PIXFMT_RGB888P, 40 | V2_PIXFMT_RGB_BAYER_8BPP, 41 | V2_PIXFMT_RGB_BAYER_10BPP, 42 | V2_PIXFMT_RGB_BAYER_12BPP, 43 | V2_PIXFMT_RGB_BAYER_14BPP, 44 | V2_PIXFMT_RGB_BAYER_16BPP, 45 | V2_PIXFMT_YUV_A422, 46 | V2_PIXFMT_YUV_A444, 47 | V2_PIXFMT_YUV422P, 48 | V2_PIXFMT_YUV420P, 49 | V2_PIXFMT_YUV444P, 50 | V2_PIXFMT_YUV422SP, 51 | V2_PIXFMT_YUV420SP, 52 | V2_PIXFMT_YUV444SP, 53 | V2_PIXFMT_YUV422_UYVY, 54 | V2_PIXFMT_YUV422_YUYV, 55 | V2_PIXFMT_YUV422_VYUY, 56 | V2_PIXFMT_YCbCrP, 57 | V2_PIXFMT_YUV400, 58 | V2_PIXFMT_END 59 | } v2_common_pixfmt; 60 | 61 | typedef enum { 62 | V2_PREC_8BPP, 63 | V2_PREC_10BPP, 64 | V2_PREC_12BPP, 65 | V2_PREC_14BPP, 66 | V2_PREC_16BPP, 67 | V2_PREC_END 68 | } v2_common_prec; 69 | 70 | typedef enum { 71 | V2_VIDFMT_LINEAR, 72 | V2_VIDFMT_TILE_256X16, 73 | V2_VIDFMT_TILE_64X16, 74 | V2_VIDFMT_END 75 | } v2_common_vidfmt; 76 | 77 | typedef enum { 78 | V2_WDR_NONE, 79 | V2_WDR_BUILTIN, 80 | V2_WDR_QUDRA, 81 | V2_WDR_2TO1_LINE, 82 | V2_WDR_2TO1_FRAME, 83 | V2_WDR_2TO1_FRAME_FULLRATE, 84 | V2_WDR_3TO1_LINE, 85 | V2_WDR_3TO1_FRAME, 86 | V2_WDR_3TO1_FRAME_FULLRATE, 87 | V2_WDR_4TO1_LINE, 88 | V2_WDR_4TO1_FRAME, 89 | V2_WDR_4TO1_FRAME_FULLRATE, 90 | V2_WDR_END 91 | } v2_common_wdr; 92 | 93 | typedef struct { 94 | unsigned int topWidth; 95 | unsigned int bottomWidth; 96 | unsigned int leftWidth; 97 | unsigned int rightWidth; 98 | unsigned int color; 99 | } v2_common_bord; 100 | 101 | typedef struct { 102 | unsigned int width; 103 | unsigned int height; 104 | } v2_common_dim; 105 | 106 | typedef struct { 107 | int x; 108 | int y; 109 | } v2_common_pnt; 110 | 111 | typedef struct { 112 | int x; 113 | int y; 114 | unsigned int width; 115 | unsigned int height; 116 | } v2_common_rect; 117 | -------------------------------------------------------------------------------- /src/hal/hisi/v2_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v2_common.h" 4 | #include "v2_aud.h" 5 | #include "v2_config.h" 6 | #include "v2_isp.h" 7 | #include "v2_rgn.h" 8 | #include "v2_snr.h" 9 | #include "v2_sys.h" 10 | #include "v2_vb.h" 11 | #include "v2_venc.h" 12 | #include "v2_vi.h" 13 | #include "v2_vpss.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | extern char audioOn, keepRunning; 21 | 22 | extern hal_chnstate v2_state[V2_VENC_CHN_NUM]; 23 | extern int (*v2_aud_cb)(hal_audframe*); 24 | extern int (*v2_vid_cb)(char, hal_vidstream*); 25 | 26 | void v2_hal_deinit(void); 27 | int v2_hal_init(void); 28 | 29 | void v2_audio_deinit(void); 30 | int v2_audio_init(int samplerate); 31 | void *v2_audio_thread(void); 32 | 33 | int v2_channel_bind(char index); 34 | int v2_channel_create(char index, short width, short height, char mirror, char flip, char framerate); 35 | int v2_channel_grayscale(char enable); 36 | int v2_channel_unbind(char index); 37 | 38 | void *v2_image_thread(void); 39 | 40 | int v2_pipeline_create(void); 41 | void v2_pipeline_destroy(void); 42 | 43 | int v2_region_create(char handle, hal_rect rect, short opacity); 44 | void v2_region_destroy(char handle); 45 | int v2_region_setbitmap(int handle, hal_bitmap *bitmap); 46 | 47 | void v2_sensor_deconfig(void); 48 | int v2_sensor_config(void); 49 | void v2_sensor_deinit(void); 50 | int v2_sensor_init(char *name, char *obj); 51 | 52 | int v2_video_create(char index, hal_vidconfig *config); 53 | int v2_video_destroy(char index); 54 | int v2_video_destroy_all(void); 55 | void v2_video_request_idr(char index); 56 | int v2_video_snapshot_grab(char index, hal_jpegdata *jpeg); 57 | void *v2_video_thread(void); 58 | 59 | int v2_system_calculate_block(short width, short height, v2_common_pixfmt pixFmt, 60 | unsigned int alignWidth); 61 | void v2_system_deinit(void); 62 | int v2_system_init(char *snrConfig); 63 | float v2_system_readtemp(void); -------------------------------------------------------------------------------- /src/hal/hisi/v2_snr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v2_common.h" 4 | 5 | #include 6 | #include 7 | 8 | #define V2_SNR_IOC_MAGIC 'm' 9 | #define V2_SNR_LANE_NUM 8 10 | #define V2_SNR_WDR_VC_NUM 4 11 | 12 | enum { 13 | V2_SNR_CMD_CONF_DEV = 1, 14 | V2_SNR_CMD_CONF_EDGE, 15 | V2_SNR_CMD_CONF_MSB 16 | }; 17 | 18 | typedef enum { 19 | V2_SNR_INPUT_MIPI, 20 | V2_SNR_INPUT_SUBLVDS, 21 | V2_SNR_INPUT_LVDS, 22 | V2_SNR_INPUT_HISPI, 23 | V2_SNR_INPUT_CMOS_18V, 24 | V2_SNR_INPUT_CMOS_33V, 25 | V2_SNR_INPUT_BT1120, 26 | V2_SNR_INPUT_BYPASS, 27 | V2_SNR_INPUT_END 28 | } v2_snr_input; 29 | 30 | typedef enum { 31 | V2_SNR_LWDR_NONE, 32 | V2_SNR_LWDR_2F, 33 | V2_SNR_LWDR_3F, 34 | V2_SNR_LWDR_4F, 35 | V2_SNR_LWDR_DOL2F, 36 | V2_SNR_LWDR_DOL3F, 37 | V2_SNR_LWDR_DOL4F, 38 | V2_SNR_LWDR_END 39 | } v2_snr_lwdr; 40 | 41 | typedef struct { 42 | v2_common_dim dest; 43 | v2_snr_lwdr wdr; 44 | int syncSavOn; 45 | v2_common_prec prec; 46 | int dataBeOn; 47 | int syncBeOn; 48 | // Value -1 signifies a lane is disabled 49 | short laneId[V2_SNR_LANE_NUM]; 50 | /* Each lane has two virtual channel, each has four params 51 | If syncSavOn is false: SOF, EOF, SOL, EOL 52 | If syncSavOn is true: invalid sav, invalid eav, valid sav, valid eav */ 53 | unsigned short syncCode[V2_SNR_LANE_NUM * V2_SNR_WDR_VC_NUM * 4]; 54 | } v2_snr_lvds; 55 | 56 | typedef struct { 57 | v2_common_prec prec; 58 | // Value -1 signifies a lane is disabled 59 | short laneId[V2_SNR_LANE_NUM]; 60 | } v2_snr_mipi; 61 | 62 | typedef struct { 63 | v2_snr_input input; 64 | union { 65 | v2_snr_mipi mipi; 66 | v2_snr_lvds lvds; 67 | }; 68 | } v2_snr_dev; 69 | 70 | typedef struct { 71 | void *handle; 72 | 73 | int (*fnRegisterCallback)(void); 74 | int (*fnUnRegisterCallback)(void); 75 | } v2_snr_drv_impl; 76 | 77 | static const char v2_snr_endp[] = {"/dev/hi_mipi"}; -------------------------------------------------------------------------------- /src/hal/hisi/v2_vb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v2_common.h" 4 | 5 | typedef enum { 6 | V2_VB_JPEG_MASK = 0x1 7 | } v2_vb_supl; 8 | 9 | typedef struct { 10 | unsigned int count; 11 | struct { 12 | unsigned int blockSize; 13 | unsigned int blockCnt; 14 | char heapName[16]; 15 | } comm[16]; 16 | } v2_vb_pool; 17 | 18 | typedef struct { 19 | void *handle; 20 | 21 | int (*fnConfigPool)(v2_vb_pool *config); 22 | int (*fnConfigSupplement)(v2_vb_supl *value); 23 | int (*fnExit)(void); 24 | int (*fnInit)(void); 25 | } v2_vb_impl; 26 | 27 | static int v2_vb_load(v2_vb_impl *vb_lib) { 28 | if (!(vb_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) 29 | HAL_ERROR("v2_vb", "Failed to load library!\nError: %s\n", dlerror()); 30 | 31 | if (!(vb_lib->fnConfigPool = (int(*)(v2_vb_pool *config)) 32 | hal_symbol_load("v2_vb", vb_lib->handle, "HI_MPI_VB_SetConf"))) 33 | return EXIT_FAILURE; 34 | 35 | if (!(vb_lib->fnConfigSupplement = (int(*)(v2_vb_supl *value)) 36 | hal_symbol_load("v2_vb", vb_lib->handle, "HI_MPI_VB_SetSupplementConf"))) 37 | return EXIT_FAILURE; 38 | 39 | if (!(vb_lib->fnExit = (int(*)(void)) 40 | hal_symbol_load("v2_vb", vb_lib->handle, "HI_MPI_VB_Exit"))) 41 | return EXIT_FAILURE; 42 | 43 | if (!(vb_lib->fnInit = (int(*)(void)) 44 | hal_symbol_load("v2_vb", vb_lib->handle, "HI_MPI_VB_Init"))) 45 | return EXIT_FAILURE; 46 | 47 | return EXIT_SUCCESS; 48 | } 49 | 50 | static void v2_vb_unload(v2_vb_impl *vb_lib) { 51 | if (vb_lib->handle) dlclose(vb_lib->handle); 52 | vb_lib->handle = NULL; 53 | memset(vb_lib, 0, sizeof(*vb_lib)); 54 | } 55 | 56 | inline static unsigned int v2_buffer_calculate_vi( 57 | unsigned int width, unsigned int height, v2_common_pixfmt pixFmt, 58 | v2_common_compr compr, unsigned int alignWidth) 59 | { 60 | unsigned int bitWidth; 61 | unsigned int size = 0, stride = 0; 62 | unsigned int cmpRatioLine = 1600, cmpRatioFrame = 2000; 63 | 64 | if (!alignWidth) 65 | alignWidth = 16; 66 | else if (alignWidth > 64) 67 | alignWidth = 64; 68 | else 69 | alignWidth = ALIGN_UP(alignWidth, 16); 70 | 71 | switch (pixFmt) { 72 | case V2_PIXFMT_RGB_BAYER_8BPP: bitWidth = 8; break; 73 | case V2_PIXFMT_RGB_BAYER_10BPP: bitWidth = 10; break; 74 | case V2_PIXFMT_RGB_BAYER_12BPP: bitWidth = 12; break; 75 | case V2_PIXFMT_RGB_BAYER_14BPP: bitWidth = 14; break; 76 | case V2_PIXFMT_RGB_BAYER_16BPP: bitWidth = 16; break; 77 | default: bitWidth = 0; break; 78 | } 79 | 80 | if (compr == V2_COMPR_NONE) { 81 | stride = ALIGN_UP(ALIGN_UP(width * bitWidth, 8) / 8, 82 | alignWidth); 83 | size = stride * height; 84 | } else if (compr == V2_COMPR_LINE) { 85 | unsigned int temp = ALIGN_UP( 86 | (16 + width * bitWidth * 1000UL / 87 | cmpRatioLine + 8192 + 127) / 128, 2); 88 | stride = ALIGN_UP(temp * 16, alignWidth); 89 | size = stride * height; 90 | } else if (compr == V2_COMPR_FRAME) { 91 | size = ALIGN_UP(height * width * bitWidth * 1000UL / 92 | (cmpRatioFrame * 8), alignWidth); 93 | } 94 | 95 | return size; 96 | } 97 | 98 | inline static unsigned int v2_buffer_calculate_venc(short width, short height, v2_common_pixfmt pixFmt, 99 | unsigned int alignWidth) 100 | { 101 | unsigned int bufSize = CEILING_2_POWER(width, alignWidth) * 102 | CEILING_2_POWER(height, alignWidth) * 103 | (pixFmt == V2_PIXFMT_YUV422SP ? 2 : 1.5); 104 | unsigned int headSize = 16 * height; 105 | if (pixFmt == V2_PIXFMT_YUV422SP || pixFmt >= V2_PIXFMT_RGB_BAYER_8BPP) 106 | headSize *= 2; 107 | else if (pixFmt == V2_PIXFMT_YUV420SP) 108 | headSize *= 3; 109 | headSize >>= 1; 110 | return bufSize + headSize; 111 | } -------------------------------------------------------------------------------- /src/hal/hisi/v3_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | V3_BAYER_RG, 12 | V3_BAYER_GR, 13 | V3_BAYER_GB, 14 | V3_BAYER_BG, 15 | V3_BAYER_END 16 | } v3_common_bayer; 17 | 18 | typedef enum { 19 | V3_COMPR_NONE, 20 | V3_COMPR_SEG, 21 | V3_COMPR_SEG128, 22 | V3_COMPR_LINE, 23 | V3_COMPR_FRAME, 24 | V3_COMPR_END 25 | } v3_common_compr; 26 | 27 | typedef enum { 28 | V3_PIXFMT_1BPP, 29 | V3_PIXFMT_2BPP, 30 | V3_PIXFMT_4BPP, 31 | V3_PIXFMT_8BPP, 32 | V3_PIXFMT_RGB444, 33 | V3_PIXFMT_ARGB4444, 34 | V3_PIXFMT_RGB555, 35 | V3_PIXFMT_RGB565, 36 | V3_PIXFMT_ARGB1555, 37 | V3_PIXFMT_RGB888, 38 | V3_PIXFMT_ARGB8888, 39 | V3_PIXFMT_RGB888P, 40 | V3_PIXFMT_RGB_BAYER_8BPP, 41 | V3_PIXFMT_RGB_BAYER_10BPP, 42 | V3_PIXFMT_RGB_BAYER_12BPP, 43 | V3_PIXFMT_RGB_BAYER_14BPP, 44 | V3_PIXFMT_RGB_BAYER_16BPP, 45 | V3_PIXFMT_YUV_A422, 46 | V3_PIXFMT_YUV_A444, 47 | V3_PIXFMT_YUV422P, 48 | V3_PIXFMT_YUV420P, 49 | V3_PIXFMT_YUV444P, 50 | V3_PIXFMT_YUV422SP, 51 | V3_PIXFMT_YUV420SP, 52 | V3_PIXFMT_YUV444SP, 53 | V3_PIXFMT_YUV422_UYVY, 54 | V3_PIXFMT_YUV422_YUYV, 55 | V3_PIXFMT_YUV422_VYUY, 56 | V3_PIXFMT_YCbCrP, 57 | V3_PIXFMT_YUV400, 58 | V3_PIXFMT_END 59 | } v3_common_pixfmt; 60 | 61 | typedef enum { 62 | V3_PREC_8BPP, 63 | V3_PREC_10BPP, 64 | V3_PREC_12BPP, 65 | V3_PREC_14BPP, 66 | V3_PREC_16BPP, 67 | V3_PREC_END 68 | } v3_common_prec; 69 | 70 | typedef enum { 71 | V3_VIDFMT_LINEAR, 72 | V3_VIDFMT_TILE_256X16, 73 | V3_VIDFMT_TILE_64X16, 74 | V3_VIDFMT_END 75 | } v3_common_vidfmt; 76 | 77 | typedef enum { 78 | V3_WDR_NONE, 79 | V3_WDR_BUILTIN, 80 | V3_WDR_QUDRA, 81 | V3_WDR_2TO1_LINE, 82 | V3_WDR_2TO1_FRAME, 83 | V3_WDR_2TO1_FRAME_FULLRATE, 84 | V3_WDR_3TO1_LINE, 85 | V3_WDR_3TO1_FRAME, 86 | V3_WDR_3TO1_FRAME_FULLRATE, 87 | V3_WDR_4TO1_LINE, 88 | V3_WDR_4TO1_FRAME, 89 | V3_WDR_4TO1_FRAME_FULLRATE, 90 | V3_WDR_END 91 | } v3_common_wdr; 92 | 93 | typedef struct { 94 | unsigned int topWidth; 95 | unsigned int bottomWidth; 96 | unsigned int leftWidth; 97 | unsigned int rightWidth; 98 | unsigned int color; 99 | } v3_common_bord; 100 | 101 | typedef struct { 102 | unsigned int width; 103 | unsigned int height; 104 | } v3_common_dim; 105 | 106 | typedef struct { 107 | int x; 108 | int y; 109 | } v3_common_pnt; 110 | 111 | typedef struct { 112 | int x; 113 | int y; 114 | unsigned int width; 115 | unsigned int height; 116 | } v3_common_rect; 117 | -------------------------------------------------------------------------------- /src/hal/hisi/v3_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v3_common.h" 4 | #include "v3_aud.h" 5 | #include "v3_config.h" 6 | #include "v3_isp.h" 7 | #include "v3_rgn.h" 8 | #include "v3_snr.h" 9 | #include "v3_sys.h" 10 | #include "v3_vb.h" 11 | #include "v3_venc.h" 12 | #include "v3_vi.h" 13 | #include "v3_vpss.h" 14 | 15 | #include "../support.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | extern char audioOn, keepRunning; 23 | 24 | extern hal_chnstate v3_state[V3_VENC_CHN_NUM]; 25 | extern int (*v3_aud_cb)(hal_audframe*); 26 | extern int (*v3_vid_cb)(char, hal_vidstream*); 27 | 28 | void v3_hal_deinit(void); 29 | int v3_hal_init(void); 30 | 31 | void v3_audio_deinit(void); 32 | int v3_audio_init(int samplerate); 33 | void *v3_audio_thread(void); 34 | 35 | int v3_channel_bind(char index); 36 | int v3_channel_create(char index, short width, short height, char mirror, char flip, char framerate); 37 | int v3_channel_grayscale(char enable); 38 | int v3_channel_unbind(char index); 39 | 40 | void *v3_image_thread(void); 41 | 42 | int v3_pipeline_create(void); 43 | void v3_pipeline_destroy(void); 44 | 45 | int v3_region_create(char handle, hal_rect rect, short opacity); 46 | void v3_region_destroy(char handle); 47 | int v3_region_setbitmap(int handle, hal_bitmap *bitmap); 48 | 49 | void v3_sensor_deconfig(void); 50 | int v3_sensor_config(void); 51 | void v3_sensor_deinit(void); 52 | int v3_sensor_init(char *name, char *obj); 53 | 54 | int v3_video_create(char index, hal_vidconfig *config); 55 | int v3_video_destroy(char index); 56 | int v3_video_destroy_all(void); 57 | void v3_video_request_idr(char index); 58 | int v3_video_snapshot_grab(char index, hal_jpegdata *jpeg); 59 | void *v3_video_thread(void); 60 | 61 | int v3_system_calculate_block(short width, short height, v3_common_pixfmt pixFmt, 62 | unsigned int alignWidth); 63 | void v3_system_deinit(void); 64 | int v3_system_init(char *snrConfig); 65 | float v3_system_readtemp(void); -------------------------------------------------------------------------------- /src/hal/hisi/v3_snr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v3_common.h" 4 | 5 | #include 6 | #include 7 | 8 | #define V3_SNR_IOC_MAGIC 'm' 9 | #define V3_SNR_LVDS_LANE_NUM 4 10 | #define V3_SNR_MIPI_LANE_NUM 4 11 | #define V3_SNR_WDR_VC_NUM 4 12 | 13 | enum { 14 | V3_SNR_CMD_CONF_DEV = 1, 15 | V3_SNR_CMD_CONF_EDGE, 16 | V3_SNR_CMD_CONF_MSB, 17 | V3_SNR_CMD_CONF_CMV, 18 | V3_SNR_CMD_RST_SENS, 19 | V3_SNR_CMD_UNRST_SENS, 20 | V3_SNR_CMD_RST_MIPI, 21 | V3_SNR_CMD_UNRST_MIPI, 22 | V3_SNR_CMD_CONF_CROP 23 | }; 24 | 25 | typedef enum { 26 | V3_SNR_INPUT_MIPI, 27 | V3_SNR_INPUT_SUBLVDS, 28 | V3_SNR_INPUT_LVDS, 29 | V3_SNR_INPUT_HISPI, 30 | V3_SNR_INPUT_CMOS_18V, 31 | V3_SNR_INPUT_CMOS_33V, 32 | V3_SNR_INPUT_BT1120, 33 | V3_SNR_INPUT_END 34 | } v3_snr_input; 35 | 36 | typedef enum { 37 | V3_SNR_LFID_NONE, 38 | V3_SNR_LFID_INSAV, 39 | V3_SNR_LFID_INDATA, 40 | V3_SNR_LFID_END 41 | } v3_snr_lfid; 42 | 43 | typedef enum { 44 | V3_SNR_LVSYNCT_NORMAL, 45 | V3_SNR_LVSYNCT_SHARE, 46 | V3_SNR_LVSYNCT_HCONNECT, 47 | V3_SNR_LVSYNCT_END 48 | } v3_snr_lvsynct; 49 | 50 | typedef enum { 51 | V3_SNR_LWDR_NONE, 52 | V3_SNR_LWDR_2F, 53 | V3_SNR_LWDR_3F, 54 | V3_SNR_LWDR_4F, 55 | V3_SNR_LWDR_DOL2F, 56 | V3_SNR_LWDR_DOL3F, 57 | V3_SNR_LWDR_DOL4F, 58 | V3_SNR_LWDR_END 59 | } v3_snr_lwdr; 60 | 61 | typedef enum { 62 | V3_SNR_MWDR_NONE, 63 | V3_SNR_MWDR_VC, 64 | V3_SNR_MWDR_DT, 65 | V3_SNR_MWDR_DOL, 66 | V3_SNR_MWDR_END 67 | } v3_snr_mwdr; 68 | 69 | typedef struct { 70 | v3_snr_lfid type; 71 | unsigned char outputFil; 72 | } v3_snr_fid; 73 | 74 | typedef struct { 75 | v3_snr_lvsynct type; 76 | unsigned short hBlank1; 77 | unsigned short hBlank2; 78 | } v3_snr_lvsync; 79 | 80 | typedef struct { 81 | v3_common_dim dest; 82 | v3_common_prec prec; 83 | v3_snr_lwdr wdr; 84 | int syncSavOn; 85 | v3_snr_lvsync vsync; 86 | v3_snr_fid fid; 87 | int dataBeOn; 88 | int syncBeOn; 89 | // Value -1 signifies a lane is disabled 90 | short laneId[V3_SNR_LVDS_LANE_NUM]; 91 | /* Each lane has two virtual channel, each has four params 92 | If syncSavOn is false: SOF, EOF, SOL, EOL 93 | If syncSavOn is true: invalid sav, invalid eav, valid sav, valid eav */ 94 | unsigned short syncCode[V3_SNR_LVDS_LANE_NUM * V3_SNR_WDR_VC_NUM * 4]; 95 | } v3_snr_lvds; 96 | 97 | typedef struct { 98 | v3_common_prec prec; 99 | v3_snr_mwdr mode; 100 | // Value -1 signifies a lane is disabled 101 | short laneId[V3_SNR_MIPI_LANE_NUM]; 102 | union { 103 | short wdrVcType[V3_SNR_WDR_VC_NUM]; 104 | }; 105 | } v3_snr_mipi; 106 | 107 | typedef struct { 108 | unsigned int device; 109 | v3_snr_input input; 110 | union { 111 | v3_snr_mipi mipi; 112 | v3_snr_lvds lvds; 113 | }; 114 | } v3_snr_dev; 115 | 116 | typedef struct { 117 | void *handle; 118 | 119 | int (*fnRegisterCallback)(void); 120 | int (*fnUnRegisterCallback)(void); 121 | } v3_snr_drv_impl; 122 | 123 | static const char v3_snr_endp[] = {"/dev/hi_mipi"}; -------------------------------------------------------------------------------- /src/hal/hisi/v4_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "v4_common.h" 4 | #include "v4_aud.h" 5 | #include "v4_config.h" 6 | #include "v4_isp.h" 7 | #include "v4_rgn.h" 8 | #include "v4_snr.h" 9 | #include "v4_sys.h" 10 | #include "v4_vb.h" 11 | #include "v4_venc.h" 12 | #include "v4_vi.h" 13 | #include "v4_vpss.h" 14 | 15 | #include "../support.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | extern char audioOn, keepRunning; 23 | 24 | extern hal_chnstate v4_state[V4_VENC_CHN_NUM]; 25 | extern int (*v4_aud_cb)(hal_audframe*); 26 | extern int (*v4_vid_cb)(char, hal_vidstream*); 27 | 28 | void v4_hal_deinit(void); 29 | int v4_hal_init(void); 30 | void *v4_audio_thread(void); 31 | 32 | void v4_audio_deinit(void); 33 | int v4_audio_init(int samplerate); 34 | 35 | int v4_channel_bind(char index); 36 | int v4_channel_create(char index, char mirror, char flip, char framerate); 37 | int v4_channel_grayscale(char enable); 38 | int v4_channel_unbind(char index); 39 | 40 | void *v4_image_thread(void); 41 | 42 | int v4_pipeline_create(void); 43 | void v4_pipeline_destroy(void); 44 | 45 | int v4_region_create(char handle, hal_rect rect, short opacity); 46 | void v4_region_destroy(char handle); 47 | int v4_region_setbitmap(int handle, hal_bitmap *bitmap); 48 | 49 | void v4_sensor_deconfig(void); 50 | int v4_sensor_config(void); 51 | void v4_sensor_deinit(void); 52 | int v4_sensor_init(char *name, char *obj); 53 | 54 | int v4_video_create(char index, hal_vidconfig *config); 55 | int v4_video_destroy(char index); 56 | int v4_video_destroy_all(void); 57 | void v4_video_request_idr(char index); 58 | int v4_video_snapshot_grab(char index, hal_jpegdata *jpeg); 59 | void *v4_video_thread(void); 60 | 61 | int v4_system_calculate_block(short width, short height, v4_common_pixfmt pixFmt, 62 | unsigned int alignWidth); 63 | void v4_system_deinit(void); 64 | int v4_system_init(char *snrConfig); 65 | float v4_system_readtemp(void); -------------------------------------------------------------------------------- /src/hal/inge/t31_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | T31_PIXFMT_YUV420P, 12 | T31_PIXFMT_YUV422_YUYV, 13 | T31_PIXFMT_YUV422_UYVY, 14 | T31_PIXFMT_YUV422P, 15 | T31_PIXFMT_YUV444P, 16 | T31_PIXFMT_YUV410P, 17 | T31_PIXFMT_YUV411P, 18 | T31_PIXFMT_GRAY8, 19 | T31_PIXFMT_MONOWHITE, 20 | T31_PIXFMT_MONOBLACK, 21 | T31_PIXFMT_NV12, 22 | T31_PIXFMT_NV24, 23 | T31_PIXFMT_RGB888, 24 | T31_PIXFMT_BGR888, 25 | T31_PIXFMT_ARGB8888, 26 | T31_PIXFMT_RGBA8888, 27 | T31_PIXFMT_ABGR8888, 28 | T31_PIXFMT_BGRA8888, 29 | T31_PIXFMT_RGB565BE, 30 | T31_PIXFMT_RGB565LE, 31 | // Following twos have their MSB set to 1 32 | T31_PIXFMT_RGB555BE, 33 | T31_PIXFMT_RGB555LE, 34 | T31_PIXFMT_BGR565BE, 35 | T31_PIXFMT_BGR565LE, 36 | // Following twos have their MSB set to 1 37 | T31_PIXFMT_BGR555BE, 38 | T31_PIXFMT_BGR555LE, 39 | T31_PIXFMT_0RGB8888, 40 | T31_PIXFMT_RGB08888, 41 | T31_PIXFMT_0BGR8888, 42 | T31_PIXFMT_BGR08888, 43 | T31_PIXFMT_BAYER_BGGR8, 44 | T31_PIXFMT_BAYER_RGGB8, 45 | T31_PIXFMT_BAYER_GBRG8, 46 | T31_PIXFMT_BAYER_GRBG8, 47 | T31_PIXFMT_RAW, 48 | T31_PIXFMT_HSV888, 49 | T31_PIXFMT_END 50 | } t31_common_pixfmt; 51 | 52 | typedef struct { 53 | int width; 54 | int height; 55 | } t31_common_dim; 56 | 57 | typedef struct { 58 | int x; 59 | int y; 60 | } t31_common_pnt; 61 | 62 | typedef struct { 63 | t31_common_pnt p0; 64 | t31_common_pnt p1; 65 | } t31_common_rect; -------------------------------------------------------------------------------- /src/hal/inge/t31_fs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "t31_common.h" 4 | 5 | typedef struct { 6 | int enable; 7 | int left; 8 | int top; 9 | int width; 10 | int height; 11 | } t31_fs_crop; 12 | 13 | typedef struct { 14 | int enable; 15 | int width; 16 | int height; 17 | } t31_fs_scale; 18 | 19 | typedef struct { 20 | t31_common_dim dest; 21 | t31_common_pixfmt pixFmt; 22 | t31_fs_crop crop; 23 | t31_fs_scale scale; 24 | int fpsNum; 25 | int fpsDen; 26 | int bufCount; 27 | int phyOrExtChn; 28 | t31_fs_crop frame; 29 | } t31_fs_chn; 30 | 31 | typedef struct { 32 | int index; 33 | int poolId; 34 | unsigned int width; 35 | unsigned int height; 36 | t31_common_pixfmt pixFmt; 37 | unsigned int size; 38 | unsigned int phyAddr; 39 | unsigned int virtAddr; 40 | long long timestamp; 41 | int rotateFlag; 42 | unsigned int priv[0]; 43 | } t31_fs_frame; 44 | 45 | typedef struct { 46 | void *handle; 47 | 48 | int (*fnCreateChannel)(int channel, t31_fs_chn *config); 49 | int (*fnDestroyChannel)(int channel); 50 | int (*fnDisableChannel)(int channel); 51 | int (*fnEnableChannel)(int channel); 52 | int (*fnSetChannelRotate)(int channel, char rotateMode, int width, int height); 53 | int (*fnSetChannelSource)(int channel, int source); 54 | 55 | int (*fnSnapshot)(int channel, t31_common_pixfmt pixFmt, int width, int height, 56 | void *data, t31_fs_frame *info); 57 | } t31_fs_impl; 58 | 59 | static int t31_fs_load(t31_fs_impl *fs_lib) { 60 | if (!(fs_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) 61 | HAL_ERROR("t31_fs", "Failed to load library!\nError: %s\n", dlerror()); 62 | 63 | if (!(fs_lib->fnCreateChannel = (int(*)(int channel, t31_fs_chn *config)) 64 | hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_CreateChn"))) 65 | return EXIT_FAILURE; 66 | 67 | if (!(fs_lib->fnDestroyChannel = (int(*)(int channel)) 68 | hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_DestroyChn"))) 69 | return EXIT_FAILURE; 70 | 71 | if (!(fs_lib->fnDisableChannel = (int(*)(int channel)) 72 | hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_DisableChn"))) 73 | return EXIT_FAILURE; 74 | 75 | if (!(fs_lib->fnEnableChannel = (int(*)(int channel)) 76 | hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_EnableChn"))) 77 | return EXIT_FAILURE; 78 | 79 | if (!(fs_lib->fnSetChannelRotate = (int(*)(int channel, char rotateMode, int width, int height)) 80 | hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_SetChnRotate"))) 81 | return EXIT_FAILURE; 82 | 83 | if (!(fs_lib->fnSetChannelSource = (int(*)(int channel, int source)) 84 | hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_SetSource"))) 85 | return EXIT_FAILURE; 86 | 87 | if (!(fs_lib->fnSnapshot = (int(*)(int channel, t31_common_pixfmt pixFmt, int width, int height, 88 | void *data, t31_fs_frame *info)) 89 | hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_SnapFrame"))) 90 | return EXIT_FAILURE; 91 | 92 | return EXIT_SUCCESS; 93 | } 94 | 95 | static void t31_fs_unload(t31_fs_impl *fs_lib) { 96 | if (fs_lib->handle) dlclose(fs_lib->handle); 97 | fs_lib->handle = NULL; 98 | memset(fs_lib, 0, sizeof(*fs_lib)); 99 | } -------------------------------------------------------------------------------- /src/hal/inge/t31_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "t31_common.h" 4 | #include "t31_aud.h" 5 | #include "t31_fs.h" 6 | #include "t31_isp.h" 7 | #include "t31_osd.h" 8 | #include "t31_sys.h" 9 | #include "t31_venc.h" 10 | 11 | #include "../config.h" 12 | #include "../support.h" 13 | 14 | #include 15 | #include 16 | 17 | extern char audioOn, keepRunning; 18 | 19 | extern hal_chnstate t31_state[T31_VENC_CHN_NUM]; 20 | extern int (*t31_aud_cb)(hal_audframe*); 21 | extern int (*t31_vid_cb)(char, hal_vidstream*); 22 | 23 | void t31_hal_deinit(void); 24 | int t31_hal_init(void); 25 | 26 | void t31_audio_deinit(void); 27 | int t31_audio_init(int samplerate); 28 | void *t31_audio_thread(void); 29 | 30 | int t31_channel_bind(char index); 31 | int t31_channel_create(char index, short width, short height, char framerate, char jpeg); 32 | int t31_channel_grayscale(char enable); 33 | int t31_channel_unbind(char index); 34 | 35 | int t31_config_load(char *path); 36 | 37 | int t31_pipeline_create(char mirror, char flip, char antiflicker, char framerate); 38 | void t31_pipeline_destroy(void); 39 | 40 | int t31_region_create(int *handle, hal_rect rect, short opacity); 41 | void t31_region_destroy(int *handle); 42 | int t31_region_setbitmap(int *handle, hal_bitmap *bitmap); 43 | 44 | int t31_video_create(char index, hal_vidconfig *config); 45 | int t31_video_destroy(char index); 46 | int t31_video_destroy_all(void); 47 | void t31_video_request_idr(char index); 48 | int t31_video_snapshot_grab(char index, hal_jpegdata *jpeg); 49 | void *t31_video_thread(void); 50 | 51 | void t31_system_deinit(void); 52 | int t31_system_init(void); -------------------------------------------------------------------------------- /src/hal/inge/t31_sys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "t31_common.h" 4 | 5 | #define T31_SYS_API "1.0" 6 | 7 | typedef enum { 8 | T31_SYS_DEV_FS, 9 | T31_SYS_DEV_ENC, 10 | T31_SYS_DEV_DEC, 11 | T31_SYS_DEV_IVS, 12 | T31_SYS_DEV_OSD, 13 | T31_SYS_DEV_FG1DIRECT, 14 | T31_SYS_DEV_RSVD, 15 | T31_SYS_DED_RSVD_END = 23, 16 | T31_SYS_DEV_END 17 | } t31_sys_dev; 18 | 19 | typedef struct { 20 | t31_sys_dev device; 21 | int group; 22 | int port; 23 | } t31_sys_bind; 24 | 25 | typedef struct { 26 | char version[64]; 27 | } t31_sys_ver; 28 | 29 | typedef struct { 30 | void *handle, *handleAlog, *handleSysutils; 31 | 32 | int (*fnExit)(void); 33 | int (*fnGetChipName)(const char *chip); 34 | int (*fnGetVersion)(t31_sys_ver *version); 35 | int (*fnInit)(void); 36 | 37 | int (*fnBind)(t31_sys_bind *source, t31_sys_bind *dest); 38 | int (*fnUnbind)(t31_sys_bind *source, t31_sys_bind *dest); 39 | } t31_sys_impl; 40 | 41 | static int t31_sys_load(t31_sys_impl *sys_lib) { 42 | if (!(sys_lib->handleSysutils = dlopen("libsysutils.so", RTLD_LAZY | RTLD_GLOBAL)) || 43 | !(sys_lib->handleAlog = dlopen("libalog.so", RTLD_LAZY | RTLD_GLOBAL)) || 44 | !(sys_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) 45 | HAL_ERROR("t31_sys", "Failed to load library!\nError: %s\n", dlerror()); 46 | 47 | if (!(sys_lib->fnExit = (int(*)(void)) 48 | hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_Exit"))) 49 | return EXIT_FAILURE; 50 | 51 | if (!(sys_lib->fnGetChipName = (int(*)(const char *chip)) 52 | hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_GetCPUInfo"))) 53 | return EXIT_FAILURE; 54 | 55 | if (!(sys_lib->fnGetVersion = (int(*)(t31_sys_ver *version)) 56 | hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_GetVersion"))) 57 | return EXIT_FAILURE; 58 | 59 | if (!(sys_lib->fnInit = (int(*)(void)) 60 | hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_Init"))) 61 | return EXIT_FAILURE; 62 | 63 | if (!(sys_lib->fnBind = (int(*)(t31_sys_bind *source, t31_sys_bind *dest)) 64 | hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_Bind"))) 65 | return EXIT_FAILURE; 66 | 67 | if (!(sys_lib->fnUnbind = (int(*)(t31_sys_bind *source, t31_sys_bind *dest)) 68 | hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_UnBind"))) 69 | return EXIT_FAILURE; 70 | 71 | return EXIT_SUCCESS; 72 | } 73 | 74 | static void t31_sys_unload(t31_sys_impl *sys_lib) { 75 | if (sys_lib->handle) dlclose(sys_lib->handle); 76 | sys_lib->handle = NULL; 77 | if (sys_lib->handleAlog) dlclose(sys_lib->handleAlog); 78 | sys_lib->handleAlog = NULL; 79 | if (sys_lib->handleSysutils) dlclose(sys_lib->handleSysutils); 80 | sys_lib->handleSysutils = NULL; 81 | memset(sys_lib, 0, sizeof(*sys_lib)); 82 | } -------------------------------------------------------------------------------- /src/hal/macros.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #define IMPORT_BIN(sect, file, sym) asm (\ 7 | ".section " #sect "\n" /* Change section */\ 8 | ".global " #sym "\n" /* Export the object address */\ 9 | ".balign 4\n" /* Word alignment */\ 10 | #sym ":\n" /* Define the object label */\ 11 | ".incbin \"" file "\"\n" /* Import the file */\ 12 | ".global " #sym "_size\n" /* Export the object size */\ 13 | ".balign 8\n" /* Word alignment */\ 14 | #sym "_size:\n" /* Define the object size label */\ 15 | ".long " #sym "_size - " #sym "\n" /* Define the object size */\ 16 | ".section \".text\"\n") /* Restore section */ 17 | 18 | #define IMPORT_STR(sect, file, sym) asm (\ 19 | ".section " #sect "\n" /* Change section */\ 20 | ".balign 4\n" /* Word alignment */\ 21 | ".global " #sym "\n" /* Export the object address */\ 22 | #sym ":\n" /* Define the object label */\ 23 | ".incbin \"" file "\"\n" /* Import the file */\ 24 | ".byte 0\n" /* Null-terminate the string */\ 25 | ".balign 4\n" /* Word alignment */\ 26 | ".section \".text\"\n") /* Restore section */ 27 | 28 | #define HAL_DANGER(mod, x, ...) \ 29 | do { \ 30 | fprintf(stderr, "[%s] \033[31m", (mod)); \ 31 | fprintf(stderr, (x), ##__VA_ARGS__); \ 32 | fprintf(stderr, "\033[0m"); \ 33 | } while (0) 34 | 35 | #define HAL_ERROR(mod, x, ...) \ 36 | do { \ 37 | fprintf(stderr, "[%s] \033[31m", (mod)); \ 38 | fprintf(stderr, (x), ##__VA_ARGS__); \ 39 | fprintf(stderr, "\033[0m"); \ 40 | return EXIT_FAILURE; \ 41 | } while (0) 42 | 43 | #define HAL_INFO(mod, x, ...) \ 44 | do { \ 45 | fprintf(stderr, "[%s] ", (mod)); \ 46 | fprintf(stderr, (x), ##__VA_ARGS__); \ 47 | } while (0) 48 | 49 | #define HAL_WARNING(mod, x, ...) \ 50 | do { \ 51 | fprintf(stderr, "[%s] \033[33m", (mod)); \ 52 | fprintf(stderr, (x), ##__VA_ARGS__); \ 53 | fprintf(stderr, "\033[0m"); \ 54 | } while (0) 55 | 56 | #ifndef CEILING 57 | #define CEILING_POS(X) ((X-(int)(X)) > 0 ? (int)(X+1) : (int)(X)) 58 | #define CEILING_NEG(X) (int)(X) 59 | #define CEILING(X) ( ((X) > 0) ? CEILING_POS(X) : CEILING_NEG(X) ) 60 | #endif 61 | 62 | #define CONTAINS(a, b) strstr(a, b) 63 | #define EMPTY(x) (x[0] == '\0') 64 | #define ENDS_WITH(a, b) \ 65 | ((strlen(a) > strlen(b)) && !strcmp(a + strlen(a) - strlen(b), b)) 66 | #define EQUALS(a, b) !strcmp(a, b) 67 | #define EQUALS_CASE(a, b) !strcasecmp(a, b) 68 | #define STARTS_WITH(a, b) !strncmp(a, b, strlen(b)) -------------------------------------------------------------------------------- /src/hal/plus/ak_aud.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ak_common.h" 4 | 5 | typedef struct { 6 | unsigned int rate; 7 | unsigned int bit; 8 | unsigned int chnNum; 9 | } ak_aud_cnf; 10 | 11 | typedef struct { 12 | unsigned char *data; 13 | unsigned int length; 14 | unsigned long long timestamp; 15 | unsigned long sequence; 16 | } ak_aud_frm; 17 | 18 | typedef struct { 19 | void *handle; 20 | 21 | int (*fnDisableDevice)(void *device); 22 | void* (*fnEnableDevice)(ak_aud_cnf *config); 23 | 24 | int (*fnSetVolume)(void *device, int level); 25 | 26 | int (*fnFreeFrame)(void *device, ak_aud_frm *frame); 27 | int (*fnGetFrame)(void *device, ak_aud_frm *frame, int millis); 28 | } ak_aud_impl; 29 | 30 | static int ak_aud_load(ak_aud_impl *aud_lib) { 31 | if (!(aud_lib->handle = dlopen("libplat_ai.so", RTLD_LAZY | RTLD_GLOBAL))) 32 | HAL_ERROR("ak_aud", "Failed to load library!\nError: %s\n", dlerror()); 33 | 34 | if (!(aud_lib->fnDisableDevice = (int(*)(void* device)) 35 | hal_symbol_load("ak_aud", aud_lib->handle, "ak_ai_close"))) 36 | return EXIT_FAILURE; 37 | 38 | if (!(aud_lib->fnEnableDevice = (void*(*)(ak_aud_cnf *config)) 39 | hal_symbol_load("ak_aud", aud_lib->handle, "ak_ai_open"))) 40 | return EXIT_FAILURE; 41 | 42 | if (!(aud_lib->fnSetVolume = (int(*)(void *device, int level)) 43 | hal_symbol_load("ak_aud", aud_lib->handle, "ak_ai_set_volume"))) 44 | return EXIT_FAILURE; 45 | 46 | if (!(aud_lib->fnFreeFrame = (int(*)(void *device, ak_aud_frm *frame)) 47 | hal_symbol_load("ak_aud", aud_lib->handle, "ak_ai_release_frame"))) 48 | return EXIT_FAILURE; 49 | 50 | if (!(aud_lib->fnGetFrame = (int(*)(void *device, ak_aud_frm *frame, int millis)) 51 | hal_symbol_load("ak_aud", aud_lib->handle, "ak_ai_get_frame"))) 52 | return EXIT_FAILURE; 53 | 54 | return EXIT_SUCCESS; 55 | } 56 | 57 | static void ak_aud_unload(ak_aud_impl *aud_lib) { 58 | if (aud_lib->handle) dlclose(aud_lib->handle); 59 | aud_lib->handle = NULL; 60 | memset(aud_lib, 0, sizeof(*aud_lib)); 61 | } -------------------------------------------------------------------------------- /src/hal/plus/ak_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | #define AK_VENC_CHN_NUM 2 11 | #define AK_VI_CHN_NUM 2 -------------------------------------------------------------------------------- /src/hal/plus/ak_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ak_common.h" 4 | #include "ak_aud.h" 5 | #include "ak_sys.h" 6 | #include "ak_venc.h" 7 | #include "ak_vi.h" 8 | 9 | extern char audioOn, keepRunning; 10 | 11 | extern hal_chnstate ak_state[AK_VENC_CHN_NUM]; 12 | extern int (*ak_aud_cb)(hal_audframe*); 13 | extern int (*ak_vid_cb)(char, hal_vidstream*); 14 | 15 | void ak_hal_deinit(void); 16 | int ak_hal_init(void); 17 | 18 | void ak_audio_deinit(void); 19 | int ak_audio_init(int samplerate); 20 | void *ak_audio_thread(void); 21 | 22 | int ak_channel_bind(char index); 23 | int ak_channel_grayscale(char enable); 24 | int ak_channel_unbind(char index); 25 | 26 | int ak_config_load(char *path); 27 | 28 | int ak_pipeline_create(char mirror, char flip); 29 | void ak_pipeline_destroy(void); 30 | 31 | int ak_video_create(char index, hal_vidconfig *config); 32 | int ak_video_destroy(char index); 33 | int ak_video_destroy_all(void); 34 | void ak_video_request_idr(char index); 35 | int ak_video_snapshot_grab(char index, hal_jpegdata *jpeg); 36 | void *ak_video_thread(void); 37 | 38 | void ak_system_deinit(void); 39 | int ak_system_init(char *snrConfig); -------------------------------------------------------------------------------- /src/hal/plus/ak_sys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ak_common.h" 4 | 5 | typedef struct { 6 | void *handle, *handleAkuio, *handleDrv, *handleIpcSrv, *handleThread; 7 | 8 | int (*fnGetErrorNum)(void); 9 | char* (*fnGetErrorStr)(int error); 10 | } ak_sys_impl; 11 | 12 | static int ak_sys_load(ak_sys_impl *sys_lib) { 13 | if (!(sys_lib->handleThread = dlopen("libplat_thread.so", RTLD_LAZY | RTLD_GLOBAL))) 14 | HAL_ERROR("ak_sys", "Failed to load library!\nError: %s\n", dlerror()); 15 | 16 | if (!(sys_lib->handle = dlopen("libplat_common.so", RTLD_LAZY | RTLD_GLOBAL))) 17 | HAL_ERROR("ak_sys", "Failed to load library!\nError: %s\n", dlerror()); 18 | 19 | if (!(sys_lib->handleAkuio = dlopen("libakuio.so", RTLD_LAZY | RTLD_GLOBAL))) 20 | HAL_ERROR("ak_sys", "Failed to load library!\nError: %s\n", dlerror()); 21 | 22 | if (!(sys_lib->handleDrv = dlopen("libplat_drv.so", RTLD_LAZY | RTLD_GLOBAL))) 23 | HAL_ERROR("ak_sys", "Failed to load library!\nError: %s\n", dlerror()); 24 | 25 | if (!(sys_lib->handleIpcSrv = dlopen("libplat_ipcsrv.so", RTLD_LAZY | RTLD_GLOBAL))) 26 | HAL_ERROR("ak_sys", "Failed to load library!\nError: %s\n", dlerror()); 27 | 28 | if (!(sys_lib->fnGetErrorNum = (int(*)(void)) 29 | hal_symbol_load("ak_sys", sys_lib->handle, "ak_get_error_no"))) 30 | return EXIT_FAILURE; 31 | 32 | if (!(sys_lib->fnGetErrorStr = (char*(*)(int error)) 33 | hal_symbol_load("ak_sys", sys_lib->handle, "ak_get_error_str"))) 34 | return EXIT_FAILURE; 35 | 36 | return EXIT_SUCCESS; 37 | } 38 | 39 | static void ak_sys_unload(ak_sys_impl *sys_lib) { 40 | if (sys_lib->handleIpcSrv) dlclose(sys_lib->handleIpcSrv); 41 | sys_lib->handleIpcSrv = NULL; 42 | if (sys_lib->handleDrv) dlclose(sys_lib->handleDrv); 43 | sys_lib->handleDrv = NULL; 44 | if (sys_lib->handleAkuio) dlclose(sys_lib->handleAkuio); 45 | sys_lib->handleAkuio = NULL; 46 | if (sys_lib->handle) dlclose(sys_lib->handle); 47 | sys_lib->handle = NULL; 48 | if (sys_lib->handleThread) dlclose(sys_lib->handleThread); 49 | sys_lib->handleThread = NULL; 50 | memset(sys_lib, 0, sizeof(*sys_lib)); 51 | } -------------------------------------------------------------------------------- /src/hal/plus/ak_vi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ak_common.h" 4 | 5 | typedef struct { 6 | int x; 7 | int y; 8 | int width; 9 | int height; 10 | } ak_vi_crop; 11 | 12 | typedef struct { 13 | int width; 14 | int height; 15 | } ak_vi_res; 16 | 17 | typedef struct { 18 | ak_vi_crop capt; 19 | ak_vi_res dest[AK_VI_CHN_NUM]; 20 | } ak_vi_cnf; 21 | 22 | typedef struct { 23 | void *handle, *handleIspSdk; 24 | 25 | int (*fnLoadSensorConfig)(char *path); 26 | 27 | int (*fnDisableDevice)(void *device); 28 | void* (*fnEnableDevice)(int device); 29 | int (*fnStartDevice)(void *device); 30 | int (*fnStopDevice)(void *device); 31 | 32 | int (*fnGetDeviceConfig)(void *device, ak_vi_cnf *config); 33 | int (*fnGetDeviceResolution)(void *device, ak_vi_res *res); 34 | int (*fnSetDeviceConfig)(void *device, ak_vi_cnf *config); 35 | int (*fnSetDeviceFlipMirror)(void *device, int flipOn, int mirrorOn); 36 | int (*fnSetDeviceMode)(void *device, int nightOn); 37 | } ak_vi_impl; 38 | 39 | static int ak_vi_load(ak_vi_impl *vi_lib) { 40 | if (!(vi_lib->handleIspSdk = dlopen("libakispsdk.so", RTLD_LAZY | RTLD_GLOBAL))) 41 | HAL_ERROR("ak_vi", "Failed to load library!\nError: %s\n", dlerror()); 42 | 43 | if (!(vi_lib->handle = dlopen("libplat_vi.so", RTLD_LAZY | RTLD_GLOBAL))) 44 | HAL_ERROR("ak_vi", "Failed to load library!\nError: %s\n", dlerror()); 45 | 46 | if (!(vi_lib->fnLoadSensorConfig = (int(*)(char *path)) 47 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_match_sensor"))) 48 | return EXIT_FAILURE; 49 | 50 | if (!(vi_lib->fnDisableDevice = (int(*)(void* device)) 51 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_close"))) 52 | return EXIT_FAILURE; 53 | 54 | if (!(vi_lib->fnEnableDevice = (void*(*)(int device)) 55 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_open"))) 56 | return EXIT_FAILURE; 57 | 58 | if (!(vi_lib->fnStartDevice = (int(*)(void *device)) 59 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_capture_on"))) 60 | return EXIT_FAILURE; 61 | 62 | if (!(vi_lib->fnStopDevice = (int(*)(void *device)) 63 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_capture_off"))) 64 | return EXIT_FAILURE; 65 | 66 | if (!(vi_lib->fnGetDeviceConfig = (int(*)(void* device, ak_vi_cnf *config)) 67 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_get_channel_attr"))) 68 | return EXIT_FAILURE; 69 | 70 | if (!(vi_lib->fnGetDeviceResolution = (int(*)(void* device, ak_vi_res *res)) 71 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_get_sensor_resolution"))) 72 | return EXIT_FAILURE; 73 | 74 | if (!(vi_lib->fnSetDeviceConfig = (int(*)(void* device, ak_vi_cnf *config)) 75 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_set_channel_attr"))) 76 | return EXIT_FAILURE; 77 | 78 | if (!(vi_lib->fnSetDeviceFlipMirror = (int(*)(void *device, int flipOn, int mirrorOn)) 79 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_set_flip_mirror"))) 80 | return EXIT_FAILURE; 81 | 82 | if (!(vi_lib->fnSetDeviceMode = (int(*)(void *device, int nightOn)) 83 | hal_symbol_load("ak_vi", vi_lib->handle, "ak_vi_switch_mode"))) 84 | return EXIT_FAILURE; 85 | 86 | return EXIT_SUCCESS; 87 | } 88 | 89 | static void ak_vi_unload(ak_vi_impl *vi_lib) { 90 | if (vi_lib->handle) dlclose(vi_lib->handle); 91 | vi_lib->handle = NULL; 92 | if (vi_lib->handleIspSdk) dlclose(vi_lib->handleIspSdk); 93 | vi_lib->handleIspSdk = NULL; 94 | memset(vi_lib, 0, sizeof(*vi_lib)); 95 | } -------------------------------------------------------------------------------- /src/hal/plus/aw_sys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "aw_common.h" 4 | 5 | #define AW_SYS_API "1.0" 6 | 7 | typedef enum { 8 | AW_SYS_MOD_CMPI, 9 | AW_SYS_MOD_VB, 10 | AW_SYS_MOD_SYS, 11 | AW_SYS_MOD_RGN, 12 | AW_SYS_MOD_CHNL, 13 | AW_SYS_MOD_VDEC, 14 | AW_SYS_MOD_GROUP, 15 | AW_SYS_MOD_VPSS, 16 | AW_SYS_MOD_VENC, 17 | AW_SYS_MOD_VDA, 18 | AW_SYS_MOD_H264E, 19 | AW_SYS_MOD_JPEGE, 20 | AW_SYS_MOD_MPEG4E, 21 | AW_SYS_MOD_H264D, 22 | AW_SYS_MOD_JPEGD, 23 | AW_SYS_MOD_VOU, 24 | AW_SYS_MOD_VIU, 25 | AW_SYS_MOD_DSU, 26 | AW_SYS_MOD_VALG, 27 | AW_SYS_MOD_RC, 28 | AW_SYS_MOD_AIO, 29 | AW_SYS_MOD_AI, 30 | AW_SYS_MOD_AO, 31 | AW_SYS_MOD_AENC, 32 | AW_SYS_MOD_ADEC, 33 | AW_SYS_MOD_AVENC, 34 | AW_SYS_MOD_PCIV, 35 | AW_SYS_MOD_PCIVFMW, 36 | AW_SYS_MOD_ISP, 37 | AW_SYS_MOD_IVE, 38 | AW_SYS_MOD_UVC, 39 | AW_SYS_MOD_DCCM, 40 | AW_SYS_MOD_DCCS, 41 | AW_SYS_MOD_PROC, 42 | AW_SYS_MOD_LOG, 43 | AW_SYS_MOD_MSTLOG, 44 | AW_SYS_MOD_VD, 45 | AW_SYS_MOD_VCMP = 38, 46 | AW_SYS_MOD_FB, 47 | AW_SYS_MOD_HDMI, 48 | AW_SYS_MOD_VOIE, 49 | AW_SYS_MOD_TDE, 50 | AW_SYS_MOD_USR, 51 | AW_SYS_MOD_VEDU, 52 | AW_SYS_MOD_VGS, 53 | AW_SYS_MOD_H265E, 54 | AW_SYS_MOD_FD, 55 | AW_SYS_MOD_ODT, 56 | AW_SYS_MOD_VQA, 57 | AW_SYS_MOD_LPR, 58 | AW_SYS_MOD_COMPCORE = 100, 59 | AW_SYS_MOD_DEMUX, 60 | AW_SYS_MOD_MUX, 61 | AW_SYS_MOD_CLOCK, 62 | AW_SYS_MOD_CSI, 63 | AW_SYS_MOD_ISE = 229, 64 | AW_SYS_MOD_EIS, 65 | AW_SYS_MOD_TENC, 66 | AW_SYS_MOD_END 67 | } aw_sys_mod; 68 | 69 | typedef struct { 70 | aw_sys_mod module; 71 | int device; 72 | int channel; 73 | } aw_sys_bind; 74 | 75 | typedef struct { 76 | char version[64]; 77 | } aw_sys_ver; 78 | 79 | typedef struct { 80 | void *handle; 81 | 82 | int (*fnExit)(void); 83 | int (*fnInit)(void); 84 | 85 | int (*fnBind)(aw_sys_bind *source, aw_sys_bind *dest); 86 | int (*fnUnbind)(aw_sys_bind *source, aw_sys_bind *dest); 87 | } aw_sys_impl; 88 | 89 | static int aw_sys_load(aw_sys_impl *sys_lib) { 90 | if (!(sys_lib->handle = dlopen("libaw_mpp.so", RTLD_LAZY | RTLD_GLOBAL))) 91 | HAL_ERROR("aw_sys", "Failed to load library!\nError: %s\n", dlerror()); 92 | 93 | if (!(sys_lib->fnExit = (int(*)(void)) 94 | hal_symbol_load("aw_sys", sys_lib->handle, "AW_MPI_SYS_Exit"))) 95 | return EXIT_FAILURE; 96 | 97 | if (!(sys_lib->fnInit = (int(*)(void)) 98 | hal_symbol_load("aw_sys", sys_lib->handle, "AW_MPI_SYS_Init"))) 99 | return EXIT_FAILURE; 100 | 101 | if (!(sys_lib->fnBind = (int(*)(aw_sys_bind *source, aw_sys_bind *dest)) 102 | hal_symbol_load("aw_sys", sys_lib->handle, "AW_MPI_SYS_Bind"))) 103 | return EXIT_FAILURE; 104 | 105 | if (!(sys_lib->fnUnbind = (int(*)(aw_sys_bind *source, aw_sys_bind *dest)) 106 | hal_symbol_load("aw_sys", sys_lib->handle, "AW_MPI_SYS_UnBind"))) 107 | return EXIT_FAILURE; 108 | 109 | return EXIT_SUCCESS; 110 | } 111 | 112 | static void aw_sys_unload(aw_sys_impl *sys_lib) { 113 | if (sys_lib->handle) dlclose(sys_lib->handle); 114 | sys_lib->handle = NULL; 115 | memset(sys_lib, 0, sizeof(*sys_lib)); 116 | } -------------------------------------------------------------------------------- /src/hal/plus/cvi_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | #define CVI_VI_PIPE_NUM 4 11 | // Non-Sophgo chips support up to 4 channels 12 | #define CVI_VPSS_CHN_NUM 3 13 | #define CVI_VPSS_GRP_NUM 16 14 | 15 | typedef enum { 16 | CVI_BAYER_BG, 17 | CVI_BAYER_GB, 18 | CVI_BAYER_GR, 19 | CVI_BAYER_RG, 20 | CVI_BAYER_END 21 | } cvi_common_bayer; 22 | 23 | typedef enum { 24 | CVI_COMPR_NONE, 25 | CVI_COMPR_TILE, 26 | CVI_COMPR_LINE, 27 | CVI_COMPR_FRAME, 28 | CVI_COMPR_END 29 | } cvi_common_compr; 30 | 31 | typedef enum { 32 | CVI_HDR_SDR8, 33 | CVI_HDR_SDR10, 34 | CVI_HDR_HDR10, 35 | CVI_HDR_HLG, 36 | CVI_HDR_SLF, 37 | CVI_HDR_XDR, 38 | CVI_HDR_END 39 | } cvi_common_hdr; 40 | 41 | typedef enum { 42 | CVI_PIXFMT_RGB888, 43 | CVI_PIXFMT_BGR888, 44 | CVI_PIXFMT_RGB888P, 45 | CVI_PIXFMT_BGR888P, 46 | CVI_PIXFMT_ARGB1555, 47 | CVI_PIXFMT_ARGB4444, 48 | CVI_PIXFMT_ARGB8888, 49 | CVI_PIXFMT_RGB_BAYER_8BPP, 50 | CVI_PIXFMT_RGB_BAYER_10BPP, 51 | CVI_PIXFMT_RGB_BAYER_12BPP, 52 | CVI_PIXFMT_RGB_BAYER_14BPP, 53 | CVI_PIXFMT_RGB_BAYER_16BPP, 54 | CVI_PIXFMT_YUV422P, 55 | CVI_PIXFMT_YUV420P, 56 | CVI_PIXFMT_YUV444P, 57 | CVI_PIXFMT_YUV400, 58 | CVI_PIXFMT_HSV888, 59 | CVI_PIXFMT_HSV888P, 60 | CVI_PIXFMT_NV12, 61 | CVI_PIXFMT_NV21, 62 | CVI_PIXFMT_NV16, 63 | CVI_PIXFMT_NV61, 64 | CVI_PIXFMT_YUV422_YUYV, 65 | CVI_PIXFMT_YUV422_UYVY, 66 | CVI_PIXFMT_YUV422_YVYU, 67 | CVI_PIXFMT_YUV422_VYUY, 68 | CVI_PIXFMT_FP32C1 = 32, 69 | CVI_PIXFMT_FP32C3P, 70 | CVI_PIXFMT_S32C1, 71 | CVI_PIXFMT_S32C3P, 72 | CVI_PIXFMT_U32C1, 73 | CVI_PIXFMT_U32C3P, 74 | CVI_PIXFMT_BF16C1, 75 | CVI_PIXFMT_BF16C3P, 76 | CVI_PIXFMT_S16C1, 77 | CVI_PIXFMT_S16C3P, 78 | CVI_PIXFMT_U16C1, 79 | CVI_PIXFMT_U16C3P, 80 | CVI_PIXFMT_S8C1, 81 | CVI_PIXFMT_S8C3P, 82 | CVI_PIXFMT_U8C1, 83 | CVI_PIXFMT_U8C3P, 84 | CVI_PIXFMT_8BITMODE = 48, 85 | CVI_PIXFMT_END 86 | } cvi_common_pixfmt; 87 | 88 | typedef enum { 89 | CVI_PREC_8BPP, 90 | CVI_PREC_10BPP, 91 | CVI_PREC_12BPP, 92 | CVI_PREC_14BPP, 93 | CVI_PREC_16BPP, 94 | CVI_PREC_END 95 | } cvi_common_prec; 96 | 97 | typedef enum { 98 | CVI_WDR_NONE, 99 | CVI_WDR_BUILTIN, 100 | CVI_WDR_QUDRA, 101 | CVI_WDR_2TO1_LINE, 102 | CVI_WDR_2TO1_FRAME, 103 | CVI_WDR_2TO1_FRAME_FULLRATE, 104 | CVI_WDR_3TO1_LINE, 105 | CVI_WDR_3TO1_FRAME, 106 | CVI_WDR_3TO1_FRAME_FULLRATE, 107 | CVI_WDR_4TO1_LINE, 108 | CVI_WDR_4TO1_FRAME, 109 | CVI_WDR_4TO1_FRAME_FULLRATE, 110 | CVI_WDR_END 111 | } cvi_common_wdr; 112 | 113 | typedef struct { 114 | unsigned int topWidth; 115 | unsigned int bottomWidth; 116 | unsigned int leftWidth; 117 | unsigned int rightWidth; 118 | unsigned int color; 119 | } cvi_common_bord; 120 | 121 | typedef struct { 122 | unsigned int width; 123 | unsigned int height; 124 | } cvi_common_dim; 125 | 126 | typedef struct { 127 | int x; 128 | int y; 129 | } cvi_common_pnt; 130 | 131 | typedef struct { 132 | int x; 133 | int y; 134 | unsigned int width; 135 | unsigned int height; 136 | } cvi_common_rect; 137 | -------------------------------------------------------------------------------- /src/hal/plus/cvi_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cvi_common.h" 4 | #include "cvi_aud.h" 5 | #include "cvi_config.h" 6 | #include "cvi_isp.h" 7 | #include "cvi_rgn.h" 8 | #include "cvi_snr.h" 9 | #include "cvi_sys.h" 10 | #include "cvi_vb.h" 11 | #include "cvi_venc.h" 12 | #include "cvi_vi.h" 13 | #include "cvi_vpss.h" 14 | 15 | #include 16 | #include 17 | 18 | extern char audioOn, keepRunning; 19 | 20 | extern hal_chnstate cvi_state[CVI_VENC_CHN_NUM]; 21 | extern int (*cvi_aud_cb)(hal_audframe*); 22 | extern int (*cvi_vid_cb)(char, hal_vidstream*); 23 | 24 | void cvi_hal_deinit(void); 25 | int cvi_hal_init(void); 26 | 27 | void cvi_audio_deinit(void); 28 | int cvi_audio_init(int samplerate); 29 | void *cvi_audio_thread(void); 30 | 31 | int cvi_channel_bind(char index); 32 | int cvi_channel_create(char index, short width, short height, char mirror, char flip); 33 | int cvi_channel_grayscale(char enable); 34 | int cvi_channel_unbind(char index); 35 | 36 | void *cvi_image_thread(void); 37 | 38 | int cvi_pipeline_create(void); 39 | void cvi_pipeline_destroy(void); 40 | 41 | int cvi_region_create(char handle, hal_rect rect, short opacity); 42 | void cvi_region_destroy(char handle); 43 | int cvi_region_setbitmap(int handle, hal_bitmap *bitmap); 44 | 45 | int cvi_sensor_config(void); 46 | void cvi_sensor_deconfig(void); 47 | void cvi_sensor_deinit(void); 48 | int cvi_sensor_init(char *name, char *obj); 49 | 50 | int cvi_video_create(char index, hal_vidconfig *config); 51 | int cvi_video_destroy(char index); 52 | int cvi_video_destroy_all(void); 53 | void cvi_video_request_idr(char index); 54 | int cvi_video_snapshot_grab(char index, hal_jpegdata *jpeg); 55 | void *cvi_video_thread(void); 56 | 57 | int cvi_system_calculate_block(short width, short height, cvi_common_pixfmt pixFmt, 58 | unsigned int alignWidth); 59 | void cvi_system_deinit(void); 60 | int cvi_system_init(char *snrConfig); -------------------------------------------------------------------------------- /src/hal/plus/cvi_vb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cvi_common.h" 4 | 5 | typedef struct { 6 | unsigned int count; 7 | struct { 8 | unsigned int blockSize; 9 | unsigned int blockCnt; 10 | // Accepts values from 0-2 (none, nocache, cached) 11 | int rempVirt; 12 | char heapName[32]; 13 | } comm[16]; 14 | } cvi_vb_pool; 15 | 16 | typedef struct { 17 | void *handle; 18 | 19 | int (*fnConfigPool)(cvi_vb_pool *config); 20 | int (*fnExit)(void); 21 | int (*fnInit)(void); 22 | } cvi_vb_impl; 23 | 24 | static int cvi_vb_load(cvi_vb_impl *vb_lib) { 25 | if (!(vb_lib->handle = dlopen("libsys.so", RTLD_LAZY | RTLD_GLOBAL))) 26 | HAL_ERROR("cvi_vb", "Failed to load library!\nError: %s\n", dlerror()); 27 | 28 | if (!(vb_lib->fnConfigPool = (int(*)(cvi_vb_pool *config)) 29 | hal_symbol_load("cvi_vb", vb_lib->handle, "CVI_VB_SetConfig"))) 30 | return EXIT_FAILURE; 31 | 32 | if (!(vb_lib->fnExit = (int(*)(void)) 33 | hal_symbol_load("cvi_vb", vb_lib->handle, "CVI_VB_Exit"))) 34 | return EXIT_FAILURE; 35 | 36 | if (!(vb_lib->fnInit = (int(*)(void)) 37 | hal_symbol_load("cvi_vb", vb_lib->handle, "CVI_VB_Init"))) 38 | return EXIT_FAILURE; 39 | 40 | return EXIT_SUCCESS; 41 | } 42 | 43 | static void cvi_vb_unload(cvi_vb_impl *vb_lib) { 44 | if (vb_lib->handle) dlclose(vb_lib->handle); 45 | vb_lib->handle = NULL; 46 | memset(vb_lib, 0, sizeof(*vb_lib)); 47 | } -------------------------------------------------------------------------------- /src/hal/plus/gm_aud.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define GM_AUD_CHN_NUM 1 4 | 5 | typedef enum { 6 | GM_AENC_TYPE_PCM = 1, 7 | GM_AENC_TYPE_AAC, 8 | GM_AENC_TYPE_ADPCM, 9 | GM_AENC_TYPE_G711A, 10 | GM_AENC_TYPE_G711U 11 | } gm_aenc_type; 12 | 13 | typedef struct { 14 | int internal[8]; 15 | gm_aenc_type codec; 16 | int bitrate; 17 | int packNumPerFrm; 18 | int reserved[4]; 19 | } gm_aenc_cnf; 20 | 21 | typedef struct { 22 | int internal[8]; 23 | int channel; 24 | int rate; 25 | int frmNum; 26 | // Must be 1 or 2 (mono or stereo) 27 | int chnNum; 28 | int reserved[5]; 29 | } gm_ain_cnf; -------------------------------------------------------------------------------- /src/hal/plus/gm_cap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef enum { 4 | GM_CAP_OUT_DISP, 5 | GM_CAP_OUT_VIDOUT, 6 | GM_CAP_OUT_SCALER1, 7 | GM_CAP_OUT_SCALER2 8 | } gm_cap_out; 9 | 10 | typedef struct { 11 | int internal[8]; 12 | int channel; 13 | // Scaler 2 generally cannot scale down 14 | gm_cap_out output; 15 | int motionDataOn; 16 | // Leave to zero to disable 17 | int intl2ProgThres; 18 | unsigned int dmaPath; 19 | unsigned short prescaleWidth; 20 | unsigned short prescaleHeight; 21 | int reserved[2]; 22 | } gm_cap_cnf; -------------------------------------------------------------------------------- /src/hal/plus/gm_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | #define GM_LIB_VER 0x41 11 | 12 | typedef enum { 13 | GM_LIB_DEV_CAPTURE = 0xFEFE0001, 14 | GM_LIB_DEV_VIDENC, 15 | GM_LIB_DEV_WINDOW, 16 | GM_LIB_DEV_FILE, 17 | GM_LIB_DEV_AUDIN, 18 | GM_LIB_DEV_AUDENC, 19 | GM_LIB_DEV_AUDOUT 20 | } gm_lib_dev; 21 | 22 | #define GM_DECLARE(hal, var, type, real) \ 23 | type var = ({hal.fnDeclareStruct(&var, real, sizeof(type), GM_LIB_VER); var;}) 24 | 25 | typedef struct { 26 | int width; 27 | int height; 28 | } gm_common_dim; 29 | 30 | typedef struct { 31 | unsigned int type; 32 | unsigned int bsLength; 33 | unsigned int mvLength; 34 | unsigned int isKeyFrame; 35 | } gm_common_pollevt; 36 | 37 | typedef struct { 38 | void *bind; 39 | unsigned int evType; 40 | gm_common_pollevt event; 41 | int internal[4]; 42 | } gm_common_pollfd; 43 | 44 | typedef struct { 45 | unsigned int x; 46 | unsigned int y; 47 | unsigned int width; 48 | unsigned int height; 49 | } gm_common_rect; 50 | 51 | typedef struct { 52 | char *bsData; 53 | unsigned int bsLength; 54 | char *mdData; 55 | unsigned int mdLength; 56 | unsigned int bsSize; 57 | unsigned int mdSize; 58 | int isKeyFrame; 59 | unsigned int timestamp; 60 | unsigned int bsChanged; 61 | unsigned int checksum; 62 | int isRefFrame; 63 | unsigned int sliceOff[3]; 64 | int reserved[5]; 65 | } gm_common_pack; 66 | 67 | typedef struct { 68 | void *bind; 69 | gm_common_pack pack; 70 | int ret; 71 | int reserved[6]; 72 | int internal[28]; 73 | } gm_common_strm; -------------------------------------------------------------------------------- /src/hal/plus/gm_osd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef enum { 4 | GM_ALIGN_TOP_LEFT, 5 | GM_ALIGN_TOP_CENTER, 6 | GM_ALIGN_TOP_RIGHT, 7 | GM_ALIGN_BOTTOM_LEFT, 8 | GM_ALIGN_BOTTOM_CENTER, 9 | GM_ALIGN_BOTTOM_RIGHT, 10 | GM_ALIGN_CENTER 11 | } gm_osd_align; 12 | 13 | typedef enum { 14 | GM_OSD_DIM_16PX, 15 | GM_OSD_DIM_32PX, 16 | GM_OSD_DIM_64PX, 17 | GM_OSD_DIM_128PX, 18 | GM_OSD_DIM_256PX, 19 | GM_OSD_DIM_512PX, 20 | GM_OSD_DIM_END 21 | } gm_osd_dim; 22 | 23 | typedef enum { 24 | GM_OSD_OPAL_100, 25 | GM_OSD_OPAL_75, 26 | GM_OSD_OPAL_62_5, 27 | GM_OSD_OPAL_50, 28 | GM_OSD_OPAL_37_5, 29 | GM_OSD_OPAL_25, 30 | GM_OSD_OPAL_12_5, 31 | GM_OSD_OPAL_0 32 | } gm_osd_opal; 33 | 34 | typedef enum { 35 | GM_OSD_ZOOM_1X, 36 | GM_OSD_ZOOM_2X, 37 | GM_OSD_ZOOM_4X 38 | } gm_osd_zoom; 39 | 40 | typedef struct { 41 | // Values >= 4 enable the OSG mode 42 | int channel; 43 | int enabled; 44 | unsigned int x; 45 | unsigned int y; 46 | gm_osd_opal opacity; 47 | gm_osd_zoom zoom; 48 | gm_osd_align align; 49 | unsigned short osgChan; 50 | char reserved[18]; 51 | } gm_osd_cnf; 52 | 53 | typedef struct { 54 | int exists; 55 | // Uses YUV422 pixel format 56 | char *buffer; 57 | // Must not exceed 16384 bytes, 8192 bytes for some chips 58 | unsigned int length; 59 | gm_osd_dim width; 60 | gm_osd_dim height; 61 | int osgTpColor; 62 | unsigned short osgChan; 63 | char reserved[14]; 64 | } gm_osd_img; 65 | 66 | typedef struct { 67 | // OSG mode only uses the first image 68 | gm_osd_img image[4]; 69 | int reserved[5]; 70 | } gm_osd_imgs; -------------------------------------------------------------------------------- /src/hal/plus/gm_venc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gm_common.h" 4 | 5 | // Considering the encoder modules we use (H.264 and JPEG) 6 | #define GM_VENC_CHN_NUM 2 7 | 8 | #define GM_VENC_SNAP_HEIGHT_MAX 576 9 | #define GM_VENC_SNAP_WIDTH_MAX 720 10 | 11 | typedef enum { 12 | GM_VENC_CKSUM_NONE, 13 | GM_VENC_CKSUM_ANY_CRC = 0x101, 14 | GM_VENC_CKSUM_ANY_SUM, 15 | GM_VENC_CKSUM_ANY_SUM32, 16 | GM_VENC_CKSUM_IDR_CRC = 0x201, 17 | GM_VENC_CKSUM_IDR_SUM, 18 | GM_VENC_CKSUM_IDR_SUM32 19 | } gm_venc_cksum; 20 | 21 | typedef enum { 22 | GM_VENC_FFWD_NONE, 23 | GM_VENC_FFWD_ONEFRAME = 2, 24 | GM_VENC_FFWD_THREEFRAMES = 4 25 | } gm_venc_ffwd; 26 | 27 | typedef enum { 28 | GM_VENC_H264CODE_DEFAULT, 29 | GM_VENC_H264CODE_CABAC, 30 | GM_VENC_H264CODE_CAVLC 31 | } gm_venc_h264code; 32 | 33 | typedef enum { 34 | GM_VENC_H264PROF_DEFAULT, 35 | GM_VENC_H264PROF_BASELINE = 66, 36 | GM_VENC_H264PROF_MAIN = 77, 37 | GM_VENC_H264PROF_HIGH = 100 38 | } gm_venc_h264prof; 39 | 40 | typedef enum { 41 | GM_VENC_H264PRES_DEFAULT, 42 | GM_VENC_H264PRES_PERFORMANCE, 43 | GM_VENC_H264PRES_BALANCED, 44 | GM_VENC_H264PRES_QUALITY 45 | } gm_venc_h264pres; 46 | 47 | typedef enum { 48 | GM_VENC_RATEMODE_CBR = 1, 49 | GM_VENC_RATEMODE_VBR = 2, 50 | GM_VENC_RATEMODE_ECBR = 3, 51 | GM_VENC_RATEMODE_EVBR = 4 52 | } gm_venc_ratemode; 53 | 54 | typedef struct { 55 | gm_venc_ratemode mode; 56 | int gop; 57 | int initQual; 58 | int minQual; 59 | int maxQual; 60 | int bitrate; 61 | int maxBitrate; 62 | int reserved[5]; 63 | } gm_venc_rate; 64 | 65 | typedef struct { 66 | void *bind; 67 | int quality; 68 | char *buffer; 69 | unsigned int length; 70 | gm_common_dim dest; 71 | int reserved1[3]; 72 | unsigned int timestamp; 73 | int reserved2[2]; 74 | } gm_venc_snap; 75 | 76 | typedef struct { 77 | int internal[8]; 78 | int multiSlice; 79 | int frameOrField; 80 | int grayscaleOn; 81 | int reserved[5]; 82 | } gm_venc_h264_adv; 83 | 84 | typedef struct { 85 | int internal[8]; 86 | gm_common_dim dest; 87 | int framerate; 88 | gm_venc_rate rate; 89 | int reserved3[2]; 90 | struct { 91 | gm_venc_h264prof profile:8; 92 | int level:8; 93 | gm_venc_h264pres preset:8; 94 | gm_venc_h264code coding:8; 95 | }; 96 | struct { 97 | char ipOffset:8; 98 | char roiDeltaQp:8; 99 | char reserved1:8; 100 | char reserved2:8; 101 | }; 102 | gm_venc_cksum cksumType; 103 | gm_venc_ffwd ffwdType; 104 | int reserved4[1]; 105 | } gm_venc_h264_cnf; 106 | 107 | typedef struct { 108 | int internal[8]; 109 | gm_common_dim dest; 110 | int framerate; 111 | int quality; 112 | gm_venc_ratemode mode; 113 | int bitrate; 114 | int maxBitrate; 115 | int reserved[2]; 116 | } gm_venc_mjpg_cnf; -------------------------------------------------------------------------------- /src/hal/plus/rk_aud.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rk_common.h" 4 | 5 | #define RK_AUD_CHN_NUM 2 6 | 7 | typedef enum { 8 | RK_AUD_BIT_8, 9 | RK_AUD_BIT_16, 10 | RK_AUD_BIT_24, 11 | RK_AUD_BIT_32, 12 | RK_AUD_BIT_FLOAT, 13 | RK_AUD_BIT_END 14 | } rk_aud_bit; 15 | 16 | typedef enum { 17 | RK_AUD_MODE_MONO, 18 | RK_AUD_MODE_STEREO, 19 | RK_AUD_MODE_4CH, 20 | RK_AUD_MODE_6CH, 21 | RK_AUD_MODE_8CH, 22 | RK_AUD_MODE_END 23 | } rk_aud_mode; 24 | 25 | typedef struct { 26 | unsigned int cardChnNum, cardRate; 27 | rk_aud_bit cardBit; 28 | // Accept industry standards from 29 | // 8000 to 96000Hz, plus 64000Hz 30 | unsigned int rate; 31 | rk_aud_bit bit; 32 | rk_aud_mode mode; 33 | // 8-to-16 bit, expand mode 34 | unsigned int expandOn; 35 | unsigned int frmNum; 36 | unsigned int packNumPerFrm; 37 | unsigned int chnNum; 38 | // If not setted, will use the device index 39 | // to open the audio card 40 | char cardName[8]; 41 | } rk_aud_cnf; 42 | 43 | typedef struct { 44 | void *mbBlk; 45 | rk_aud_bit bit; 46 | rk_aud_mode mode; 47 | unsigned long long timestamp; 48 | unsigned int sequence; 49 | unsigned int length; 50 | int bypassMbOn; 51 | } rk_aud_frm; 52 | 53 | typedef struct { 54 | rk_aud_frm frame; 55 | char isValid; 56 | char isSysBound; 57 | } rk_aud_efrm; 58 | 59 | typedef struct { 60 | void *handle; 61 | 62 | int (*fnDisableDevice)(int device); 63 | int (*fnEnableDevice)(int device); 64 | int (*fnSetDeviceConfig)(int device, rk_aud_cnf *config); 65 | 66 | int (*fnDisableChannel)(int device, int channel); 67 | int (*fnEnableChannel)(int device, int channel); 68 | 69 | int (*fnFreeFrame)(int device, int channel, rk_aud_frm *frame, rk_aud_efrm *encFrame); 70 | int (*fnGetFrame)(int device, int channel, rk_aud_frm *frame, rk_aud_efrm *encFrame, int millis); 71 | } rk_aud_impl; 72 | 73 | static int rk_aud_load(rk_aud_impl *aud_lib) { 74 | if (!(aud_lib->handle = dlopen("librockit.so", RTLD_LAZY | RTLD_GLOBAL))) 75 | HAL_ERROR("rk_aud", "Failed to load library!\nError: %s\n", dlerror()); 76 | 77 | if (!(aud_lib->fnDisableDevice = (int(*)(int device)) 78 | hal_symbol_load("rk_aud", aud_lib->handle, "RK_MPI_AI_Disable"))) 79 | return EXIT_FAILURE; 80 | 81 | if (!(aud_lib->fnEnableDevice = (int(*)(int device)) 82 | hal_symbol_load("rk_aud", aud_lib->handle, "RK_MPI_AI_Enable"))) 83 | return EXIT_FAILURE; 84 | 85 | if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, rk_aud_cnf *config)) 86 | hal_symbol_load("rk_aud", aud_lib->handle, "RK_MPI_AI_SetPubAttr"))) 87 | return EXIT_FAILURE; 88 | 89 | if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel)) 90 | hal_symbol_load("rk_aud", aud_lib->handle, "RK_MPI_AI_DisableChn"))) 91 | return EXIT_FAILURE; 92 | 93 | if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel)) 94 | hal_symbol_load("rk_aud", aud_lib->handle, "RK_MPI_AI_EnableChn"))) 95 | return EXIT_FAILURE; 96 | 97 | if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, rk_aud_frm *frame, rk_aud_efrm *encFrame)) 98 | hal_symbol_load("rk_aud", aud_lib->handle, "RK_MPI_AI_ReleaseFrame"))) 99 | return EXIT_FAILURE; 100 | 101 | if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, rk_aud_frm *frame, rk_aud_efrm *encFrame, int millis)) 102 | hal_symbol_load("rk_aud", aud_lib->handle, "RK_MPI_AI_GetFrame"))) 103 | return EXIT_FAILURE; 104 | 105 | return EXIT_SUCCESS; 106 | } 107 | 108 | static void rk_aud_unload(rk_aud_impl *aud_lib) { 109 | if (aud_lib->handle) dlclose(aud_lib->handle); 110 | aud_lib->handle = NULL; 111 | memset(aud_lib, 0, sizeof(*aud_lib)); 112 | } -------------------------------------------------------------------------------- /src/hal/plus/rk_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rk_common.h" 4 | #include "rk_aiq.h" 5 | #include "rk_aud.h" 6 | #include "rk_mb.h" 7 | #include "rk_rgn.h" 8 | #include "rk_sys.h" 9 | #include "rk_venc.h" 10 | #include "rk_vi.h" 11 | #include "rk_vpss.h" 12 | 13 | #include "../support.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | extern char audioOn, keepRunning; 22 | 23 | extern hal_chnstate rk_state[RK_VENC_CHN_NUM]; 24 | extern int (*rk_aud_cb)(hal_audframe*); 25 | extern int (*rk_vid_cb)(char, hal_vidstream*); 26 | 27 | void rk_hal_deinit(void); 28 | int rk_hal_init(void); 29 | 30 | void rk_audio_deinit(void); 31 | int rk_audio_init(int samplerate); 32 | void *rk_audio_thread(void); 33 | 34 | int rk_channel_bind(char index); 35 | int rk_channel_create(char index, short width, short height, char mirror, char flip); 36 | int rk_channel_grayscale(char enable); 37 | int rk_channel_unbind(char index); 38 | 39 | int rk_pipeline_create(short width, short height); 40 | void rk_pipeline_destroy(void); 41 | 42 | int rk_region_create(char handle, hal_rect rect, short opacity); 43 | void rk_region_destroy(char handle); 44 | int rk_region_setbitmap(int handle, hal_bitmap *bitmap); 45 | 46 | int rk_sensor_find_v4l2_endpoint(void); 47 | 48 | int rk_video_create(char index, hal_vidconfig *config); 49 | int rk_video_destroy(char index); 50 | int rk_video_destroy_all(void); 51 | void rk_video_request_idr(char index); 52 | int rk_video_snapshot_grab(char index, hal_jpegdata *jpeg); 53 | void *rk_video_thread(void); 54 | 55 | int rk_system_calculate_block(short width, short height, rk_common_pixfmt pixFmt, 56 | unsigned int alignWidth); 57 | void rk_system_deinit(void); 58 | int rk_system_init(char *snrConfig); -------------------------------------------------------------------------------- /src/hal/plus/rk_mb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rk_common.h" 4 | 5 | typedef struct { 6 | void *handle; 7 | 8 | char* (*fnGetData)(void *block); 9 | 10 | } rk_mb_impl; 11 | 12 | static int rk_mb_load(rk_mb_impl *mb_lib) { 13 | if (!(mb_lib->handle = dlopen("librockit.so", RTLD_LAZY | RTLD_GLOBAL))) 14 | HAL_ERROR("rk_mb", "Failed to load library!\nError: %s\n", dlerror()); 15 | 16 | if (!(mb_lib->fnGetData = (char*(*)(void *block)) 17 | hal_symbol_load("rk_mb", mb_lib->handle, "RK_MPI_MB_Handle2VirAddr"))) 18 | return EXIT_FAILURE; 19 | 20 | return EXIT_SUCCESS; 21 | } 22 | 23 | static void rk_mb_unload(rk_mb_impl *mb_lib) { 24 | if (mb_lib->handle) dlclose(mb_lib->handle); 25 | mb_lib->handle = NULL; 26 | memset(mb_lib, 0, sizeof(*mb_lib)); 27 | } -------------------------------------------------------------------------------- /src/hal/plus/rk_sys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rk_common.h" 4 | 5 | #define RK_SYS_API "1.0" 6 | 7 | typedef enum { 8 | RK_SYS_MOD_CMPI, 9 | RK_SYS_MOD_VB, 10 | RK_SYS_MOD_SYS, 11 | RK_SYS_MOD_RGN, 12 | RK_SYS_MOD_VENC, 13 | RK_SYS_MOD_VDEC, 14 | RK_SYS_MOD_VPSS, 15 | RK_SYS_MOD_VGS, 16 | RK_SYS_MOD_VI, 17 | RK_SYS_MOD_VO, 18 | RK_SYS_MOD_AI, 19 | RK_SYS_MOD_AO, 20 | RK_SYS_MOD_AENC, 21 | RK_SYS_MOD_ADEC, 22 | RK_SYS_MOD_TDE, 23 | RK_SYS_MOD_ISP, 24 | RK_SYS_MOD_WBC, 25 | RK_SYS_MOD_AVS, 26 | RK_SYS_MOD_RGA, 27 | RK_SYS_MOD_AF, 28 | RK_SYS_MOD_IVS, 29 | RK_SYS_MOD_GPU, 30 | RK_SYS_MOD_NN, 31 | RK_SYS_MOD_END 32 | } rk_sys_mod; 33 | 34 | typedef struct { 35 | rk_sys_mod module; 36 | int device; 37 | int channel; 38 | } rk_sys_bind; 39 | 40 | typedef struct { 41 | char version[64]; 42 | } rk_sys_ver; 43 | 44 | typedef struct { 45 | void *handle; 46 | 47 | int (*fnExit)(void); 48 | int (*fnInit)(void); 49 | 50 | int (*fnBind)(rk_sys_bind *source, rk_sys_bind *dest); 51 | int (*fnUnbind)(rk_sys_bind *source, rk_sys_bind *dest); 52 | } rk_sys_impl; 53 | 54 | static int rk_sys_load(rk_sys_impl *sys_lib) { 55 | if (!(sys_lib->handle = dlopen("librockit.so", RTLD_LAZY | RTLD_GLOBAL))) 56 | HAL_ERROR("rk_sys", "Failed to load library!\nError: %s\n", dlerror()); 57 | 58 | if (!(sys_lib->fnExit = (int(*)(void)) 59 | hal_symbol_load("rk_sys", sys_lib->handle, "RK_MPI_SYS_Exit"))) 60 | return EXIT_FAILURE; 61 | 62 | if (!(sys_lib->fnInit = (int(*)(void)) 63 | hal_symbol_load("rk_sys", sys_lib->handle, "RK_MPI_SYS_Init"))) 64 | return EXIT_FAILURE; 65 | 66 | if (!(sys_lib->fnBind = (int(*)(rk_sys_bind *source, rk_sys_bind *dest)) 67 | hal_symbol_load("rk_sys", sys_lib->handle, "RK_MPI_SYS_Bind"))) 68 | return EXIT_FAILURE; 69 | 70 | if (!(sys_lib->fnUnbind = (int(*)(rk_sys_bind *source, rk_sys_bind *dest)) 71 | hal_symbol_load("rk_sys", sys_lib->handle, "RK_MPI_SYS_UnBind"))) 72 | return EXIT_FAILURE; 73 | 74 | return EXIT_SUCCESS; 75 | } 76 | 77 | static void rk_sys_unload(rk_sys_impl *sys_lib) { 78 | if (sys_lib->handle) dlclose(sys_lib->handle); 79 | sys_lib->handle = NULL; 80 | memset(sys_lib, 0, sizeof(*sys_lib)); 81 | } -------------------------------------------------------------------------------- /src/hal/star/i3_aud.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i3_common.h" 4 | 5 | typedef struct { 6 | // Accept industry standards from 8000 to 48000Hz 7 | int rate; 8 | // Accepts from 4 to 24 bits 9 | int bit; 10 | int stereoOn; 11 | unsigned int length; 12 | int leftOrRight; 13 | int absTimeOn; 14 | } i3_aud_cnf; 15 | 16 | typedef struct { 17 | unsigned char *addr; 18 | int bit; 19 | int stereoOn; 20 | unsigned long long timestamp; 21 | unsigned int sequence; 22 | unsigned int length; 23 | void *reserved; 24 | } i3_aud_frm; 25 | 26 | typedef struct { 27 | void *handle; 28 | 29 | int (*fnDisableDevice)(int device); 30 | int (*fnEnableDevice)(int device); 31 | int (*fnSetDeviceConfig)(int device, i3_aud_cnf *config); 32 | 33 | int (*fnDisableChannel)(int device, int channel); 34 | int (*fnEnableChannel)(int device, int channel); 35 | 36 | int (*fnSetMute)(int device, int *muteOn); 37 | int (*fnSetVolume)(int device, int dbLevel); 38 | 39 | int (*fnFreeFrame)(int device, int channel, i3_aud_frm *frame); 40 | int (*fnGetFrame)(int device, int channel, i3_aud_frm *frame, int millis); 41 | int (*fnStartFrame)(int device, int channel); 42 | } i3_aud_impl; 43 | 44 | static int i3_aud_load(i3_aud_impl *aud_lib) { 45 | if (!(aud_lib->handle = dlopen("libmi.so", RTLD_LAZY | RTLD_GLOBAL))) 46 | HAL_ERROR("i3_aud", "Failed to load library!\nError: %s\n", dlerror()); 47 | 48 | if (!(aud_lib->fnDisableDevice = (int(*)(int device)) 49 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_Disable"))) 50 | return EXIT_FAILURE; 51 | 52 | if (!(aud_lib->fnEnableDevice = (int(*)(int device)) 53 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_Enable"))) 54 | return EXIT_FAILURE; 55 | 56 | if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, i3_aud_cnf *config)) 57 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_SetDevAttr"))) 58 | return EXIT_FAILURE; 59 | 60 | if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel)) 61 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_DisableChn"))) 62 | return EXIT_FAILURE; 63 | 64 | if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel)) 65 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_EnableChn"))) 66 | return EXIT_FAILURE; 67 | 68 | if (!(aud_lib->fnSetMute = (int(*)(int device,int *muteOn)) 69 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_SetMute"))) 70 | return EXIT_FAILURE; 71 | 72 | if (!(aud_lib->fnSetVolume = (int(*)(int device, int dbLevel)) 73 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_SetVolume"))) 74 | return EXIT_FAILURE; 75 | 76 | if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, i3_aud_frm *frame)) 77 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_ReleaseFrame"))) 78 | return EXIT_FAILURE; 79 | 80 | if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, i3_aud_frm *frame, int millis)) 81 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_GetFrame"))) 82 | return EXIT_FAILURE; 83 | 84 | if (!(aud_lib->fnStartFrame = (int(*)(int device, int channel)) 85 | hal_symbol_load("i3_aud", aud_lib->handle, "MI_AI_StartFrame"))) 86 | return EXIT_FAILURE; 87 | 88 | return EXIT_SUCCESS; 89 | } 90 | 91 | static void i3_aud_unload(i3_aud_impl *aud_lib) { 92 | if (aud_lib->handle) dlclose(aud_lib->handle); 93 | aud_lib->handle = NULL; 94 | memset(aud_lib, 0, sizeof(*aud_lib)); 95 | } -------------------------------------------------------------------------------- /src/hal/star/i3_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | I3_MODE_TUNNEL, 12 | I3_MODE_USER, 13 | I3_MODE_SHARE, 14 | I3_MODE_NOT_TUNNEL, 15 | I3_MODE_INVALID 16 | } i3_common_mode; 17 | 18 | typedef enum { 19 | I3_PIXFMT_UNUSED, 20 | I3_PIXFMT_YUV422_YUYV, 21 | I3_PIXFMT_MSTAR_RAW16, 22 | I3_PIXFMT_MSTAR_YC16, 23 | I3_PIXFMT_MSTAR_STS16, 24 | I3_PIXFMT_YUV420SP, 25 | I3_PIXFMT_YUV420P, 26 | I3_PIXFMT_BGR565, 27 | I3_PIXFMT_ARGB4444, 28 | I3_PIXFMT_ARGB1555, 29 | I3_PIXFMT_RGB888, 30 | I3_PIXFMT_ABGR8888, 31 | I3_PIXFMT_YUV400, 32 | I3_PIXFMT_END 33 | } i3_common_pixfmt; 34 | 35 | typedef struct { 36 | unsigned int width; 37 | unsigned int height; 38 | } i3_common_dim; 39 | 40 | typedef struct { 41 | int x; 42 | int y; 43 | } i3_common_pnt; 44 | 45 | typedef struct { 46 | int x; 47 | int y; 48 | unsigned int width; 49 | unsigned int height; 50 | } i3_common_rect; -------------------------------------------------------------------------------- /src/hal/star/i3_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i3_common.h" 4 | #include "i3_aud.h" 5 | #include "i3_isp.h" 6 | #include "i3_osd.h" 7 | #include "i3_sys.h" 8 | #include "i3_venc.h" 9 | #include "i3_vi.h" 10 | 11 | #include "../support.h" 12 | 13 | #include 14 | #include 15 | 16 | extern char audioOn, keepRunning; 17 | 18 | extern hal_chnstate i3_state[I3_VENC_CHN_NUM]; 19 | extern int (*i3_aud_cb)(hal_audframe*); 20 | extern int (*i3_vid_cb)(char, hal_vidstream*); 21 | 22 | void i3_hal_deinit(void); 23 | int i3_hal_init(void); 24 | 25 | /*void i3_audio_deinit(void); 26 | int i3_audio_init(int samplerate); 27 | void *i3_audio_thread(void); 28 | 29 | int i3_channel_bind(char index, char framerate); 30 | int i3_channel_create(char index, short width, short height, char mirror, char flip, char jpeg); 31 | int i3_channel_grayscale(char enable); 32 | int i3_channel_unbind(char index);*/ 33 | 34 | int i3_config_load(char *path); 35 | 36 | /*int i3_pipeline_create(char sensor, short width, short height, char framerate); 37 | void i3_pipeline_destroy(void); 38 | 39 | int i3_region_create(char handle, hal_rect rect, short opacity); 40 | void i3_region_destroy(char handle); 41 | int i3_region_setbitmap(int handle, hal_bitmap *bitmap); 42 | 43 | int i3_video_create(char index, hal_vidconfig *config); 44 | int i3_video_destroy(char index); 45 | int i3_video_destroy_all(void); 46 | void i3_video_request_idr(char index); 47 | int i3_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg); 48 | void *i3_video_thread(void);*/ 49 | 50 | void i3_system_deinit(void); 51 | int i3_system_init(void); -------------------------------------------------------------------------------- /src/hal/star/i3_isp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i3_common.h" 4 | 5 | typedef struct { 6 | void *handle; 7 | 8 | int (*fnLoadChannelConfig)(int channel, char *path, unsigned int key); 9 | int (*fnSetColorToGray)(int channel, char *enable); 10 | } i3_isp_impl; 11 | 12 | static int i3_isp_load(i3_isp_impl *isp_lib) { 13 | if (!(isp_lib->handle = dlopen("libmi_isp.so", RTLD_LAZY | RTLD_GLOBAL))) 14 | HAL_ERROR("i3_isp", "Failed to load library!\nError: %s\n", dlerror()); 15 | 16 | if (!(isp_lib->fnLoadChannelConfig = (int(*)(int channel, char *path, unsigned int key)) 17 | hal_symbol_load("i3_isp", isp_lib->handle, "MI_ISP_Load_ISPCmdBinFile"))) 18 | return EXIT_FAILURE; 19 | 20 | if (!(isp_lib->fnSetColorToGray = (int(*)(int channel, char *enable)) 21 | hal_symbol_load("i3_isp", isp_lib->handle, "MI_ISP_SetColorToGray"))) 22 | return EXIT_FAILURE; 23 | 24 | return EXIT_SUCCESS; 25 | } 26 | 27 | static void i3_isp_unload(i3_isp_impl *isp_lib) { 28 | if (isp_lib->handle) dlclose(isp_lib->handle); 29 | isp_lib->handle = NULL; 30 | memset(isp_lib, 0, sizeof(*isp_lib)); 31 | } -------------------------------------------------------------------------------- /src/hal/star/i3_osd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i3_common.h" 4 | #include "i3_sys.h" 5 | 6 | typedef struct { 7 | i3_common_pixfmt pixFmt; 8 | unsigned short width; 9 | unsigned short height; 10 | unsigned char *data; 11 | } i3_osd_bmp; 12 | 13 | typedef struct { 14 | void *handle; 15 | 16 | int (*fnCreateRegion)(void *handle, int channel, i3_osd_bmp *bitmap, i3_common_pnt *point, i3_common_rect *rect); 17 | int (*fnDestroyRegion)(void *handle); 18 | int (*fnUpdateRegion)(void *handle, i3_osd_bmp *bitmap, i3_common_pnt *point, i3_common_rect *rect); 19 | } i3_osd_impl; 20 | 21 | static int i3_osd_load(i3_osd_impl *osd_lib) { 22 | if (!(osd_lib->handle = dlopen("libmi.so", RTLD_LAZY | RTLD_GLOBAL))) 23 | HAL_ERROR("i3_osd", "Failed to load library!\nError: %s\n", dlerror()); 24 | 25 | if (!(osd_lib->fnCreateRegion = (int(*)(void *handle, int channel, i3_osd_bmp *bitmap, i3_common_pnt *point, i3_common_rect *rect)) 26 | hal_symbol_load("i3_osd", osd_lib->handle, "MI_OSD_CreateBitmapWidget"))) 27 | return EXIT_FAILURE; 28 | 29 | if (!(osd_lib->fnDestroyRegion = (int(*)(void *handle)) 30 | hal_symbol_load("i3_osd", osd_lib->handle, "MI_OSD_DestroyWidget"))) 31 | return EXIT_FAILURE; 32 | 33 | if (!(osd_lib->fnUpdateRegion = (int(*)(void *handle, i3_osd_bmp *bitmap, i3_common_pnt *point, i3_common_rect *rect)) 34 | hal_symbol_load("i3_osd", osd_lib->handle, "MI_OSD_UpdateBitmapWidget"))) 35 | return EXIT_FAILURE; 36 | 37 | return EXIT_SUCCESS; 38 | } 39 | 40 | static void i3_osd_unload(i3_osd_impl *osd_lib) { 41 | if (osd_lib->handle) dlclose(osd_lib->handle); 42 | osd_lib->handle = NULL; 43 | memset(osd_lib, 0, sizeof(*osd_lib)); 44 | } -------------------------------------------------------------------------------- /src/hal/star/i3_sys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i3_common.h" 4 | 5 | #define I3_SYS_API "1.0" 6 | 7 | typedef enum { 8 | I3_SYS_MOD_AI, 9 | I3_SYS_MOD_AO, 10 | I3_SYS_MOD_AENC, 11 | I3_SYS_MOD_ADEC, 12 | I3_SYS_MOD_VI, 13 | I3_SYS_MOD_VENC, 14 | I3_SYS_MOD_END, 15 | } i3_sys_mod; 16 | 17 | typedef struct { 18 | i3_sys_mod module; 19 | unsigned int device; 20 | unsigned int channel; 21 | } i3_sys_bind; 22 | 23 | typedef struct { 24 | char version[64]; 25 | } i3_sys_ver; 26 | 27 | typedef struct { 28 | void *handle; 29 | 30 | int (*fnExit)(void); 31 | int (*fnGetVersion)(i3_sys_ver *version); 32 | int (*fnInit)(void); 33 | int (*fnSetAlignment)(unsigned int *width); 34 | 35 | int (*fnBind)(i3_sys_bind *source, i3_sys_bind *dest); 36 | int (*fnUnbind)(i3_sys_bind *source, i3_sys_bind *dest); 37 | } i3_sys_impl; 38 | 39 | static int i3_sys_load(i3_sys_impl *sys_lib) { 40 | if (!(sys_lib->handle = dlopen("libmi.so", RTLD_LAZY | RTLD_GLOBAL))) 41 | HAL_ERROR("i3_sys", "Failed to load library!\nError: %s\n", dlerror()); 42 | 43 | if (!(sys_lib->fnExit = (int(*)(void)) 44 | hal_symbol_load("i3_sys", sys_lib->handle, "MI_SYS_Exit"))) 45 | return EXIT_FAILURE; 46 | 47 | if (!(sys_lib->fnGetVersion = (int(*)(i3_sys_ver *version)) 48 | hal_symbol_load("i3_sys", sys_lib->handle, "MI_SYS_GetVersion"))) 49 | return EXIT_FAILURE; 50 | 51 | if (!(sys_lib->fnInit = (int(*)(void)) 52 | hal_symbol_load("i3_sys", sys_lib->handle, "MI_SYS_Init"))) 53 | return EXIT_FAILURE; 54 | 55 | if (!(sys_lib->fnSetAlignment = (int(*)(unsigned int *width)) 56 | hal_symbol_load("i3_sys", sys_lib->handle, "MI_SYS_SetConf"))) 57 | return EXIT_FAILURE; 58 | 59 | if (!(sys_lib->fnBind = (int(*)(i3_sys_bind *source, i3_sys_bind *dest)) 60 | hal_symbol_load("i3_sys", sys_lib->handle, "MI_SYS_Bind"))) 61 | return EXIT_FAILURE; 62 | 63 | if (!(sys_lib->fnUnbind = (int(*)(i3_sys_bind *source, i3_sys_bind *dest)) 64 | hal_symbol_load("i3_sys", sys_lib->handle, "MI_SYS_UnBind"))) 65 | return EXIT_FAILURE; 66 | 67 | return EXIT_SUCCESS; 68 | } 69 | 70 | static void i3_sys_unload(i3_sys_impl *sys_lib) { 71 | if (sys_lib->handle) dlclose(sys_lib->handle); 72 | sys_lib->handle = NULL; 73 | memset(sys_lib, 0, sizeof(*sys_lib)); 74 | } -------------------------------------------------------------------------------- /src/hal/star/i3_vi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i3_common.h" 4 | 5 | typedef enum { 6 | I3_VI_SRC_VGA, 7 | I3_VI_SRC_YPBPR, 8 | I3_VI_SRC_CVBS, 9 | I3_VI_SRC_CVBS2, 10 | I3_VI_SRC_CVBS3, 11 | I3_VI_SRC_SVIDEO, 12 | I3_VI_SRC_DTV, 13 | I3_VI_SRC_SC0_VOP, 14 | I3_VI_SRC_SC1_VOP, 15 | I3_VI_SRC_SC2_VOP, 16 | I3_VI_SRC_BT656, 17 | I3_VI_SRC_BT656_1, 18 | I3_VI_SRC_CAMERA, 19 | I3_VI_SRC_HVSP, 20 | I3_VI_SRC_END, 21 | } i3_vi_src; 22 | 23 | typedef struct { 24 | i3_common_dim dest; 25 | i3_common_pixfmt pixFmt; 26 | i3_common_mode mode; 27 | void *reserved1; 28 | int reserved2[1]; 29 | } i3_vi_chn; 30 | 31 | typedef struct { 32 | int enable; 33 | unsigned int x; 34 | unsigned int y; 35 | unsigned int width; 36 | unsigned int height; 37 | } i3_vi_crop; 38 | 39 | typedef struct { 40 | i3_vi_src source; 41 | float srcFps; 42 | i3_vi_crop crop; 43 | int reserved[1]; 44 | } i3_vi_dev; 45 | 46 | typedef struct { 47 | void *handle; 48 | 49 | int (*fnSetDeviceConfig)(i3_vi_dev *config); 50 | 51 | int (*fnDisableChannel)(int channel); 52 | int (*fnEnableChannel)(int channel); 53 | int (*fnSetChannelConfig)(int channel, i3_vi_chn *config); 54 | } i3_vi_impl; 55 | 56 | static int i3_vi_load(i3_vi_impl *vi_lib) { 57 | if (!(vi_lib->handle = dlopen("libmi.so", RTLD_LAZY | RTLD_GLOBAL))) 58 | HAL_ERROR("i3_vi", "Failed to load library!\nError: %s\n", dlerror()); 59 | 60 | if (!(vi_lib->fnSetDeviceConfig = (int(*)(i3_vi_dev *config)) 61 | hal_symbol_load("i3_vi", vi_lib->handle, "MI_VI_SetDevAttr"))) 62 | return EXIT_FAILURE; 63 | 64 | if (!(vi_lib->fnDisableChannel = (int(*)(int channel)) 65 | hal_symbol_load("i3_vi", vi_lib->handle, "MI_VI_DisableChn"))) 66 | return EXIT_FAILURE; 67 | 68 | if (!(vi_lib->fnEnableChannel = (int(*)(int channel)) 69 | hal_symbol_load("i3_vi", vi_lib->handle, "MI_VI_EnableChn"))) 70 | return EXIT_FAILURE; 71 | 72 | if (!(vi_lib->fnSetChannelConfig = (int(*)(int channel, i3_vi_chn *config)) 73 | hal_symbol_load("i3_vi", vi_lib->handle, "MI_VI_SetChnAttr"))) 74 | return EXIT_FAILURE; 75 | 76 | return EXIT_SUCCESS; 77 | } 78 | 79 | static void i3_vi_unload(i3_vi_impl *vi_lib) { 80 | if (vi_lib->handle) dlclose(vi_lib->handle); 81 | vi_lib->handle = NULL; 82 | memset(vi_lib, 0, sizeof(*vi_lib)); 83 | } -------------------------------------------------------------------------------- /src/hal/star/i6_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | I6_BAYER_RG, 12 | I6_BAYER_GR, 13 | I6_BAYER_BG, 14 | I6_BAYER_GB, 15 | I6_BAYER_R0, 16 | I6_BAYER_G0, 17 | I6_BAYER_B0, 18 | I6_BAYER_G1, 19 | I6_BAYER_G2, 20 | I6_BAYER_I0, 21 | I6_BAYER_G3, 22 | I6_BAYER_I1, 23 | I6_BAYER_END 24 | } i6_common_bayer; 25 | 26 | typedef enum { 27 | I6_COMPR_NONE, 28 | I6_COMPR_SEG, 29 | I6_COMPR_LINE, 30 | I6_COMPR_FRAME, 31 | // Valid on infinity6e only 32 | I6_COMPR_8BIT, 33 | I6_COMPR_END 34 | } i6_common_compr; 35 | 36 | typedef enum { 37 | I6_EDGE_SINGLE_UP, 38 | I6_EDGE_SINGLE_DOWN, 39 | I6_EDGE_DOUBLE, 40 | I6_EDGE_END 41 | } i6_common_edge; 42 | 43 | typedef enum { 44 | I6_HDR_OFF, 45 | I6_HDR_VC, 46 | I6_HDR_DOL, 47 | I6_HDR_EMBED, 48 | I6_HDR_LI, 49 | I6_HDR_END 50 | } i6_common_hdr; 51 | 52 | typedef enum { 53 | I6_INPUT_VUVU = 0, 54 | I6_INPUT_UVUV, 55 | I6_INPUT_UYVY = 0, 56 | I6_INPUT_VYUY, 57 | I6_INPUT_YUYV, 58 | I6_INPUT_YVYU, 59 | I6_INPUT_END 60 | } i6_common_input; 61 | 62 | typedef enum { 63 | I6_INTF_BT656, 64 | I6_INTF_DIGITAL_CAMERA, 65 | I6_INTF_BT1120_STANDARD, 66 | I6_INTF_BT1120_INTERLEAVED, 67 | I6_INTF_MIPI, 68 | I6_INTF_END 69 | } i6_common_intf; 70 | 71 | typedef enum { 72 | I6_PREC_8BPP, 73 | I6_PREC_10BPP, 74 | I6_PREC_12BPP, 75 | I6_PREC_14BPP, 76 | I6_PREC_16BPP, 77 | I6_PREC_END 78 | } i6_common_prec; 79 | 80 | typedef enum { 81 | I6_PIXFMT_YUV422_YUYV, 82 | I6_PIXFMT_ARGB8888, 83 | I6_PIXFMT_ABGR8888, 84 | I6_PIXFMT_BGRA8888, 85 | I6_PIXFMT_RGB565, 86 | I6_PIXFMT_ARGB1555, 87 | I6_PIXFMT_ARGB4444, 88 | I6_PIXFMT_I2, 89 | I6_PIXFMT_I4, 90 | I6_PIXFMT_I8, 91 | I6_PIXFMT_YUV422SP, 92 | I6_PIXFMT_YUV420SP, 93 | I6_PIXFMT_YUV420SP_NV21, 94 | I6_PIXFMT_YUV420_MST, 95 | I6_PIXFMT_YUV422_UYVY, 96 | I6_PIXFMT_YUV422_YVYU, 97 | I6_PIXFMT_YUV422_VYUY, 98 | I6_PIXFMT_YC420_MSTITLE1_H264, 99 | I6_PIXFMT_YC420_MSTITLE2_H265, 100 | I6_PIXFMT_YC420_MSTITLE3_H265, 101 | I6_PIXFMT_RGB_BAYER, 102 | I6_PIXFMT_RGB_BAYER_END = 103 | I6_PIXFMT_RGB_BAYER + I6_PREC_END * I6_BAYER_END - 1, 104 | I6_PIXFMT_RGB888, 105 | I6_PIXFMT_BGR888, 106 | I6_PIXFMT_GRAY8, 107 | I6_PIXFMT_RGB101010, 108 | I6_PIXFMT_RGB888P, 109 | I6_PIXFMT_END 110 | } i6_common_pixfmt; 111 | 112 | typedef struct { 113 | unsigned short width; 114 | unsigned short height; 115 | } i6_common_dim; 116 | 117 | typedef struct { 118 | unsigned short x; 119 | unsigned short y; 120 | unsigned short width; 121 | unsigned short height; 122 | } i6_common_rect; 123 | 124 | typedef struct { 125 | int vsyncInv; 126 | int hsyncInv; 127 | int pixclkInv; 128 | unsigned int vsyncDelay; 129 | unsigned int hsyncDelay; 130 | unsigned int pixclkDelay; 131 | } i6_common_sync; -------------------------------------------------------------------------------- /src/hal/star/i6_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i6_common.h" 4 | #include "i6_aud.h" 5 | #include "i6_ipu.h" 6 | #include "i6_isp.h" 7 | #include "i6_rgn.h" 8 | #include "i6_snr.h" 9 | #include "i6_sys.h" 10 | #include "i6_venc.h" 11 | #include "i6_vif.h" 12 | #include "i6_vpe.h" 13 | 14 | #include "../support.h" 15 | 16 | #include 17 | #include 18 | 19 | extern char audioOn, keepRunning; 20 | 21 | extern hal_chnstate i6_state[I6_VENC_CHN_NUM]; 22 | extern int (*i6_aud_cb)(hal_audframe*); 23 | extern int (*i6_vid_cb)(char, hal_vidstream*); 24 | 25 | void i6_hal_deinit(void); 26 | int i6_hal_init(void); 27 | 28 | void i6_audio_deinit(void); 29 | int i6_audio_init(int samplerate, int gain); 30 | void *i6_audio_thread(void); 31 | 32 | int i6_channel_bind(char index, char framerate); 33 | int i6_channel_create(char index, short width, short height, char jpeg); 34 | int i6_channel_grayscale(char enable); 35 | int i6_channel_unbind(char index); 36 | 37 | int i6_config_load(char *path); 38 | 39 | int i6_pipeline_create(char sensor, short width, short height, char mirror, char flip, char framerate); 40 | void i6_pipeline_destroy(void); 41 | 42 | int i6_region_create(char handle, hal_rect rect, short opacity); 43 | void i6_region_deinit(void); 44 | void i6_region_destroy(char handle); 45 | void i6_region_init(void); 46 | int i6_region_setbitmap(int handle, hal_bitmap *bitmap); 47 | 48 | int i6_sensor_exposure(unsigned int micros); 49 | 50 | int i6_video_create(char index, hal_vidconfig *config); 51 | int i6_video_destroy(char index); 52 | int i6_video_destroy_all(void); 53 | void i6_video_request_idr(char index); 54 | int i6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg); 55 | void *i6_video_thread(void); 56 | 57 | void i6_system_deinit(void); 58 | int i6_system_init(void); -------------------------------------------------------------------------------- /src/hal/star/i6_isp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i6_common.h" 4 | 5 | typedef struct { 6 | unsigned int minShutterUs; 7 | unsigned int maxShutterUs; 8 | unsigned int minApertX10; 9 | unsigned int maxApertX10; 10 | unsigned int minSensorGain; 11 | unsigned int minIspGain; 12 | unsigned int maxSensorGain; 13 | unsigned int maxIspGain; 14 | } i6_isp_exp; 15 | 16 | typedef struct { 17 | int params[13]; 18 | } i6_isp_p3a; 19 | 20 | typedef struct { 21 | void *handle, *handleCus3a, *handleIspAlgo; 22 | 23 | int (*fnDisableUserspace3A)(int channel); 24 | int (*fnEnableUserspace3A)(int channel, i6_isp_p3a *params); 25 | int (*fnLoadChannelConfig)(int channel, char *path, unsigned int key); 26 | int (*fnSetColorToGray)(int channel, char *enable); 27 | int (*fnGetExposureLimit)(int channel, i6_isp_exp *config); 28 | int (*fnSetExposureLimit)(int channel, i6_isp_exp *config); 29 | } i6_isp_impl; 30 | 31 | static int i6_isp_load(i6_isp_impl *isp_lib) { 32 | isp_lib->handleIspAlgo = dlopen("libispalgo.so", RTLD_LAZY | RTLD_GLOBAL); 33 | 34 | isp_lib->handleCus3a = dlopen("libcus3a.so", RTLD_LAZY | RTLD_GLOBAL); 35 | 36 | if (!(isp_lib->handle = dlopen("libmi_isp.so", RTLD_LAZY | RTLD_GLOBAL))) 37 | HAL_ERROR("i6_isp", "Failed to load library!\nError: %s\n", dlerror()); 38 | 39 | if (!(isp_lib->fnDisableUserspace3A = (int(*)(int channel)) 40 | hal_symbol_load("i6_isp", isp_lib->handle, "MI_ISP_DisableUserspace3A"))) 41 | return EXIT_FAILURE; 42 | 43 | if (!(isp_lib->fnEnableUserspace3A = (int(*)(int channel, i6_isp_p3a *params)) 44 | hal_symbol_load("i6_isp", isp_lib->handle, "MI_ISP_CUS3A_Enable"))) 45 | return EXIT_FAILURE; 46 | 47 | if (!(isp_lib->fnLoadChannelConfig = (int(*)(int channel, char *path, unsigned int key)) 48 | hal_symbol_load("i6_isp", isp_lib->handle, "MI_ISP_API_CmdLoadBinFile"))) 49 | return EXIT_FAILURE; 50 | 51 | if (!(isp_lib->fnSetColorToGray = (int(*)(int channel, char *enable)) 52 | hal_symbol_load("i6_isp", isp_lib->handle, "MI_ISP_IQ_SetColorToGray"))) 53 | return EXIT_FAILURE; 54 | 55 | if (!(isp_lib->fnGetExposureLimit = (int(*)(int channel, i6_isp_exp *config)) 56 | hal_symbol_load("i6_isp", isp_lib->handle, "MI_ISP_AE_GetExposureLimit"))) 57 | return EXIT_FAILURE; 58 | 59 | if (!(isp_lib->fnSetExposureLimit = (int(*)(int channel, i6_isp_exp *config)) 60 | hal_symbol_load("i6_isp", isp_lib->handle, "MI_ISP_AE_SetExposureLimit"))) 61 | return EXIT_FAILURE; 62 | 63 | return EXIT_SUCCESS; 64 | } 65 | 66 | static void i6_isp_unload(i6_isp_impl *isp_lib) { 67 | if (isp_lib->handle) dlclose(isp_lib->handle); 68 | isp_lib->handle = NULL; 69 | if (isp_lib->handleCus3a) dlclose(isp_lib->handleCus3a); 70 | isp_lib->handleCus3a = NULL; 71 | if (isp_lib->handleIspAlgo) dlclose(isp_lib->handleIspAlgo); 72 | isp_lib->handleIspAlgo = NULL; 73 | memset(isp_lib, 0, sizeof(*isp_lib)); 74 | } -------------------------------------------------------------------------------- /src/hal/star/i6_vif.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i6_common.h" 4 | 5 | typedef enum { 6 | I6_VIF_FRATE_FULL, 7 | I6_VIF_FRATE_HALF, 8 | I6_VIF_FRATE_QUART, 9 | I6_VIF_FRATE_OCTANT, 10 | I6_VIF_FRATE_3QUARTS, 11 | I6_VIF_FRATE_END 12 | } i6_vif_frate; 13 | 14 | typedef enum { 15 | I6_VIF_WORK_1MULTIPLEX, 16 | I6_VIF_WORK_2MULTIPLEX, 17 | I6_VIF_WORK_4MULTIPLEX, 18 | I6_VIF_WORK_RGB_REALTIME, 19 | I6_VIF_WORK_RGB_FRAME, 20 | I6_VIF_WORK_END 21 | } i6_vif_work; 22 | 23 | typedef struct { 24 | i6_common_intf intf; 25 | i6_vif_work work; 26 | i6_common_hdr hdr; 27 | i6_common_edge edge; 28 | i6_common_input input; 29 | char bitswap; 30 | i6_common_sync sync; 31 | } i6_vif_dev; 32 | 33 | typedef struct { 34 | i6_common_rect capt; 35 | i6_common_dim dest; 36 | // Values 0-3 correspond to No, Top, Bottom, Both 37 | int field; 38 | int interlaceOn; 39 | i6_common_pixfmt pixFmt; 40 | i6_vif_frate frate; 41 | unsigned int frameLineCnt; 42 | } i6_vif_port; 43 | 44 | typedef struct { 45 | void *handle; 46 | 47 | int (*fnDisableDevice)(int device); 48 | int (*fnEnableDevice)(int device); 49 | int (*fnSetDeviceConfig)(int device, i6_vif_dev *config); 50 | 51 | int (*fnDisablePort)(int channel, int port); 52 | int (*fnEnablePort)(int channel, int port); 53 | int (*fnSetPortConfig)(int channel, int port, i6_vif_port *config); 54 | } i6_vif_impl; 55 | 56 | static int i6_vif_load(i6_vif_impl *vif_lib) { 57 | if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) 58 | HAL_ERROR("i6_vif", "Failed to load library!\nError: %s\n", dlerror()); 59 | 60 | if (!(vif_lib->fnDisableDevice = (int(*)(int device)) 61 | hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_DisableDev"))) 62 | return EXIT_FAILURE; 63 | 64 | if (!(vif_lib->fnEnableDevice = (int(*)(int device)) 65 | hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_EnableDev"))) 66 | return EXIT_FAILURE; 67 | 68 | if (!(vif_lib->fnSetDeviceConfig = (int(*)(int device, i6_vif_dev *config)) 69 | hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_SetDevAttr"))) 70 | return EXIT_FAILURE; 71 | 72 | if (!(vif_lib->fnDisablePort = (int(*)(int channel, int port)) 73 | hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_DisableChnPort"))) 74 | return EXIT_FAILURE; 75 | 76 | if (!(vif_lib->fnEnablePort = (int(*)(int channel, int port)) 77 | hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_EnableChnPort"))) 78 | return EXIT_FAILURE; 79 | 80 | if (!(vif_lib->fnSetPortConfig = (int(*)(int channel, int port, i6_vif_port *config)) 81 | hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_SetChnPortAttr"))) 82 | return EXIT_FAILURE; 83 | 84 | return EXIT_SUCCESS; 85 | } 86 | 87 | static void i6_vif_unload(i6_vif_impl *vif_lib) { 88 | if (vif_lib->handle) dlclose(vif_lib->handle); 89 | vif_lib->handle = NULL; 90 | memset(vif_lib, 0, sizeof(*vif_lib)); 91 | } -------------------------------------------------------------------------------- /src/hal/star/i6c_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | I6C_BAYER_RG, 12 | I6C_BAYER_GR, 13 | I6C_BAYER_BG, 14 | I6C_BAYER_GB, 15 | I6C_BAYER_R0, 16 | I6C_BAYER_G0, 17 | I6C_BAYER_B0, 18 | I6C_BAYER_G1, 19 | I6C_BAYER_G2, 20 | I6C_BAYER_I0, 21 | I6C_BAYER_G3, 22 | I6C_BAYER_I1, 23 | I6C_BAYER_END 24 | } i6c_common_bayer; 25 | 26 | typedef enum { 27 | I6C_COMPR_NONE, 28 | I6C_COMPR_SEG, 29 | I6C_COMPR_LINE, 30 | I6C_COMPR_FRAME, 31 | I6C_COMPR_8BIT, 32 | I6C_COMPR_6BIT, 33 | I6C_COMPR_IFC, 34 | I6C_COMPR_SFBC0, 35 | I6C_COMPR_SFBC1, 36 | I6C_COMPR_SFBC2, 37 | I6C_COMPR_END 38 | } i6c_common_compr; 39 | 40 | typedef enum { 41 | I6C_EDGE_SINGLE_UP, 42 | I6C_EDGE_SINGLE_DOWN, 43 | I6C_EDGE_DOUBLE, 44 | I6C_EDGE_END 45 | } i6c_common_edge; 46 | 47 | typedef enum { 48 | I6C_HDR_OFF, 49 | I6C_HDR_VC, 50 | I6C_HDR_DOL, 51 | I6C_HDR_EMBED, 52 | I6C_HDR_LI, 53 | I6C_HDR_END 54 | } i6c_common_hdr; 55 | 56 | typedef enum { 57 | I6C_INTF_BT656, 58 | I6C_INTF_DIGITAL_CAMERA, 59 | I6C_INTF_BT1120_STANDARD, 60 | I6C_INTF_BT1120_INTERLEAVED, 61 | I6C_INTF_MIPI, 62 | I6C_INTF_LVDS, 63 | I6C_INTF_END 64 | } i6c_common_intf; 65 | 66 | typedef enum { 67 | I6C_PREC_8BPP, 68 | I6C_PREC_10BPP, 69 | I6C_PREC_12BPP, 70 | I6C_PREC_14BPP, 71 | I6C_PREC_16BPP, 72 | I6C_PREC_END 73 | } i6c_common_prec; 74 | 75 | typedef enum { 76 | I6C_PIXFMT_YUV422_YUYV, 77 | I6C_PIXFMT_ARGB8888, 78 | I6C_PIXFMT_ABGR8888, 79 | I6C_PIXFMT_BGRA8888, 80 | I6C_PIXFMT_RGB565, 81 | I6C_PIXFMT_ARGB1555, 82 | I6C_PIXFMT_ARGB4444, 83 | I6C_PIXFMT_I2, 84 | I6C_PIXFMT_I4, 85 | I6C_PIXFMT_I8, 86 | I6C_PIXFMT_YUV422SP, 87 | I6C_PIXFMT_YUV420SP, 88 | I6C_PIXFMT_YUV420SP_NV21, 89 | I6C_PIXFMT_YUV420_TILE, 90 | I6C_PIXFMT_YUV422_UYVY, 91 | I6C_PIXFMT_YUV422_YVYU, 92 | I6C_PIXFMT_YUV422_VYUY, 93 | I6C_PIXFMT_YUV422P, 94 | I6C_PIXFMT_YUV420P, 95 | I6C_PIXFMT_YUV420_FBC, 96 | I6C_PIXFMT_RGB_BAYER, 97 | I6C_PIXFMT_RGB_BAYER_END = 98 | I6C_PIXFMT_RGB_BAYER + I6C_PREC_END * I6C_BAYER_END - 1, 99 | I6C_PIXFMT_RGB888, 100 | I6C_PIXFMT_BGR888, 101 | I6C_PIXFMT_GRAY8, 102 | I6C_PIXFMT_RGB101010, 103 | I6C_PIXFMT_RGB888P, 104 | I6C_PIXFMT_END 105 | } i6c_common_pixfmt; 106 | 107 | typedef struct { 108 | unsigned short width; 109 | unsigned short height; 110 | } i6c_common_dim; 111 | 112 | typedef struct { 113 | unsigned short x; 114 | unsigned short y; 115 | unsigned short width; 116 | unsigned short height; 117 | } i6c_common_rect; -------------------------------------------------------------------------------- /src/hal/star/i6c_hal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i6c_common.h" 4 | #include "i6c_aud.h" 5 | #include "i6c_ipu.h" 6 | #include "i6c_isp.h" 7 | #include "i6c_rgn.h" 8 | #include "i6c_scl.h" 9 | #include "i6c_snr.h" 10 | #include "i6c_sys.h" 11 | #include "i6c_venc.h" 12 | #include "i6c_vif.h" 13 | 14 | #include 15 | #include 16 | 17 | extern char audioOn, keepRunning; 18 | 19 | extern hal_chnstate i6c_state[I6C_VENC_CHN_NUM]; 20 | extern int (*i6c_aud_cb)(hal_audframe*); 21 | extern int (*i6c_vid_cb)(char, hal_vidstream*); 22 | 23 | void i6c_hal_deinit(void); 24 | int i6c_hal_init(void); 25 | 26 | void i6c_audio_deinit(void); 27 | int i6c_audio_init(int samplerate, int gain); 28 | void *i6c_audio_thread(void); 29 | 30 | int i6c_channel_bind(char index, char framerate); 31 | int i6c_channel_create(char index, short width, short height, char jpeg); 32 | int i6c_channel_grayscale(char enable); 33 | int i6c_channel_unbind(char index); 34 | 35 | int i6c_config_load(char *path); 36 | 37 | int i6c_pipeline_create(char sensor, short width, short height, char mirror, char flip, char framerate); 38 | void i6c_pipeline_destroy(void); 39 | 40 | int i6c_region_create(char handle, hal_rect rect, short opacity); 41 | void i6c_region_deinit(void); 42 | void i6c_region_destroy(char handle); 43 | void i6c_region_init(void); 44 | int i6c_region_setbitmap(int handle, hal_bitmap *bitmap); 45 | 46 | int i6c_video_create(char index, hal_vidconfig *config); 47 | int i6c_video_destroy(char index); 48 | int i6c_video_destroy_all(void); 49 | void i6c_video_request_idr(char index); 50 | int i6c_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg); 51 | void *i6c_video_thread(void); 52 | 53 | void i6c_system_deinit(void); 54 | int i6c_system_init(void); -------------------------------------------------------------------------------- /src/hal/star/i6c_scl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i6c_common.h" 4 | 5 | typedef enum { 6 | I6C_SCL_BIND_INVALID, 7 | I6C_SCL_BIND_ID0 = 0x1, 8 | I6C_SCL_BIND_ID1 = 0x2, 9 | I6C_SCL_BIND_ID2 = 0x4, 10 | I6C_SCL_BIND_ID3 = 0x8, 11 | I6C_SCL_BIND_ID4 = 0x10, 12 | I6C_SCL_BIND_ID5 = 0x20, 13 | I6C_SCL_BIND_ID6 = 0x40, 14 | I6C_SCL_BIND_ID7 = 0x80, 15 | I6C_SCL_BIND_ID8 = 0x100, 16 | I6C_SCL_BIND_END = 0xffff, 17 | } i6c_scl_bind; 18 | 19 | typedef struct { 20 | i6c_common_rect crop; 21 | i6c_common_dim output; 22 | char mirror; 23 | char flip; 24 | i6c_common_pixfmt pixFmt; 25 | i6c_common_compr compress; 26 | } i6c_scl_port; 27 | 28 | typedef struct { 29 | void *handle; 30 | 31 | int (*fnCreateDevice)(int device, unsigned int *binds); 32 | int (*fnDestroyDevice)(int device); 33 | 34 | int (*fnAdjustChannelRotation)(int device, int channel, int *rotate); 35 | int (*fnCreateChannel)(int device, int channel, unsigned int *reserved); 36 | int (*fnDestroyChannel)(int device, int channel); 37 | int (*fnStartChannel)(int device, int channel); 38 | int (*fnStopChannel)(int device, int channel); 39 | 40 | int (*fnDisablePort)(int device, int channel, int port); 41 | int (*fnEnablePort)(int device, int channel, int port); 42 | int (*fnSetPortConfig)(int device, int channel, int port, i6c_scl_port *config); 43 | } i6c_scl_impl; 44 | 45 | static int i6c_scl_load(i6c_scl_impl *scl_lib) { 46 | if (!(scl_lib->handle = dlopen("libmi_scl.so", RTLD_LAZY | RTLD_GLOBAL))) 47 | HAL_ERROR("i6c_scl", "Failed to load library!\nError: %s\n", dlerror()); 48 | 49 | if (!(scl_lib->fnCreateDevice = (int(*)(int device, unsigned int *binds)) 50 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_CreateDevice"))) 51 | return EXIT_FAILURE; 52 | 53 | if (!(scl_lib->fnDestroyDevice = (int(*)(int device)) 54 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_DestroyDevice"))) 55 | return EXIT_FAILURE; 56 | 57 | if (!(scl_lib->fnAdjustChannelRotation = (int(*)(int device, int channel, int *rotate)) 58 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_SetChnParam"))) 59 | return EXIT_FAILURE; 60 | 61 | if (!(scl_lib->fnCreateChannel = (int(*)(int device, int channel, unsigned int *reserved)) 62 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_CreateChannel"))) 63 | return EXIT_FAILURE; 64 | 65 | if (!(scl_lib->fnDestroyChannel = (int(*)(int device, int channel)) 66 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_DestroyChannel"))) 67 | return EXIT_FAILURE; 68 | 69 | if (!(scl_lib->fnStartChannel = (int(*)(int device, int channel)) 70 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_StartChannel"))) 71 | return EXIT_FAILURE; 72 | 73 | if (!(scl_lib->fnStopChannel = (int(*)(int device, int channel)) 74 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_StopChannel"))) 75 | return EXIT_FAILURE; 76 | 77 | if (!(scl_lib->fnDisablePort = (int(*)(int device, int channel, int port)) 78 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_DisableOutputPort"))) 79 | return EXIT_FAILURE; 80 | 81 | if (!(scl_lib->fnEnablePort = (int(*)(int device, int channel, int port)) 82 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_EnableOutputPort"))) 83 | return EXIT_FAILURE; 84 | 85 | if (!(scl_lib->fnSetPortConfig = (int(*)(int device, int channel, int port, i6c_scl_port *config)) 86 | hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_SetOutputPortParam"))) 87 | return EXIT_FAILURE; 88 | 89 | return EXIT_SUCCESS; 90 | } 91 | 92 | static void i6c_scl_unload(i6c_scl_impl *scl_lib) { 93 | if (scl_lib->handle) dlclose(scl_lib->handle); 94 | scl_lib->handle = NULL; 95 | memset(scl_lib, 0, sizeof(*scl_lib)); 96 | } -------------------------------------------------------------------------------- /src/hal/star/m6_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../symbols.h" 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | M6_BAYER_RG, 12 | M6_BAYER_GR, 13 | M6_BAYER_BG, 14 | M6_BAYER_GB, 15 | M6_BAYER_R0, 16 | M6_BAYER_G0, 17 | M6_BAYER_B0, 18 | M6_BAYER_G1, 19 | M6_BAYER_G2, 20 | M6_BAYER_I0, 21 | M6_BAYER_G3, 22 | M6_BAYER_I1, 23 | M6_BAYER_END 24 | } m6_common_bayer; 25 | 26 | typedef enum { 27 | M6_COMPR_NONE, 28 | M6_COMPR_SEG, 29 | M6_COMPR_LINE, 30 | M6_COMPR_FRAME, 31 | M6_COMPR_8BIT, 32 | M6_COMPR_END 33 | } m6_common_compr; 34 | 35 | typedef enum { 36 | M6_EDGE_SINGLE_UP, 37 | M6_EDGE_SINGLE_DOWN, 38 | M6_EDGE_DOUBLE, 39 | M6_EDGE_END 40 | } m6_common_edge; 41 | 42 | typedef enum { 43 | M6_HDR_OFF, 44 | M6_HDR_VC, 45 | M6_HDR_DOL, 46 | M6_HDR_EMBED, 47 | M6_HDR_LI, 48 | M6_HDR_END 49 | } m6_common_hdr; 50 | 51 | typedef enum { 52 | M6_INTF_BT656, 53 | M6_INTF_DIGITAL_CAMERA, 54 | M6_INTF_BT1120_STANDARD, 55 | M6_INTF_BT1120_INTERLEAVED, 56 | M6_INTF_MIPI, 57 | M6_INTF_END 58 | } m6_common_intf; 59 | 60 | typedef enum { 61 | M6_PREC_8BPP, 62 | M6_PREC_10BPP, 63 | M6_PREC_12BPP, 64 | M6_PREC_14BPP, 65 | M6_PREC_16BPP, 66 | M6_PREC_END 67 | } m6_common_prec; 68 | 69 | typedef enum { 70 | M6_PIXFMT_YUV422_YUYV, 71 | M6_PIXFMT_ARGB8888, 72 | M6_PIXFMT_ABGR8888, 73 | M6_PIXFMT_BGRA8888, 74 | M6_PIXFMT_RGB565, 75 | M6_PIXFMT_ARGB1555, 76 | M6_PIXFMT_ARGB4444, 77 | M6_PIXFMT_I2, 78 | M6_PIXFMT_I4, 79 | M6_PIXFMT_I8, 80 | M6_PIXFMT_YUV422SP, 81 | M6_PIXFMT_YUV420SP, 82 | M6_PIXFMT_YUV420SP_NV21, 83 | M6_PIXFMT_YUV420_TILE, 84 | M6_PIXFMT_YUV422_UYVY, 85 | M6_PIXFMT_YUV422_YVYU, 86 | M6_PIXFMT_YUV422_VYUY, 87 | M6_PIXFMT_YUV422P, 88 | M6_PIXFMT_YUV420P, 89 | M6_PIXFMT_YUV420_FBC, 90 | M6_PIXFMT_RGB_BAYER, 91 | M6_PIXFMT_RGB_BAYER_END = 92 | M6_PIXFMT_RGB_BAYER + M6_PREC_END * M6_BAYER_END - 1, 93 | M6_PIXFMT_RGB888, 94 | M6_PIXFMT_BGR888, 95 | M6_PIXFMT_GRAY8, 96 | M6_PIXFMT_RGB101010, 97 | M6_PIXFMT_END 98 | } m6_common_pixfmt; 99 | 100 | typedef struct { 101 | unsigned short width; 102 | unsigned short height; 103 | } m6_common_dim; 104 | 105 | typedef struct { 106 | unsigned short x; 107 | unsigned short y; 108 | unsigned short width; 109 | unsigned short height; 110 | } m6_common_rect; -------------------------------------------------------------------------------- /src/hal/star/m6_hal.h: -------------------------------------------------------------------------------- 1 | #include "m6_common.h" 2 | #include "m6_aud.h" 3 | #include "m6_ipu.h" 4 | #include "m6_isp.h" 5 | #include "m6_rgn.h" 6 | #include "m6_scl.h" 7 | #include "m6_snr.h" 8 | #include "m6_sys.h" 9 | #include "m6_venc.h" 10 | #include "m6_vif.h" 11 | 12 | #include 13 | #include 14 | 15 | extern char audioOn, keepRunning; 16 | 17 | extern hal_chnstate m6_state[M6_VENC_CHN_NUM]; 18 | extern int (*m6_aud_cb)(hal_audframe*); 19 | extern int (*m6_vid_cb)(char, hal_vidstream*); 20 | 21 | void m6_hal_deinit(void); 22 | int m6_hal_init(void); 23 | 24 | void m6_audio_deinit(void); 25 | int m6_audio_init(int samplerate, int gain); 26 | void *m6_audio_thread(void); 27 | 28 | int m6_channel_bind(char index, char framerate); 29 | int m6_channel_create(char index, short width, short height, char jpeg); 30 | int m6_channel_grayscale(char enable); 31 | int m6_channel_unbind(char index); 32 | 33 | int m6_config_load(char *path); 34 | 35 | int m6_pipeline_create(char sensor, short width, short height, char mirror, char flip, char framerate); 36 | void m6_pipeline_destroy(void); 37 | 38 | int m6_region_create(char handle, hal_rect rect, short opacity); 39 | void m6_region_deinit(void); 40 | void m6_region_destroy(char handle); 41 | void m6_region_init(void); 42 | int m6_region_setbitmap(int handle, hal_bitmap *bitmap); 43 | 44 | int m6_video_create(char index, hal_vidconfig *config); 45 | int m6_video_destroy(char index); 46 | int m6_video_destroy_all(void); 47 | void m6_video_request_idr(char index); 48 | int m6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg); 49 | void *m6_video_thread(void); 50 | 51 | void m6_system_deinit(void); 52 | int m6_system_init(void); -------------------------------------------------------------------------------- /src/hal/star/m6_scl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m6_common.h" 4 | 5 | typedef enum { 6 | M6_SCL_BIND_INVALID, 7 | M6_SCL_BIND_ID0 = 0x1, 8 | M6_SCL_BIND_ID1 = 0x2, 9 | M6_SCL_BIND_ID2 = 0x4, 10 | M6_SCL_BIND_ID3 = 0x8, 11 | M6_SCL_BIND_ID4 = 0x10, 12 | M6_SCL_BIND_ID5 = 0x20, 13 | M6_SCL_BIND_END = 0xffff, 14 | } m6_scl_bind; 15 | 16 | typedef struct { 17 | m6_common_rect crop; 18 | m6_common_dim output; 19 | char mirror; 20 | char flip; 21 | m6_common_pixfmt pixFmt; 22 | m6_common_compr compress; 23 | } m6_scl_port; 24 | 25 | typedef struct { 26 | void *handle; 27 | 28 | int (*fnCreateDevice)(int device, unsigned int *binds); 29 | int (*fnDestroyDevice)(int device); 30 | 31 | int (*fnAdjustChannelRotation)(int device, int channel, int *rotate); 32 | int (*fnCreateChannel)(int device, int channel, unsigned int *reserved); 33 | int (*fnDestroyChannel)(int device, int channel); 34 | int (*fnStartChannel)(int device, int channel); 35 | int (*fnStopChannel)(int device, int channel); 36 | 37 | int (*fnDisablePort)(int device, int channel, int port); 38 | int (*fnEnablePort)(int device, int channel, int port); 39 | int (*fnSetPortConfig)(int device, int channel, int port, m6_scl_port *config); 40 | } m6_scl_impl; 41 | 42 | static int m6_scl_load(m6_scl_impl *scl_lib) { 43 | if (!(scl_lib->handle = dlopen("libmi_scl.so", RTLD_LAZY | RTLD_GLOBAL))) 44 | HAL_ERROR("m6_scl", "Failed to load library!\nError: %s\n", dlerror()); 45 | 46 | if (!(scl_lib->fnCreateDevice = (int(*)(int device, unsigned int *binds)) 47 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_CreateDevice"))) 48 | return EXIT_FAILURE; 49 | 50 | if (!(scl_lib->fnDestroyDevice = (int(*)(int device)) 51 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_DestroyDevice"))) 52 | return EXIT_FAILURE; 53 | 54 | if (!(scl_lib->fnAdjustChannelRotation = (int(*)(int device, int channel, int *rotate)) 55 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_SetChnParam"))) 56 | return EXIT_FAILURE; 57 | 58 | if (!(scl_lib->fnCreateChannel = (int(*)(int device, int channel, unsigned int *reserved)) 59 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_CreateChannel"))) 60 | return EXIT_FAILURE; 61 | 62 | if (!(scl_lib->fnDestroyChannel = (int(*)(int device, int channel)) 63 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_DestroyChannel"))) 64 | return EXIT_FAILURE; 65 | 66 | if (!(scl_lib->fnStartChannel = (int(*)(int device, int channel)) 67 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_StartChannel"))) 68 | return EXIT_FAILURE; 69 | 70 | if (!(scl_lib->fnStopChannel = (int(*)(int device, int channel)) 71 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_StopChannel"))) 72 | return EXIT_FAILURE; 73 | 74 | if (!(scl_lib->fnDisablePort = (int(*)(int device, int channel, int port)) 75 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_DisableOutputPort"))) 76 | return EXIT_FAILURE; 77 | 78 | if (!(scl_lib->fnEnablePort = (int(*)(int device, int channel, int port)) 79 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_EnableOutputPort"))) 80 | return EXIT_FAILURE; 81 | 82 | if (!(scl_lib->fnSetPortConfig = (int(*)(int device, int channel, int port, m6_scl_port *config)) 83 | hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_SetOutputPortParam"))) 84 | return EXIT_FAILURE; 85 | 86 | return EXIT_SUCCESS; 87 | } 88 | 89 | static void m6_scl_unload(m6_scl_impl *scl_lib) { 90 | if (scl_lib->handle) dlclose(scl_lib->handle); 91 | scl_lib->handle = NULL; 92 | memset(scl_lib, 0, sizeof(*scl_lib)); 93 | } -------------------------------------------------------------------------------- /src/hal/star/m6_vif.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "m6_common.h" 4 | 5 | typedef enum { 6 | M6_VIF_FRATE_FULL, 7 | M6_VIF_FRATE_HALF, 8 | M6_VIF_FRATE_QUART, 9 | M6_VIF_FRATE_OCTANT, 10 | M6_VIF_FRATE_3QUARTS, 11 | M6_VIF_FRATE_END 12 | } m6_vif_frate; 13 | 14 | typedef enum { 15 | M6_VIF_CLK_12MHZ, 16 | M6_VIF_CLK_18MHZ, 17 | M6_VIF_CLK_27MHZ, 18 | M6_VIF_CLK_36MHZ, 19 | M6_VIF_CLK_54MHZ, 20 | M6_VIF_CLK_108MHZ, 21 | M6_VIF_CLK_END 22 | } m6_vif_clk; 23 | 24 | typedef enum { 25 | M6_VIF_WORK_1MULTIPLEX, 26 | M6_VIF_WORK_2MULTIPLEX, 27 | M6_VIF_WORK_4MULTIPLEX, 28 | M6_VIF_WORK_END 29 | } m6_vif_work; 30 | 31 | typedef struct { 32 | m6_common_pixfmt pixFmt; 33 | m6_common_rect crop; 34 | // Values 0-3 correspond to No, Top, Bottom, Both 35 | int field; 36 | char halfHScan; 37 | } m6_vif_dev; 38 | 39 | typedef struct { 40 | m6_common_intf intf; 41 | m6_vif_work work; 42 | m6_common_hdr hdr; 43 | m6_common_edge edge; 44 | m6_vif_clk clock; 45 | int interlaceOn; 46 | unsigned int grpStitch; 47 | } m6_vif_grp; 48 | 49 | typedef struct { 50 | m6_common_rect capt; 51 | m6_common_dim dest; 52 | m6_common_pixfmt pixFmt; 53 | m6_vif_frate frate; 54 | } m6_vif_port; 55 | 56 | typedef struct { 57 | void *handle; 58 | 59 | int (*fnDisableDevice)(int device); 60 | int (*fnEnableDevice)(int device); 61 | int (*fnSetDeviceConfig)(int device, m6_vif_dev *config); 62 | 63 | int (*fnCreateGroup)(int group, m6_vif_grp *config); 64 | int (*fnDestroyGroup)(int group); 65 | 66 | int (*fnDisablePort)(int device, int port); 67 | int (*fnEnablePort)(int device, int port); 68 | int (*fnSetPortConfig)(int device, int port, m6_vif_port *config); 69 | } m6_vif_impl; 70 | 71 | static int m6_vif_load(m6_vif_impl *vif_lib) { 72 | if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) 73 | HAL_ERROR("m6_vif", "Failed to load library!\nError: %s\n", dlerror()); 74 | 75 | if (!(vif_lib->fnDisableDevice = (int(*)(int device)) 76 | hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_DisableDev"))) 77 | return EXIT_FAILURE; 78 | 79 | if (!(vif_lib->fnEnableDevice = (int(*)(int device)) 80 | hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_EnableDev"))) 81 | return EXIT_FAILURE; 82 | 83 | if (!(vif_lib->fnSetDeviceConfig = (int(*)(int device, m6_vif_dev *config)) 84 | hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_SetDevAttr"))) 85 | return EXIT_FAILURE; 86 | 87 | if (!(vif_lib->fnCreateGroup = (int(*)(int group, m6_vif_grp *config)) 88 | hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_CreateDevGroup"))) 89 | return EXIT_FAILURE; 90 | 91 | if (!(vif_lib->fnDestroyGroup = (int(*)(int group)) 92 | hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_DestroyDevGroup"))) 93 | return EXIT_FAILURE; 94 | 95 | if (!(vif_lib->fnDisablePort = (int(*)(int device, int port)) 96 | hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_DisableOutputPort"))) 97 | return EXIT_FAILURE; 98 | 99 | if (!(vif_lib->fnEnablePort = (int(*)(int device, int port)) 100 | hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_EnableOutputPort"))) 101 | return EXIT_FAILURE; 102 | 103 | if (!(vif_lib->fnSetPortConfig = (int(*)(int device, int port, m6_vif_port *config)) 104 | hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_SetOutputPortAttr"))) 105 | return EXIT_FAILURE; 106 | 107 | return EXIT_SUCCESS; 108 | } 109 | 110 | static void m6_vif_unload(m6_vif_impl *vif_lib) { 111 | if (vif_lib->handle) dlclose(vif_lib->handle); 112 | vif_lib->handle = NULL; 113 | memset(vif_lib, 0, sizeof(*vif_lib)); 114 | } -------------------------------------------------------------------------------- /src/hal/support.h: -------------------------------------------------------------------------------- 1 | #include "tools.h" 2 | #include "types.h" 3 | 4 | #if defined(__ARM_PCS_VFP) 5 | #include "star/i3_hal.h" 6 | #include "star/i6_hal.h" 7 | #include "star/i6c_hal.h" 8 | #include "star/m6_hal.h" 9 | #include "plus/rk_hal.h" 10 | #elif defined(__arm__) && !defined(__ARM_PCS_VFP) 11 | #include "plus/ak_hal.h" 12 | #include "plus/gm_hal.h" 13 | #include "hisi/v1_hal.h" 14 | #include "hisi/v2_hal.h" 15 | #include "hisi/v3_hal.h" 16 | #include "hisi/v4_hal.h" 17 | #elif defined(__mips__) 18 | #include "inge/t31_hal.h" 19 | #elif defined(__riscv) || defined(__riscv__) 20 | #include "plus/cvi_hal.h" 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | // Newer versions of musl have UAPI headers 28 | // that redefine struct sysinfo 29 | #if defined(__GLIBC__) || defined(__UCLIBC__) \ 30 | || LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | #ifdef __UCLIBC__ 37 | extern int asprintf(char **restrict strp, const char *restrict fmt, ...); 38 | #endif 39 | 40 | extern int sysinfo (struct sysinfo *__info); 41 | 42 | extern void *aud_thread; 43 | extern void *isp_thread; 44 | extern void *vid_thread; 45 | 46 | extern char chnCount; 47 | extern hal_chnstate *chnState; 48 | 49 | extern char chip[16]; 50 | extern char family[32]; 51 | extern hal_platform plat; 52 | extern char sensor[16]; 53 | extern int series; 54 | 55 | void hal_identify(void); 56 | float hal_temperature_read(void); -------------------------------------------------------------------------------- /src/hal/symbols.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "macros.h" 7 | 8 | static void inline *hal_symbol_load(const char *module, void *handle, const char *symbol) { 9 | void *function = dlsym(handle, symbol); 10 | if (!function) { 11 | HAL_DANGER(module, "Failed to acquire symbol %s!\n", symbol); 12 | return (void*)0; 13 | } 14 | return function; 15 | } -------------------------------------------------------------------------------- /src/hal/tools.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define SHA1_BLOCK_SIZE 64 23 | #define SHA1_DIGEST_SIZE 20 24 | 25 | typedef struct { 26 | unsigned int state[5]; 27 | unsigned int count[2]; 28 | unsigned char buffer[64]; 29 | } sha1_context; 30 | 31 | void *mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off); 32 | 33 | static inline int alt_isspace(int c) { 34 | return (c == ' ' || c == '\f' || c == '\n' || 35 | c == '\r' || c == '\t' || c == '\v'); 36 | } 37 | 38 | int base64_decode(char *decoded, const char *string, int maxLen); 39 | 40 | int base64_encode_length(int len); 41 | 42 | int base64_encode(char *encoded, const char *string, int len); 43 | 44 | int color_convert555(int color); 45 | 46 | int color_parse(const char *str); 47 | 48 | int compile_regex(regex_t *r, const char *regex_text); 49 | 50 | int escape_url(char *dst, const char *src, size_t maxlen); 51 | 52 | void generate_nonce(char *nonce, size_t len); 53 | 54 | const char *get_extension(const char *path); 55 | 56 | bool get_uint64(char *str, char *pattern, uint64_t *value); 57 | 58 | bool get_uint32(char *str, char *pattern, uint32_t *value); 59 | 60 | bool get_uint16(char *str, char *pattern, uint16_t *value); 61 | 62 | bool get_uint8(char *str, char *pattern, uint8_t *value); 63 | 64 | bool hal_registry(unsigned int addr, unsigned int *data, hal_register_op op); 65 | 66 | int hex_to_int(char value); 67 | 68 | unsigned int ip_to_int(const char *ip); 69 | 70 | char ip_in_cidr(const char *ip, const char *cidr); 71 | 72 | char *memstr(char *haystack, char *needle, int size, char needlesize); 73 | 74 | unsigned int millis(); 75 | 76 | void reverse(void *arr, size_t width); 77 | 78 | void sha1_init(sha1_context *context); 79 | 80 | void sha1_update(sha1_context *context, const unsigned char *data, unsigned int len); 81 | 82 | void sha1_final(unsigned char digest[20], sha1_context *context); 83 | 84 | char *split(char **input, char *sep); 85 | 86 | void unescape_uri(char *uri); 87 | 88 | void uuid_generate(char *uuid); -------------------------------------------------------------------------------- /src/hal/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "macros.h" 4 | 5 | #ifndef ALIGN_BACK 6 | #define ALIGN_BACK(x, a) (((x) / (a)) * (a)) 7 | #endif 8 | #ifndef ALIGN_UP 9 | #define ALIGN_UP(x, a) ((((x) + ((a)-1)) / a) * a) 10 | #endif 11 | #ifndef CEILING_2_POWER 12 | #define CEILING_2_POWER(x, a) (((x) + ((a)-1)) & (~((a) - 1))) 13 | #endif 14 | #ifndef MIN 15 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 16 | #endif 17 | #ifndef MAX 18 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 19 | #endif 20 | 21 | typedef enum { 22 | HAL_PLATFORM_UNK, 23 | HAL_PLATFORM_AK, 24 | HAL_PLATFORM_CVI, 25 | HAL_PLATFORM_GM, 26 | HAL_PLATFORM_I3, 27 | HAL_PLATFORM_I6, 28 | HAL_PLATFORM_I6C, 29 | HAL_PLATFORM_M6, 30 | HAL_PLATFORM_RK, 31 | HAL_PLATFORM_T31, 32 | HAL_PLATFORM_V1, 33 | HAL_PLATFORM_V2, 34 | HAL_PLATFORM_V3, 35 | HAL_PLATFORM_V4 36 | } hal_platform; 37 | 38 | typedef enum { 39 | OP_READ = 0b1, 40 | OP_WRITE = 0b10, 41 | OP_MODIFY = 0b11 42 | } hal_register_op; 43 | 44 | typedef enum { 45 | HAL_AUDCODEC_UNSPEC, 46 | HAL_AUDCODEC_MP3 = 0x69, 47 | HAL_AUDCODEC_NONE = 0xFF 48 | } hal_audcodec; 49 | 50 | typedef enum { 51 | HAL_VIDCODEC_UNSPEC, 52 | HAL_VIDCODEC_H264, 53 | HAL_VIDCODEC_H265, 54 | HAL_VIDCODEC_MJPG, 55 | HAL_VIDCODEC_JPG 56 | } hal_vidcodec; 57 | 58 | typedef enum { 59 | HAL_VIDMODE_CBR, 60 | HAL_VIDMODE_VBR, 61 | HAL_VIDMODE_QP, 62 | HAL_VIDMODE_ABR, 63 | HAL_VIDMODE_AVBR, 64 | HAL_VIDMODE_END 65 | } hal_vidmode; 66 | 67 | typedef enum { 68 | HAL_VIDPROFILE_BASELINE, 69 | HAL_VIDPROFILE_MAIN, 70 | HAL_VIDPROFILE_HIGH 71 | } hal_vidprofile; 72 | 73 | typedef struct { 74 | unsigned char *data[8]; 75 | unsigned int length[8]; 76 | unsigned int seq; 77 | unsigned int timestamp; 78 | char channelCnt; 79 | char interleavedOn; 80 | } hal_audframe; 81 | 82 | typedef struct { 83 | int fileDesc; 84 | char enable; 85 | char mainLoop; 86 | hal_vidcodec payload; 87 | } hal_chnstate; 88 | 89 | typedef struct { 90 | unsigned short width, height; 91 | } hal_dim; 92 | 93 | typedef struct { 94 | hal_dim dim; 95 | void *data; 96 | } hal_bitmap; 97 | 98 | typedef struct { 99 | unsigned char *data; 100 | unsigned int length; 101 | unsigned int jpegSize; 102 | } hal_jpegdata; 103 | 104 | typedef struct { 105 | unsigned short x, y, width, height; 106 | } hal_rect; 107 | 108 | typedef struct { 109 | unsigned short width, height; 110 | hal_vidcodec codec; 111 | hal_vidmode mode; 112 | hal_vidprofile profile; 113 | unsigned char gop, framerate, minQual, maxQual; 114 | unsigned short bitrate, maxBitrate; 115 | } hal_vidconfig; 116 | 117 | typedef struct { 118 | unsigned int length; 119 | unsigned int offset; 120 | int type; 121 | } hal_vidnalu; 122 | 123 | typedef struct { 124 | unsigned char *data; 125 | unsigned int length; 126 | int naluCnt; 127 | hal_vidnalu nalu[8]; 128 | unsigned int offset; 129 | unsigned long long timestamp; 130 | } hal_vidpack; 131 | 132 | typedef struct { 133 | hal_vidpack *pack; 134 | unsigned int count; 135 | unsigned int seq; 136 | } hal_vidstream; -------------------------------------------------------------------------------- /src/http_post.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "hal/macros.h" 14 | #include "jpeg.h" 15 | 16 | extern char keepRunning; 17 | 18 | void start_http_post_send(); 19 | void stop_http_post_send(); -------------------------------------------------------------------------------- /src/jpeg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "error.h" 15 | #include "hal/types.h" 16 | #include "media.h" 17 | #include "night.h" 18 | 19 | void jpeg_deinit(); 20 | int jpeg_init(); 21 | int jpeg_get(short width, short height, char quality, 22 | char grayscale, hal_jpegdata *jpeg); 23 | -------------------------------------------------------------------------------- /src/lib/miniz/miniz_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "miniz_export.h" 8 | 9 | /* ------------------- Types and macros */ 10 | typedef unsigned char mz_uint8; 11 | typedef int16_t mz_int16; 12 | typedef uint16_t mz_uint16; 13 | typedef uint32_t mz_uint32; 14 | typedef uint32_t mz_uint; 15 | typedef int64_t mz_int64; 16 | typedef uint64_t mz_uint64; 17 | typedef int mz_bool; 18 | 19 | #define MZ_FALSE (0) 20 | #define MZ_TRUE (1) 21 | 22 | /* Works around MSVC's spammy "warning C4127: conditional expression is constant" message. */ 23 | #ifdef _MSC_VER 24 | #define MZ_MACRO_END while (0, 0) 25 | #else 26 | #define MZ_MACRO_END while (0) 27 | #endif 28 | 29 | #ifdef MINIZ_NO_STDIO 30 | #define MZ_FILE void * 31 | #else 32 | #include 33 | #define MZ_FILE FILE 34 | #endif /* #ifdef MINIZ_NO_STDIO */ 35 | 36 | #ifdef MINIZ_NO_TIME 37 | typedef struct mz_dummy_time_t_tag 38 | { 39 | mz_uint32 m_dummy1; 40 | mz_uint32 m_dummy2; 41 | } mz_dummy_time_t; 42 | #define MZ_TIME_T mz_dummy_time_t 43 | #else 44 | #define MZ_TIME_T time_t 45 | #endif 46 | 47 | #define MZ_ASSERT(x) assert(x) 48 | 49 | #ifdef MINIZ_NO_MALLOC 50 | #define MZ_MALLOC(x) NULL 51 | #define MZ_FREE(x) (void)x, ((void)0) 52 | #define MZ_REALLOC(p, x) NULL 53 | #else 54 | #define MZ_MALLOC(x) malloc(x) 55 | #define MZ_FREE(x) free(x) 56 | #define MZ_REALLOC(p, x) realloc(p, x) 57 | #endif 58 | 59 | #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b)) 60 | #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b)) 61 | #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) 62 | #define MZ_CLEAR_ARR(obj) memset((obj), 0, sizeof(obj)) 63 | #define MZ_CLEAR_PTR(obj) memset((obj), 0, sizeof(*obj)) 64 | 65 | #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN 66 | #define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) 67 | #define MZ_READ_LE32(p) *((const mz_uint32 *)(p)) 68 | #else 69 | #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U)) 70 | #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U)) 71 | #endif 72 | 73 | #define MZ_READ_LE64(p) (((mz_uint64)MZ_READ_LE32(p)) | (((mz_uint64)MZ_READ_LE32((const mz_uint8 *)(p) + sizeof(mz_uint32))) << 32U)) 74 | 75 | #ifdef _MSC_VER 76 | #define MZ_FORCEINLINE __forceinline 77 | #elif defined(__GNUC__) 78 | #define MZ_FORCEINLINE __inline__ __attribute__((__always_inline__)) 79 | #else 80 | #define MZ_FORCEINLINE inline 81 | #endif 82 | 83 | #ifdef __cplusplus 84 | extern "C" 85 | { 86 | #endif 87 | 88 | extern MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); 89 | extern MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address); 90 | extern MINIZ_EXPORT void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size); 91 | 92 | #define MZ_UINT16_MAX (0xFFFFU) 93 | #define MZ_UINT32_MAX (0xFFFFFFFFU) 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif -------------------------------------------------------------------------------- /src/lib/miniz/miniz_export.h: -------------------------------------------------------------------------------- 1 | #define MINIZ_NO_ARCHIVE_APIS 2 | #define MINIZ_NO_ARCHIVE_WRITING_APIS 3 | #define MINIZ_NO_DEFLATE_APIS 4 | #define MINIZ_NO_STDIO 5 | #define MINIZ_NO_TIME 6 | 7 | #ifndef MINIZ_EXPORT 8 | #define MINIZ_EXPORT 9 | #endif -------------------------------------------------------------------------------- /src/lib/schrift.h: -------------------------------------------------------------------------------- 1 | /* This file is part of libschrift. 2 | * 3 | * © 2019-2022 Thomas Oltmann and contributors 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 16 | 17 | #ifndef SCHRIFT_H 18 | #define SCHRIFT_H 1 19 | 20 | #include /* size_t */ 21 | #include /* uint_fast32_t, uint_least32_t */ 22 | 23 | #define xreallocarray(ptr, nmemb, size) \ 24 | realloc(ptr, (nmemb) * size) 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #define SFT_DOWNWARD_Y 0x01 31 | 32 | typedef struct SFT SFT; 33 | typedef struct SFT_Font SFT_Font; 34 | typedef uint_least32_t SFT_UChar; /* Guaranteed to be compatible with char32_t. */ 35 | typedef uint_fast32_t SFT_Glyph; 36 | typedef struct SFT_LMetrics SFT_LMetrics; 37 | typedef struct SFT_GMetrics SFT_GMetrics; 38 | typedef struct SFT_Kerning SFT_Kerning; 39 | typedef struct SFT_Image SFT_Image; 40 | 41 | struct SFT 42 | { 43 | SFT_Font *font; 44 | double xScale; 45 | double yScale; 46 | double xOffset; 47 | double yOffset; 48 | int flags; 49 | }; 50 | 51 | struct SFT_LMetrics 52 | { 53 | double ascender; 54 | double descender; 55 | double lineGap; 56 | }; 57 | 58 | struct SFT_GMetrics 59 | { 60 | double advanceWidth; 61 | double leftSideBearing; 62 | int yOffset; 63 | int minWidth; 64 | int minHeight; 65 | }; 66 | 67 | struct SFT_Kerning 68 | { 69 | double xShift; 70 | double yShift; 71 | }; 72 | 73 | struct SFT_Image 74 | { 75 | void *pixels; 76 | int width; 77 | int height; 78 | }; 79 | 80 | extern void *__mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off); 81 | 82 | const char *sft_version(void); 83 | 84 | SFT_Font *sft_loadmem (const void *mem, size_t size); 85 | SFT_Font *sft_loadfile(const char *filename); 86 | void sft_freefont(SFT_Font *font); 87 | 88 | int sft_lmetrics(const SFT *sft, SFT_LMetrics *metrics); 89 | int sft_lookup (const SFT *sft, SFT_UChar codepoint, SFT_Glyph *glyph); 90 | int sft_gmetrics(const SFT *sft, SFT_Glyph glyph, SFT_GMetrics *metrics); 91 | int sft_kerning (const SFT *sft, SFT_Glyph leftGlyph, SFT_Glyph rightGlyph, 92 | SFT_Kerning *kerning); 93 | int sft_render (const SFT *sft, SFT_Glyph glyph, SFT_Image image); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif -------------------------------------------------------------------------------- /src/lib/shine/bitstream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bit_stream.c package 3 | * Author: Jean-Georges Fritsch, C-Cube Microsystems 4 | * 5 | * This package provides functions to write information to the bit stream. 6 | * 7 | * Removed unused functions. Feb 2001 P.Everett 8 | */ 9 | 10 | #include "bitstream.h" 11 | #include "types.h" 12 | 13 | #if !defined(__APPLE__) && !defined(__FreeBSD__) 14 | #include 15 | #endif 16 | 17 | /* open the device to write the bit stream into it */ 18 | void shine_open_bit_stream(bitstream_t *bs, int size) { 19 | bs->data = (unsigned char *)malloc(size * sizeof(unsigned char)); 20 | bs->data_size = size; 21 | bs->data_position = 0; 22 | bs->cache = 0; 23 | bs->cache_bits = 32; 24 | } 25 | 26 | /*close the device containing the bit stream */ 27 | void shine_close_bit_stream(bitstream_t *bs) { 28 | if (bs->data) 29 | free(bs->data); 30 | } 31 | 32 | /* 33 | * shine_putbits: 34 | * -------- 35 | * write N bits into the bit stream. 36 | * bs = bit stream structure 37 | * val = value to write into the buffer 38 | * N = number of bits of val 39 | */ 40 | void shine_putbits(bitstream_t *bs, unsigned int val, unsigned int N) { 41 | #ifdef DEBUG 42 | if (N > 32) 43 | printf("Cannot write more than 32 bits at a time.\n"); 44 | if (N < 32 && (val >> N) != 0) 45 | printf("Upper bits (higher than %d) are not all zeros.\n", N); 46 | #endif 47 | 48 | if (bs->cache_bits > N) { 49 | bs->cache_bits -= N; 50 | bs->cache |= val << bs->cache_bits; 51 | } else { 52 | if (bs->data_position + sizeof(unsigned int) >= bs->data_size) { 53 | bs->data = (unsigned char *)realloc(bs->data, 54 | bs->data_size + (bs->data_size / 2)); 55 | bs->data_size += (bs->data_size / 2); 56 | } 57 | 58 | N -= bs->cache_bits; 59 | bs->cache |= val >> N; 60 | #ifdef SHINE_BIG_ENDIAN 61 | *(unsigned int *)(bs->data + bs->data_position) = bs->cache; 62 | #else 63 | *(unsigned int *)(bs->data + bs->data_position) = SWAB32(bs->cache); 64 | #endif 65 | bs->data_position += sizeof(unsigned int); 66 | bs->cache_bits = 32 - N; 67 | if (N != 0) 68 | bs->cache = val << bs->cache_bits; 69 | else 70 | bs->cache = 0; 71 | } 72 | } 73 | 74 | /* 75 | * shine_flush_end_of_frame: 76 | * ------------------------- 77 | * Flush remaining bits of the frame to the bitstream. Must be called only at end of 78 | * frame, because only then is the cache guaranteed to be filled to a byte boundary. 79 | */ 80 | void shine_flush_end_of_frame(bitstream_t *bs) 81 | { 82 | int bits_to_flush; 83 | int cache_bytes; 84 | 85 | if (bs->cache_bits < 32) { 86 | bits_to_flush = 32 - bs->cache_bits; 87 | 88 | /* fill the remaining cache bits with zeros (they will be ignored). */ 89 | shine_putbits(bs, 0, bs->cache_bits); 90 | 91 | /* correct output position because a full 4 bytes may not have been written */ 92 | cache_bytes = bits_to_flush / 8; 93 | bs->data_position += cache_bytes - 4; 94 | 95 | /* clear the cache for the next frame */ 96 | bs->cache_bits = 32; 97 | bs->cache = 0; 98 | } 99 | } 100 | 101 | int shine_get_bits_count(bitstream_t *bs) { 102 | return bs->data_position * 8 + 32 - bs->cache_bits; 103 | } 104 | -------------------------------------------------------------------------------- /src/lib/shine/bitstream.h: -------------------------------------------------------------------------------- 1 | #ifndef BITSTREAM_H 2 | #define BITSTREAM_H 3 | 4 | typedef struct bit_stream_struc { 5 | unsigned char *data; /* Processed data */ 6 | int data_size; /* Total data size */ 7 | int data_position; /* Data position */ 8 | unsigned int cache; /* bit stream cache */ 9 | int cache_bits; /* free bits in cache */ 10 | } bitstream_t; 11 | 12 | /* "bit_stream.h" Definitions */ 13 | 14 | #define MINIMUM 4 /* Minimum size of the buffer in bytes */ 15 | #define MAX_LENGTH \ 16 | 32 /* Maximum length of word written or \ 17 | read from bit stream */ 18 | 19 | #define BUFFER_SIZE 4096 20 | 21 | #define MIN(A, B) ((A) < (B) ? (A) : (B)) 22 | #define MAX(A, B) ((A) > (B) ? (A) : (B)) 23 | 24 | void shine_open_bit_stream(bitstream_t *bs, const int size); 25 | void shine_close_bit_stream(bitstream_t *bs); 26 | void shine_putbits(bitstream_t *bs, unsigned int val, unsigned int N); 27 | void shine_flush_end_of_frame(bitstream_t *bs); 28 | int shine_get_bits_count(bitstream_t *bs); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/lib/shine/huffman.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define HUFFBITS uint16_t 4 | #define HTN 34 5 | #define MXOFF 250 6 | 7 | struct huffcodetab { 8 | unsigned int xlen; /*max. x-index+ */ 9 | unsigned int ylen; /*max. y-index+ */ 10 | unsigned int linbits; /*number of linbits */ 11 | unsigned int linmax; /*max number to be stored in linbits */ 12 | const HUFFBITS *table; /*pointer to array[xlen][ylen] */ 13 | const unsigned char *hlen; /*pointer to array[xlen][ylen] */ 14 | }; 15 | 16 | extern const struct huffcodetab 17 | shine_huffman_table[HTN]; /* global memory block */ 18 | /* array of all huffcodtable headers */ 19 | /* 0..31 Huffman code table 0..31 */ 20 | /* 32,33 count1-tables */ 21 | -------------------------------------------------------------------------------- /src/lib/shine/l3bitstream.h: -------------------------------------------------------------------------------- 1 | #ifndef shine_BITSTREAM_H 2 | #define shine_BITSTREAM_H 3 | 4 | #include "types.h" 5 | 6 | void shine_format_bitstream(shine_global_config *config); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/lib/shine/l3loop.h: -------------------------------------------------------------------------------- 1 | #ifndef L3LOOP_H 2 | #define L3LOOP_H 3 | 4 | #include "types.h" 5 | 6 | void shine_loop_initialise(shine_global_config *config); 7 | 8 | void shine_iteration_loop(shine_global_config *config); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/lib/shine/l3mdct.h: -------------------------------------------------------------------------------- 1 | #ifndef shine_MDCT_H 2 | #define shine_MDCT_H 3 | 4 | #include "types.h" 5 | 6 | void shine_mdct_initialise(shine_global_config *config); 7 | void shine_mdct_sub(shine_global_config *config, int stride); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/lib/shine/l3subband.h: -------------------------------------------------------------------------------- 1 | #ifndef L3SUBBAND_H 2 | #define L3SUBBAND_H 3 | 4 | #include "types.h" 5 | #include 6 | 7 | void shine_subband_initialise(shine_global_config *config); 8 | void shine_window_filter_subband(int16_t **buffer, int32_t s[SBLIMIT], int k, 9 | shine_global_config *config, int stride); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/lib/shine/mult_mips_gcc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define mul(a, b) \ 4 | ({ \ 5 | register int32_t res; \ 6 | __asm__ __volatile__("mult %0, %1" : : "r"(a), "r"(b)); \ 7 | __asm__ __volatile__("mfhi %0" : "=r"(res)); \ 8 | res; \ 9 | }) 10 | 11 | #define mul0(hi, lo, a, b) \ 12 | __asm__ __volatile__("mult %0, %1" : : "r"(a), "r"(b)) 13 | 14 | #define muladd(hi, lo, a, b) \ 15 | __asm__ __volatile__("madd %0, %1" : : "r"(a), "r"(b)) 16 | 17 | #define mulsub(hi, lo, a, b) \ 18 | __asm__ __volatile__("msub %0, %1" : : "r"(a), "r"(b)) 19 | 20 | #define mulz(hi, lo) \ 21 | do { \ 22 | register int32_t t; \ 23 | __asm__ __volatile__("mfhi %0" : "=r"(t)); \ 24 | (hi) = t; \ 25 | } while (0) 26 | 27 | #define cmuls(dre, dim, are, aim, bre, bim) \ 28 | do { \ 29 | register int32_t t1, t2, tre; \ 30 | __asm__ __volatile__("mult %0, %1" : : "r"(are), "r"(bre)); \ 31 | __asm__ __volatile__("msub %0, %1" : : "r"(aim), "r"(bim)); \ 32 | __asm__ __volatile__("mfhi %0; mflo %1" : "=r"(t1), "=r"(t2)); \ 33 | tre = (t1 << 1) | ((uint32_t)t2 >> 31); \ 34 | __asm__ __volatile__("mult %0, %1" : : "r"(are), "r"(bim)); \ 35 | __asm__ __volatile__("madd %0, %1" : : "r"(bre), "r"(aim)); \ 36 | dre = tre; \ 37 | __asm__ __volatile__("mfhi %0; mflo %1" : "=r"(t1), "=r"(t2)); \ 38 | dim = (t1 << 1) | ((uint32_t)t2 >> 31); \ 39 | } while (0) 40 | 41 | #if __mips_isa_rev >= 2 42 | static inline uint32_t SWAB32(uint32_t x) { 43 | __asm__(" wsbh %0, %1 \n" 44 | " rotr %0, %0, 16 \n" 45 | : "=r"(x) 46 | : "r"(x)); 47 | return x; 48 | } 49 | #define SWAB32 SWAB32 50 | #endif 51 | -------------------------------------------------------------------------------- /src/lib/shine/mult_noarch_gcc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef mul 4 | #define mul(a, b) (int32_t)((((int64_t)a) * ((int64_t)b)) >> 32) 5 | #endif 6 | 7 | #ifndef muls 8 | #define muls(a, b) (int32_t)((((int64_t)a) * ((int64_t)b)) >> 31) 9 | #endif 10 | 11 | #ifndef mulr 12 | #define mulr(a, b) \ 13 | (int32_t)(((((int64_t)a) * ((int64_t)b)) + 0x80000000LL) >> 32) 14 | #endif 15 | 16 | #ifndef mulsr 17 | #define mulsr(a, b) \ 18 | (int32_t)(((((int64_t)a) * ((int64_t)b)) + 0x40000000LL) >> 31) 19 | #endif 20 | 21 | #ifndef mul0 22 | #define mul0(hi, lo, a, b) ((hi) = mul((a), (b))) 23 | #define muladd(hi, lo, a, b) ((hi) += mul((a), (b))) 24 | #define mulsub(hi, lo, a, b) ((hi) -= mul((a), (b))) 25 | #define mulz(hi, lo) 26 | #endif 27 | 28 | #ifndef cmuls 29 | #define cmuls(dre, dim, are, aim, bre, bim) \ 30 | do { \ 31 | int32_t tre; \ 32 | (tre) = (int32_t)(((int64_t)(are) * (int64_t)(bre) - \ 33 | (int64_t)(aim) * (int64_t)(bim)) >> \ 34 | 31); \ 35 | (dim) = (int32_t)(((int64_t)(are) * (int64_t)(bim) + \ 36 | (int64_t)(aim) * (int64_t)(bre)) >> \ 37 | 31); \ 38 | (dre) = tre; \ 39 | } while (0) 40 | #endif 41 | -------------------------------------------------------------------------------- /src/lib/shine/reservoir.h: -------------------------------------------------------------------------------- 1 | #ifndef RESERVOIR_H 2 | #define RESERVOIR_H 3 | 4 | #include "types.h" 5 | 6 | void shine_ResvFrameBegin(int frameLength, shine_global_config *config); 7 | int shine_max_reservoir_bits(double *pe, shine_global_config *config); 8 | void shine_ResvAdjust(gr_info *gi, shine_global_config *config); 9 | void shine_ResvFrameEnd(shine_global_config *config); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/lib/shine/tables.h: -------------------------------------------------------------------------------- 1 | #ifndef TABLES_H 2 | #define TABLES_H 3 | 4 | #include "types.h" 5 | 6 | extern const int shine_slen1_tab[16]; 7 | extern const int shine_slen2_tab[16]; 8 | 9 | extern const int samplerates[9]; 10 | extern const int bitrates[16][4]; 11 | 12 | extern const int shine_scale_fact_band_index[9][23]; 13 | extern const int32_t shine_enwindow[]; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/media.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "app_config.h" 12 | #include "error.h" 13 | #include "hal/types.h" 14 | #include "http_post.h" 15 | #include "lib/shine/layer3.h" 16 | #include "jpeg.h" 17 | #include "rtsp/rtsp_server.h" 18 | #include "server.h" 19 | #include "stream.h" 20 | 21 | extern char audioOn, recordOn, udpOn; 22 | extern rtsp_handle rtspHandle; 23 | 24 | int start_sdk(void); 25 | int stop_sdk(void); 26 | 27 | int start_streaming(void); 28 | void stop_streaming(void); 29 | 30 | void request_idr(void); 31 | void set_grayscale(bool active); 32 | int take_next_free_channel(bool mainLoop); 33 | 34 | int create_channel(char index, short width, short height, char framerate, char jpeg); 35 | int bind_channel(char index, char framerate, char jpeg); 36 | int unbind_channel(char index, char jpeg); 37 | int disable_video(char index, char jpeg); 38 | 39 | void disable_audio(void); 40 | int enable_audio(void); 41 | int disable_mjpeg(void); 42 | int enable_mjpeg(void); 43 | int disable_mp4(void); 44 | int enable_mp4(void); -------------------------------------------------------------------------------- /src/network.c: -------------------------------------------------------------------------------- 1 | #include "network.h" 2 | 3 | char configured = 0; 4 | struct mdnsd *mdns = {0}; 5 | NetInfo netinfo; 6 | 7 | void init_network(void) { 8 | if (configured) return; 9 | 10 | struct ifaddrs *ifa, *ifaddr; 11 | if (getifaddrs(&ifaddr) == -1) { 12 | HAL_DANGER("network", "Failed to get network interfaces!\n"); 13 | return; 14 | } 15 | 16 | struct utsname uts; 17 | if (uname(&uts) == -1) { 18 | HAL_DANGER("network", "Failed to get system information!\n"); 19 | return; 20 | } 21 | strcpy(netinfo.host, uts.nodename); 22 | 23 | for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) { 24 | if (netinfo.count >= 3) break; 25 | if (!ifa->ifa_addr || ifa->ifa_addr->sa_family != AF_INET) continue; 26 | if (ifa->ifa_flags & IFF_LOOPBACK) continue; 27 | struct sockaddr_in *addr = (struct sockaddr_in *)ifa->ifa_addr; 28 | strcpy(netinfo.intf[netinfo.count], ifa->ifa_name); 29 | inet_ntop(AF_INET, &addr->sin_addr.s_addr, 30 | netinfo.ipaddr[netinfo.count], sizeof(*netinfo.ipaddr)); 31 | HAL_INFO("network", "Interface %s has address %s\n", 32 | netinfo.intf[netinfo.count], netinfo.ipaddr[netinfo.count]); 33 | netinfo.count++; 34 | } 35 | freeifaddrs(ifaddr); 36 | 37 | configured = 1; 38 | } 39 | 40 | int start_network(void) { 41 | init_network(); 42 | if (!configured) 43 | return EXIT_FAILURE; 44 | 45 | if (app_config.mdns_enable) 46 | start_mdns(); 47 | 48 | if (app_config.onvif_enable) 49 | start_onvif(); 50 | 51 | return EXIT_SUCCESS; 52 | } 53 | 54 | void stop_network(void) { 55 | if (app_config.mdns_enable) 56 | stop_mdns(); 57 | 58 | if (app_config.onvif_enable) 59 | stop_onvif(); 60 | } 61 | 62 | int start_mdns(void) { 63 | char hostname[71]; 64 | 65 | if (!(mdns = mdnsd_start())) 66 | HAL_ERROR("mdns", "Failed to start mDNS server!\n"); 67 | 68 | strcpy(hostname, netinfo.host); 69 | strcat(hostname, ".local"); 70 | mdnsd_set_hostname(mdns, hostname, ip_to_int(netinfo.ipaddr[0])); 71 | 72 | for (char i = 0; i < netinfo.count; i++) { 73 | struct rr_entry *entry = NULL; 74 | HAL_INFO("mdns", "Adding an A entry for IP %s...\n", netinfo.ipaddr[i]); 75 | entry = rr_create_a(create_nlabel(hostname), ip_to_int(netinfo.ipaddr[i])); 76 | mdnsd_add_rr(mdns, entry); 77 | } 78 | } 79 | 80 | void stop_mdns(void) { 81 | if (mdns) 82 | mdnsd_stop(mdns); 83 | 84 | mdns = NULL; 85 | } -------------------------------------------------------------------------------- /src/network.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "app_config.h" 9 | #include "hal/support.h" 10 | #include "lib/tinysvcmdns.h" 11 | #include "onvif.h" 12 | 13 | typedef struct { 14 | char intf[3][16]; 15 | char ipaddr[3][INET_ADDRSTRLEN]; 16 | char count; 17 | char host[65]; 18 | } NetInfo; 19 | 20 | void init_network(void); 21 | int start_network(void); 22 | void stop_network(void); 23 | 24 | int start_mdns(void); 25 | void stop_mdns(void); -------------------------------------------------------------------------------- /src/night.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "app_config.h" 11 | #include "gpio.h" 12 | #include "hal/macros.h" 13 | #include "media.h" 14 | 15 | bool night_grayscale_on(void); 16 | bool night_ircut_on(void); 17 | bool night_irled_on(void); 18 | bool night_manual_on(void); 19 | bool night_mode_on(void); 20 | 21 | void night_grayscale(bool enable); 22 | void night_ircut(bool enable); 23 | void night_irled(bool enable); 24 | void night_manual(bool enable); 25 | void night_mode(bool enable); 26 | 27 | void disable_night(void); 28 | int enable_night(void); -------------------------------------------------------------------------------- /src/onvif.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "app_config.h" 9 | #include "network.h" 10 | 11 | int start_onvif(void); 12 | void stop_onvif(void); 13 | 14 | void *onvif_thread(); 15 | 16 | char* onvif_extract_soap_action(const char* soap_data); 17 | bool onvif_validate_soap_auth(const char *soap_data); 18 | 19 | void onvif_respond_capabilities(char *response, int *respLen); 20 | void onvif_respond_deviceinfo(char *response, int *respLen); 21 | void onvif_respond_mediaprofiles(char *response, int *respLen); 22 | void onvif_respond_snapshot(char *response, int *respLen); 23 | void onvif_respond_stream(char *response, int *respLen); 24 | void onvif_respond_systemtime(char *response, int *respLen); 25 | void onvif_respond_videosources(char *response, int *respLen); -------------------------------------------------------------------------------- /src/record.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "app_config.h" 6 | #include "fmt/mp4.h" 7 | #include "hal/macros.h" 8 | #include "hal/types.h" 9 | 10 | void record_start(void); 11 | void record_stop(void); 12 | void send_mp4_to_record(hal_vidstream *stream, char isH265); -------------------------------------------------------------------------------- /src/region.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "app_config.h" 12 | #include "hal/support.h" 13 | #include "lib/spng.h" 14 | #include "text.h" 15 | 16 | #define DEF_COLOR 0xFFFF 17 | #define DEF_FONT "UbuntuMono-Regular" 18 | #define DEF_OPAL 255 19 | #define DEF_OUTL 0x8000 20 | #define DEF_POSX 16 21 | #define DEF_POSY 16 22 | #define DEF_SIZE 32.0f 23 | #define DEF_THICK 0.0f 24 | #define DEF_TIMEFMT "%Y/%m/%d %H:%M:%S" 25 | #define MAX_OSD 10 26 | 27 | extern char keepRunning; 28 | 29 | typedef struct { 30 | unsigned int size; 31 | unsigned short reserved1; 32 | unsigned short reserved2; 33 | unsigned int offBits; 34 | } bitmapfile; 35 | 36 | typedef struct { 37 | unsigned short size; 38 | unsigned int width; 39 | int height; 40 | unsigned short planes; 41 | unsigned short bitCount; 42 | unsigned int compression; 43 | unsigned int sizeImage; 44 | unsigned int xPerMeter; 45 | unsigned int yPerMeter; 46 | unsigned int clrUsed; 47 | unsigned int clrImportant; 48 | } bitmapinfo; 49 | 50 | typedef struct { 51 | unsigned int redMask; 52 | unsigned int greenMask; 53 | unsigned int blueMask; 54 | unsigned int alphaMask; 55 | unsigned char clrSpace[4]; 56 | unsigned char csEndpoints[24]; 57 | unsigned int redGamma; 58 | unsigned int greenGamma; 59 | unsigned int blueGamma; 60 | } bitmapfields; 61 | 62 | typedef struct { 63 | double size; 64 | int hand, color; 65 | short opal, posx, posy; 66 | char updt; 67 | char font[32]; 68 | char text[80]; 69 | char img[64]; 70 | int outl; 71 | double thick; 72 | } osd; 73 | 74 | extern osd osds[MAX_OSD]; 75 | extern char timefmt[64]; 76 | 77 | int start_region_handler(); 78 | void stop_region_handler(); -------------------------------------------------------------------------------- /src/rtsp/mime.h: -------------------------------------------------------------------------------- 1 | #ifndef _RTSP_MIME_H 2 | #define _RTSP_MIME_H 3 | 4 | #if defined (__cplusplus) 5 | extern "C" { 6 | #endif 7 | 8 | #if defined (__cplusplus) 9 | } 10 | #endif 11 | 12 | /****************************************************************************** 13 | * DATA STRUCTURES 14 | ******************************************************************************/ 15 | struct __mime_encoded_obj_t { 16 | char *result; 17 | size_t len_result; 18 | size_t len_src; 19 | unsigned int base; /* 16 or 32 or 64 */ 20 | }; 21 | typedef struct __mime_encoded_obj_t *mime_encoded_handle; 22 | 23 | /****************************************************************************** 24 | * DECLARATIONS 25 | ******************************************************************************/ 26 | mime_encoded_handle mime_base64_create(char *src, size_t len); 27 | mime_encoded_handle mime_base16_create(char *src, size_t len); 28 | static inline void mime_encoded_delete(mime_encoded_handle h); 29 | 30 | /****************************************************************************** 31 | * INLINE FUNCTIONS 32 | ******************************************************************************/ 33 | static inline void mime_encoded_delete(mime_encoded_handle h) 34 | { 35 | if(h) { 36 | FREE(h->result); 37 | FREE(h); 38 | } 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /src/rtsp/rtcp.h: -------------------------------------------------------------------------------- 1 | #ifndef _RTSP_RTCP_H 2 | #define _RTSP_RTCP_H 3 | 4 | #include 5 | #include 6 | #include "rtp.h" 7 | #include "rfc.h" 8 | #include "rtsp.h" 9 | #include "common.h" 10 | /****************************************************************************** 11 | * DECLARATIONS 12 | ******************************************************************************/ 13 | 14 | static inline int __rtcp_send_sr(struct connection_item_t *con); 15 | 16 | 17 | /****************************************************************************** 18 | * INLINE FUNCTIONS 19 | ******************************************************************************/ 20 | static inline int __rtcp_send_sr(struct connection_item_t *con) 21 | { 22 | struct timeval tv; 23 | unsigned int ts_h; 24 | unsigned int ts_l; 25 | int send_bytes; 26 | struct sockaddr_in to_addr; 27 | 28 | ASSERT(gettimeofday(&tv,NULL) == 0, return FAILURE); 29 | 30 | ts_h = (unsigned int)tv.tv_sec + 2208988800U; 31 | ts_l = (((double)tv.tv_usec) / 1e6) * 4294967296.0; 32 | 33 | rtcp_t rtcp = { common: {version: 2, length: htons(6), p:0, count: 0, pt:RTCP_SR}, 34 | r: { sr: { ssrc: htonl(con->ssrc), 35 | ntp_sec: htonl(ts_h), 36 | ntp_frac: htonl(ts_l), 37 | rtp_ts: htonl(con->trans[con->track_id].rtp_timestamp), 38 | psent: htonl(con->trans[con->track_id].rtcp_packet_cnt), 39 | osent: htonl(con->trans[con->track_id].rtcp_octet)}}}; 40 | 41 | to_addr = con->addr; 42 | to_addr.sin_port = con->trans[con->track_id].client_port_rtcp; 43 | 44 | ASSERT((send_bytes = send(con->trans[con->track_id].server_rtcp_fd, 45 | &(rtcp),36,0)) == 36, ({ 46 | ERR("send:%d:%s¥n",send_bytes,strerror(errno)); 47 | return FAILURE;})); 48 | 49 | con->trans[con->track_id].rtcp_packet_cnt = 0; 50 | con->trans[con->track_id].rtcp_octet = 0; 51 | con->trans[con->track_id].rtcp_tick = con->trans[con->track_id].rtcp_tick_org; 52 | 53 | return SUCCESS; 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /src/rtsp/rtp.h: -------------------------------------------------------------------------------- 1 | #ifndef _RTSP_RTP_H 2 | #define _RTSP_RTP_H 3 | 4 | #if defined (__cplusplus) 5 | extern "C" { 6 | #endif 7 | 8 | #include "../hal/tools.h" 9 | 10 | /****************************************************************************** 11 | * DEFINITIONS 12 | ******************************************************************************/ 13 | #define __RTP_MAXPAYLOADSIZE 1460 14 | 15 | /****************************************************************************** 16 | * DATA STRUCTURES 17 | ******************************************************************************/ 18 | /* 19 | * RTP data header 20 | */ 21 | typedef struct { 22 | #ifdef __RTSP_BIG_ENDIAN 23 | unsigned int version:2; /* protocol version */ 24 | unsigned int p:1; /* padding flag */ 25 | unsigned int x:1; /* header extension flag */ 26 | unsigned int cc:4; /* CSRC count */ 27 | unsigned int m:1; /* marker bit */ 28 | unsigned int pt:7; /* payload type */ 29 | #else 30 | unsigned int cc:4; /* CSRC count */ 31 | unsigned int x:1; /* header extension flag */ 32 | unsigned int p:1; /* padding flag */ 33 | unsigned int version:2; /* protocol version */ 34 | unsigned int pt:7; /* payload type */ 35 | unsigned int m:1; /* marker bit */ 36 | #endif 37 | unsigned int seq:16; /* sequence number */ 38 | unsigned int ts; /* timestamp */ 39 | unsigned int ssrc; /* synchronization source */ 40 | //unsigned int csrc[1]; /* optional CSRC list */ 41 | } rtp_hdr_t; 42 | 43 | struct nal_rtp_t { 44 | struct { 45 | rtp_hdr_t header; 46 | unsigned char payload[__RTP_MAXPAYLOADSIZE]; 47 | } packet; 48 | int rtpsize; 49 | struct list_t list_entry; 50 | }; 51 | 52 | /****************************************************************************** 53 | * DECLARATIONS 54 | ******************************************************************************/ 55 | static inline int __split_nal(unsigned char *buf, unsigned char **nalptr, size_t *p_len, size_t max_len); 56 | 57 | /****************************************************************************** 58 | * INLINE FUNCTIONS 59 | ******************************************************************************/ 60 | static inline int __split_nal(unsigned char *buf, unsigned char **nalptr, size_t *p_len, size_t max_len) 61 | { 62 | int i; 63 | int start = -1; 64 | 65 | for(i = (*nalptr) - buf + *p_len;i 8 | #include 9 | 10 | /****************************************************************************** 11 | * DEFINITIONS 12 | ******************************************************************************/ 13 | #define SERVER_RTP_PORT 5004 14 | #define SERVER_RTCP_PORT 5025 15 | #define RTSP_MAXIMUM_FRAMERATE 60 16 | #define RTSP_MAXIMUM_CONNECTIONS 16 17 | 18 | #define STR_RTSP_VERSION "RTSP/1.0" 19 | 20 | /* __rtsp_obj_t is private. you will not see it */ 21 | typedef struct __rtsp_obj_t *rtsp_handle; 22 | 23 | /****************************************************************************** 24 | * LIBRARY FUNCTIONS 25 | ******************************************************************************/ 26 | /* put virtual pointer to 'buf', which consists of 1 or more NALUs (start code required). 27 | SPS and PPS parameters are automatically collected during execution. */ 28 | 29 | void rtp_disable_audio(rtsp_handle h); 30 | int rtp_send_h26x(rtsp_handle h, unsigned char *buf, size_t len, char isH265); 31 | int rtp_send_mp3(rtsp_handle h, unsigned char *buf, size_t len); 32 | 33 | extern void rtsp_finish(rtsp_handle h); 34 | 35 | extern rtsp_handle rtsp_create(unsigned char max_con, unsigned int port, int priority); 36 | 37 | extern void rtsp_configure_auth(rtsp_handle h, const char *user, const char *pass); 38 | 39 | #if defined (__cplusplus) 40 | } 41 | #endif 42 | 43 | #endif -------------------------------------------------------------------------------- /src/server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "app_config.h" 18 | #include "fmt/mp4.h" 19 | #include "fmt/nal.h" 20 | #include "hal/types.h" 21 | #include "jpeg.h" 22 | #include "media.h" 23 | #include "network.h" 24 | #include "night.h" 25 | #include "record.h" 26 | #include "region.h" 27 | #include "watchdog.h" 28 | 29 | extern char graceful, keepRunning, recordOn; 30 | extern time_t recordStartTime; 31 | 32 | int start_server(); 33 | int stop_server(); 34 | 35 | void send_jpeg_to_client(char index, char *buf, ssize_t size); 36 | void send_mjpeg_to_client(char index, char *buf, ssize_t size); 37 | void send_h26x_to_client(char index, hal_vidstream *stream); 38 | void send_mp3_to_client(char *buf, ssize_t size); 39 | void send_mp4_to_client(char index, hal_vidstream *stream, char isH265); 40 | void send_pcm_to_client(hal_audframe *frame); -------------------------------------------------------------------------------- /src/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #if UINT32_MAX == UINTPTR_MAX 5 | #define STACK_CHK_GUARD 0xe2dee396 6 | #else 7 | #define STACK_CHK_GUARD 0x595e9fbd94fda766 8 | #endif 9 | 10 | uintptr_t __stack_chk_guard = STACK_CHK_GUARD; 11 | 12 | __attribute__((noreturn)) void __stack_chk_fail(void) { 13 | #if __STDC_HOSTED__ 14 | abort(); 15 | #elif __is_myos_kernel 16 | panic("Stack smashing detected"); 17 | #endif 18 | } 19 | 20 | void __stack_chk_fail_local(void) { 21 | __stack_chk_fail(); 22 | } -------------------------------------------------------------------------------- /src/stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "hal/support.h" 16 | 17 | #define MAX_UDP_PACKET_SIZE 1400 18 | #define UDP_DEFAULT_PORT 5600 19 | #define RTP_HEADER_SIZE 12 20 | #define UDP_MAX_CLIENTS 8 21 | 22 | typedef struct { 23 | struct sockaddr_in addr; 24 | int active; 25 | unsigned int ssrc; 26 | unsigned short seq; 27 | unsigned int tstamp; 28 | time_t last_act; 29 | } udp_client_t; 30 | 31 | struct udp_stream_ctx { 32 | int socket_fd; 33 | unsigned short port; 34 | volatile int running; 35 | pthread_t thread; 36 | pthread_mutex_t mutex; 37 | udp_client_t clients[UDP_MAX_CLIENTS]; 38 | int client_count; 39 | char is_mcast; 40 | unsigned int mcast_addr; 41 | }; 42 | 43 | int udp_stream_init(unsigned short port, const char *mcast_addr); 44 | void udp_stream_close(void); 45 | int udp_stream_add_client(const char *host, unsigned short port); 46 | void udp_stream_remove_client(int client_id); 47 | int udp_stream_send_nal(const char *nal_data, int nal_size, int is_keyframe, int is_h265); -------------------------------------------------------------------------------- /src/text.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "hal/support.h" 6 | #include "lib/schrift.h" 7 | 8 | hal_bitmap text_create_rendered(const char *font, double size, const char *text, 9 | int color, int outline, double thick); -------------------------------------------------------------------------------- /src/watchdog.c: -------------------------------------------------------------------------------- 1 | #include "watchdog.h" 2 | 3 | int fd = 0; 4 | 5 | void watchdog_reset(void) { 6 | if (!fd) return; 7 | write(fd, "", 1); 8 | } 9 | 10 | int watchdog_start(int timeout) { 11 | if (fd) return EXIT_SUCCESS; 12 | const char* paths[] = {"/dev/watchdog0", "/dev/watchdog"}; 13 | const char **path = paths; 14 | 15 | while (*path) { 16 | if (access(*path++, F_OK)) continue; 17 | if ((fd = open(*(path - 1), O_WRONLY)) == -1) 18 | HAL_ERROR("watchdog", "%s could not be opened!\n", *(path - 1)); 19 | break; 20 | } if (!fd) HAL_ERROR("watchdog", "No matching device has been found!\n"); 21 | 22 | ioctl(fd, WDIOC_SETTIMEOUT, &timeout); 23 | 24 | HAL_INFO("watchdog", "Watchdog started!\n"); 25 | return EXIT_SUCCESS; 26 | } 27 | 28 | void watchdog_stop(void) { 29 | if (!fd) return; 30 | write(fd, "V", 1); 31 | close(fd); 32 | fd = 0; 33 | 34 | HAL_INFO("watchdog", "Watchdog stopped!\n"); 35 | } -------------------------------------------------------------------------------- /src/watchdog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "hal/macros.h" 11 | 12 | void watchdog_reset(void); 13 | int watchdog_start(int timeout); 14 | void watchdog_stop(void); --------------------------------------------------------------------------------