Skip to content

Commit 809f0a5

Browse files
committed
avformat/whip: add srtp setup for video rtx
unique ssrc need to use unique srtp context, otherwise the server couldn't decrypted the rtx packet. move the "a=ssrc-group:FID" on top of SSRCs Signed-off-by: Jack Lau <jacklau1222@qq.com>
1 parent 890afb8 commit 809f0a5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

libavformat/whip.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ typedef struct WHIPContext {
294294
/* The SRTP send context, to encrypt outgoing packets. */
295295
SRTPContext srtp_audio_send;
296296
SRTPContext srtp_video_send;
297+
SRTPContext srtp_video_rtx_send;
297298
SRTPContext srtp_rtcp_send;
298299
/* The SRTP receive context, to decrypt incoming packets. */
299300
SRTPContext srtp_recv;
@@ -717,11 +718,11 @@ static int generate_sdp_offer(AVFormatContext *s)
717718
"a=rtcp-fb:%u nack\r\n"
718719
"a=rtpmap:%u rtx/90000\r\n"
719720
"a=fmtp:%u apt=%u\r\n"
721+
"a=ssrc-group:FID %u %u\r\n"
720722
"a=ssrc:%u cname:FFmpeg\r\n"
721723
"a=ssrc:%u msid:FFmpeg video\r\n"
722724
"a=ssrc:%u cname:FFmpeg\r\n"
723-
"a=ssrc:%u msid:FFmpeg video\r\n"
724-
"a=ssrc-group:FID %u %u\r\n",
725+
"a=ssrc:%u msid:FFmpeg video\r\n",
725726
whip->video_payload_type,
726727
whip->rtx_payload_type,
727728
whip->ice_ufrag_local,
@@ -738,10 +739,10 @@ static int generate_sdp_offer(AVFormatContext *s)
738739
whip->rtx_payload_type,
739740
whip->video_payload_type,
740741
whip->video_ssrc,
741-
whip->video_ssrc,
742-
whip->video_rtx_ssrc,
743742
whip->video_rtx_ssrc,
744743
whip->video_ssrc,
744+
whip->video_ssrc,
745+
whip->video_rtx_ssrc,
745746
whip->video_rtx_ssrc);
746747
}
747748

@@ -1442,6 +1443,12 @@ static int setup_srtp(AVFormatContext *s)
14421443
goto end;
14431444
}
14441445

1446+
ret = ff_srtp_set_crypto(&whip->srtp_video_rtx_send, suite, buf);
1447+
if (ret < 0) {
1448+
av_log(whip, AV_LOG_ERROR, "WHIP: Failed to set crypto for video rtx send\n");
1449+
goto end;
1450+
}
1451+
14451452
ret = ff_srtp_set_crypto(&whip->srtp_rtcp_send, suite, buf);
14461453
if (ret < 0) {
14471454
av_log(whip, AV_LOG_ERROR, "Failed to set crypto for rtcp send\n");
@@ -1583,7 +1590,7 @@ static int send_rtx_packet(AVFormatContext *s, const uint8_t * orig_pkt, int ori
15831590
new_size = orig_size + 2;
15841591

15851592
/* Encrypt by SRTP and send out. */
1586-
cipher_size = ff_srtp_encrypt(&whip->srtp_video_send, whip->buf, new_size, whip->buf, sizeof(whip->buf));
1593+
cipher_size = ff_srtp_encrypt(&whip->srtp_video_rtx_send, whip->buf, new_size, whip->buf, sizeof(whip->buf));
15871594
if (cipher_size <= 0 || cipher_size < new_size) {
15881595
av_log(whip, AV_LOG_WARNING, "WHIP: Failed to encrypt packet=%dB, cipher=%dB\n", new_size, cipher_size);
15891596
return 0;

0 commit comments

Comments
 (0)