WebRTC 오디오 및 비디오 통화 - SDP에서 비트 전송률 제한을 추가하거나 수정합니다.

WebRTC 오디오 및 비디오 통화 - SDP에서 비트 전송률 제한 매개변수 추가 또는 수정

ossrs 서비스를 설정하기 전에 다음을 확인할 수 있습니다. https://blog.csdn.net/gloryFlow/article/details/132257196
iOS를 구현하여 ossrs 음성 및 영상 통화를 호출하기 전에 다음을 확인할 수 있습니다. https://blog.csdn .net/gloryFlow/article/details/132262724
고해상도 이전의 WebRTC 오디오 및 비디오 호출에 화면 문제가 표시되지 않으면 다음에서 볼 수 있습니다. https://blog.csdn.net/gloryFlow/article/details/132240952

여기에서 WebRTC 오디오 및 비디오 통화 중에 SDP의 비트 전송률 Bitrate를 수정합니다.

1. SDP란 무엇인가요?

SDP는 세션 설명 프로토콜(Session Description Protocol)입니다.
SDP는 하나 이상의 UTF-8 텍스트 줄로 구성됩니다. 각 줄은 문자 유형으로 시작하고 그 뒤에 등호(=)가 오고 값이나 설명이 포함됩니다. 구조화된 텍스트 , 형식은 유형에 따라 다릅니다. 다음은 SDP 콘텐츠의 예입니다.

v=0
o=앨리스 2890844526 2890844526 IN IP4
s=
c=IN IP4
t=0 0
m=오디오 49170 RTP/AVP 0
a=rtpmap:0 PCMU/8000
m=비디오 51372 RTP/AVP 31
a=rtpmap:31 H261 /90000m
=비디오 53000 RTP/AVP 32
a=rtpmap:32 MPV/90000

로컬에서 얻은 전체 SDP 데이터는 다음과 같습니다.

v=0
\no=SRS/6.0.64(Bee) 107408568903808 2 IN IP4 0.0.0.0
\ns=SRSPublishSession
\nt=0 0
\na=ice-lite
\na=group:BUNDLE 0 1
\na=msid-semantic : WMS 라이브/라이브 스트림
\nm=오디오 9 UDP/TLS/RTP/SAVPF 111
\nc=IN IP4 0.0.0.0
\na=ice-fragment:4ahia260
\na=ice-pwd:11777k546394014cto09595g5em82339
\na=fingerprint:sha-256 26:AF:1F:AA:18:C0:4F:69:E3:19:B4:EF:9C:43:98:A9:E6:56:9A:2D:D4:2E:A8:31:D7: B1:C9:A1:08:CA:B2:13
\na=setup:passive
\na=mid:0
\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport -wide-cc-extensions-01
\na=recvonly
\na=rtcp-mux
\na=rtcp-rsize
\na=rtpmap:111 opus/48000/2
/ N N NY EPPPP:111,
301 ) 질문 질문 , 10: 0 1 , 10-1
307444 \nm=video 9 UDP/TLS/RTP/SAVPF 96 127 \nc=IN IP4 0.0. 0.0 \na=ice-subfragment:4ahia260 \na=ice-pwd:11777k546394014cto09595g5em82339 \na=fingerprint :sha-256 26:AF:1F:AA:18:C0:4F:69:E3:19:B4:EF:9C :43:98:A9:E6:56:9A:2D:D4:2E:A8: 31:D7:B1:C9:A1:08:CA:B2:13 \na=setup:passive \na=mid : 1 \na=extmap:3 http://www.ietf.org/id/draft-holmer -rmcat-transport-wide-cc-extensions-01 \na=recvonly \na=rtcp-mux \na=rtcp-rsize \ na=rtpmap:96 H264/90000













\na=rtcp-fb:96 Transport-cc
\na=rtcp-fb:96 nack
\na=rtcp-fb:96 nack pli
\na=fmtp:96 level-asymmetry-allowed=1;packetization-mode=1; profile-level-id=640c33
\na=rtpmap:127 빨간색/90000
\na=candidate:0 1 udp 2130706431 169.254.136.162 8000 일반 호스트 세대 0
\na=candidate:1 1 udp 2130706431 192.168.10.100 8 000 일반 호스트 0세대
\N

위의 데이터 형식에서 볼 수 있듯이

다음과 같은 일반적인

m은 미디어를 나타내고
m=audio는 이 행이 오디오 정보를 설명한다는 것을 의미합니다.
m=video는 이 줄이 비디오 정보를 설명한다는 의미입니다.

a는 a=candidate와 같은 속성을 나타냅니다. 이는 이 행이 후보 정보를 설명한다는 의미입니다.

그리고 해상도와 관련된 프로필 수준 ID 640c33이 표시됩니다.

2. SDP에서 비트 전송률 제한 매개변수를 추가하거나 수정합니다.

다음으로 SDP에서 code rate Bitrate를 수정해야 하며, b=AS가 없으면 새로 추가합니다.

구체적인 코드는 다음과 같습니다

+ (NSString *)setMediaBitrate:(NSString *)sdp media:(NSString *)media bitrate:(int)bitrate {
    
    
    if (!(sdp && [sdp isKindOfClass:[NSString class]] && sdp.length > 0)) {
    
    
        return sdp;
    }
    
    NSMutableArray *lines = [NSMutableArray arrayWithArray:[sdp componentsSeparatedByString:@"\n"]];
    int line = -1;
    for (int i = 0; i < lines.count; i++) {
    
    
        NSString *start = [NSString stringWithFormat:@"m=%@",media];
        if ([lines[i] hasPrefix:start]) {
    
    
            line = i;
            break;
        }
    }
    
    if (line == -1) {
    
    
        NSLog(@"Could not find the m line for %@", media);
        return sdp;
    }
    
    NSLog(@"Found the m line for %@", media);
    line++;
    
    while ([lines[line] hasPrefix:@"i="] || [lines[line] hasPrefix:@"c="]) {
    
    
        line++;
    }
    
    if ([lines[line] hasPrefix:@"b"]) {
    
    
        NSLog(@"Replaced b line at line:%d", line);
        lines[line] = [NSString stringWithFormat:@"b=AS:%d", bitrate];

        return [lines componentsJoinedByString:@"\n"];
    }
    
    NSLog(@"Adding new b line before line:%d", line);
    NSMutableArray *newLines = [NSMutableArray arrayWithArray:[lines subarrayWithRange:NSMakeRange(0, line)]];
    
    NSMutableArray *aLeftLines = [NSMutableArray arrayWithArray:[lines subarrayWithRange:NSMakeRange(line, lines.count - line)]];
    
    NSString *aLineStr = [NSString stringWithFormat:@"b=AS:%d", bitrate];
    [newLines addObject:aLineStr];
    
    NSMutableArray *resultLines = [NSMutableArray arrayWithCapacity:0];
    [resultLines addObjectsFromArray:newLines];
    [resultLines addObjectsFromArray:aLeftLines];

    return [resultLines componentsJoinedByString:@"\n"];
}

렌더링

여기에 이미지 설명을 삽입하세요

3. 요약

WebRTC 오디오 및 비디오 통화 - SDP에서 비트 전송률 제한 매개변수를 추가하거나 수정합니다. 내용이 많아 설명이 정확하지 않을 수 있으니 양해 부탁드립니다.

https://blog.csdn.net/gloryFlow/article/details/132263021

학습 기록, 매일 계속 향상됩니다.

추천

출처blog.csdn.net/gloryFlow/article/details/132263021