Kane610 / axis

Python library enabling easy communication with Axis devices and its metadatastream
MIT License
30 stars 14 forks source link

fix: reassemble RTP fragments #503

Closed swoga closed 1 month ago

swoga commented 1 month ago

During my troubleshooting of #502 I noticed that the camera sends fragmented RTP packets, which are not handled correctly and trigger an exception. I don't know if this has only been happening since Axis OS 11.11 or if it has been happening for a while.

wireshark excerpt:

no. time        proto   size    info
388 14.018802   RTP 228 PT=DynamicRTP-Type-98, SSRC=0x1F93C2BA, Seq=3799, Time=2365376825, Mark
389 14.057391   RTP 992 PT=DynamicRTP-Type-98, SSRC=0x1F93C2BA, Seq=3800, Time=2365380299, Mark
390 14.107531   RTP 930 PT=DynamicRTP-Type-98, SSRC=0x1F93C2BA, Seq=3801, Time=2365384762, Mark
391 14.185768   RTP 1442    PT=DynamicRTP-Type-98, SSRC=0x1F93C2BA, Seq=3802, Time=2365391782
392 14.186232   RTP 228 PT=DynamicRTP-Type-98, SSRC=0x1F93C2BA, Seq=3803, Time=2365391782, Mark
393 14.323092   RTP 1442    PT=DynamicRTP-Type-98, SSRC=0x1F93C2BA, Seq=3804, Time=2365404094
394 14.323172   RTP 228 PT=DynamicRTP-Type-98, SSRC=0x1F93C2BA, Seq=3805, Time=2365404094, Mark

As one can see the packets with size 1442 have no marker bit set because they were fragmented, the remaining content is received immediately afterwards (see timestamp).

payload of packet no. 391:

<?xml version="1.0" encoding="UTF-8"?>
<tt:MetadataStream xmlns:tt="http://www.onvif.org/ver10/schema">
<tt:Event><wsnt:NotificationMessage xmlns:tns1="http://www.onvif.org/ver10/topics" mlns:tnsaxis="http://www.axis.com/2009/event/topics" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa5="http://www.w3.org/2005/08/addressing"><wsnt:Topic Dialect="http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple">tnsaxis:CameraApplicationPlatform/ObjectAnalytics/xinternal_data</wsnt:Topic><wsnt:ProducerReference><wsa5:Address>uri://cfbf96f2-9dc7-437f-aa12-155aacbb0b8f/ProducerReference</wsa5:Address></wsnt:ProducerReference><wsnt:Message><tt:Message UtcTime="2024-10-07T19:52:09.903990Z"><tt:Source></tt:Source><tt:Data><tt:SimpleItem Name="svgframe" Value="&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot; baseProfile=&quot;full&quot; 
xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; 
width=&quot;100%&quot; height=&quot;100%&quot; 
viewBox=&quot;-1 -1 2 2 &quot; 
preserveAspectRatio=&quot;none&quot; &gt;
&lt;g transform=&quot;matrix(1 0 0 -1 0 0) matrix(1.0000 0.0000 0.0000 1.0000 0.0000 0.0000 )&quot; &gt;&lt;polygon class=&quot;&quot; points=&quot;0.970,-0.970 -0.480,-0.967 -0.949,-0.678 -0.976,-0.199 -0.866,-0.376 -0.752,-0.356 -0.970,0.970 &quot; style=&quot;fill:#FF0000;fill-opacity:0.2;stroke-opacity:1;stroke:#FF0000;stroke-width

payload of packet no. 392:

:2.5px;vector-effect:non-scaling-stroke&quot; /&gt;
&lt;/g&gt;&lt;/svg&gt;"/></tt:Data></tt:Message></wsnt:Message></wsnt:NotificationMessage></tt:Event></tt:MetadataStream>
Kane610 commented 1 month ago

Awesome! I'll get back to you during the weekend, you can start by adding a test that covers this situation

swoga commented 1 month ago

added a test!

I had to adapt an existing test, because the dummy value 0123456789ABCDEF was used as data and therefore failed. I replaced it with a "minimal RTP header" (zeros and only set the position of the RTP marker bit).

Kane610 commented 1 month ago

I will publish a release tonight

If you see more improvements don't hesitate to to contribute <3

Kane610 commented 1 month ago

Release is out, will you publish a PR for home assistant @swoga

swoga commented 1 month ago

Yes, I am happy to do it!