Skip to content

Commit 4b2167b

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

9 files changed

+124
-171
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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ ISrsRequest *MockRtcAsyncCallRequest::as_http()
306306
MockRtcSource::MockRtcSource()
307307
{
308308
on_rtp_count_ = 0;
309+
rtp_audio_count_ = 0;
310+
rtp_video_count_ = 0;
309311
}
310312

311313
MockRtcSource::~MockRtcSource()
@@ -315,6 +317,14 @@ MockRtcSource::~MockRtcSource()
315317
srs_error_t MockRtcSource::on_rtp(SrsRtpPacket *pkt)
316318
{
317319
on_rtp_count_++;
320+
321+
// Count audio and video packets separately
322+
if (pkt->frame_type_ == SrsFrameTypeAudio) {
323+
rtp_audio_count_++;
324+
} else if (pkt->frame_type_ == SrsFrameTypeVideo) {
325+
rtp_video_count_++;
326+
}
327+
318328
return SrsRtcSource::on_rtp(pkt);
319329
}
320330

@@ -2337,3 +2347,53 @@ void MockAudioTranscoder::aac_codec_header(uint8_t **data, int *len)
23372347
*data = copy;
23382348
*len = size;
23392349
}
2350+
2351+
// Mock ISrsProtocolUtility implementation
2352+
MockProtocolUtility::MockProtocolUtility(std::string ip)
2353+
{
2354+
mock_ip_ = ip;
2355+
}
2356+
2357+
MockProtocolUtility::~MockProtocolUtility()
2358+
{
2359+
clear_ips();
2360+
}
2361+
2362+
std::vector<SrsIPAddress *> &MockProtocolUtility::local_ips()
2363+
{
2364+
if (!ips_.empty()) {
2365+
return ips_;
2366+
}
2367+
2368+
// If mock_ip_ is set (via constructor), create a default IP address
2369+
if (!mock_ip_.empty()) {
2370+
SrsIPAddress *addr = new SrsIPAddress();
2371+
addr->ip_ = mock_ip_;
2372+
addr->is_ipv4_ = true;
2373+
addr->is_loopback_ = false; // Not loopback
2374+
addr->is_internet_ = true; // Public IP
2375+
addr->ifname_ = "eth0"; // Interface name
2376+
ips_.push_back(addr);
2377+
}
2378+
2379+
return ips_;
2380+
}
2381+
2382+
void MockProtocolUtility::add_ip(std::string ip, std::string ifname, bool is_ipv4, bool is_loopback, bool is_internet)
2383+
{
2384+
SrsIPAddress *addr = new SrsIPAddress();
2385+
addr->ip_ = ip;
2386+
addr->ifname_ = ifname;
2387+
addr->is_ipv4_ = is_ipv4;
2388+
addr->is_loopback_ = is_loopback;
2389+
addr->is_internet_ = is_internet;
2390+
ips_.push_back(addr);
2391+
}
2392+
2393+
void MockProtocolUtility::clear_ips()
2394+
{
2395+
for (size_t i = 0; i < ips_.size(); i++) {
2396+
srs_freep(ips_[i]);
2397+
}
2398+
ips_.clear();
2399+
}

trunk/src/utest/srs_utest_manual_mock.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class MockRtcSource : public SrsRtcSource
162162
{
163163
public:
164164
int on_rtp_count_;
165+
int rtp_audio_count_;
166+
int rtp_video_count_;
165167

166168
public:
167169
MockRtcSource();
@@ -1332,4 +1334,23 @@ class MockAudioTranscoder : public ISrsAudioTranscoder
13321334
virtual void aac_codec_header(uint8_t **data, int *len);
13331335
};
13341336

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

trunk/src/utest/srs_utest_workflow_rtc_conn.cpp

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -34,73 +34,6 @@
3434
#include <srs_utest_manual_mock.hpp>
3535
#include <srs_utest_manual_service.hpp>
3636

37-
MockProtocolUtilityForRtcConn::MockProtocolUtilityForRtcConn(std::string ip)
38-
{
39-
mock_ip_ = ip;
40-
}
41-
42-
MockProtocolUtilityForRtcConn::~MockProtocolUtilityForRtcConn()
43-
{
44-
}
45-
46-
std::vector<SrsIPAddress *> &MockProtocolUtilityForRtcConn::local_ips()
47-
{
48-
if (!ips_.empty()) {
49-
return ips_;
50-
}
51-
52-
SrsIPAddress *addr = new SrsIPAddress();
53-
addr->ip_ = mock_ip_;
54-
addr->is_ipv4_ = true;
55-
addr->is_loopback_ = false; // Not loopback
56-
addr->is_internet_ = true; // Public IP
57-
addr->ifname_ = "eth0"; // Interface name
58-
ips_.push_back(addr);
59-
60-
return ips_;
61-
}
62-
63-
MockAppFactoryForRtcConn::MockAppFactoryForRtcConn()
64-
{
65-
mock_protocol_utility_ = NULL;
66-
}
67-
68-
MockAppFactoryForRtcConn::~MockAppFactoryForRtcConn()
69-
{
70-
}
71-
72-
ISrsProtocolUtility *MockAppFactoryForRtcConn::create_protocol_utility()
73-
{
74-
return mock_protocol_utility_;
75-
}
76-
77-
ISrsRtcPublishStream *MockAppFactoryForRtcConn::create_rtc_publish_stream(ISrsExecRtcAsyncTask *exec, ISrsExpire *expire, ISrsRtcPacketReceiver *receiver, const SrsContextId &cid)
78-
{
79-
SrsRtcPublishStream *publisher = new SrsRtcPublishStream(exec, expire, receiver, cid);
80-
publisher->rtc_sources_ = rtc_sources_;
81-
return publisher;
82-
}
83-
84-
MockRtcSourceForRtcConn::MockRtcSourceForRtcConn()
85-
{
86-
rtp_audio_count_ = 0;
87-
rtp_video_count_ = 0;
88-
}
89-
90-
MockRtcSourceForRtcConn::~MockRtcSourceForRtcConn()
91-
{
92-
}
93-
94-
srs_error_t MockRtcSourceForRtcConn::on_rtp(SrsRtpPacket *pkt)
95-
{
96-
if (pkt->frame_type_ == SrsFrameTypeAudio) {
97-
rtp_audio_count_++;
98-
} else if (pkt->frame_type_ == SrsFrameTypeVideo) {
99-
rtp_video_count_++;
100-
}
101-
return srs_success;
102-
}
103-
10437
// This test is used to verify the basic workflow of the RTC connection.
10538
// It's finished with the help of AI, but each step is manually designed
10639
// and verified. So this is not dominated by AI, but by humanbeing.
@@ -120,8 +53,8 @@ VOID TEST(BasicWorkflowRtcConnTest, ManuallyVerifyForPlayer)
12053
mock_config->rtc_dtls_role_ = "passive";
12154
mock_dtls_certificate->fingerprint_ = "test-fingerprint";
12255
mock_app_factory->rtc_sources_ = mock_rtc_sources.get();
123-
mock_app_factory->mock_protocol_utility_ = new MockProtocolUtilityForRtcConn("192.168.1.100");
124-
MockRtcSourceForRtcConn *mock_rtc_source = new MockRtcSourceForRtcConn();
56+
mock_app_factory->mock_protocol_utility_ = new MockProtocolUtility("192.168.1.100");
57+
MockRtcSource *mock_rtc_source = new MockRtcSource();
12558
mock_rtc_sources->mock_source_ = SrsSharedPtr<SrsRtcSource>(mock_rtc_source);
12659

12760
// Create a real ISrsRtcConnection using _srs_app_factory_
@@ -271,8 +204,8 @@ VOID TEST(BasicWorkflowRtcConnTest, ManuallyVerifyForPublisher)
271204
mock_config->rtc_dtls_role_ = "passive";
272205
mock_dtls_certificate->fingerprint_ = "test-fingerprint";
273206
mock_app_factory->rtc_sources_ = mock_rtc_sources.get();
274-
mock_app_factory->mock_protocol_utility_ = new MockProtocolUtilityForRtcConn("192.168.1.100");
275-
MockRtcSourceForRtcConn *mock_rtc_source = new MockRtcSourceForRtcConn();
207+
mock_app_factory->mock_protocol_utility_ = new MockProtocolUtility("192.168.1.100");
208+
MockRtcSource *mock_rtc_source = new MockRtcSource();
276209
mock_rtc_sources->mock_source_ = SrsSharedPtr<SrsRtcSource>(mock_rtc_source);
277210

278211
// Create a real ISrsRtcConnection using _srs_app_factory_

0 commit comments

Comments
 (0)