FDH2 / UxPlay

AirPlay Unix mirroring server
GNU General Public License v3.0
1.64k stars 82 forks source link

Segmentation fault when trying to use v4l2sink #349

Closed tovrstra closed 1 month ago

tovrstra commented 1 month ago

Wheb I run:

uxplay -vs "v4l2sink device=/dev/video42" -p

I get this output:

``` UxPlay 1.69: An Open-Source AirPlay mirroring and audio-streaming server. using network ports UDP 7011 6001 6000 TCP 7100 7000 7001 using system MAC address 00:e0:4c:68:00:5a Initialized server socket(s) Accepted IPv6 client on socket 27 Local : fe80::bc83:7728:428f:1aff%3 Remote: fe80::0c5b:1a59:3295:a889%3 connection request from iPad (iPad8,5) with deviceID = 08:2C:B6:75:F4:FA Client identified as User-Agent: AirPlay/775.3.1 raop_rtp_mirror starting mirroring Begin streaming to GStreamer video pipeline Segmentation fault (core dumped) toon ~ $ 139 uxplay -vs "v4l2sink device=/dev/video42" -p UxPlay 1.69: An Open-Source AirPlay mirroring and audio-streaming server. using network ports UDP 7011 6001 6000 TCP 7100 7000 7001 using system MAC address 00:e0:4c:68:00:5a Initialized server socket(s) Accepted IPv6 client on socket 27 Local : fe80::bc83:7728:428f:1aff%3 Remote: fe80::0c5b:1a59:3295:a889%3 connection request from iPad (iPad8,5) with deviceID = 08:2C:B6:75:F4:FA Client identified as User-Agent: AirPlay/775.3.1 raop_rtp_mirror starting mirroring Begin streaming to GStreamer video pipeline Segmentation fault (core dumped) toon ~ $ 139 uxplay -vs "v4l2sink device=/dev/video42" -p-d unknown option -p-d, stopping (for help use option "-h") toon ~ $ 1 uxplay -vs "v4l2sink device=/dev/video42" -p -d UxPlay 1.69: An Open-Source AirPlay mirroring and audio-streaming server. Audio format 1: AAC-ELD 44100/2 GStreamer audio pipeline 1: "appsrc name=audio_source ! queue ! avdec_aac ! audioconvert ! audioresample ! volume name=volume ! level ! autoaudiosink sync=true" Audio format 2: ALAC 44100/16/2 GStreamer audio pipeline 2: "appsrc name=audio_source ! queue ! avdec_alac ! audioconvert ! audioresample ! volume name=volume ! level ! autoaudiosink sync=false" GStreamer video pipeline will be: "appsrc name=video_source ! queue ! h264parse ! decodebin ! videoconvert ! videoscale ! v4l2sink device=/dev/video42 sync=true" Initialized GStreamer video renderer using network ports UDP 7011 6001 6000 TCP 7100 7000 7001 using system MAC address 00:e0:4c:68:00:5a Initialized server socket(s) register_dnssd: advertised AirPlay service with "Features" code = 0x527FFEE6 Accepted IPv6 client on socket 21 Local : fe80::bc83:7728:428f:1aff%3 Remote: fe80::0c5b:1a59:3295:a889%3 Open connections: 1 Accepted IPv4 client on socket 27 Local : 192.168.1.193 Remote: 192.168.1.172 Open connections: 2 httpd receiving on socket 27, connection 1 Connection closed for socket 27 Destroying connection Open connections: 1 httpd receiving on socket 21, connection 0 httpd request received on socket 21, connection 0, method = GET, url = /info, protocol = RTSP/1.0 GET /info RTSP/1.0 X-Apple-ProtocolVersion: 1 Content-Length: 70 Content-Type: application/x-apple-binary-plist CSeq: 0 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 User-Agent: AirPlay/775.3.1 qualifier txtAirPlay Handling request GET with URL /info RTSP/1.0 200 OK Content-Type: application/x-apple-binary-plist Server: AirTunes/220.68 CSeq: 0 Content-Length: 1077 deviceID 00:e0:4c:68:00:5a pk h+rqzCgJhLsJO574d0IEWDuQPS8CeUKn5khyoXJamJQ= txtAirPlay GmRldmljZWlkPTAwOmUwOjRjOjY4OjAwOjVhF2ZlYXR1cmVzPTB4NTI3RkZFRTYsMHgw CWZsYWdzPTB4NBBtb2RlbD1BcHBsZVRWMywyQ3BrPTg3ZWFlYWNjMjgwOTg0YmIwOTNi OWVmODc3NDIwNDU4M2I5MDNkMmYwMjc5NDJhN2U2NDg3MmExNzI1YTk4OTQIcHc9ZmFs c2UncGk9MmUzODgwMDYtMTNiYS00MDQxLTlhNjctMjVkZDRhNDNkNTM2DnNyY3ZlcnM9 MjIwLjY4BHZ2PTI= features 1384120038 name UxPlay@molmod00 audioFormats type 100 audioInputFormats 67108860 audioOutputFormats 67108860 type 101 audioInputFormats 67108860 audioOutputFormats 67108860 pi 2e388006-13ba-4041-9a67-25dd4a43d536 vv 2 statusFlags 68 keepAliveLowPower 1 sourceVersion 220.68 keepAliveSendStatsAsBody 1 audioLatencies outputLatencyMicros type 100 audioType default inputLatencyMicros outputLatencyMicros type 101 audioType default inputLatencyMicros model AppleTV3,2 macAddress 00:e0:4c:68:00:5a displays uuid e0ff8a27-6738-3d56-8a16-cc53aacee925 widthPhysical heightPhysical width 1920 height 1080 widthPixels 1920 heightPixels 1080 rotation refreshRate 60 maxFPS 30 overscanned features 14 httpd receiving on socket 21, connection 0 httpd request received on socket 21, connection 0, method = POST, url = /fp-setup, protocol = RTSP/1.0 POST /fp-setup RTSP/1.0 X-Apple-ET: 32 Content-Length: 16 Content-Type: application/octet-stream CSeq: 1 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 User-Agent: AirPlay/775.3.1 46 50 4c 59 03 01 01 00 00 00 00 04 02 00 01 bb Handling request POST with URL /fp-setup RTSP/1.0 200 OK Content-Type: application/octet-stream Server: AirTunes/220.68 CSeq: 1 Content-Length: 142 46 50 4c 59 03 01 02 00 00 00 00 82 02 01 cf 32 a2 57 14 b2 52 4f 8a a0 ad 7a f1 64 e3 7b cf 44 24 e2 00 04 7e fc 0a d6 7a fc d9 5d ed 1c 27 30 bb 59 1b 96 2e d6 3a 9c 4d ed 88 ba 8f c7 8d e6 4d 91 cc fd 5c 7b 56 da 88 e3 1f 5c ce af c7 43 19 95 a0 16 65 a5 4e 19 39 d2 5b 94 db 64 b9 e4 5d 8d 06 3e 1e 6a f0 7e 96 56 16 2b 0e fa 40 42 75 ea 5a 44 d9 59 1c 72 56 b9 fb e6 51 38 98 b8 02 27 72 19 88 57 16 50 94 2a d9 46 68 8a httpd receiving on socket 21, connection 0 httpd request received on socket 21, connection 0, method = POST, url = /fp-setup, protocol = RTSP/1.0 POST /fp-setup RTSP/1.0 X-Apple-ET: 32 Content-Length: 164 Content-Type: application/octet-stream CSeq: 2 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 User-Agent: AirPlay/775.3.1 46 50 4c 59 03 01 03 00 00 00 00 98 01 8f 1a 9c e7 df 2b e8 b2 0b fc a9 c9 ee 78 cd f9 07 15 73 00 8d d2 90 61 45 f3 ca 96 6b 44 c7 c3 21 ab f6 d6 83 f2 28 fc 1d ce 02 34 1b 94 8a b5 f0 5c e2 6e fc c1 78 68 c3 ad bf 36 13 f5 dd 87 b3 90 0a cb 10 cb 6d 65 ef a6 89 c2 cf 8e f4 ea e7 a0 6e b8 31 a6 cf e2 49 81 a8 97 27 91 27 d1 33 d2 29 59 77 d7 ae 69 08 06 eb 01 22 44 0f f3 ac 36 f7 93 39 5f 10 99 9f 6e b3 bd 69 59 88 ad 5a ee 22 ce 70 d4 4e 67 8d 0e 11 92 82 6c 52 be 5d d9 1b 46 f6 df 79 Handling request POST with URL /fp-setup RTSP/1.0 200 OK Content-Type: application/octet-stream Server: AirTunes/220.68 CSeq: 2 Content-Length: 32 46 50 4c 59 03 01 04 00 00 00 00 14 ce 70 d4 4e 67 8d 0e 11 92 82 6c 52 be 5d d9 1b 46 f6 df 79 httpd receiving on socket 21, connection 0 httpd request received on socket 21, connection 0, method = SETUP, url = rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538, protocol = RTSP/1.0 SETUP rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538 RTSP/1.0 Content-Length: 666 Content-Type: application/x-apple-binary-plist CSeq: 3 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 User-Agent: AirPlay/775.3.1 et 32 statsCollectionEnabled eiv B3u46zoz2UxEcUmWF8Tqdg== sessionUUID 57237F25-4634-4CC2-9B07-FC5ED0EE45DD timingProtocol NTP diagnosticsAndUsage osName iPhone OS osBuildVersion 21H16 sourceVersion 775.3.1 timingPort 65314 isScreenMirroringSession osVersion 17.7 ekey RlBMWQECAQAAAAA8AAAAAGrLwHceYNpEjk+J4CzMdFkAAAAQI6kgAuI5pGgb+Hhzh/UG OmgFs1rQ9diyx2MPWfYH3PuKqJ07 sessionCorrelationUUID 31AE5BD7-4703-45BC-8AA4-EE310F004AD1 internalBuild deviceID 08:2C:B6:75:F4:FA model iPad8,5 name iPad macAddress 8E:BA:7E:B6:8B:01 Handling request SETUP with URL rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 SETUP 1 connection request from iPad (iPad8,5) with deviceID = 08:2C:B6:75:F4:FA eiv_len = 16 16 byte aesiv (needed for AES-CBC audio decryption iv): 07 7b b8 eb 3a 33 d9 4c 44 71 49 96 17 c4 ea 76 ekey_len = 72 ekey: 46 50 4c 59 01 02 01 00 00 00 00 3c 00 00 00 00 6a cb c0 77 1e 60 da 44 8e 4f 89 e0 2c cc 74 59 00 00 00 10 23 a9 20 02 e2 39 a4 68 1b f8 78 73 87 f5 06 3a 68 05 b3 5a d0 f5 d8 b2 c7 63 0f 59 f6 07 dc fb 8a a8 9d 3b fairplay_decrypt ret = 0 16 byte aeskey (fairplay-decrypted from ekey): 4a c8 de 76 2b da 6e cd b2 d3 86 46 0e 95 42 90 Client identified as User-Agent: AirPlay/775.3.1 timing_rport = 65314 raop_ntp parse remote ip = fe80::0c5b:1a59:3295:a889%3 raop_ntp starting time raop_ntp local timing port socket 27 port UDP 7011 raop_ntp send time type_t=82 packetlen = 32, now = 1727205053.797336 80 d2 00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ea 9d 8d 3d cc 1e 3a e9 raop_rtp parse remote ip = fe80::0c5b:1a59:3295:a889%3 raop_rtp_mirror parse remote ip = fe80::0c5b:1a59:3295:a889%3 eport = 0, tport = 7011 RTSP/1.0 200 OK Content-Type: application/x-apple-binary-plist Server: AirTunes/220.68 CSeq: 3 Content-Length: 76 timingPort 7011 eventPort 0 raop_ntp receive time type_t=83 packetlen = 32, now = 1727205053.802328 t1 = 12269.728061, t2 = 12269.728270 80 d3 00 07 00 00 00 00 ea 9d 8d 3d cc 1e 3a e9 83 aa ae 6d ba 62 3b a6 83 aa ae 6d ba 6f ee c9 raop_ntp sync correction = -1727192784071666261 httpd receiving on socket 21, connection 0 httpd request received on socket 21, connection 0, method = GET, url = /info, protocol = RTSP/1.0 GET /info RTSP/1.0 X-Apple-ProtocolVersion: 1 CSeq: 4 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 User-Agent: AirPlay/775.3.1 Handling request GET with URL /info RTSP/1.0 200 OK Content-Type: application/x-apple-binary-plist Server: AirTunes/220.68 CSeq: 4 Content-Length: 1077 deviceID 00:e0:4c:68:00:5a pk h+rqzCgJhLsJO574d0IEWDuQPS8CeUKn5khyoXJamJQ= txtAirPlay GmRldmljZWlkPTAwOmUwOjRjOjY4OjAwOjVhF2ZlYXR1cmVzPTB4NTI3RkZFRTYsMHgw CWZsYWdzPTB4NBBtb2RlbD1BcHBsZVRWMywyQ3BrPTg3ZWFlYWNjMjgwOTg0YmIwOTNi OWVmODc3NDIwNDU4M2I5MDNkMmYwMjc5NDJhN2U2NDg3MmExNzI1YTk4OTQIcHc9ZmFs c2UncGk9MmUzODgwMDYtMTNiYS00MDQxLTlhNjctMjVkZDRhNDNkNTM2DnNyY3ZlcnM9 MjIwLjY4BHZ2PTI= features 1384120038 name UxPlay@molmod00 audioFormats type 100 audioInputFormats 67108860 audioOutputFormats 67108860 type 101 audioInputFormats 67108860 audioOutputFormats 67108860 pi 2e388006-13ba-4041-9a67-25dd4a43d536 vv 2 statusFlags 68 keepAliveLowPower 1 sourceVersion 220.68 keepAliveSendStatsAsBody 1 audioLatencies outputLatencyMicros type 100 audioType default inputLatencyMicros outputLatencyMicros type 101 audioType default inputLatencyMicros model AppleTV3,2 macAddress 00:e0:4c:68:00:5a displays uuid e0ff8a27-6738-3d56-8a16-cc53aacee925 widthPhysical heightPhysical width 1920 height 1080 widthPixels 1920 heightPixels 1080 rotation refreshRate 60 maxFPS 30 overscanned features 14 httpd receiving on socket 21, connection 0 httpd request received on socket 21, connection 0, method = GET_PARAMETER, url = rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538, protocol = RTSP/1.0 GET_PARAMETER rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538 RTSP/1.0 Content-Length: 8 Content-Type: text/parameters CSeq: 5 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 User-Agent: AirPlay/775.3.1 volume Handling request GET_PARAMETER with URL rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538 RTSP/1.0 200 OK Content-Type: text/parameters Server: AirTunes/220.68 CSeq: 5 Content-Length: 13 volume: 0.0 httpd receiving on socket 21, connection 0 httpd request received on socket 21, connection 0, method = RECORD, url = rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538, protocol = RTSP/1.0 RECORD rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538 RTSP/1.0 CSeq: 6 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 User-Agent: AirPlay/775.3.1 Handling request RECORD with URL rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538 raop_handler_record RTSP/1.0 200 OK Audio-Latency: 11025 Audio-Jack-Status: connected; type=analog Server: AirTunes/220.68 CSeq: 6 httpd receiving on socket 21, connection 0 httpd request received on socket 21, connection 0, method = SETUP, url = rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538, protocol = RTSP/1.0 SETUP rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538 RTSP/1.0 Content-Length: 204 Content-Type: application/x-apple-binary-plist CSeq: 7 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 User-Agent: AirPlay/775.3.1 streams timestampInfo name SubSu name BePxT name AfPxT name BefEn name EmEnc latencyMs 100 type 110 streamConnectionID -1511317600117701915 Handling request SETUP with URL rtsp://fe80::bc83:7728:428f:1aff/6279002103552953538 DACP-ID: B449B276F00A40A3 Active-Remote: 503395354 type = 110 streamConnectionID (needed for AES-CTR video decryption key and iv): 16935426473591849701 raop_rtp_mirror starting mirroring raop_rtp_mirror local data port socket 28 port TCP 7100 Mirroring initialized successfully RTSP/1.0 200 OK Content-Type: application/x-apple-binary-plist Server: AirTunes/220.68 CSeq: 7 Content-Length: 85 streams dataPort 7100 type 110 raop_rtp_mirror accepting client Received unencrypted codec packet from client: payload_size 37 header 01 00 16 01 ts_client = 12269.960065 raop_rtp_mirror: unidentified extra header data 239.000000, 0.000000 begin video stream wxh = 1442x1080; source 1442x1080 raop_rtp_mirror width_source = 1442.000000 height_source = 1080.000000 width = 1442.000000 height = 1080.000000 raop_rtp_mirror: SPS+PPS header size = 6 raop_rtp_mirror h264 SPS+PPS header: 01 64 00 28 ff e1 raop_rtp_mirror SPS NAL size = 18 raop_rtp_mirror h264 Sequence Parameter Set: 27 64 00 28 ac 13 14 50 16 c0 89 e2 25 9b 80 80 80 81 raop_rtp_mirror PPS NAL size = 4 raop_rtp_mirror h264 Picture Parameter Set: 28 ee 3c b0 remainder size = 4 remainder of SPS+PPS packet: 02 00 00 00 raop_rtp video: now = 1727205053.960608, ntp = 1727205054.031731, latency = -0.071123, ts = 12269.960065, 00 10 00 00 Begin streaming to GStreamer video pipeline raop_rtp video: now = 1727205053.976126, ntp = 1727205054.073424, latency = -0.097298, ts = 12270.001758, 00 00 00 00 Segmentation fault (core dumped) ```
tovrstra commented 1 month ago

The following work:

  1. Using v4l2loopback with gstreamer, e.g. using the following pair of commands:

    gst-launch-1.0 videotestsrc ! v4l2sink device=/dev/video42
    gst-launch-1.0 v4l2src device=/dev/video42 ! videoconvert ! xvimagesink
  2. Using uxplay with another sink works, e.g.:

    uxplay -vs "autovideosink" -p

I'm running this test on Fedora 40, for which I've rebuilt the RPM package to be able to install uxplay 1.69. My gstreamer version is gstreamer1-1.24.8-1.fc40.x86_64.

fduncanh commented 1 month ago

We have never tested with "-vs v4l2sink". https://gstreamer.freedesktop.org/documentation/video4linux2/v4l2sink.html?gi-language=c

why do you use it? what sort of device is the v4l2 output device at /dev/video42?

(Usually uxplay outputs video to a monitor screen)

fduncanh commented 1 month ago

I suppose you are trying to capture a video stream to retransmit it or something?

If you need to edit the gstreamer pipeline, modify it in /lib/video/renderer_gstreamer.c

Let us know if you develop some useful new use case for uxplay.

fduncanh commented 1 month ago
fduncanh commented 1 month ago

we are not planning to support v4l2sink as a videosink option, but if you feel there is a good use case for it, please let us know.

I'm sure you will be able to work out what causes the segfault. Let us know if it is something that can be fixed in uxplay itself, as opposed to GStreamer. Maybe it is just that you did not get the correct pipeline set up.

closing, but feel free to add more info or reopen.

tovrstra commented 1 month ago

I'd like to use the mirrored IPad as an input in obs-studio. Currently, I'm using xvimagesink, put it to full screen and then capture with pipewire, which is a bit clumsy and not giving the right resolution. A more direct route is to let UxPlay stream to a v4l2loopback device and use that lookback device as input in obs-studio. This involves no rescaling, no rendering overhead and introduces no redundant black borders. I'm not sure if there are other options to get the output of UxPlay directly into obs-studio without first showing it on screen? (The reason for obs-studio is the convenient of switching between slides on the tablet, video demonstrations, quizzes while teaching.)

My current schedule is a bit dense, so testing will be for later. In any case, thank you for providing all the suggestions. These should help me to figure out what is going wrong.

thiccaxe commented 1 month ago

Pipe wire comes with a gstreamer plugin, I wonder if you can directly pipe to that

fduncanh commented 1 month ago

what kind of output? is it video without audio ? what format is obs-studio expecting?

fduncanh commented 1 month ago

sound like you are trying to use the obs-gstreamer plugin?

https://github.com/fzwoch/obs-gstreamer

fduncanh commented 1 month ago

unfortunately, "obs-gstreamer" is not part of gstreamer, it seems to be an add-on to obs-studio that runs its own gstreamer process.

obs-gstreamer seems to provide a videosink and an audiosink; ideally there ought to be gstreamer plugins built with names like obs_videosink and obs_audiosink that treat a running obs-studio as an output device that can supply information about what types of audio/video it accepts, but I dont think that is what the author of obs-gstreamer has done (?).

thiccaxe commented 1 month ago

https://docs.automotivelinux.org/en/ricefish/#06_Component_Documentation/07_pipewire_wireplumber/#gstreamer-recommended

fduncanh commented 1 month ago

I didn't know that pipewire does video too... https://www.youtube.com/watch?v=LUbF-d77lAs