Skip to content

Commit

Permalink
fix: Fix crash on Android pixel4a with vulkan (#874)
Browse files Browse the repository at this point in the history
* fix crash on android pixel4a with vulkan

* fix bug

* fix code format

* fix unittest error

* fix crash of H.264 hw codec

* [skip ci] Update plugins
  • Loading branch information
karasusan authored Jan 16, 2023
1 parent 7481842 commit 9188e54
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 18 deletions.
7 changes: 6 additions & 1 deletion Plugin~/WebRTCPlugin/Codec/NvCodec/NvEncoderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,12 @@ namespace webrtc
if (!m_encodedCompleteCallback)
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;

auto videoFrameBuffer = static_cast<ScalableBufferInterface*>(frame.video_frame_buffer().get());
auto frameBuffer = frame.video_frame_buffer();
if (frameBuffer->type() != VideoFrameBuffer::Type::kNative || frameBuffer->width() != m_codec.width ||
frameBuffer->height() != m_codec.height)
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;

auto videoFrameBuffer = static_cast<ScalableBufferInterface*>(frameBuffer.get());
rtc::scoped_refptr<VideoFrame> video_frame = videoFrameBuffer->scaled()
? static_cast<VideoFrameAdapter::ScaledBuffer*>(videoFrameBuffer)->GetVideoFrame()
: static_cast<VideoFrameAdapter*>(videoFrameBuffer)->GetVideoFrame();
Expand Down
5 changes: 4 additions & 1 deletion Plugin~/WebRTCPlugin/GpuMemoryBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ namespace webrtc

GpuMemoryBufferFromUnity::~GpuMemoryBufferFromUnity() { }

void GpuMemoryBufferFromUnity::ResetSync()
bool GpuMemoryBufferFromUnity::ResetSync()
{
if (!device_->ResetSync(texture_.get()))
{
RTC_LOG(LS_INFO) << "ResetSync failed.";
return false;
}
if (!device_->ResetSync(textureCpuRead_.get()))
{
RTC_LOG(LS_INFO) << "ResetSync failed.";
return false;
}
return true;
}

void GpuMemoryBufferFromUnity::CopyBuffer(NativeTexPtr ptr)
Expand Down
2 changes: 1 addition & 1 deletion Plugin~/WebRTCPlugin/GpuMemoryBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace webrtc
GpuMemoryBufferFromUnity(const GpuMemoryBufferFromUnity&) = delete;
GpuMemoryBufferFromUnity& operator=(const GpuMemoryBufferFromUnity&) = delete;

void ResetSync();
bool ResetSync();
void CopyBuffer(NativeTexPtr ptr);
UnityRenderingExtTextureFormat GetFormat() const override;
Size GetSize() const override;
Expand Down
8 changes: 6 additions & 2 deletions Plugin~/WebRTCPlugin/GpuMemoryBufferPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ namespace webrtc
FrameResources* resources = it->get();
if (!resources->IsUsed() && AreFrameResourcesCompatible(resources, size, format))
{
resources->MarkUsed(clock_->CurrentTime());
GpuMemoryBufferFromUnity* buffer = static_cast<GpuMemoryBufferFromUnity*>(resources->buffer_.get());
buffer->ResetSync();
if (!buffer->ResetSync())
{
RTC_LOG(LS_INFO) << "It has not signaled yet";
continue;
}
resources->MarkUsed(clock_->CurrentTime());
buffer->CopyBuffer(ptr);
return resources->buffer_;
}
Expand Down
11 changes: 2 additions & 9 deletions Plugin~/WebRTCPlugin/VideoFrameAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,12 @@ namespace webrtc

rtc::scoped_refptr<webrtc::I420BufferInterface> VideoFrameAdapter::ScaledBuffer::ToI420()
{
auto buffer = parent_->GetOrCreateFrameBufferForSize(Size(width_, height_));
if(!buffer)
return nullptr;
return buffer->ToI420();
return parent_->GetOrCreateFrameBufferForSize(Size(width_, height_))->ToI420();
}

const I420BufferInterface* VideoFrameAdapter::ScaledBuffer::GetI420() const
{
auto buffer = parent_->GetOrCreateFrameBufferForSize(Size(width_, height_));
if(!buffer)
return nullptr;
return buffer->GetI420();
return parent_->GetOrCreateFrameBufferForSize(Size(width_, height_))->GetI420();
}

rtc::scoped_refptr<VideoFrameBuffer>
Expand Down Expand Up @@ -117,7 +111,6 @@ namespace webrtc
}
auto buffer = VideoFrameBuffer::CropAndScale(0, 0, width(), height(), size.width(), size.height());
scaledI40Buffers_.push_back(buffer);
RTC_LOG(LS_INFO) << "size.width:" << size.width() << " size.height:" << size.height();
return buffer;
}

Expand Down
Binary file modified Runtime/Plugins/Android/libwebrtc.aar
Binary file not shown.
Binary file modified Runtime/Plugins/iOS/webrtc.framework/webrtc
Binary file not shown.
Binary file modified Runtime/Plugins/macOS/libwebrtc.dylib
Binary file not shown.
Binary file modified Runtime/Plugins/x86_64/libwebrtc.so
Binary file not shown.
Binary file modified Runtime/Plugins/x86_64/webrtc.dll
Binary file not shown.
3 changes: 0 additions & 3 deletions Tests/Runtime/StatsReportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ public static void Test(RTCStats stats)
Ignore.Pass(sentRtpStats.packetsSent);
Ignore.Pass(sentRtpStats.bytesSent);
break;
default:
Debug.LogWarning(stats.Type);
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Runtime/VideoReceiveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ IEnumerator VideoReceive()
var receiveVideoTrack = test.component.RecvVideoTrack;
Assert.That(receiveVideoTrack, Is.Not.Null);

yield return new WaitUntilWithTimeout(() => receiveVideoTrack.Texture != null, 5000);
yield return new WaitUntilWithTimeout(() => receiveVideoTrack.Texture != null, 15000);
Assert.That(receiveVideoTrack.Texture, Is.Not.Null);
test.component.Clear();
}
Expand Down

0 comments on commit 9188e54

Please sign in to comment.