Skip to content

Commit

Permalink
Merge pull request #34 from shiguredo/feature/add-stream-id
Browse files Browse the repository at this point in the history
Track の stream_id が取れる SoraMediaTrack を追加する
  • Loading branch information
voluntas authored Sep 5, 2023
2 parents 93ccc49 + 2310428 commit 6807c20
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

## develop

- [UPDATE] SoraMediaTrack を追加し、 SoraConnection.on_track の引数を SoraMediaTrack に変更
- @tnoho
- [ADD] 発話区間の検出が可能な SoraVAD の追加
- @tnoho
- [ADD] リアルタイム性を重視した AudioStreamSink の追加
Expand Down
5 changes: 3 additions & 2 deletions src/sora_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ void SoraConnection::OnTrack(
rtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver) {
if (on_track_) {
// shared_ptr になってないとリークする
auto track = std::make_shared<SoraTrackInterface>(
this, transceiver->receiver()->track());
auto track = std::make_shared<SoraMediaTrack>(
this, transceiver->receiver()->track(),
transceiver->receiver()->stream_ids()[0]);
AddSubscriber(track.get());
on_track_(track);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sora_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SoraConnection : public sora::SoraSignalingObserver,
std::function<void(std::string)> on_notify_;
std::function<void(std::string)> on_push_;
std::function<void(std::string, nb::bytes)> on_message_;
std::function<void(std::shared_ptr<SoraTrackInterface>)> on_track_;
std::function<void(std::shared_ptr<SoraMediaTrack>)> on_track_;
std::function<void(std::string)> on_data_channel_;

private:
Expand Down
3 changes: 3 additions & 0 deletions src/sora_sdk_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ NB_MODULE(sora_sdk_ext, m) {
.def_prop_ro("state", &SoraTrackInterface::state)
.def("set_enabled", &SoraTrackInterface::set_enabled, "enable"_a);

nb::class_<SoraMediaTrack, SoraTrackInterface>(m, "SoraMediaTrack")
.def_prop_ro("stream_id", &SoraMediaTrack::stream_id);

nb::class_<SoraAudioSource, SoraTrackInterface>(m, "SoraAudioSource")
.def("on_data", nb::overload_cast<const int16_t*, size_t, double>(
&SoraAudioSource::OnData))
Expand Down
24 changes: 24 additions & 0 deletions src/sora_track_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,28 @@ class SoraTrackInterface : public DisposePublisher, public DisposeSubscriber {
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track_;
};

/**
* SoraConnection の on_track で渡されるリモートトラックを格納する SoraTrackInterface です。
*
* webrtc::MediaStreamTrackInterface のメンバーにはない stream_id を on_track で渡すために追加しました。
*/
class SoraMediaTrack : public SoraTrackInterface {
public:
SoraMediaTrack(DisposePublisher* publisher,
rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track,
std::string stream_id)
: SoraTrackInterface(publisher, track), stream_id_(stream_id) {}

/**
* この Track の Stream ID を std::string で返します。
*
* Python で呼び出すための関数です。
* 本来 Track には複数の Stream ID を紐づけることができるのですが、
* Sora の使用上 Track には Stream ID が 1 つしか紐づかないため Track のメンバーとしました。
*/
std::string stream_id() const { return stream_id_; }

private:
std::string stream_id_;
};
#endif

0 comments on commit 6807c20

Please sign in to comment.