Swiftgram/submodules/ffmpeg/FFMpeg/FFMpegAVIOContext.m
Peter 6086305304 Add 'submodules/ffmpeg/' from commit '53fc3dcb6022f35015afd2605ead32bfd7417144'
git-subtree-dir: submodules/ffmpeg
git-subtree-mainline: 8f5a4f7dc119599d326c72d9a6115973e825491b
git-subtree-split: 53fc3dcb6022f35015afd2605ead32bfd7417144
2019-06-11 18:46:03 +01:00

40 lines
967 B
Objective-C

#import "FFMpegAVIOContext.h"
#import "libavformat/avformat.h"
@interface FFMpegAVIOContext () {
AVIOContext *_impl;
}
@end
@implementation FFMpegAVIOContext
- (instancetype _Nullable)initWithBufferSize:(int32_t)bufferSize opaqueContext:(void * const)opaqueContext readPacket:(int (*)(void * _Nullable opaque, uint8_t * _Nullable buf, int buf_size))readPacket seek:(int64_t (*)(void * _Nullable opaque, int64_t offset, int whence))seek {
self = [super init];
if (self != nil) {
void *avIoBuffer = av_malloc(bufferSize);
_impl = avio_alloc_context(avIoBuffer, bufferSize, 0, opaqueContext, readPacket, nil, seek);
if (_impl == nil) {
av_free(avIoBuffer);
return nil;
}
}
return self;
}
- (void)dealloc {
if (_impl != nil) {
if (_impl->buffer != nil) {
av_free(_impl->buffer);
}
av_free(_impl);
}
}
- (void *)impl {
return _impl;
}
@end