GstBuffer * gst_core_media_buffer_new (CMSampleBufferRef sample_buf, gboolean use_video_meta, GstVideoTextureCache * cache) { CVImageBufferRef image_buf; CMBlockBufferRef block_buf; GstBuffer *buf; image_buf = CMSampleBufferGetImageBuffer (sample_buf); block_buf = CMSampleBufferGetDataBuffer (sample_buf); buf = gst_buffer_new (); gst_core_media_meta_add (buf, sample_buf, image_buf, block_buf); if (image_buf != NULL && CFGetTypeID (image_buf) == CVPixelBufferGetTypeID () && cache) { GstVideoInfo info; gboolean has_padding = FALSE; CVPixelBufferRef pixel_buf = (CVPixelBufferRef) image_buf; if (!gst_video_info_init_from_pixel_buffer (&info, pixel_buf)) { goto error; } gst_core_video_wrap_pixel_buffer (buf, &info, pixel_buf, cache, &has_padding); /* If the video meta API is not supported, remove padding by * copying the core media buffer to a system memory buffer */ if (has_padding && !use_video_meta) { GstBuffer *copy_buf; copy_buf = gst_core_media_buffer_new_from_buffer (buf, &info); if (!copy_buf) { goto error; } gst_buffer_unref (buf); buf = copy_buf; } } else if (block_buf != NULL) { if (!gst_core_media_buffer_wrap_block_buffer (buf, block_buf)) { goto error; } } else { goto error; } return buf; error: if (buf) { gst_buffer_unref (buf); } return NULL; }
GstBuffer * gst_core_media_buffer_new (CMSampleBufferRef sample_buf, gboolean use_video_meta, gboolean map) { CVImageBufferRef image_buf; CMBlockBufferRef block_buf; GstCoreMediaMeta *meta; GstBuffer *buf; image_buf = CMSampleBufferGetImageBuffer (sample_buf); block_buf = CMSampleBufferGetDataBuffer (sample_buf); buf = gst_buffer_new (); meta = (GstCoreMediaMeta *) gst_buffer_add_meta (buf, gst_core_media_meta_get_info (), NULL); CFRetain (sample_buf); if (image_buf) CVBufferRetain (image_buf); if (block_buf) CFRetain (block_buf); meta->sample_buf = sample_buf; meta->image_buf = image_buf; meta->pixel_buf = NULL; meta->block_buf = block_buf; if (image_buf != NULL && CFGetTypeID (image_buf) == CVPixelBufferGetTypeID ()) { GstVideoInfo info; gboolean has_padding = FALSE; meta->pixel_buf = (CVPixelBufferRef) image_buf; if (!gst_video_info_init_from_pixel_buffer (&info, meta->pixel_buf)) { goto error; } if (!gst_core_media_buffer_wrap_pixel_buffer (buf, &info, meta->pixel_buf, &has_padding, map)) { goto error; } /* If the video meta API is not supported, remove padding by * copying the core media buffer to a system memory buffer */ if (map && has_padding && !use_video_meta) { GstBuffer *copy_buf; copy_buf = gst_core_media_buffer_new_from_buffer (buf, &info); if (!copy_buf) { goto error; } gst_buffer_unref (buf); buf = copy_buf; } } else if (block_buf != NULL) { if (map && !gst_core_media_buffer_wrap_block_buffer (buf, block_buf)) { goto error; } } else { goto error; } return buf; error: if (buf) { gst_buffer_unref (buf); } return NULL; }