Skip to content

Instantly share code, notes, and snippets.

@ikonst
Created July 1, 2015 13:12
Show Gist options
  • Save ikonst/e7385ccd5c07a5b84e30 to your computer and use it in GitHub Desktop.
Save ikonst/e7385ccd5c07a5b84e30 to your computer and use it in GitHub Desktop.
NSData+GStreamer
@import Foundation;
#include <gst/gst.h>
@interface NSData (GStreamer)
- (GstBuffer *)gstBuffer;
@end
@interface NSMutableData (GStreamer)
+ (NSMutableData *)dataWithGstBuffer:(GstBuffer *)buffer;
@end
#import "NSData+GStreamer.h"
@implementation NSData (GstBuffer)
- (GstBuffer *)gstBuffer
{
const void * bytes = [self bytes];
gsize length = [self length];
return gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY,
(gpointer)bytes, length, 0, length,
(gpointer)CFBridgingRetain(self),
(GDestroyNotify)CFRelease);
}
@end
@implementation NSMutableData (GstBuffer)
+ (NSMutableData *)dataWithGstBuffer:(GstBuffer *)buffer
{
gsize size = gst_buffer_get_size(buffer);
NSMutableData *data = [NSMutableData dataWithLength:size];
gst_buffer_extract(buffer, 0, [data mutableBytes], size);
return data;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment