@@ -599,19 +599,7 @@ void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiToAllParticipan
599599
600600template <class UdpClass , class Settings , class Platform >
601601void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiBuffer (Participant<Settings>* participant)
602- {
603- const IPAddress remoteIP = participant->remoteIP ;
604- const uint16_t remotePort = participant->remotePort + 1 ;
605-
606- if (!dataPort.beginPacket (remoteIP, remotePort))
607- {
608- #ifdef USE_EXT_CALLBACKS
609- if (nullptr != _exceptionCallback)
610- _exceptionCallback (ssrc, UdpBeginPacketFailed, 5 );
611- #endif
612- return ;
613- }
614-
602+ {
615603 Rtp rtp;
616604 rtp.vpxcc = 0b10000000 ; // TODO: fun with flags
617605 rtp.mpayload = PAYLOADTYPE_RTPMIDI; // TODO: set or unset marker
@@ -647,11 +635,21 @@ void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiBuffer(Particip
647635 rtp.ssrc = __htonl (rtp.ssrc );
648636 rtp.sequenceNr = __htons (rtp.sequenceNr );
649637
638+ if (!dataPort.beginPacket (participant->remoteIP , participant->remotePort + 1 ))
639+ {
640+ #ifdef USE_EXT_CALLBACKS
641+ if (nullptr != _exceptionCallback)
642+ _exceptionCallback (ssrc, UdpBeginPacketFailed, 5 );
643+ #endif
644+ return ;
645+ }
646+
647+ // write rtp header
650648 dataPort.write ((uint8_t *)&rtp, sizeof (rtp));
651649
652- // only now the length is known
653- auto bufferLen = outMidiBuffer.size ();
650+ const auto bufferLen = outMidiBuffer.size ();
654651
652+ // Write rtpMIDI section
655653 RtpMIDI_t rtpMidi;
656654
657655 if (bufferLen <= 0x0F )
@@ -673,20 +671,20 @@ void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiBuffer(Particip
673671 dataPort.write (rtpMidi.flags );
674672 dataPort.write ((uint8_t )(bufferLen));
675673 }
676-
674+
677675 // write out the MIDI Section
678676 for (size_t i = 0 ; i < bufferLen; i++)
679677 dataPort.write (outMidiBuffer[i]);
680678
681679 // *No* journal section (Not supported)
682680
681+ dataPort.endPacket ();
682+ dataPort.flush ();
683+
683684#ifdef USE_EXT_CALLBACKS
684685 if (_sentRtpMidiCallback)
685686 _sentRtpMidiCallback (rtpMidi);
686687#endif
687-
688- dataPort.endPacket ();
689- dataPort.flush ();
690688}
691689
692690//
0 commit comments