gboolean gst_vdp_output_buffer_calculate_size (GstVdpOutputBuffer * output_buf, guint * size) { g_return_val_if_fail (GST_IS_VDP_OUTPUT_BUFFER (output_buf), FALSE); switch (output_buf->rgba_format) { case VDP_RGBA_FORMAT_A8: { *size = output_buf->width * output_buf->height; break; } case VDP_RGBA_FORMAT_B10G10R10A2: case VDP_RGBA_FORMAT_B8G8R8A8: case VDP_RGBA_FORMAT_R10G10B10A2: case VDP_RGBA_FORMAT_R8G8B8A8: { *size = output_buf->width * output_buf->height * 4; break; } default: g_assert_not_reached (); return FALSE; } return TRUE; }
GstFlowReturn gst_vdp_output_src_pad_push (GstVdpOutputSrcPad * vdp_pad, GstVdpOutputBuffer * output_buf, GError ** error) { GstPad *pad; GstBuffer *outbuf; g_return_val_if_fail (GST_IS_VDP_OUTPUT_SRC_PAD (vdp_pad), GST_FLOW_ERROR); g_return_val_if_fail (GST_IS_VDP_OUTPUT_BUFFER (output_buf), GST_FLOW_ERROR); pad = (GstPad *) vdp_pad; if (G_UNLIKELY (!GST_PAD_CAPS (pad))) return GST_FLOW_NOT_NEGOTIATED; switch (vdp_pad->output_format) { case GST_VDP_OUTPUT_SRC_PAD_FORMAT_RGB: { GstFlowReturn ret; guint size; gst_vdp_output_buffer_calculate_size (output_buf, &size); vdp_pad->lock_caps = TRUE; ret = gst_pad_alloc_buffer (pad, 0, size, GST_PAD_CAPS (vdp_pad), &outbuf); vdp_pad->lock_caps = FALSE; if (ret != GST_FLOW_OK) { gst_buffer_unref (GST_BUFFER_CAST (output_buf)); return ret; } if (!gst_vdp_output_buffer_download (output_buf, outbuf, error)) { gst_buffer_unref (GST_BUFFER_CAST (output_buf)); gst_buffer_unref (outbuf); return GST_FLOW_ERROR; } gst_buffer_copy_metadata (outbuf, (const GstBuffer *) output_buf, GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS); gst_buffer_unref (GST_BUFFER_CAST (output_buf)); break; } case GST_VDP_OUTPUT_SRC_PAD_FORMAT_VDPAU: { outbuf = GST_BUFFER_CAST (output_buf); break; } default: g_assert_not_reached (); break; } gst_buffer_set_caps (outbuf, GST_PAD_CAPS (vdp_pad)); return gst_pad_push (pad, outbuf); }
gboolean gst_vdp_output_buffer_download (GstVdpOutputBuffer * output_buf, GstBuffer * outbuf, GError ** error) { guint8 *data[1]; guint32 stride[1]; GstVdpDevice *device; VdpOutputSurface surface; VdpStatus status; g_return_val_if_fail (GST_IS_VDP_OUTPUT_BUFFER (output_buf), FALSE); switch (output_buf->rgba_format) { case VDP_RGBA_FORMAT_A8: { stride[0] = output_buf->width; break; } case VDP_RGBA_FORMAT_B10G10R10A2: case VDP_RGBA_FORMAT_B8G8R8A8: case VDP_RGBA_FORMAT_R10G10B10A2: case VDP_RGBA_FORMAT_R8G8B8A8: { stride[0] = output_buf->width * 4; break; } default: return FALSE; } device = output_buf->device; surface = output_buf->surface; data[0] = GST_BUFFER_DATA (outbuf); GST_LOG_OBJECT (output_buf, "Entering vdp_output_surface_get_bits_native"); status = device->vdp_output_surface_get_bits_native (surface, NULL, (void *) data, stride); GST_LOG_OBJECT (output_buf, "Got status %d from vdp_output_get_bits_native", status); if (G_UNLIKELY (status != VDP_STATUS_OK)) { g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_READ, "Couldn't get data from vdpau, error returned from vdpau was: %s", device->vdp_get_error_string (status)); return FALSE; } return TRUE; }
static GstFlowReturn gst_vdp_output_src_pad_alloc_with_caps (GstVdpOutputSrcPad * vdp_pad, GstCaps * caps, GstVdpOutputBuffer ** output_buf, GError ** error) { GstFlowReturn ret; ret = gst_pad_alloc_buffer_and_set_caps ((GstPad *) vdp_pad, 0, 0, caps, (GstBuffer **) output_buf); if (ret != GST_FLOW_OK) return ret; if (!GST_IS_VDP_OUTPUT_BUFFER (*output_buf)) goto invalid_buf; return GST_FLOW_OK; invalid_buf: gst_buffer_unref (GST_BUFFER (*output_buf)); g_set_error (error, GST_STREAM_ERROR, GST_STREAM_ERROR_FAILED, "Sink element returned buffer of wrong type"); return GST_FLOW_ERROR; }