fyhertz / libstreaming

A solution for streaming H.264, H.263, AMR, AAC using RTP on Android
Apache License 2.0
3.49k stars 1.08k forks source link

[help] made a fork to mirror the screen (rather than the camera) but can't get the video stream to work.. I'm in over my head #300

Closed warren-bank closed 4 years ago

warren-bank commented 4 years ago

Hi, I was talking with Izzy (from f-droid) the other day.. and we got to discussing screen mirroring: Google Cast vs. AirPlay vs. Miracast.. and how there isn't a good open-source app to stream it over RTSP. Of course, libstreaming immediately popped to my mind.. and I accepted the challenge to write one (quickly). I just pushed my repo, but it isn't quite finished. The app builds and everything looks to be working correctly.. but clients immediately disconnect after requesting the video stream, which makes me think it has something to do with how I'm piping the Surface (from a VirtualDisplay) to a MediaCodec and finally to the Packetizer; either the data isn't flowing, or the format isn't what the Packetizer is expecting.. honestly, I have no idea.

I was wondering if you'd be so kind to take a quick look. I'm guessing that you know this stuff backwards and forwards.. and could probably spot the problem with a glance.

I attached an apk that was built from the code in the initial commit, since there's no tagged releases yet. (The .zip file extension was added so github would allow it.) RTSP-ScreenCaster-release.apk.zip

As far as the design goes, my changes focus mainly on the VideoStream and SessionBuilder classes.. removing anything having to do with the Camera, and adding some code to initialize a MediaProjection. Otherwise, it's mostly the same. This app corresponds to your example1. Once it's working, I plan to include another one that corresponds to your example3, but running as another foreground Service.

Anyway, any help would be greatly appreciated. And btw.. great library! ..really great code!! :smiley:

warren-bank commented 4 years ago

Oh, I should also mention.. that the VideoQuality attributes (width, height, dpi) are all obtained from DisplayMetrics that match the physical screen.

warren-bank commented 4 years ago

Nevermind.. I got it (mostly) working. The biggest issue now is that the Surface doesn't update anywhere close to 60 fps..