GstMemory * gst_droid_media_buffer_allocator_alloc_from_data (GstAllocator * allocator, GstVideoInfo * info, DroidMediaData * data, DroidMediaBufferCallbacks * cb) { GstDroidMediaBufferMemory *mem; DroidMediaBuffer *buffer; int format; GstDroidMediaBufferAllocator *alloc; if (!GST_IS_DROID_MEDIA_BUFFER_ALLOCATOR (allocator)) { GST_WARNING_OBJECT (allocator, "allocator is not the correct allocator for droidmediabuffer"); return NULL; } alloc = (GstDroidMediaBufferAllocator *) allocator; if (info->finfo->format == GST_VIDEO_FORMAT_YV12) { format = alloc->c.HAL_PIXEL_FORMAT_YV12; } else if (info->finfo->format == GST_VIDEO_FORMAT_NV21) { format = alloc->c.HAL_PIXEL_FORMAT_YCrCb_420_SP; } else { GST_WARNING_OBJECT (allocator, "Unknown GStreamer format %s", gst_video_format_to_string (info->finfo->format)); return NULL; } mem = g_slice_new0 (GstDroidMediaBufferMemory); buffer = droid_media_buffer_create_from_raw_data (info->width, info->height, GST_VIDEO_INFO_COMP_STRIDE (info, 0), GST_VIDEO_INFO_COMP_STRIDE (info, 1), format, data, cb); if (!buffer) { GST_ERROR_OBJECT (allocator, "failed to acquire media buffer"); g_slice_free (GstDroidMediaBufferMemory, mem); return NULL; } mem->buffer = buffer; gst_memory_init (GST_MEMORY_CAST (mem), GST_MEMORY_FLAG_NO_SHARE | GST_MEMORY_FLAG_NOT_MAPPABLE, allocator, NULL, 0, 0, 0, 0); GST_DEBUG_OBJECT (allocator, "alloc %p", mem); return GST_MEMORY_CAST (mem); }
GstMemory * gst_droid_media_buffer_allocator_alloc_from_data (GstAllocator * allocator, GstVideoInfo * info, DroidMediaData * data, DroidMediaBufferCallbacks * cb) { GstDroidMediaBufferMemory *mem; DroidMediaBuffer *buffer; DroidMediaBufferInfo droid_info; int format_index; if (!GST_IS_DROID_MEDIA_BUFFER_ALLOCATOR (allocator)) { GST_WARNING_OBJECT (allocator, "allocator is not the correct allocator for droidmediabuffer"); return NULL; } format_index = gst_droid_media_buffer_index_of_gst_format (info->finfo->format); if (format_index == GST_DROID_MEDIA_BUFFER_FORMAT_COUNT) { GST_WARNING_OBJECT (allocator, "Unknown GStreamer format %s", gst_video_format_to_string (info->finfo->format)); return NULL; } buffer = droid_media_buffer_create_from_raw_data (info->width, info->height, GST_VIDEO_INFO_COMP_STRIDE (info, 0), GST_VIDEO_INFO_COMP_STRIDE (info, 1), gst_droid_media_buffer_formats[format_index].hal_format, data, cb); if (!buffer) { GST_ERROR_OBJECT (allocator, "failed to acquire media buffer"); return NULL; } droid_media_buffer_get_info (buffer, &droid_info); mem = gst_droid_media_buffer_allocator_alloc_from_buffer (allocator, buffer, format_index, info->width, info->height, droid_info.stride); GST_DEBUG_OBJECT (allocator, "alloc %p", mem); return GST_MEMORY_CAST (mem); }