Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track の stream_id が取れる SoraMediaTrack を追加する #34

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

## develop

- [ADD] SoraTrackInterface に stream_id の追加
voluntas marked this conversation as resolved.
Show resolved Hide resolved
- @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
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
26 changes: 26 additions & 0 deletions src/sora_track_interface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SORA_TRACK_INTERFACE_H_
#define SORA_TRACK_INTERFACE_H_

#include <optional>
voluntas marked this conversation as resolved.
Show resolved Hide resolved

// WebRTC
#include <api/media_stream_interface.h>
#include <api/scoped_refptr.h>
Expand Down Expand Up @@ -63,4 +65,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