Change ownership of encoded data buffer in H264 encoder.

Bug: None
Change-Id: I92b5acacf6bb3a81f8d67043674ea63b4898cbd9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169721
Commit-Queue: Kári Helgason <kthelgason@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30680}
This commit is contained in:
Kári Tristan Helgason
2020-03-04 13:45:38 +01:00
committed by Commit Bot
parent 420ad1af1e
commit 589b41e743

View File

@ -782,9 +782,7 @@ NSUInteger GetMaxSampleRate(const webrtc::H264::ProfileLevelId &profile_level_id
RTC_LOG(LS_INFO) << "Generated keyframe";
}
// Convert the sample buffer into a buffer suitable for RTP packetization.
// TODO(tkchin): Allocate buffers through a pool.
std::unique_ptr<rtc::Buffer> buffer(new rtc::Buffer());
__block std::unique_ptr<rtc::Buffer> buffer = std::make_unique<rtc::Buffer>();
RTCRtpFragmentationHeader *header;
{
std::unique_ptr<webrtc::RTPFragmentationHeader> header_cpp;
@ -797,7 +795,12 @@ NSUInteger GetMaxSampleRate(const webrtc::H264::ProfileLevelId &profile_level_id
}
RTCEncodedImage *frame = [[RTCEncodedImage alloc] init];
frame.buffer = [NSData dataWithBytesNoCopy:buffer->data() length:buffer->size() freeWhenDone:NO];
// This assumes ownership of `buffer` and is responsible for freeing it when done.
frame.buffer = [[NSData alloc] initWithBytesNoCopy:buffer->data()
length:buffer->size()
deallocator:^(void *bytes, NSUInteger size) {
buffer.reset();
}];
frame.encodedWidth = width;
frame.encodedHeight = height;
frame.completeFrame = YES;