Skip to content

Commit

Permalink
Fixed Metal renderer memory leak (#3909)
Browse files Browse the repository at this point in the history
  • Loading branch information
sauwming authored Mar 29, 2024
1 parent 478aeb9 commit 51e5206
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pjmedia/src/pjmedia-codec/vid_toolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -554,17 +554,20 @@ static OSStatus create_encoder(vtool_codec_data *vtool_data)

ret = VTSessionCopySupportedPropertyDictionary(vtool_data->enc,
&supported_prop);
if (ret == noErr &&
CFDictionaryContainsKey(supported_prop,
if (ret == noErr) {
if (CFDictionaryContainsKey(supported_prop,
kVTCompressionPropertyKey_MaxH264SliceBytes))
{
/* kVTCompressionPropertyKey_MaxH264SliceBytes is not yet supported
* by Apple. We leave it here for possible future enhancements.
SET_PROPERTY(vtool_data->enc,
kVTCompressionPropertyKey_MaxH264SliceBytes,
// param->enc_mtu - NAL_HEADER_ADD_0X30BYTES
(__bridge CFTypeRef)@(param->enc_mtu - 50));
*/
{
/* kVTCompressionPropertyKey_MaxH264SliceBytes is not yet supported
* by Apple. We leave it here for possible future enhancements.
SET_PROPERTY(vtool_data->enc,
kVTCompressionPropertyKey_MaxH264SliceBytes,
// param->enc_mtu - NAL_HEADER_ADD_0X30BYTES
(__bridge CFTypeRef)@(param->enc_mtu - 50));
*/
}

CFRelease(supported_prop);
}

VTCompressionSessionPrepareToEncodeFrames(vtool_data->enc);
Expand Down
7 changes: 7 additions & 0 deletions pjmedia/src/pjmedia-videodev/metal_dev.m
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ - (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView
textureCoordBuffer = [device newBufferWithBytes:textureCoordinates
length:sizeof(textureCoordinates)
options:MTLResourceStorageModeShared];

[pQuadPipelineStateDescriptor release];
[fragmentProgram release];
[vertexProgram release];
[shaderLibrary release];
}

return self;
Expand Down Expand Up @@ -509,6 +514,8 @@ - (void)update_image
[commandBuffer presentDrawable:drawable];
[commandBuffer commit];

[texture release];

stream->is_rendering = PJ_FALSE;
}

Expand Down

0 comments on commit 51e5206

Please sign in to comment.