Skip to content

Commit

Permalink
Merge branch 'release/2022.7.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Jul 12, 2022
2 parents b3a4c91 + f3338f8 commit 600cb4c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

## develop

## 2022.7.2 (2022-07-12)

- [FIX] DataChannel の切れ方によってはアクセス違反になることがあったのを修正
- @melpon

## 2022.7.1 (2022-07-11)

- [ADD] run.py に --relwithdebinfo フラグを追加
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SORA_CPP_SDK_VERSION=2022.7.1
SORA_CPP_SDK_VERSION=2022.7.2
WEBRTC_BUILD_VERSION=m103.5060.5.0
BOOST_VERSION=1.79.0
CMAKE_VERSION=3.23.1
Expand Down
2 changes: 1 addition & 1 deletion include/sora/data_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DataChannelObserver {
};

// 複数の DataChannel を纏めてコールバックで受け取るためのクラス
class DataChannel {
class DataChannel : public std::enable_shared_from_this<DataChannel> {
struct Thunk : webrtc::DataChannelObserver,
std::enable_shared_from_this<Thunk> {
DataChannel* p;
Expand Down
40 changes: 24 additions & 16 deletions src/data_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,35 @@ void DataChannel::Close(const webrtc::DataBuffer& disconnect_message,

void DataChannel::AddDataChannel(
rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
boost::asio::post(*ioc_, [this, data_channel]() {
boost::asio::post(*ioc_, [self = shared_from_this(), data_channel]() {
std::shared_ptr<Thunk> thunk(new Thunk());
thunk->p = this;
thunk->p = self.get();
thunk->dc = data_channel;
data_channel->RegisterObserver(thunk.get());
thunks_.insert(std::make_pair(thunk, data_channel));
labels_.insert(std::make_pair(data_channel->label(), data_channel));
self->thunks_.insert(std::make_pair(thunk, data_channel));
self->labels_.insert(std::make_pair(data_channel->label(), data_channel));
});
}

void DataChannel::OnStateChange(std::shared_ptr<Thunk> thunk) {
boost::asio::post(*ioc_, [this, thunk]() {
auto data_channel = thunks_.at(thunk);
boost::asio::post(*ioc_, [self = shared_from_this(), thunk]() {
if (self->thunks_.find(thunk) == self->thunks_.end()) {
return;
}

auto data_channel = self->thunks_.at(thunk);
if (data_channel->state() == webrtc::DataChannelInterface::kClosed) {
labels_.erase(data_channel->label());
thunks_.erase(thunk);
self->labels_.erase(data_channel->label());
self->thunks_.erase(thunk);
data_channel->UnregisterObserver();
RTC_LOG(LS_INFO) << "DataChannel closed label=" << data_channel->label();
}
auto observer = observer_;
auto on_close = on_close_;
auto empty = thunks_.empty();
auto observer = self->observer_;
auto on_close = self->on_close_;
auto empty = self->thunks_.empty();
if (on_close != nullptr && empty) {
on_close_ = nullptr;
timer_.cancel();
self->on_close_ = nullptr;
self->timer_.cancel();
}
auto ob = observer.lock();
if (ob != nullptr) {
Expand All @@ -101,9 +105,13 @@ void DataChannel::OnStateChange(std::shared_ptr<Thunk> thunk) {

void DataChannel::OnMessage(std::shared_ptr<Thunk> thunk,
const webrtc::DataBuffer& buffer) {
boost::asio::post(*ioc_, [this, thunk, buffer]() {
auto observer = observer_;
auto data_channel = thunks_.at(thunk);
boost::asio::post(*ioc_, [self = shared_from_this(), thunk, buffer]() {
if (self->thunks_.find(thunk) == self->thunks_.end()) {
return;
}

auto observer = self->observer_;
auto data_channel = self->thunks_.at(thunk);
auto ob = observer.lock();
if (ob != nullptr) {
ob->OnMessage(data_channel, buffer);
Expand Down

0 comments on commit 600cb4c

Please sign in to comment.