Created
July 1, 2015 13:12
-
-
Save ikonst/e7385ccd5c07a5b84e30 to your computer and use it in GitHub Desktop.
NSData+GStreamer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import Foundation; | |
#include <gst/gst.h> | |
@interface NSData (GStreamer) | |
- (GstBuffer *)gstBuffer; | |
@end | |
@interface NSMutableData (GStreamer) | |
+ (NSMutableData *)dataWithGstBuffer:(GstBuffer *)buffer; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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