Skip to content

Commit 1e1b85b

Browse files
ossrs-aiwinlinvip
authored andcommitted
AI: Refine utest for WebRTC AV1.
1 parent 1a96abc commit 1e1b85b

9 files changed

+399
-177
lines changed

trunk/src/app/srs_app_rtc_api.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,16 +666,16 @@ srs_error_t SrsGoApiRtcWhip::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
666666
string code_str;
667667
if (true) {
668668
srs_error_t err = srs_success;
669-
669+
670670
err = serve_http_with(w, r);
671671
if (err == srs_success) {
672672
return err;
673673
}
674674

675675
code = srs_error_code(err);
676676
code_str = srs_error_code_str(err);
677-
srs_warn("WHIP: serve http for %s with err %d:%s, %s",
678-
r->url().c_str(), code, code_str.c_str(), srs_error_desc(err).c_str());
677+
srs_warn("WHIP: serve http for %s with err %d:%s, %s",
678+
r->url().c_str(), code, code_str.c_str(), srs_error_desc(err).c_str());
679679
srs_freep(err);
680680
}
681681

trunk/src/app/srs_app_rtc_source.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3851,7 +3851,7 @@ srs_error_t SrsRtcFormat::on_rtp_packet(SrsRtcRecvTrack *track, bool is_audio)
38513851
SrsAudioChannels channels = (SrsAudioChannels)audio_media->channel_;
38523852

38533853
if ((err = stat_->on_audio_info(req_, codec_id, sample_rate, channels,
3854-
SrsAacObjectTypeReserved)) != srs_success) {
3854+
SrsAacObjectTypeReserved)) != srs_success) {
38553855
return srs_error_wrap(err, "stat audio info");
38563856
}
38573857
srs_trace("RTC: parsed %s codec, sample_rate=%dHz, channels=%d",

trunk/src/kernel/srs_kernel_error.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,9 @@
111111
XX(ERROR_STREAM_DISPOSING, 1098, "StreamDisposing", "Stream is disposing") \
112112
XX(ERROR_NOT_IMPLEMENTED, 1099, "NotImplemented", "Feature is not implemented") \
113113
XX(ERROR_NOT_SUPPORTED, 1100, "NotSupported", "Feature is not supported") \
114-
XX(ERROR_SYSTEM_FILE_UNLINK, 1101, "FileUnlink", "Failed to unlink file") \
114+
XX(ERROR_SYSTEM_FILE_UNLINK, 1101, "FileUnlink", "Failed to unlink file") \
115115
XX(ERROR_SYSTEM_AUTH, 1102, "SystemAuth", "Failed to authenticate stream")
116116

117-
118117
/**************************************************/
119118
/* RTMP protocol error. */
120119
#define SRS_ERRNO_MAP_RTMP(XX) \
@@ -382,7 +381,7 @@
382381
XX(ERROR_RTSP_NO_TRACK, 5039, "RtspNoTrack", "Drop RTSP packet for track not found") \
383382
XX(ERROR_RTSP_TOKEN_NOT_NORMAL, 5040, "RtspToken", "Invalid RTSP token state not normal") \
384383
XX(ERROR_RTSP_REQUEST_HEADER_EOF, 5041, "RtspHeaderEof", "Invalid RTSP request for header EOF") \
385-
XX(ERROR_RTSP_NEED_MORE_DATA, 5042, "RtspNeedMoreData", "Need more data to complete RTCP frame parsing") \
384+
XX(ERROR_RTSP_NEED_MORE_DATA, 5042, "RtspNeedMoreData", "Need more data to complete RTCP frame parsing") \
386385
XX(ERROR_RTC_INVALID_SDP, 5043, "RtcInvalidSdp", "Invalid SDP for RTC")
387386

388387
/**************************************************/
@@ -492,7 +491,7 @@ class SrsCplxError
492491
// }
493492
#define srs_error_new(code, fmt, ...) SrsCplxError::create(__FUNCTION__, __FILE__, __LINE__, code, fmt, ##__VA_ARGS__)
494493

495-
// Wrap an existing error with additional context. The error code is
494+
// Wrap an existing error with additional context. The error code is
496495
// preserved from the wrapped error.
497496
//
498497
// Example:
@@ -501,8 +500,8 @@ class SrsCplxError
501500
// }
502501
#define srs_error_wrap(err, fmt, ...) SrsCplxError::wrap(__FUNCTION__, __FILE__, __LINE__, err, fmt, ##__VA_ARGS__)
503502

504-
// Transform an error by wrapping it and changing its error code. Useful
505-
// for converting internal errors to protocol-specific error codes (e.g.,
503+
// Transform an error by wrapping it and changing its error code. Useful
504+
// for converting internal errors to protocol-specific error codes (e.g.,
506505
// HTTP, RTMP). The wrapped error chain is preserved.
507506
//
508507
// Example:

trunk/src/utest/srs_utest_ai18.cpp

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using namespace std;
2121
#include <srs_kernel_utility.hpp>
2222
#include <srs_protocol_utility.hpp>
2323
#include <srs_utest_ai23.hpp>
24+
#include <srs_utest_manual_mock.hpp>
2425
#include <sstream>
2526

2627
// Mock ISrsSrtSocket implementation
@@ -193,10 +194,11 @@ VOID TEST(UdpListenerTest, ListenAndReceivePacket)
193194
dest_addr.sin_port = htons(port);
194195
dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
195196

196-
for (int i = 0; i < 3; i++) {
197+
for (int i = 0; i < 10; i++) {
197198
int sent = srs_sendto(client_fd, (void *)test_data.c_str(), test_data.size(),
198199
(sockaddr *)&dest_addr, sizeof(dest_addr), SRS_UTIME_NO_TIMEOUT);
199200
EXPECT_EQ(sent, (int)test_data.size());
201+
srs_usleep(1 * SRS_UTIME_MILLISECONDS);
200202
}
201203

202204
// Wait a bit for the listener to receive and process the packet
@@ -2186,39 +2188,8 @@ VOID TEST(ApiServerAsCandidatesTest, MajorUseScenario)
21862188
EXPECT_TRUE(candidate_ips.find("192.168.1.100") != candidate_ips.end());
21872189
}
21882190

2189-
// Mock SrsProtocolUtility implementation
2190-
MockProtocolUtility::MockProtocolUtility()
2191-
{
2192-
}
2193-
2194-
MockProtocolUtility::~MockProtocolUtility()
2195-
{
2196-
clear_ips();
2197-
}
2198-
2199-
vector<SrsIPAddress *> &MockProtocolUtility::local_ips()
2200-
{
2201-
return mock_ips_;
2202-
}
2203-
2204-
void MockProtocolUtility::add_ip(string ip, string ifname, bool is_ipv4, bool is_loopback, bool is_internet)
2205-
{
2206-
SrsIPAddress *addr = new SrsIPAddress();
2207-
addr->ip_ = ip;
2208-
addr->ifname_ = ifname;
2209-
addr->is_ipv4_ = is_ipv4;
2210-
addr->is_loopback_ = is_loopback;
2211-
addr->is_internet_ = is_internet;
2212-
mock_ips_.push_back(addr);
2213-
}
2214-
2215-
void MockProtocolUtility::clear_ips()
2216-
{
2217-
for (size_t i = 0; i < mock_ips_.size(); i++) {
2218-
srs_freep(mock_ips_[i]);
2219-
}
2220-
mock_ips_.clear();
2221-
}
2191+
// Note: MockProtocolUtility has been merged into MockProtocolUtility
2192+
// in srs_utest_manual_mock.hpp/cpp. All usages below now use MockProtocolUtility.
22222193

22232194
// Mock ISrsAppConfig for discover_candidates implementation
22242195
MockAppConfigForDiscoverCandidates::MockAppConfigForDiscoverCandidates()

trunk/src/utest/srs_utest_ai18.hpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,8 @@ class MockHttpHooksForSrt : public ISrsHttpHooks
196196
void clear_calls();
197197
};
198198

199-
// Mock SrsProtocolUtility for testing discover_candidates
200-
class MockProtocolUtility : public SrsProtocolUtility
201-
{
202-
public:
203-
std::vector<SrsIPAddress *> mock_ips_;
204-
205-
public:
206-
MockProtocolUtility();
207-
virtual ~MockProtocolUtility();
208-
virtual std::vector<SrsIPAddress *> &local_ips();
209-
void add_ip(std::string ip, std::string ifname, bool is_ipv4, bool is_loopback, bool is_internet);
210-
void clear_ips();
211-
};
199+
// Note: MockProtocolUtility has been merged into MockProtocolUtility
200+
// in srs_utest_manual_mock.hpp. Use MockProtocolUtility instead.
212201

213202
// Mock ISrsAppConfig for testing discover_candidates
214203
class MockAppConfigForDiscoverCandidates : public MockAppConfig

trunk/src/utest/srs_utest_manual_mock.cpp

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ MockSdpFactory::~MockSdpFactory()
5656
{
5757
}
5858

59-
std::string MockSdpFactory::create_chrome_player_offer()
59+
std::string MockSdpFactory::create_chrome_player_offer_with_h264()
6060
{
6161
// Create a real Chrome-like WebRTC SDP offer for a player (subscriber) with H.264 video and Opus audio
6262
// Use member variables for SSRC and payload type values
@@ -104,7 +104,7 @@ std::string MockSdpFactory::create_chrome_player_offer()
104104
return ss.str();
105105
}
106106

107-
std::string MockSdpFactory::create_chrome_publisher_offer()
107+
std::string MockSdpFactory::create_chrome_publisher_offer_with_h264()
108108
{
109109
// Create a real Chrome-like WebRTC SDP offer with H.264 video and Opus audio
110110
// Use member variables for SSRC and payload type values
@@ -155,6 +155,58 @@ std::string MockSdpFactory::create_chrome_publisher_offer()
155155
return ss.str();
156156
}
157157

158+
std::string MockSdpFactory::create_chrome_publisher_offer_with_av1()
159+
{
160+
// Create a real Chrome-like WebRTC SDP offer with AV1 video and Opus audio
161+
// Use member variables for SSRC and payload type values
162+
// AV1 payload type is typically 45 or 96+
163+
uint8_t av1_pt = 45;
164+
std::stringstream ss;
165+
ss << "v=0\r\n"
166+
<< "o=- 4611731400430051338 2 IN IP4 127.0.0.1\r\n"
167+
<< "s=-\r\n"
168+
<< "t=0 0\r\n"
169+
<< "a=group:BUNDLE 0 1\r\n"
170+
<< "a=msid-semantic: WMS stream\r\n"
171+
// Audio media description (Opus)
172+
<< "m=audio 9 UDP/TLS/RTP/SAVPF " << (int)audio_pt_ << "\r\n"
173+
<< "c=IN IP4 0.0.0.0\r\n"
174+
<< "a=rtcp:9 IN IP4 0.0.0.0\r\n"
175+
<< "a=ice-ufrag:test1234\r\n"
176+
<< "a=ice-pwd:testpassword1234567890\r\n"
177+
<< "a=ice-options:trickle\r\n"
178+
<< "a=fingerprint:sha-256 AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99\r\n"
179+
<< "a=setup:actpass\r\n"
180+
<< "a=mid:0\r\n"
181+
<< "a=sendonly\r\n"
182+
<< "a=rtcp-mux\r\n"
183+
<< "a=rtpmap:" << (int)audio_pt_ << " opus/48000/2\r\n"
184+
<< "a=fmtp:" << (int)audio_pt_ << " minptime=10;useinbandfec=1\r\n"
185+
<< "a=ssrc:" << audio_ssrc_ << " cname:test-audio-cname\r\n"
186+
<< "a=ssrc:" << audio_ssrc_ << " msid:stream audio\r\n"
187+
// Video media description (AV1)
188+
<< "m=video 9 UDP/TLS/RTP/SAVPF " << (int)av1_pt << "\r\n"
189+
<< "c=IN IP4 0.0.0.0\r\n"
190+
<< "a=rtcp:9 IN IP4 0.0.0.0\r\n"
191+
<< "a=ice-ufrag:test1234\r\n"
192+
<< "a=ice-pwd:testpassword1234567890\r\n"
193+
<< "a=ice-options:trickle\r\n"
194+
<< "a=fingerprint:sha-256 AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99\r\n"
195+
<< "a=setup:actpass\r\n"
196+
<< "a=mid:1\r\n"
197+
<< "a=sendonly\r\n"
198+
<< "a=rtcp-mux\r\n"
199+
<< "a=rtcp-rsize\r\n"
200+
<< "a=rtpmap:" << (int)av1_pt << " AV1/90000\r\n"
201+
<< "a=rtcp-fb:" << (int)av1_pt << " nack\r\n"
202+
<< "a=rtcp-fb:" << (int)av1_pt << " nack pli\r\n"
203+
<< "a=rtcp-fb:" << (int)av1_pt << " transport-cc\r\n"
204+
<< "a=ssrc:" << video_ssrc_ << " cname:test-video-cname\r\n"
205+
<< "a=ssrc:" << video_ssrc_ << " msid:stream video\r\n";
206+
207+
return ss.str();
208+
}
209+
158210
MockDtlsCertificate::MockDtlsCertificate()
159211
{
160212
fingerprint_ = "AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99";
@@ -306,6 +358,8 @@ ISrsRequest *MockRtcAsyncCallRequest::as_http()
306358
MockRtcSource::MockRtcSource()
307359
{
308360
on_rtp_count_ = 0;
361+
rtp_audio_count_ = 0;
362+
rtp_video_count_ = 0;
309363
}
310364

311365
MockRtcSource::~MockRtcSource()
@@ -315,6 +369,14 @@ MockRtcSource::~MockRtcSource()
315369
srs_error_t MockRtcSource::on_rtp(SrsRtpPacket *pkt)
316370
{
317371
on_rtp_count_++;
372+
373+
// Count audio and video packets separately
374+
if (pkt->frame_type_ == SrsFrameTypeAudio) {
375+
rtp_audio_count_++;
376+
} else if (pkt->frame_type_ == SrsFrameTypeVideo) {
377+
rtp_video_count_++;
378+
}
379+
318380
return SrsRtcSource::on_rtp(pkt);
319381
}
320382

@@ -2337,3 +2399,53 @@ void MockAudioTranscoder::aac_codec_header(uint8_t **data, int *len)
23372399
*data = copy;
23382400
*len = size;
23392401
}
2402+
2403+
// Mock ISrsProtocolUtility implementation
2404+
MockProtocolUtility::MockProtocolUtility(std::string ip)
2405+
{
2406+
mock_ip_ = ip;
2407+
}
2408+
2409+
MockProtocolUtility::~MockProtocolUtility()
2410+
{
2411+
clear_ips();
2412+
}
2413+
2414+
std::vector<SrsIPAddress *> &MockProtocolUtility::local_ips()
2415+
{
2416+
if (!ips_.empty()) {
2417+
return ips_;
2418+
}
2419+
2420+
// If mock_ip_ is set (via constructor), create a default IP address
2421+
if (!mock_ip_.empty()) {
2422+
SrsIPAddress *addr = new SrsIPAddress();
2423+
addr->ip_ = mock_ip_;
2424+
addr->is_ipv4_ = true;
2425+
addr->is_loopback_ = false; // Not loopback
2426+
addr->is_internet_ = true; // Public IP
2427+
addr->ifname_ = "eth0"; // Interface name
2428+
ips_.push_back(addr);
2429+
}
2430+
2431+
return ips_;
2432+
}
2433+
2434+
void MockProtocolUtility::add_ip(std::string ip, std::string ifname, bool is_ipv4, bool is_loopback, bool is_internet)
2435+
{
2436+
SrsIPAddress *addr = new SrsIPAddress();
2437+
addr->ip_ = ip;
2438+
addr->ifname_ = ifname;
2439+
addr->is_ipv4_ = is_ipv4;
2440+
addr->is_loopback_ = is_loopback;
2441+
addr->is_internet_ = is_internet;
2442+
ips_.push_back(addr);
2443+
}
2444+
2445+
void MockProtocolUtility::clear_ips()
2446+
{
2447+
for (size_t i = 0; i < ips_.size(); i++) {
2448+
srs_freep(ips_[i]);
2449+
}
2450+
ips_.clear();
2451+
}

trunk/src/utest/srs_utest_manual_mock.hpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ class MockSdpFactory
7878

7979
public:
8080
// Create a Chrome-like WebRTC publisher offer SDP
81-
std::string create_chrome_publisher_offer();
81+
std::string create_chrome_publisher_offer_with_h264();
8282
// Create a Chrome-like WebRTC player offer SDP
83-
std::string create_chrome_player_offer();
83+
std::string create_chrome_player_offer_with_h264();
84+
// Create a Chrome-like WebRTC publisher offer SDP with AV1
85+
std::string create_chrome_publisher_offer_with_av1();
8486
};
8587

8688
// Mock DTLS certificate for testing
@@ -162,6 +164,8 @@ class MockRtcSource : public SrsRtcSource
162164
{
163165
public:
164166
int on_rtp_count_;
167+
int rtp_audio_count_;
168+
int rtp_video_count_;
165169

166170
public:
167171
MockRtcSource();
@@ -1332,4 +1336,23 @@ class MockAudioTranscoder : public ISrsAudioTranscoder
13321336
virtual void aac_codec_header(uint8_t **data, int *len);
13331337
};
13341338

1339+
// Mock ISrsProtocolUtility for testing RTC connections
1340+
// This class merges functionality from MockProtocolUtility in srs_utest_ai18.hpp
1341+
// It supports both simple single-IP usage (via constructor) and complex multi-IP usage (via add_ip)
1342+
class MockProtocolUtility : public ISrsProtocolUtility
1343+
{
1344+
public:
1345+
std::vector<SrsIPAddress *> ips_;
1346+
std::string mock_ip_;
1347+
1348+
public:
1349+
MockProtocolUtility(std::string ip = "");
1350+
virtual ~MockProtocolUtility();
1351+
1352+
public:
1353+
virtual std::vector<SrsIPAddress *> &local_ips();
1354+
void add_ip(std::string ip, std::string ifname, bool is_ipv4, bool is_loopback, bool is_internet);
1355+
void clear_ips();
1356+
};
1357+
13351358
#endif

0 commit comments

Comments
 (0)