Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ if [[ $SRS_UTEST == YES ]]; then
"srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" "srs_utest_config2"
"srs_utest_protocol" "srs_utest_protocol2" "srs_utest_kernel2" "srs_utest_protocol3"
"srs_utest_st" "srs_utest_rtc2" "srs_utest_rtc3" "srs_utest_fmp4" "srs_utest_source_lock"
"srs_utest_stream_token" "srs_utest_rtc_recv_track")
"srs_utest_stream_token" "srs_utest_rtc_recv_track" "srs_utest_st2")
# Always include SRT utest
MODULE_FILES+=("srs_utest_srt")
if [[ $SRS_GB28181 == YES ]]; then
Expand Down
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The changelog for SRS.
<a name="v7-changes"></a>

## SRS 7.0 Changelog
* v7.0, 2025-09-06, Merge [#4475](https://github.com/ossrs/srs/pull/4475): AI: Support anonymous coroutine with code block. v7.0.80 (#4475)
* v7.0, 2025-09-05, Merge [#4474](https://github.com/ossrs/srs/pull/4474): WebRTC: Fix race condition in RTC nack timer callbacks. v7.0.79 (#4474)
* v7.0, 2025-09-04, Merge [#4467](https://github.com/ossrs/srs/pull/4467): WebRTC: Fix NACK recovered packets not being added to receive queue. v7.0.78 (#4467)
* v7.0, 2025-09-03, Merge [#4469](https://github.com/ossrs/srs/pull/4469): Upgrade HTTP parser from http-parser to llhttp. v7.0.77 (#4469)
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_async_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void SrsAsyncCallWorker::flush_tasks()
// Avoid the async call blocking other coroutines.
std::vector<ISrsAsyncCallTask *> copy;
if (true) {
SrsLocker(lock);
SrsLocker(&lock);

if (tasks.empty()) {
return;
Expand Down
12 changes: 6 additions & 6 deletions trunk/src/app/srs_app_rtc_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ SrsRtcPublishRtcpTimer::SrsRtcPublishRtcpTimer(SrsRtcPublishStream *p) : p_(p)
SrsRtcPublishRtcpTimer::~SrsRtcPublishRtcpTimer()
{
if (true) {
SrsLocker(lock_);
SrsLocker(&lock_);
_srs_shared_timer->timer1s()->unsubscribe(this);
}
srs_mutex_destroy(lock_);
Expand All @@ -949,7 +949,7 @@ srs_error_t SrsRtcPublishRtcpTimer::on_timer(srs_utime_t interval)
// Therefore, during this function, the 'this' pointer might become invalid because
// the object could be freed by another thread. As a result, we must lock the object
// to prevent it from being freed.
SrsLocker(lock_);
SrsLocker(&lock_);

++_srs_pps_pub->sugar;

Expand Down Expand Up @@ -982,7 +982,7 @@ SrsRtcPublishTwccTimer::SrsRtcPublishTwccTimer(SrsRtcPublishStream *p) : p_(p)
SrsRtcPublishTwccTimer::~SrsRtcPublishTwccTimer()
{
if (true) {
SrsLocker(lock_);
SrsLocker(&lock_);
_srs_shared_timer->timer100ms()->unsubscribe(this);
}
srs_mutex_destroy(lock_);
Expand All @@ -996,7 +996,7 @@ srs_error_t SrsRtcPublishTwccTimer::on_timer(srs_utime_t interval)
// Therefore, during this function, the 'this' pointer might become invalid because
// the object could be freed by another thread. As a result, we must lock the object
// to prevent it from being freed.
SrsLocker(lock_);
SrsLocker(&lock_);

++_srs_pps_pub->sugar;

Expand Down Expand Up @@ -1752,7 +1752,7 @@ SrsRtcConnectionNackTimer::SrsRtcConnectionNackTimer(SrsRtcConnection *p) : p_(p
SrsRtcConnectionNackTimer::~SrsRtcConnectionNackTimer()
{
if (true) {
SrsLocker(lock_);
SrsLocker(&lock_);
_srs_shared_timer->timer20ms()->unsubscribe(this);
}
srs_mutex_destroy(lock_);
Expand All @@ -1766,7 +1766,7 @@ srs_error_t SrsRtcConnectionNackTimer::on_timer(srs_utime_t interval)
// Therefore, during this function, the 'this' pointer might become invalid because
// the object could be freed by another thread. As a result, we must lock the object
// to prevent it from being freed.
SrsLocker(lock_);
SrsLocker(&lock_);

if (!p_->nack_enabled_) {
return err;
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_rtc_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ srs_error_t SrsRtcSourceManager::fetch_or_create(ISrsRequest *r, SrsSharedPtr<Sr
if (true) {
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
SrsLocker(lock);
SrsLocker(&lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsSharedPtr<SrsRtcSource> >::iterator it = pool.find(stream_url);
Expand Down Expand Up @@ -339,7 +339,7 @@ SrsSharedPtr<SrsRtcSource> SrsRtcSourceManager::fetch(ISrsRequest *r)
{
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
SrsLocker(lock);
SrsLocker(&lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsSharedPtr<SrsRtcSource> >::iterator it = pool.find(stream_url);
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_rtsp_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ srs_error_t SrsRtspSourceManager::fetch_or_create(ISrsRequest *r, SrsSharedPtr<S
if (true) {
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
SrsLocker(lock);
SrsLocker(&lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsSharedPtr<SrsRtspSource> >::iterator it = pool.find(stream_url);
Expand Down Expand Up @@ -213,7 +213,7 @@ SrsSharedPtr<SrsRtspSource> SrsRtspSourceManager::fetch(ISrsRequest *r)
{
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
SrsLocker(lock);
SrsLocker(&lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsSharedPtr<SrsRtspSource> >::iterator it = pool.find(stream_url);
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ srs_error_t SrsLiveSourceManager::fetch_or_create(ISrsRequest *r, SrsSharedPtr<S
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
// TODO: FIXME: Use smaller scope lock.
SrsLocker(lock);
SrsLocker(&lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsSharedPtr<SrsLiveSource> >::iterator it = pool.find(stream_url);
Expand Down Expand Up @@ -1620,7 +1620,7 @@ SrsSharedPtr<SrsLiveSource> SrsLiveSourceManager::fetch(ISrsRequest *r)
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
// TODO: FIXME: Use smaller scope lock.
SrsLocker(lock);
SrsLocker(&lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsSharedPtr<SrsLiveSource> >::iterator it = pool.find(stream_url);
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_srt_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ srs_error_t SrsSrtSourceManager::fetch_or_create(ISrsRequest *r, SrsSharedPtr<Sr
if (true) {
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
SrsLocker(lock);
SrsLocker(&lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsSharedPtr<SrsSrtSource> >::iterator it = pool.find(stream_url);
Expand Down Expand Up @@ -196,7 +196,7 @@ SrsSharedPtr<SrsSrtSource> SrsSrtSourceManager::fetch(ISrsRequest *r)
{
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
SrsLocker(lock);
SrsLocker(&lock);

string stream_url = r->get_stream_url();
std::map<std::string, SrsSharedPtr<SrsSrtSource> >::iterator it = pool.find(stream_url);
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_stream_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ srs_error_t SrsStreamPublishTokenManager::acquire_token(ISrsRequest *req, SrsStr
std::string stream_url = req->get_stream_url();
SrsContextId current_cid = _srs_context->get_id();

SrsLocker(mutex_);
SrsLocker(&mutex_);

// Get or create token for this stream
SrsStreamPublishToken *stream_token = NULL;
Expand Down Expand Up @@ -116,7 +116,7 @@ srs_error_t SrsStreamPublishTokenManager::acquire_token(ISrsRequest *req, SrsStr

void SrsStreamPublishTokenManager::release_token(const std::string &stream_url)
{
SrsLocker(mutex_);
SrsLocker(&mutex_);

// Find and erase the token from the map
std::map<std::string, SrsStreamPublishToken *>::iterator it = tokens_.find(stream_url);
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version7.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 7
#define VERSION_MINOR 0
#define VERSION_REVISION 79
#define VERSION_REVISION 80

#endif
68 changes: 66 additions & 2 deletions trunk/src/protocol/srs_protocol_st.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,13 @@ srs_cond_t srs_cond_new()

int srs_cond_destroy(srs_cond_t cond)
{
return st_cond_destroy((st_cond_t)cond);
if (!cond) {
return 0;
}

int r0 = st_cond_destroy((st_cond_t)cond);
srs_assert(r0 == 0);
return r0;
}

int srs_cond_wait(srs_cond_t cond)
Expand Down Expand Up @@ -425,7 +431,10 @@ int srs_mutex_destroy(srs_mutex_t mutex)
if (!mutex) {
return 0;
}
return st_mutex_destroy((st_mutex_t)mutex);

int r0 = st_mutex_destroy((st_mutex_t)mutex);
srs_assert(r0 == 0);
return r0;
}

int srs_mutex_lock(srs_mutex_t mutex)
Expand All @@ -438,6 +447,61 @@ int srs_mutex_unlock(srs_mutex_t mutex)
return st_mutex_unlock((st_mutex_t)mutex);
}

SrsCond::SrsCond()
{
cond_ = srs_cond_new();
}

SrsCond::~SrsCond()
{
srs_cond_destroy(cond_);
}

int SrsCond::wait()
{
return srs_cond_wait(cond_);
}

int SrsCond::timedwait(srs_utime_t timeout)
{
return srs_cond_timedwait(cond_, timeout);
}

int SrsCond::signal()
{
return srs_cond_signal(cond_);
}

int SrsCond::broadcast()
{
return srs_cond_broadcast(cond_);
}

SrsMutex::SrsMutex()
{
mutex_ = srs_mutex_new();
}

SrsMutex::~SrsMutex()
{
srs_mutex_destroy(mutex_);
}

int SrsMutex::lock()
{
return srs_mutex_lock(mutex_);
}

int SrsMutex::unlock()
{
return srs_mutex_unlock(mutex_);
}

srs_mutex_t *SrsMutex::get()
{
return &mutex_;
}

int srs_key_create(int *keyp, void (*destructor)(void *))
{
return st_key_create(keyp, destructor);
Expand Down
41 changes: 40 additions & 1 deletion trunk/src/protocol/srs_protocol_st.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,45 @@ extern int srs_mutex_destroy(srs_mutex_t mutex);
extern int srs_mutex_lock(srs_mutex_t mutex);
extern int srs_mutex_unlock(srs_mutex_t mutex);

// Wrap as ptr, so you can use SrsUniquePtr and SrsSharedPtr to manage it.
// For example:
// SrsUniquePtr<SrsCond> cond(new SrsCond());
// cond->signal();
class SrsCond
{
private:
srs_cond_t cond_;

public:
SrsCond();
virtual ~SrsCond();

public:
int wait();
int timedwait(srs_utime_t timeout);
int signal();
int broadcast();
};

// Wrap as ptr, so you can use SrsUniquePtr and SrsSharedPtr to manage it.
// For example:
// SrsUniquePtr<SrsMutex> mutex(new SrsMutex());
// SrsLocker(mutex->get());
class SrsMutex
{
private:
srs_mutex_t mutex_;

public:
SrsMutex();
virtual ~SrsMutex();

public:
int lock();
int unlock();
srs_mutex_t *get();
};

extern int srs_key_create(int *keyp, void (*destructor)(void *));
extern int srs_thread_setspecific(int key, void *value);
extern int srs_thread_setspecific2(srs_thread_t thread, int key, void *value);
Expand All @@ -109,7 +148,7 @@ extern bool srs_is_never_timeout(srs_utime_t tm);

// The mutex locker.
#define SrsLocker(instance) \
impl__SrsLocker _SRS_free_##instance(&instance)
impl__SrsLocker _SRS_free_instance(instance)

class impl__SrsLocker
{
Expand Down
38 changes: 38 additions & 0 deletions trunk/src/utest/srs_utest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include <srs_app_log.hpp>
#include <srs_app_rtc_dtls.hpp>
#include <srs_app_server.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_protocol_st.hpp>

#include <string>
using namespace std;
Expand Down Expand Up @@ -253,3 +255,39 @@ int MockProtectedBuffer::alloc(int size)

return 0;
}

SrsCoroutineChan::SrsCoroutineChan()
{
lock_ = srs_mutex_new();
}

SrsCoroutineChan::~SrsCoroutineChan()
{
srs_mutex_destroy(lock_);
}

SrsCoroutineChan &SrsCoroutineChan::push(void *value)
{
SrsLocker(&lock_);

args_.push_back(value);
return *this;
}

void *SrsCoroutineChan::pop()
{
SrsLocker(&lock_);

void *arg = *args_.begin();
args_.erase(args_.begin());
return arg;
}

SrsCoroutineChan *SrsCoroutineChan::copy()
{
SrsLocker(&lock_);

SrsCoroutineChan *cp = new SrsCoroutineChan();
cp->args_ = args_;
return cp;
}
Loading
Loading