diff --git a/Sora/Sora.cs b/Sora/Sora.cs index 8f384ae..f1e2cd1 100644 --- a/Sora/Sora.cs +++ b/Sora/Sora.cs @@ -868,9 +868,9 @@ public void GetStats(Action onGetStats) } public (bool, string) GetTrackId(uint trackId) { - bool found = false; - string trackId_ = get_track_id(trackId, ref found); - return (found, trackId_); + IntPtr p = get_track_id(trackId); + bool found = p != IntPtr.Zero; + return (found, found ? Marshal.PtrToStringAnsi(p) : ""); } /// @@ -1102,9 +1102,8 @@ public string ConnectedSignalingURL private static extern void sora_get_selected_signaling_url(IntPtr p, [Out] byte[] buf, int size); [DllImport(DllName)] private static extern void sora_get_connected_signaling_url(IntPtr p, [Out] byte[] buf, int size); - [DllImport(DllName)] - [return: MarshalAs(UnmanagedType.LPStr)] - private static extern string get_track_id(uint track_id, [MarshalAs(UnmanagedType.I1)] ref bool found); + [DllImport(DllName, CharSet=CharSet.Ansi)] + private static extern IntPtr get_track_id(uint track_id, [MarshalAs(UnmanagedType.I1)] ref bool found); public class AudioOutputHelper : IDisposable { diff --git a/src/unity.cpp b/src/unity.cpp index 8afa332..269f4ac 100644 --- a/src/unity.cpp +++ b/src/unity.cpp @@ -310,14 +310,11 @@ void sora_audio_output_helper_set_handsfree(void* p, unity_bool_t enabled) { helper->SetHandsfree(enabled != 0); } -UNITY_INTERFACE_EXPORT const char* get_track_id(ptrid_t track_id, - unity_bool_t* found) { +UNITY_INTERFACE_EXPORT const char* get_track_id(ptrid_t track_id) { void* p = sora_unity_sdk::IdPointer::Instance().Lookup(track_id); - *found = p != nullptr ? 1 : 0; - - // return *found ? ((sora_unity_sdk::UnityRenderer::Sink*)p)->GetTrackId().c_str() - return *found ? ((sora_unity_sdk::UnityRenderer::Sink*)p)->GetTrackIdC() - : nullptr; + return p != nullptr + ? ((sora_unity_sdk::UnityRenderer::Sink*)p)->GetTrackId().c_str() + : nullptr; } // iOS の場合は static link で名前が被る可能性があるので、別の名前にしておく diff --git a/src/unity.h b/src/unity.h index b568fd6..4405d8e 100644 --- a/src/unity.h +++ b/src/unity.h @@ -126,8 +126,7 @@ sora_audio_output_helper_is_handsfree(void* p); UNITY_INTERFACE_EXPORT void sora_audio_output_helper_set_handsfree( void* p, unity_bool_t enabled); -UNITY_INTERFACE_EXPORT const char* get_track_id(ptrid_t track_id, - unity_bool_t* found); +UNITY_INTERFACE_EXPORT const char* get_track_id(ptrid_t track_id); #ifdef __cplusplus } diff --git a/src/unity_renderer.cpp b/src/unity_renderer.cpp index be711e8..936a620 100644 --- a/src/unity_renderer.cpp +++ b/src/unity_renderer.cpp @@ -17,10 +17,6 @@ UnityRenderer::Sink::Sink(webrtc::VideoTrackInterface* track) updating_ = false; ptrid_ = IdPointer::Instance().Register(this); track_->AddOrUpdateSink(this, rtc::VideoSinkWants()); - - size_t size = strlen(track_id_.c_str()); - track_id_c_ = new char[size + 1]; - strcpy(track_id_c_, track_id_.c_str()); } UnityRenderer::Sink::~Sink() { RTC_LOG(LS_INFO) << "[" << (void*)this << "] Sink::~Sink"; @@ -41,9 +37,6 @@ ptrid_t UnityRenderer::Sink::GetSinkID() const { const std::string& UnityRenderer::Sink::GetTrackId() const { return track_id_; } -char* UnityRenderer::Sink::GetTrackIdC() const { - return track_id_c_; -} void UnityRenderer::Sink::SetTrack(webrtc::VideoTrackInterface* track) { track_->RemoveSink(this); diff --git a/src/unity_renderer.h b/src/unity_renderer.h index c1a50d2..f388397 100644 --- a/src/unity_renderer.h +++ b/src/unity_renderer.h @@ -32,7 +32,6 @@ class UnityRenderer { ~Sink(); ptrid_t GetSinkID() const; const std::string& GetTrackId() const; - char* GetTrackIdC() const; void SetTrack(webrtc::VideoTrackInterface* track); private: