Skip to content

Commit

Permalink
Marshal.PtrToStringAnsi に戻す
Browse files Browse the repository at this point in the history
  • Loading branch information
enm10k committed Feb 8, 2024
1 parent 4844029 commit 8566f24
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
11 changes: 5 additions & 6 deletions Sora/Sora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,9 @@ public void GetStats(Action<string> 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) : "");
}

/// <summary>
Expand Down Expand Up @@ -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
{
Expand Down
11 changes: 4 additions & 7 deletions src/unity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 で名前が被る可能性があるので、別の名前にしておく
Expand Down
3 changes: 1 addition & 2 deletions src/unity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 0 additions & 7 deletions src/unity_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/unity_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8566f24

Please sign in to comment.