Add property to RTCEncodedImage to own underlying EncodedImage.
Bug: None Change-Id: Ic07b880c3a29789e2e74cb311267c05eb776a38a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/134104 Commit-Queue: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Anders Carlsson <andersc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27753}
This commit is contained in:
committed by
Commit Bot
parent
f8c1ed5646
commit
03e85d2b3b
@ -10,10 +10,41 @@
|
||||
|
||||
#import "RTCEncodedImage+Private.h"
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
#include "rtc_base/numerics/safe_conversions.h"
|
||||
|
||||
// A simple wrapper around rtc::CopyOnWriteBuffer to make it usable with
|
||||
// associated objects.
|
||||
@interface RTCWrappedCOWBuffer : NSObject
|
||||
@property(nonatomic) rtc::CopyOnWriteBuffer buffer;
|
||||
- (instancetype)initWithCOWBuffer:(rtc::CopyOnWriteBuffer)buffer;
|
||||
@end
|
||||
@implementation RTCWrappedCOWBuffer
|
||||
@synthesize buffer = _buffer;
|
||||
- (instancetype)initWithCOWBuffer:(rtc::CopyOnWriteBuffer)buffer {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_buffer = buffer;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation RTCEncodedImage (Private)
|
||||
|
||||
- (rtc::CopyOnWriteBuffer)encodedData {
|
||||
RTCWrappedCOWBuffer *wrappedBuffer = objc_getAssociatedObject(self, @selector(encodedData));
|
||||
return wrappedBuffer.buffer;
|
||||
}
|
||||
|
||||
- (void)setEncodedData:(rtc::CopyOnWriteBuffer)buffer {
|
||||
return objc_setAssociatedObject(self,
|
||||
@selector(encodedData),
|
||||
[[RTCWrappedCOWBuffer alloc] initWithCOWBuffer:buffer],
|
||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (instancetype)initWithNativeEncodedImage:(const webrtc::EncodedImage &)encodedImage {
|
||||
if (self = [super init]) {
|
||||
// Wrap the buffer in NSData without copying, do not take ownership.
|
||||
|
||||
Reference in New Issue
Block a user