Allocate CMBlockBuffers using a memory pool.

Bug: webrtc:5258
Change-Id: Iae7549d618f797f4dc413671f0f2e53ed23be3e7
Reviewed-on: https://webrtc-review.googlesource.com/c/107738
Reviewed-by: Anders Carlsson <andersc@webrtc.org>
Commit-Queue: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25383}
diff --git a/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm b/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm
index a6edbc8..3bfb918 100644
--- a/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm
+++ b/sdk/objc/components/video_codec/RTCVideoDecoderH264.mm
@@ -71,12 +71,23 @@
 // Decoder.
 @implementation RTCVideoDecoderH264 {
   CMVideoFormatDescriptionRef _videoFormat;
+  CMMemoryPoolRef _memoryPool;
   VTDecompressionSessionRef _decompressionSession;
   RTCVideoDecoderCallback _callback;
   OSStatus _error;
 }
 
+- (instancetype)init {
+  self = [super init];
+  if (self) {
+    _memoryPool = CMMemoryPoolCreate(nil);
+  }
+  return self;
+}
+
 - (void)dealloc {
+  CMMemoryPoolInvalidate(_memoryPool);
+  CFRelease(_memoryPool);
   [self destroyDecompressionSession];
   [self setVideoFormat:nullptr];
 }
@@ -129,7 +140,8 @@
   if (!webrtc::H264AnnexBBufferToCMSampleBuffer((uint8_t *)inputImage.buffer.bytes,
                                                 inputImage.buffer.length,
                                                 _videoFormat,
-                                                &sampleBuffer)) {
+                                                &sampleBuffer,
+                                                _memoryPool)) {
     return WEBRTC_VIDEO_CODEC_ERROR;
   }
   RTC_DCHECK(sampleBuffer);