Skip to content

Commit 805f03a

Browse files
committed
v01
0 parents  commit 805f03a

83 files changed

Lines changed: 7432 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# RTSPServer for RTS3903N based YI Cameras
2+
*While this repo is focused on Yi based cameras, it should compile and run on any RTS3903N based camera!*
3+
4+
## Background
5+
It took many hours of research to put this together. The SDK was very hard to find, and I luckily stumbled across it by
6+
finding similar cameras (TP Link) that had shared the source due to GPL requirements.
7+
8+
**Important**: This method doesn't overwrite the existing flash, simply remove the SD card, and the 'hack' will be disabled.
9+
10+
## Getting Started
11+
- Download the latest zip from the releases page
12+
- Extract the contents to the root of a MicroSD card (minimum 2GB) that is FAT32 partitioned
13+
- (Optional) If you're using WiFi, edit Factory/wpa_supplicant.conf and add your WiFi credentials
14+
- Connect to RTSP via `rtsp://[YOUR_CAMERA_IP]/ch0_0.h264`
15+
- Does the picture look normal? No, see troubleshooting below
16+
17+
### What's Working
18+
- H264 encoded stream via `rtsp://[YOUR_CAMERA_IP]/ch0_0.h264`
19+
- Telnet server open by default (root, no password)
20+
- WiFi connection without having to go through the initial vendor pairing process
21+
- Yi Camera
22+
- Tested with `7.1.00.25A_202002271051` and
23+
24+
### TODO:
25+
- Add audio to the feed
26+
- Control PTZ (pan/tilt) based cameras
27+
- ONVIF
28+
- Better documentation
29+
- Create a flash version / permanent solution
30+
## Developers / Compiling
31+
- Install Docker
32+
- Run `./compile.sh`
33+
- This chipset is very capable and there are many features / options available for the encoder see `stream.c` where there are
34+
calls to `manage_modes`
35+
- To find out what options are available see `rtsvideo.h` where `enum_rts_video_ctrl_id` is defined.
36+
- If you create / discover better settings to improve the picture quality, please push to this repo :)
37+
38+
## Video Quality
39+
- See the `Developers/Compiling` section and tweak the settings in `stream.c` inside the `start_stream()` function -
40+
if you find an improved configuration, **please push it to this repo**, so we can all benefit.
41+
- Significant settings:
42+
- h264_attr.bps
43+
- RTS_VIDEO_CTRL_ID_NOISE_REDUCTION
44+
- RTS_VIDEO_CTRL_ID_LDC
45+
- RTS_VIDEO_CTRL_ID_DETAIL_ENHANCEMENT
46+
- RTS_VIDEO_CTRL_ID_3DNR **(Offers significant improvement but can't find the 'sweet' spot)**
47+
- RTS_VIDEO_CTRL_ID_IR_MODE **(If you're having issues with nightmode)**
48+
## Troubleshooting
49+
The RTS3903N has a dedicated ADC that's used for sensing the light, I've discovered that some cameras had their logic inverted
50+
and to get around this, do the following
51+
- Create an empty file on the root of the sd card named `invert_adc` (exact path `/sdcard/invert_adc`)
52+
53+
If this doesn't solve the issue, take a look at the `stream.c` where `sensor_sensitivity` is declared.
54+
55+
## Credit
56+
- The RTSPServer part of this repo was taken from another repo, full credit to be given to:
57+
- `roleo` I believe is the original author[?]
58+
- `alienatedsec` I copied the modified version that repo

build/.gitignore

Whitespace-only changes.

build/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
cmake_minimum_required(VERSION 3.19)
2+
project(RTS3903N_RTSP)
3+
set(SOURCE_FILES src/stream.c headers)
4+
set(CMAKE_CROSSCOMPILING TRUE)
5+
set(CMAKE_SYSROOT /toolchains/sdk/mips-linux-uclibc)
6+
set(CMAKE_C_COMPILER /toolchains/sdk/bin/mips-linux-gcc)
7+
set(CMAKE_CXX_COMPILER /toolchains/sdk/bin/mips-linux-g++)
8+
9+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
10+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
11+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
12+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
13+
set(OUTPUT_DIR ${PROJECT_SOURCE_DIR}/to_sd/)
14+
15+
add_executable(stream ${SOURCE_FILES})
16+
17+
include_directories(headers lib)
18+
target_link_libraries(stream -L${PROJECT_SOURCE_DIR}/lib/ -lrtsio -lopus -lrtsjpeg -lsbc -lasound -lrtsgeom -lrtstream -lrtsv4l2 -lrtscamkit -lh1encoder -lrtsosd -lrtsutils -lrtsosd2 -lrtsjpeg -lrtsisp -lrtsaec )
19+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=5281 -Wl,-rpath-link=${PROJECT_SOURCE_DIR}/lib/")
20+
set(CMAKE_VERBOSE_MAKEFILE FALSE)
21+
22+
add_custom_command(
23+
TARGET stream
24+
PRE_BUILD
25+
COMMAND rm -Rf ${OUTPUT_DIR}
26+
COMMENT "Cleaning output directory"
27+
)
28+
# TODO: Fix the static building so the dynamic linking mess isn't required
29+
add_custom_command(
30+
TARGET stream
31+
POST_BUILD
32+
COMMENT "Copying libs and bins to output"
33+
COMMAND mkdir -p ${OUTPUT_DIR}
34+
COMMAND cp stream ${OUTPUT_DIR}/stream
35+
COMMAND cp -R ${PROJECT_SOURCE_DIR}/lib ${OUTPUT_DIR}/lib
36+
COMMAND rm -rf stream
37+
COMMENT "Fixing annoying dynamic linker issues"
38+
COMMAND mv ${OUTPUT_DIR}/lib/librtsio.so ${OUTPUT_DIR}/lib/librtsio.so.0
39+
COMMAND mv ${OUTPUT_DIR}/lib/librtsjpeg.so ${OUTPUT_DIR}/lib/librtsjpeg.so.1
40+
COMMAND mv ${OUTPUT_DIR}/lib/librtsgeom.so ${OUTPUT_DIR}/lib/librtsgeom.so.1
41+
COMMAND mv ${OUTPUT_DIR}/lib/librtstream.so ${OUTPUT_DIR}/lib/librtstream.so.2
42+
COMMAND mv ${OUTPUT_DIR}/lib/librtsv4l2.so ${OUTPUT_DIR}/lib/librtsv4l2.so.1
43+
COMMAND mv ${OUTPUT_DIR}/lib/librtscamkit.so ${OUTPUT_DIR}/lib/librtscamkit.so.1
44+
COMMAND mv ${OUTPUT_DIR}/lib/libh1encoder.so ${OUTPUT_DIR}/lib/libh1encoder.so.1
45+
COMMAND mv ${OUTPUT_DIR}/lib/librtsosd.so ${OUTPUT_DIR}/lib/librtsosd.so.1
46+
COMMAND mv ${OUTPUT_DIR}/lib/librtsutils.so ${OUTPUT_DIR}/lib/librtsutils.so.1
47+
COMMAND mv ${OUTPUT_DIR}/lib/librtsosd2.so ${OUTPUT_DIR}/lib/librtsosd2.so.0
48+
COMMAND mv ${OUTPUT_DIR}/lib/librtsisp.so ${OUTPUT_DIR}/lib/librtsisp.so.1
49+
COMMAND mv ${OUTPUT_DIR}/lib/libasound.so ${OUTPUT_DIR}/lib/libasound.so.2
50+
COMMAND mv ${OUTPUT_DIR}/lib/libopus.so ${OUTPUT_DIR}/lib/libopus.so.0
51+
COMMAND mv ${OUTPUT_DIR}/lib/libsbc.so ${OUTPUT_DIR}/lib/libsbc.so.1
52+
COMMAND cp /toolchains/sdk/lib/libstdc++.so.6 ${OUTPUT_DIR}/lib/
53+
COMMAND cp /toolchains/sdk/lib/libatomic.so.1 ${OUTPUT_DIR}/lib/
54+
)

build/build.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
# /toolchains/sdk/activate
3+
rm -rf to_sd
4+
cd /to_build/
5+
rm -rf output
6+
mkdir output && cd output
7+
cmake ..
8+
make clean && make
9+
if [ $? -ne 0 ]; then
10+
echo "CMake reported an error, set CMAKE_VERBOSE_MAKEFILE to true and see the output"
11+
exit 1
12+
fi
13+
14+
cd ..
15+
rm -rf output
16+
echo "Build stream grabber complete, compiling RTSPServer"
17+
# Activate the full build env
18+
source /toolchains/sdk/activate
19+
cd src/rRTSPServer
20+
./cleanup.rRTSPServer
21+
./init.rRTSPServer
22+
./compile.rRTSPServer
23+
if [ $? -ne 0 ]; then
24+
echo "Problem compiling RTSPServer"
25+
exit 1
26+
fi
27+
cp -R _install/bin/rRTSPServer /to_build/to_sd/
28+
echo "Grabber and RTSPServer compiled, creating payload for SD card"
29+
cd /to_build/sd_payload
30+
rm -rf Factory
31+
rm -rf /to_build/sd_payload/root
32+
git clone https://github.com/cjj25/yi-hack-telnet-root root
33+
if [ $? -ne 0 ]; then
34+
echo "Problem cloning the payload repo"
35+
exit 1
36+
fi
37+
cp -R root/Factory .
38+
cp *.conf *.sh Factory/
39+
chmod +x Factory/*
40+
mv Factory /to_build/to_sd/ && chmod +x /to_build/to_sd/
41+
cd /to_build/to_sd/
42+
tar cvzf /to_build/release/Yi-RTS3903N-RTSPServerV01.tar.gz .
43+
44+
45+
46+

build/headers/AACEncoder_API.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef __AACENCODER_API_H__
2+
#define __AACENCODER_API_H__
3+
4+
/* Create Encoder object */
5+
6+
void *AACEncoder_API_context_Create();
7+
8+
/* Encode process */
9+
10+
int AACEncoder_API_Process(void *API,
11+
short *Input, char *Output, int InputLen);
12+
13+
/* Free object */
14+
15+
void AACEncoder_API_free(void *API);
16+
17+
/* Set/Get parameter function */
18+
19+
int AACEncoder_API_Set(void *API,
20+
void *pParameters, int size, unsigned int IDs);
21+
int AACEncoder_API_Get(void *API,
22+
void *pParameters, int size, unsigned int IDs);
23+
24+
/* Get block length of I/O buffer */
25+
26+
int AACEncoder_API_GetBlockLen(void *API);
27+
28+
#endif /* __AACENCODER_API_H__ */
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef _AACENCODER_PARAMETERS_
2+
#define _AACENCODER_PARAMETERS_
3+
4+
/* ID = 0 => Set SampleRate and BitRate */
5+
6+
typedef struct {
7+
int m_SampleRate;
8+
int m_BitRate;
9+
} AacEncoder_Para0;
10+
11+
/* ID = 1 => Set channel number */
12+
13+
typedef struct {
14+
int m_Channels;
15+
} AacEncoder_Para1;
16+
17+
#endif

build/headers/AecNs_Parameters.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef _AECNS_PARAMETERS_
2+
#define _AECNS_PARAMETERS_
3+
4+
// Note that NS will be enabled when AEC is enabled.
5+
// If both AEC and NS are disabled then the output will be the input mic signal
6+
7+
// ID = 0 => Set AEC enable
8+
9+
typedef struct
10+
{
11+
int Enable;
12+
} AecNs_Para0;
13+
14+
// ID = 1 => Set NS enable
15+
16+
typedef struct
17+
{
18+
int Enable;
19+
} AecNs_Para1;
20+
21+
// ID = 2 => Set AEC input signal delay
22+
23+
typedef struct
24+
{
25+
int SpkDelay;
26+
int MicDelay;
27+
} AecNs_Para2;
28+
29+
// ID = 3 => Set AecNs bypass
30+
31+
typedef struct
32+
{
33+
int Bypass_En;
34+
} AecNs_Para3;
35+
36+
// ID = 4 => Set NS Suppression Level
37+
38+
typedef struct
39+
{
40+
int Level;
41+
} AecNs_Para4;
42+
43+
#endif

build/headers/RT_AecNs_API.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef _RT_AEC_NS_API_H_
2+
#define _RT_AEC_NS_API_H_
3+
4+
/*
5+
Realtek AEC and NS spec:
6+
7+
Speaker Number¡G1
8+
Microphone Number¡G1
9+
SampleRate¡G16000 Hz
10+
Process Block length¡G256 samples
11+
Input string must be "DeInterleaved". Interleaved string is not supported.
12+
I/O Data format is defined by AecNs_Resolution. It means the number of fractional bits.
13+
Output is mono signal string.
14+
*/
15+
16+
#define AecNs_Resolution 24
17+
#define One_AecNs (long)(1<<AecNs_Resolution)
18+
19+
/* Function for processing data. Where
20+
pMic is 1-dimensional deinterleaved microphone signal array.
21+
pSpk is 1-dimensional deinterleaved speaker signal array.
22+
pOut is 1-dimensional output signal array.
23+
*/
24+
25+
// Create AecNs object and initial
26+
27+
void* RTAecNs_API_context_Create(int fs);
28+
29+
// Free all objects and buffers
30+
31+
void RTAecNs_API_free(void* AecNsAPI);
32+
33+
// Main process , return value is useless so far
34+
35+
int RTAecNs_API_Process(void* AecNsAPI , long **pMic , long **pSpk , long *pOut);
36+
37+
// Set/Get Aec and NS parameter , return value equals to -1 means Set/Get fail.
38+
// The IDs and parameter define can be found in AecNs_Parameters.h
39+
40+
int RTAecNs_API_Set(void* AecNsAPI , void* pParameters , int size , unsigned int IDs);
41+
int RTAecNs_API_Get(void* AecNsAPI , void* pParameters , int size , unsigned int IDs);
42+
43+
#endif

build/headers/basetype.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*------------------------------------------------------------------------------
2+
-- --
3+
-- This software is confidential and proprietary and may be used --
4+
-- only as expressly authorized by a licensing agreement from --
5+
-- --
6+
-- Hantro Products Oy. --
7+
-- --
8+
-- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
9+
-- ALL RIGHTS RESERVED --
10+
-- --
11+
-- The entire notice above must be reproduced --
12+
-- on all copies and should not be removed. --
13+
-- --
14+
--------------------------------------------------------------------------------
15+
--
16+
-- Description : Basic type definitions.
17+
--
18+
------------------------------------------------------------------------------*/
19+
20+
#ifndef BASETYPE_H_INCLUDED
21+
#define BASETYPE_H_INCLUDED
22+
23+
#include <stdint.h>
24+
25+
#define VOLATILE volatile
26+
27+
#ifdef __linux__ /* typedefs for Linux */
28+
29+
#include <stddef.h> /* for size_t, NULL, etc. */
30+
31+
typedef unsigned char u8;
32+
typedef signed char i8;
33+
typedef unsigned short u16;
34+
typedef signed short i16;
35+
typedef unsigned int u32;
36+
typedef signed int i32;
37+
typedef unsigned long long u64;
38+
typedef int64_t i64;
39+
40+
typedef size_t ptr_t;
41+
42+
#ifdef ADDRESS_WIDTH_64
43+
#define PRT_PTR "lx"
44+
#else
45+
#define PRT_PTR "x"
46+
#endif
47+
48+
#ifndef __cplusplus
49+
typedef enum {
50+
false = 0,
51+
true = 1
52+
} bool;
53+
#endif
54+
55+
#else /* __symbian__ or __win__ or whatever, customize it to suit well */
56+
57+
#ifndef _SIZE_T_DEFINED
58+
typedef unsigned int size_t;
59+
60+
#define _SIZE_T_DEFINED
61+
#endif
62+
63+
#ifndef NULL
64+
#ifdef __cplusplus
65+
#define NULL 0
66+
#else /* */
67+
#define NULL ((void *)0)
68+
#endif /* */
69+
#endif
70+
71+
typedef unsigned char u8;
72+
typedef signed char i8;
73+
typedef unsigned short u16;
74+
typedef signed short i16;
75+
typedef unsigned int u32;
76+
typedef signed int i32;
77+
typedef unsigned long long u64;
78+
typedef int64_t i64;
79+
80+
81+
#ifndef __cplusplus
82+
typedef enum {
83+
false = 0,
84+
true = 1
85+
} bool;
86+
#endif
87+
88+
#endif
89+
90+
#if defined(VC1SWDEC_16BIT) || defined(MP4ENC_ARM11)
91+
typedef unsigned short u16x;
92+
typedef signed short i16x;
93+
#else
94+
typedef unsigned int u16x;
95+
typedef signed int i16x;
96+
#endif
97+
98+
#endif /* BASETYPE_H_INCLUDED */

0 commit comments

Comments
 (0)