diff --git a/src/sora.cpp b/src/sora.cpp index c7d6a99..862e2d7 100644 --- a/src/sora.cpp +++ b/src/sora.cpp @@ -10,9 +10,7 @@ Sora::Sora(std::optional use_hardware_encoder, factory_.reset(new SoraFactory(use_hardware_encoder, openh264)); } -Sora::~Sora() { - Disposed(); -} +Sora::~Sora() {} std::shared_ptr Sora::CreateConnection( const nb::handle& signaling_urls, @@ -60,7 +58,7 @@ std::shared_ptr Sora::CreateConnection( std::optional proxy_username, std::optional proxy_password, std::optional proxy_agent) { - std::shared_ptr conn = std::make_shared(this); + std::shared_ptr conn = std::make_shared(); sora::SoraSignalingConfig config; config.pc_factory = factory_->GetPeerConnectionFactory(); config.observer = conn; @@ -220,7 +218,7 @@ SoraAudioSource* Sora::CreateAudioSource(size_t channels, int sample_rate) { auto track = factory_->GetPeerConnectionFactory()->CreateAudioTrack( track_id, source.get()); SoraAudioSource* audio_source = - new SoraAudioSource(this, source, track, channels, sample_rate); + new SoraAudioSource(source, track, channels, sample_rate); return audio_source; } @@ -232,7 +230,7 @@ SoraVideoSource* Sora::CreateVideoSource() { auto track = factory_->GetPeerConnectionFactory()->CreateVideoTrack(source, track_id); - SoraVideoSource* video_source = new SoraVideoSource(this, source, track); + SoraVideoSource* video_source = new SoraVideoSource(source, track); return video_source; } diff --git a/src/sora.h b/src/sora.h index 3ec8bcb..11fe1f6 100644 --- a/src/sora.h +++ b/src/sora.h @@ -21,7 +21,7 @@ * 同じ Sora インスタンス内でしか Connection や AudioSource、VideoSource を共有できないので、 * 複数の Sora インスタンスを生成することは不具合の原因になります。 */ -class Sora : public DisposePublisher { +class Sora { public: /** * このタイミングで SoraFactory の生成まで行うため SoraFactory の生成にあたって必要な引数はここで設定します。 diff --git a/src/sora_audio_sink.cpp b/src/sora_audio_sink.cpp index a1860af..f8d913d 100644 --- a/src/sora_audio_sink.cpp +++ b/src/sora_audio_sink.cpp @@ -17,20 +17,12 @@ SoraAudioSinkImpl::SoraAudioSinkImpl(SoraTrackInterface* track, sample_rate_(0), number_of_channels_(0) { audio_frame_ = std::make_unique(); - track_->AddSubscriber(this); webrtc::AudioTrackInterface* audio_track = static_cast(track_->GetTrack().get()); audio_track->AddSink(this); } SoraAudioSinkImpl::~SoraAudioSinkImpl() { - Del(); -} - -void SoraAudioSinkImpl::Del() { - if (track_) { - track_->RemoveSubscriber(this); - } Disposed(); } @@ -43,10 +35,6 @@ void SoraAudioSinkImpl::Disposed() { track_ = nullptr; } -void SoraAudioSinkImpl::PublisherDisposed() { - Disposed(); -} - void SoraAudioSinkImpl::OnData( const void* audio_data, int bits_per_sample, diff --git a/src/sora_audio_sink.h b/src/sora_audio_sink.h index f7ca7d8..96e3c99 100644 --- a/src/sora_audio_sink.h +++ b/src/sora_audio_sink.h @@ -28,8 +28,7 @@ namespace nb = nanobind; * 実装上の留意点:Track の参照保持のための Impl のない SoraAudioSink を __init__.py に定義しています。 * SoraAudioSinkImpl を直接 Python から呼び出すことは想定していません。 */ -class SoraAudioSinkImpl : public webrtc::AudioTrackSinkInterface, - public DisposeSubscriber { +class SoraAudioSinkImpl : public webrtc::AudioTrackSinkInterface { public: /** * @param track 音声を取り出す OnTrack コールバックから渡されるリモート Track @@ -41,9 +40,7 @@ class SoraAudioSinkImpl : public webrtc::AudioTrackSinkInterface, size_t output_channels); ~SoraAudioSinkImpl(); - void Del(); void Disposed(); - void PublisherDisposed() override; // webrtc::AudioTrackSinkInterface void OnData(const void* audio_data, int bits_per_sample, diff --git a/src/sora_audio_source.cpp b/src/sora_audio_source.cpp index 9c5e1d1..4948459 100644 --- a/src/sora_audio_source.cpp +++ b/src/sora_audio_source.cpp @@ -127,14 +127,11 @@ void SoraAudioSourceInterface::Add10MsData(const int16_t* data, } SoraAudioSource::SoraAudioSource( - DisposePublisher* publisher, rtc::scoped_refptr source, rtc::scoped_refptr track, size_t channels, int sample_rate) - : SoraTrackInterface(publisher, track), source_(source) { - publisher_->AddSubscriber(this); -} + : SoraTrackInterface(track), source_(source) {} void SoraAudioSource::OnData(const int16_t* data, size_t samples_per_channel, diff --git a/src/sora_audio_source.h b/src/sora_audio_source.h index c98b193..1e98f63 100644 --- a/src/sora_audio_source.h +++ b/src/sora_audio_source.h @@ -70,8 +70,7 @@ class SoraAudioSourceInterface */ class SoraAudioSource : public SoraTrackInterface { public: - SoraAudioSource(DisposePublisher* publisher, - rtc::scoped_refptr source, + SoraAudioSource(rtc::scoped_refptr source, rtc::scoped_refptr track, size_t channels, int sample_rate); diff --git a/src/sora_audio_stream_sink.cpp b/src/sora_audio_stream_sink.cpp index 9367f6f..c4b6735 100644 --- a/src/sora_audio_stream_sink.cpp +++ b/src/sora_audio_stream_sink.cpp @@ -143,20 +143,12 @@ SoraAudioStreamSinkImpl::SoraAudioStreamSinkImpl(SoraTrackInterface* track, : track_(track), output_sample_rate_(output_sample_rate), output_channels_(output_channels) { - track_->AddSubscriber(this); webrtc::AudioTrackInterface* audio_track = static_cast(track_->GetTrack().get()); audio_track->AddSink(this); } SoraAudioStreamSinkImpl::~SoraAudioStreamSinkImpl() { - Del(); -} - -void SoraAudioStreamSinkImpl::Del() { - if (track_) { - track_->RemoveSubscriber(this); - } Disposed(); } @@ -169,10 +161,6 @@ void SoraAudioStreamSinkImpl::Disposed() { track_ = nullptr; } -void SoraAudioStreamSinkImpl::PublisherDisposed() { - Disposed(); -} - void SoraAudioStreamSinkImpl::OnData( const void* audio_data, int bits_per_sample, diff --git a/src/sora_audio_stream_sink.h b/src/sora_audio_stream_sink.h index 5f0a6ef..1a2baca 100644 --- a/src/sora_audio_stream_sink.h +++ b/src/sora_audio_stream_sink.h @@ -163,17 +163,13 @@ class SoraAudioFrame { * 実装上の留意点:Track の参照保持のための Impl のない SoraAudioStreamSink を __init__.py に定義しています。 * SoraAudioStreamSinkImpl を直接 Python から呼び出すことは想定していません。 */ -class SoraAudioStreamSinkImpl : public webrtc::AudioTrackSinkInterface, - public DisposeSubscriber { +class SoraAudioStreamSinkImpl : public webrtc::AudioTrackSinkInterface { public: SoraAudioStreamSinkImpl(SoraTrackInterface* track, int output_sample_rate, size_t output_channels); ~SoraAudioStreamSinkImpl(); - void Del(); - void Disposed(); - void PublisherDisposed() override; // webrtc::AudioTrackSinkInterface void OnData(const void* audio_data, int bits_per_sample, @@ -192,6 +188,8 @@ class SoraAudioStreamSinkImpl : public webrtc::AudioTrackSinkInterface, std::function)> on_frame_; private: + void Disposed(); + SoraTrackInterface* track_; const int output_sample_rate_; const size_t output_channels_; diff --git a/src/sora_connection.cpp b/src/sora_connection.cpp index 61f12fd..4164b4f 100644 --- a/src/sora_connection.cpp +++ b/src/sora_connection.cpp @@ -20,27 +20,9 @@ namespace nb = nanobind; -SoraConnection::SoraConnection(DisposePublisher* publisher) - : publisher_(publisher) { - publisher_->AddSubscriber(this); -} - -SoraConnection::~SoraConnection() { - if (publisher_) { - publisher_->RemoveSubscriber(this); - } - Disposed(); -} +SoraConnection::SoraConnection() {} -void SoraConnection::Disposed() { - DisposePublisher::Disposed(); - Disconnect(); - publisher_ = nullptr; -} - -void SoraConnection::PublisherDisposed() { - Disposed(); -} +SoraConnection::~SoraConnection() {} void SoraConnection::Init(sora::SoraSignalingConfig& config) { // TODO(tnoho): 複数回の呼び出しは禁止なので、ちゃんと throw する @@ -91,10 +73,6 @@ void SoraConnection::SetAudioTrack(SoraTrackInterface* audio_source) { if (audio_sender_) { audio_sender_->SetTrack(audio_source->GetTrack().get()); } - if (audio_source_) { - audio_source_->RemoveSubscriber(this); - } - audio_source->AddSubscriber(this); audio_source_ = audio_source; } @@ -103,10 +81,6 @@ void SoraConnection::SetVideoTrack(SoraTrackInterface* video_source) { if (video_sender_) { video_sender_->SetTrack(video_source->GetTrack().get()); } - if (video_source_) { - video_source_->RemoveSubscriber(this); - } - video_source->AddSubscriber(this); video_source_ = video_source; } @@ -243,8 +217,7 @@ void SoraConnection::OnTrack( if (on_track_) { auto receiver = transceiver->receiver(); // shared_ptr になってないとリークする - auto track = std::make_shared(this, receiver); - AddSubscriber(track.get()); + auto track = std::make_shared(receiver); call_python(on_track_, track); } } diff --git a/src/sora_connection.h b/src/sora_connection.h index c53be2b..b12a024 100644 --- a/src/sora_connection.h +++ b/src/sora_connection.h @@ -29,19 +29,14 @@ namespace nb = nanobind; * * Python に Connection を制御する関数を提供します。 */ -class SoraConnection : public sora::SoraSignalingObserver, - public DisposePublisher, - public DisposeSubscriber { +class SoraConnection : public sora::SoraSignalingObserver { public: /** * コンストラクタではインスタンスの生成のみで実際の生成処理は Init 関数で行います。 */ - SoraConnection(DisposePublisher* publisher); + SoraConnection(); ~SoraConnection(); - void Disposed() override; - void PublisherDisposed() override; - /** * SoraConnection の初期化を行う関数です。 * @@ -146,7 +141,6 @@ class SoraConnection : public sora::SoraSignalingObserver, std::function on_data_channel_; private: - DisposePublisher* publisher_; std::unique_ptr ioc_; std::shared_ptr conn_; std::unique_ptr thread_; diff --git a/src/sora_sdk/__init__.py b/src/sora_sdk/__init__.py index 3bf7e4e..1af3728 100644 --- a/src/sora_sdk/__init__.py +++ b/src/sora_sdk/__init__.py @@ -1,3 +1,4 @@ +from typing import Optional, List, Dict from .sora_sdk_ext import * # noqa: F401,F403 """ @@ -14,7 +15,6 @@ def __init__(self, track, output_frequency, output_channels): self.__track = track def __del__(self): - super().__del__() del self.__track @@ -24,7 +24,6 @@ def __init__(self, track, output_frequency, output_channels): self.__track = track def __del__(self): - super().__del__() del self.__track @@ -34,17 +33,43 @@ def __init__(self, track): self.__track = track def __del__(self): - super().__del__() del self.__track +class SoraAudioSource(): + def __init__(self, sora, source): + self._sora = sora + self.source = source + + def __del__(self): + print("__del__ SoraAudioSource") + + def on_data(self, *args, **kwargs): + self.source.on_data(*args, **kwargs) + + +class SoraVideoSource(): + def __init__(self, sora, source): + self._sora = sora + self.source = source + + def __del__(self): + print("__del__ SoraVideoSource") + + def on_captured(self, *args, **kwargs): + self.source.on_captured(*args, **kwargs) + + class SoraConnection(): - def __init__(self, sora, connection): + def __init__(self, sora, connection, audio_source: Optional[SoraAudioSource] = None, video_source: Optional[SoraVideoSource] = None): self._sora = sora self._connection = connection + self._audio_source = audio_source + self._video_source = video_source def __del__(self): self._sora._remove_connection(self) + print("__del__ SoraConnection") def connect(self): self._connection.connect() @@ -144,14 +169,77 @@ class Sora(SoraImpl): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._connections = [] + self._audio_sources = [] + self._video_sources = [] def __del__(self): - self._connections.clear() - - def create_connection(self, *args, **kwargs): - # 新しい接続を生成してリストに追加 - conn = super().create_connection(*args, **kwargs) - wrapped_conn = SoraConnection(self, conn) + print("__del__ Sora") + + def create_connection( + self, + signaling_urls: List[str], + role: str, + channel_id: str, + client_id: Optional[str] = None, + bundle_id: Optional[str] = None, + metadata: Optional[Dict] = None, + signaling_notify_metadata: Optional[Dict] = None, + audio_source: Optional[SoraAudioSource] = None, + video_source: Optional[SoraVideoSource] = None, + audio_frame_transformer: Optional[SoraAudioFrameTransformer] = None, + video_frame_transformer: Optional[SoraVideoFrameTransformer] = None, + audio: Optional[bool] = None, + video: Optional[bool] = None, + audio_codec_type: Optional[str] = None, + video_codec_type: Optional[str] = None, + video_bit_rate: Optional[int] = None, + audio_bit_rate: Optional[int] = None, + video_vp9_params: Optional[Dict] = None, + video_av1_params: Optional[Dict] = None, + video_h264_params: Optional[Dict] = None, + audio_opus_params: Optional[Dict] = None, + simulcast: Optional[bool] = None, + spotlight: Optional[bool] = None, + spotlight_number: Optional[int] = None, + simulcast_rid: Optional[str] = None, + spotlight_focus_rid: Optional[str] = None, + spotlight_unfocus_rid: Optional[str] = None, + forwarding_filter: Optional[Dict] = None, + forwarding_filters: Optional[List[Dict]] = None, + data_channels: Optional[List[Dict]] = None, + data_channel_signaling: Optional[bool] = None, + ignore_disconnect_websocket: Optional[bool] = None, + data_channel_signaling_timeout: Optional[int] = None, + disconnect_wait_timeout: Optional[int] = None, + websocket_close_timeout: Optional[int] = None, + websocket_connection_timeout: Optional[int] = None, + audio_streaming_language_code: Optional[str] = None, + insecure: Optional[bool] = None, + client_cert: Optional[bytes] = None, + client_key: Optional[bytes] = None, + ca_cert: Optional[bytes] = None, + proxy_url: Optional[str] = None, + proxy_username: Optional[str] = None, + proxy_password: Optional[str] = None, + proxy_agent: Optional[str] = None, + ) -> SoraConnection: + conn = super().create_connection( + signaling_urls, role, channel_id, client_id, bundle_id, metadata, + signaling_notify_metadata, audio_source.source if audio_source else None, video_source.source if video_source else None, + audio_frame_transformer, video_frame_transformer, audio, video, + audio_codec_type, video_codec_type, video_bit_rate, audio_bit_rate, + video_vp9_params, video_av1_params, video_h264_params, + audio_opus_params, simulcast, spotlight, spotlight_number, + simulcast_rid, spotlight_focus_rid, spotlight_unfocus_rid, + forwarding_filter, forwarding_filters, data_channels, + data_channel_signaling, ignore_disconnect_websocket, + data_channel_signaling_timeout, disconnect_wait_timeout, + websocket_close_timeout, websocket_connection_timeout, + audio_streaming_language_code, insecure, client_cert, + client_key, ca_cert, proxy_url, proxy_username, proxy_password, + proxy_agent + ) + wrapped_conn = SoraConnection(self, conn, audio_source, video_source) self._connections.append(wrapped_conn) return wrapped_conn @@ -161,7 +249,13 @@ def _remove_connection(self, conn): self._connections.remove(conn) def create_audio_source(self, *args): - return super().create_audio_source(*args) + audio_source = super().create_audio_source(*args) + wrapped_audio_source = SoraAudioSource(self, audio_source) + self._audio_sources.append(wrapped_audio_source) + return wrapped_audio_source def create_video_source(self): - return super().create_video_source() \ No newline at end of file + video_source = super().create_video_source() + wrapped_video_source = SoraVideoSource(self, video_source) + self._video_sources.append(wrapped_video_source) + return wrapped_video_source diff --git a/src/sora_sdk_ext.cpp b/src/sora_sdk_ext.cpp index 1e24466..1766595 100644 --- a/src/sora_sdk_ext.cpp +++ b/src/sora_sdk_ext.cpp @@ -344,7 +344,7 @@ NB_MODULE(sora_sdk_ext, m) { .def_prop_ro("stream_id", &SoraMediaTrack::stream_id) .def("set_frame_transformer", &SoraMediaTrack::SetFrameTransformer); - nb::class_(m, "SoraAudioSource") + nb::class_(m, "SoraAudioSourceImpl") .def("on_data", nb::overload_cast( &SoraAudioSource::OnData), @@ -363,7 +363,7 @@ NB_MODULE(sora_sdk_ext, m) { &SoraAudioSource::OnData), "ndarray"_a); - nb::class_(m, "SoraVideoSource") + nb::class_(m, "SoraVideoSourceImpl") .def("on_captured", nb::overload_cast, nb::c_contig, nb::device::cpu>>( @@ -384,7 +384,6 @@ NB_MODULE(sora_sdk_ext, m) { nb::type_slots(audio_sink_slots)) .def(nb::init(), "track"_a, "output_frequency"_a = -1, "output_channels"_a = 0) - .def("__del__", &SoraAudioSinkImpl::Del) .def("read", &SoraAudioSinkImpl::Read, "frames"_a = 0, "timeout"_a = 1, nb::rv_policy::move) .def_rw("on_data", &SoraAudioSinkImpl::on_data_) @@ -419,7 +418,6 @@ NB_MODULE(sora_sdk_ext, m) { nb::type_slots(audio_stream_sink_slots)) .def(nb::init(), "track"_a, "output_frequency"_a = -1, "output_channels"_a = 0) - .def("__del__", &SoraAudioStreamSinkImpl::Del) .def_rw("on_frame", &SoraAudioStreamSinkImpl::on_frame_); nb::class_(m, "SoraVAD") @@ -432,7 +430,6 @@ NB_MODULE(sora_sdk_ext, m) { nb::class_(m, "SoraVideoSinkImpl", nb::type_slots(video_sink_slots)) .def(nb::init()) - .def("__del__", &SoraVideoSinkImpl::Del) .def_rw("on_frame", &SoraVideoSinkImpl::on_frame_); nb::class_(m, "SoraConnectionImpl", diff --git a/src/sora_track_interface.h b/src/sora_track_interface.h index 21c83ba..4bc6dcf 100644 --- a/src/sora_track_interface.h +++ b/src/sora_track_interface.h @@ -15,18 +15,12 @@ * webrtc::MediaStreamTrackInterface は rtc::scoped_refptr なので、 * nanobind で直接のハンドリングが難しいので用意しました。 */ -class SoraTrackInterface : public DisposePublisher, public DisposeSubscriber { +class SoraTrackInterface { public: SoraTrackInterface( - DisposePublisher* publisher, rtc::scoped_refptr track) - : publisher_(publisher), track_(track) {} - virtual ~SoraTrackInterface() { - if (publisher_) { - publisher_->RemoveSubscriber(this); - } - Disposed(); - } + : track_(track) {} + virtual ~SoraTrackInterface() {} /** * Python で呼び出すための関数 @@ -50,18 +44,7 @@ class SoraTrackInterface : public DisposePublisher, public DisposeSubscriber { return track_; } - virtual void Disposed() override { - DisposePublisher::Disposed(); - publisher_ = nullptr; - track_ = nullptr; - } - virtual void PublisherDisposed() override { - // Track は生成元が破棄された後に再利用することはないので Disposed() を呼ぶ - Disposed(); - } - protected: - DisposePublisher* publisher_; rtc::scoped_refptr track_; }; @@ -72,9 +55,8 @@ class SoraTrackInterface : public DisposePublisher, public DisposeSubscriber { */ class SoraMediaTrack : public SoraTrackInterface { public: - SoraMediaTrack(DisposePublisher* publisher, - rtc::scoped_refptr receiver) - : SoraTrackInterface(publisher, receiver->track()), receiver_(receiver) {} + SoraMediaTrack(rtc::scoped_refptr receiver) + : SoraTrackInterface(receiver->track()), receiver_(receiver) {} ~SoraMediaTrack() override { // Disposed() は SoraTrackInterface で呼ばれるため、ここでは SoraMediaTrack 分のみ処理する receiver_ = nullptr; @@ -99,12 +81,6 @@ class SoraMediaTrack : public SoraTrackInterface { receiver_->SetFrameTransformer(interface); } - void Disposed() override { - // receiver_ を先に消したいところだがデストラクタはそうはならないのでこの順序 - receiver_ = nullptr; - SoraTrackInterface::Disposed(); - } - private: rtc::scoped_refptr receiver_; }; diff --git a/src/sora_video_sink.cpp b/src/sora_video_sink.cpp index 71edbd8..552a5da 100644 --- a/src/sora_video_sink.cpp +++ b/src/sora_video_sink.cpp @@ -41,7 +41,6 @@ SoraVideoSinkImpl::SoraVideoSinkImpl(const webrtc::Environment& env, on_frame_queue_ = env.task_queue_factory().CreateTaskQueue( "OnFrameQueue", webrtc::TaskQueueFactory::Priority::NORMAL); - track_->AddSubscriber(this); webrtc::VideoTrackInterface* video_track = static_cast(track_->GetTrack().get()); // video_track にこの Sink を追加し OnFrame を呼び出してもらいます。 @@ -49,7 +48,7 @@ SoraVideoSinkImpl::SoraVideoSinkImpl(const webrtc::Environment& env, } SoraVideoSinkImpl::~SoraVideoSinkImpl() { - Del(); + Disposed(); // OnFrameQueue スレッドの join 待ちでデッドロックしてしまうので、ここで GIL を解放する // 具体的には、以下の順序で実行された時にデッドロックする。 @@ -61,13 +60,6 @@ SoraVideoSinkImpl::~SoraVideoSinkImpl() { on_frame_queue_.reset(); } -void SoraVideoSinkImpl::Del() { - if (track_) { - track_->RemoveSubscriber(this); - } - Disposed(); -} - void SoraVideoSinkImpl::Disposed() { if (track_ && track_->GetTrack()) { webrtc::VideoTrackInterface* video_track = @@ -79,10 +71,6 @@ void SoraVideoSinkImpl::Disposed() { on_frame_ = nullptr; } -void SoraVideoSinkImpl::PublisherDisposed() { - Disposed(); -} - void SoraVideoSinkImpl::OnFrame(const webrtc::VideoFrame& frame) { if (frame.width() == 0 || frame.height() == 0) return; diff --git a/src/sora_video_sink.h b/src/sora_video_sink.h index 44add80..6c9937b 100644 --- a/src/sora_video_sink.h +++ b/src/sora_video_sink.h @@ -51,8 +51,7 @@ class SoraVideoFrame { * 実装上の留意点:Track の参照保持のための Impl のない SoraVideoSink を __init__.py に定義しています。 * SoraVideoSinkImpl を直接 Python から呼び出すことは想定していません。 */ -class SoraVideoSinkImpl : public rtc::VideoSinkInterface, - public DisposeSubscriber { +class SoraVideoSinkImpl : public rtc::VideoSinkInterface { public: /** * @param track 映像を取り出す OnTrack コールバックから渡されるリモート Track @@ -61,9 +60,6 @@ class SoraVideoSinkImpl : public rtc::VideoSinkInterface, SoraVideoSinkImpl(const webrtc::Environment& env, SoraTrackInterface* track); ~SoraVideoSinkImpl(); - void Del(); - void Disposed(); - /** * VideoTrack からフレームデータが来るたびに呼び出される関数です。 * @@ -73,9 +69,6 @@ class SoraVideoSinkImpl : public rtc::VideoSinkInterface, */ void OnFrame(const webrtc::VideoFrame& frame) override; - // DisposeSubscriber - void PublisherDisposed() override; - /** * フレームデータが来るたびに呼び出されるコールバック変数です。 * @@ -87,6 +80,8 @@ class SoraVideoSinkImpl : public rtc::VideoSinkInterface, std::function)> on_frame_; private: + void Disposed(); + SoraTrackInterface* track_; std::unique_ptr on_frame_queue_; diff --git a/src/sora_video_source.cpp b/src/sora_video_source.cpp index e03eb59..896d170 100644 --- a/src/sora_video_source.cpp +++ b/src/sora_video_source.cpp @@ -8,11 +8,9 @@ #include "gil.h" SoraVideoSource::SoraVideoSource( - DisposePublisher* publisher, rtc::scoped_refptr source, rtc::scoped_refptr track) - : SoraTrackInterface(publisher, track), source_(source), finished_(false) { - publisher_->AddSubscriber(this); + : SoraTrackInterface(track), source_(source), finished_(false) { thread_.reset(new std::thread([this]() { gil_scoped_acquire acq; while (SendFrameProcess()) { @@ -20,7 +18,7 @@ SoraVideoSource::SoraVideoSource( })); } -void SoraVideoSource::Disposed() { +SoraVideoSource::~SoraVideoSource() { if (!finished_) { finished_ = true; queue_cond_.notify_all(); @@ -28,11 +26,6 @@ void SoraVideoSource::Disposed() { thread_->join(); thread_ = nullptr; } - SoraTrackInterface::Disposed(); -} - -void SoraVideoSource::PublisherDisposed() { - Disposed(); } void SoraVideoSource::OnCaptured( diff --git a/src/sora_video_source.h b/src/sora_video_source.h index cbc843f..0ae20ce 100644 --- a/src/sora_video_source.h +++ b/src/sora_video_source.h @@ -32,12 +32,10 @@ namespace nb = nanobind; */ class SoraVideoSource : public SoraTrackInterface { public: - SoraVideoSource(DisposePublisher* publisher, - rtc::scoped_refptr source, + SoraVideoSource(rtc::scoped_refptr source, rtc::scoped_refptr track); + ~SoraVideoSource(); - void Disposed() override; - void PublisherDisposed() override; /** * Sora に映像データとして送るフレームを渡します。 *