xmflsct / yi-hack-1080p

Xiaomi Yi camera 1080p hack
104 stars 18 forks source link

rtsp server not working #7

Closed comicchang closed 7 years ago

comicchang commented 7 years ago

Just test on master branch, telnet and ftp working well, but rtsp server not

logs

/tmp/sd/test/app # ./rtsp2301
size of 2RTSP server START
Streaming URL: rtsp://192.168.234.220:554/ch0_0.h264
listen for client connecting...
enSize=16, u32BlkSize=1491840
=============SAMPLE_COMM_VI_SetMipiAttr enWDRMode: 0
linear mode
sesnorID:0x80; sensoraddr:0x1; sensordata:0x1
=========================================================================
===F22sensor 1080P25fps(Parallel port) init success
=========================================================================
         c) cbr.
[SAMPLE_COMM_VENC_GetVencStreamProc_RTSP]-75: HI_MPI_VENC_GetChnAttr chn[0] failed with 0xffffffff!
********************* Open pwm device error! *********************
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
Config ISP register Failed with ec 0xffffffff!
...

ffmpeg log

$ ffmpeg -i rtsp://root:1234qwer@192.168.234.220/ch0_0.h264 -r 15 test.avi
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
...
[rtsp @ 0x7fdd55005800] Missing PPS in sprop-parameter-sets, ignoring
[rtsp @ 0x7fdd55005800] method SETUP failed: 461 Unsupported transport
    Last message repeated 2 times
rtsp://root:1234qwer@192.168.234.220/ch0_0.h264: Protocol not supported

maybe my firmware is too old? checked, my camera firmware is 2.0.0.1A_201612231003

xmflsct commented 7 years ago

@comicchang Actually your firmware is too 'new'. This program is tested on firmware 2.0.0.1A_201612051401, and it does not run well on newer firmwares as some system libraries have been updated. Do you have a backup of your previous firmware?

comicchang commented 7 years ago

@xmflsct nope, my camera shipped with 2.0.0.1A_201612231003

is there anyway to flash it back to 2.0.0.1A_201612051401?

xmflsct commented 7 years ago

@comicchang Try this one, and let me know if it is working.

comicchang commented 7 years ago

@xmflsct it's not woking, maybe I should try upgrade to the newest firmware and then downgrade it?

comicchang commented 7 years ago

I found the problem, I formatted the tf card to exfat format instead of fat32 after reformat, the image worked

thank you

xmflsct commented 7 years ago

@comicchang Yes, you need to have the SD card in FAT32. So the RTSP is working now?

comicchang commented 7 years ago

@xmflsct

well, the rtsp server still not working

trying to connect to the webcam from my laptop

$ mpv rtsp://192.168.234.220:554/ch0_0.h264
Playing: rtsp://192.168.234.220:554/ch0_0.h264
[ffmpeg/demuxer] rtsp: method SETUP failed: 461 Unsupported transport
[lavf] avformat_open_input() failed
Failed to recognize file format.

Exiting... (Errors when loading file)

log on webcam

/tmp/sd/test # /home/app/localbin/rtsp2301
size of 2RTSP server START
Streaming URL: rtsp://192.168.234.220:554/ch0_0.h264
listen for client connecting...
enSize=16, u32BlkSize=1491840
=============SAMPLE_COMM_VI_SetMipiAttr enWDRMode: 0
linear mode
sesnorID:0x80; sensoraddr:0x1; sensordata:0x1
=========================================================================
===F22sensor 1080P25fps(Parallel port) init success
=========================================================================
         c) cbr.
********************* Open pwm device error! *********************
Incoming RTSP connection accepted on socket: 16
EventLoop Connection reached: 3
192.168.234.32 Port:60374
exit Rtsp_state_machine
4
S192.168.234.32 Port:60374
server:192.168.234.220
port:-1095240150

GetSdpDescr,703===>psp.base64profileid=42001F,psp.base64sps=Z0IAH52oFAFum4CAgIE=,psp.base64pps=aM48gA==

exit Rtsp_state_machine
4
S192.168.234.32 Port:60374
*** transport: RTP/AVP/TCP;unicast;interleaved=0-1 ***
pstr=/TCP;unicast;interleaved=0-1
AAAAAAAAAAA Unsupported Transport,rtspservice.c,1118
TRANSFER TO READY STATE!
exit Rtsp_state_machine
4
Sfd:16,RTSP connection closed by client.
WARNING! fd:16 RTSP connection truncated before ending operations.
first error,pRtsp is null

how did you test the rtsp server?

comicchang commented 7 years ago

@xmflsct ah, I tried vlc and its working now

thank you

xmflsct commented 7 years ago

Great! You are welcome. :)

iokeonglok commented 7 years ago

Hi @xmflsct , originally i have the same condition as @comicchang. i have the 1080p cam shipped with firmware 2.0.0.1A_201612231003. tried the "test" folder, got ftp and telnet working but not rtsp.

then tried the home_y20 & rootfs_y20 (from issues/#3 (comment)). yellow led flashed for around 10 seconds (very short time). then format the sd card again and put "test" folder to try again. nothing happened. i got yellow led light, but the cam seems not working at all. router can't find the cam. checked the sd card, no log.txt file created.

xmflsct commented 7 years ago

@iokeonglok very short flashing time means only the rootfs is flashed successfully. Try to place only home_y20 in SD card and see if it gets flashed. Flashing home partition usually takes more than half a minute.

iokeonglok commented 7 years ago

@xmflsct i started from the beginning again on a another new 1080p cam also shipped with a newer firmware. first, with hom_y20 only and it can be flashed successfully, firmware downgraded (confirmed with the log.txt) however can't connect to my router. i got the same log.txt (short log.txt) as this one. following his method, i tried to flash rootfs_y20. yellow led flashed, seems successfully restored the rootfs_y20. however, the cam then stopped working, like the one i tested before. no more log.txt created in the sd_card. The system not even booted? the rootfs_y20 file not correct?

xmflsct commented 7 years ago

@iokeonglok Try this rootfs. rootfs_y20.zip

iokeonglok commented 7 years ago

@xmflsct your file can be flashed and the cam has respond again. however, with DHCP ON, i still got the short log.txt stopped at "Do network configuration (DHCP)" with DHCP OFF, i got the log.txt as below

Starting to log... [INIT] Your firmware version is: 2.0.0.1A_201612051401 [INIT] Killing original init.sh script. [good] busybox 1.16.1 is in the system. [good] rtsp2301 is in the system. Check for wifi configuration file... /tmp/wpa_supplicant.conf /tmp/sd/test/wpa_supplicant.conf Start wifi configuration... Status for wifi configuration=127 (0 is ok) Do network configuration 1/2 (IP and Gateway) Done Do network configuration 2/2 (DNS) Done

seems still can't get the IP. by the way, if i start the cam without the sd_card, the cam won't start as stock with the voice command.

xmflsct commented 7 years ago

@iokeonglok Can you try this home partition of my original packaging? It seems that you still have a incorrect home partition with unknown wpa_supplicant.

iokeonglok commented 7 years ago

@xmflsct Thank you very much, it works!

i guess you guys are still working on this cam to make it better. just some findings want to share with you for your information. (maybe you already knew)

computer using VLC player to access rtsp has absolutely no problem, even i opened multi VLC to access the samp rtsp. however when mobile apps (both tinycam Free and MXplayer) tried to connect to the cam, it seems crashing the rtsp service, but i still can access via ftp and telnet. i need to power restart the cam to resume rtsp. i'm willing to test and provide logs for any testing you request. Thanks anyway!

iokeonglok commented 7 years ago

NAS try to connect the cam via rtsp also causes rtsp service to fail

xmflsct commented 7 years ago

@iokeonglok Do you know which program is running behind your NAS? Like ffmpeg or live555 or others?

iokeonglok commented 7 years ago

@xmflsct sorry not sure. i'm using Synology DS214Play surveillance station application.

comicchang commented 7 years ago

I encountered this too,

try

  1. set surveillance station to record continuously (instead of on motion)
  2. add a daemon to restart rtsp on crash

but in my experience, rtsp2301 will report something about PWM error after few crashes

xmflsct commented 7 years ago

@iokeonglok @comicchang

I cannot reproduce your issue of crashing. I tried with VLC, ffmpeg and live555 for receiving stream, either it complaints that the protocol is not supported (won't crash the RTSP server), or just runs fine without any problem for quite some time.

When you encounter a crash of RTSP server, you mean the program exit completely? In this case, I can definitely add a daemon to restart the service on crash.

iokeonglok commented 7 years ago

@xmflsct @comicchang The continuously record in surveillance station won't work neither, because the rtsp service crashed when I just click to test the connection. When encountering the rtsp crash, my mobile app (and NAS app) said can't play the stream. Then the original VLC program on computer just stopped working and can't reconnect any more. I try to post the VLC log later on.

xmflsct commented 7 years ago

@iokeonglok As far as I know, the RTSP service code used in this program is not the most up-to-date one, thus it could not be supporting all features requested by new software.

A simple way to check if the RTSP exits after crashing, just telnet in and run ps and see if the program is still in the list.

iokeonglok commented 7 years ago

@xmflsct Yes, the rtsp2301 isn't in the list anymore when crashed.

xmflsct commented 7 years ago

@iokeonglok Right, I will get a daemon and let you know.

iokeonglok commented 7 years ago

@xmflsct but not sure whether the extra rtsp request from other application will keep causing rtsp to crash here are the error message from VLC when rtsp crashed. hope this can help.

core error: ES_OUTSET(GROUP_)PCR is called too late (pts_delay increased to 1163 ms) core error: ES_OUT_RESET_PCR called live555 error: Failed to connect with rtsp://192.168.1.95/ch0_0.h264 access_realrtsp error: cannot connect to 192.168.1.95:554 core error: open of `rtsp://192.168.1.95/ch0_0.h264' failed

iokeonglok commented 7 years ago

@xmflsct i restart the rtsp2301 in telnet. when VLC connects, it shows

_Incoming RTSP connection accepted on socket: 16 EventLoop Connection reached: 3 192.168.1.136 Port:52013 exit Rtsp_statemachine

but when my mobile app connects, it shows

Incoming RTSP connection accepted on socket: 18 EventLoop Connection reached: 4 fd:18,RTSP connection closed by client. user abort! no user online now resetfifo WARNING! fd:18 RTSP connection truncated before ending operations. dell current fd:18 Segmentation fault

xmflsct commented 7 years ago

@iokeonglok So after you restart rtsp2301 in telnet, VLC connects fine and does show video, right?

iokeonglok commented 7 years ago

@xmflsct yes VLC shows video again but i have to start the stream again manually.

cnberg commented 7 years ago

I got the same issue after I put shadow-1's "Stock Firmware" rootfs_y20 firmware(on the end of this page: https://github.com/shadow-1/yi-hack-v3) in SD card with the "test" folder by yi-hack-1080p.

I can access the telnet & ftp, but the rtsp server crashes after about 10-20s streaming.

cnberg commented 7 years ago

Oh, I got the problem. When I try to connect the rtsp server via VLC, everything goes fine; but ffmpeg causes this error.

xmflsct commented 7 years ago

@cnberg Can you post your command line of ffmpeg?

cnberg commented 7 years ago

ffmpeg -rtsp_transport udp -i "rtsp://10.0.1.27:554/ch0_0.h264" -vframes 1 -s 640x360 test-1.jpg ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers built with Apple LLVM version 8.1.0 (clang-802.0.41) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libavresample 3. 5. 0 / 3. 5. 0 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100 [rtsp @ 0x7fe2d7800000] method SETUP failed: 461 Unsupported transport rtsp://10.0.1.27:554/ch0_0.h264: Protocol not supported

But this one works:

VLC -I rc rtsp://10.0.1.27:554/ch0_0.h264 --video-filter=scene --scene-prefix=$prefix --scene-format=jpg --scene-path=./ --sout-x264-lookahead=10 --sout-x264-tune=stillimage --vout=dummy --run-time 5 vlc://quit

xmflsct commented 7 years ago

@cnberg For me, ffmpeg won't work no matter what protocol I specify. But live555 works perfectly fine. I guess the source code of RTSP implementation used in this version is incomplete. For this RTSP server, use other alternatives to connect, like live555.

cnberg commented 7 years ago

@xmflsct Fine, I will try.

I have one more question, on my camera with this hack, the 720p rtsp streaming output was clipped from the original 1080p, my expectation is a half size of the original output. Am I got wrong with some settings?

xmflsct commented 7 years ago

@cnberg Hmm.. I didn't notice this. This seems to be weird, as the 720p stream is requested directly from the hardware, as far as I know. The RTSP service is developed by @andy2301, so he might have an idea why.

xmflsct commented 7 years ago

@comicchang I have update the project with a rtsp2301 watch process. Now it will restart the process if it crashes. This watch process will also log how many times it has been restarted on /var/run/restart.log just for your reference.