if (!vlsurface)
return VDP_STATUS_RESOURCES;
- vlsurface->device = dev;
+ DeviceReference(&vlsurface->device, dev);
memset(&res_tmpl, 0, sizeof(res_tmpl));
res_tmpl.target = PIPE_TEXTURE_2D;
pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
err_unlock:
pipe_mutex_unlock(dev->mutex);
+ DeviceReference(&vlsurface->device, NULL);
FREE(vlsurface);
return ret;
}
pipe_mutex_unlock(vlsurface->device->mutex);
vlRemoveDataHTAB(surface);
+ DeviceReference(&vlsurface->device, NULL);
FREE(vlsurface);
return VDP_STATUS_OK;
return VDP_STATUS_RESOURCES;
}
- vldecoder->device = dev;
+ DeviceReference(&vldecoder->device, dev);
templat.entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM;
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
error_decoder:
pipe_mutex_unlock(dev->mutex);
+ DeviceReference(&vldecoder->device, NULL);
FREE(vldecoder);
return ret;
}
pipe_mutex_destroy(vldecoder->mutex);
vlRemoveDataHTAB(decoder);
+ DeviceReference(&vldecoder->device, NULL);
FREE(vldecoder);
return VDP_STATUS_OK;
goto no_dev;
}
+ pipe_reference_init(&dev->reference, 1);
+
dev->vscreen = vl_screen_create(display, screen);
if (!dev->vscreen) {
ret = VDP_STATUS_RESOURCES;
if (!pqt)
return VDP_STATUS_RESOURCES;
- pqt->device = dev;
+ DeviceReference(&pqt->device, dev);
pqt->drawable = drawable;
*target = vlAddDataHTAB(pqt);
return VDP_STATUS_INVALID_HANDLE;
vlRemoveDataHTAB(presentation_queue_target);
+ DeviceReference(&pqt->device, NULL);
FREE(pqt);
return VDP_STATUS_OK;
if (!dev)
return VDP_STATUS_INVALID_HANDLE;
+ vlRemoveDataHTAB(device);
+ DeviceReference(&dev, NULL);
+
+ return VDP_STATUS_OK;
+}
+
+/**
+ * Free a VdpDevice.
+ */
+void
+vlVdpDeviceFree(vlVdpDevice *dev)
+{
pipe_mutex_destroy(dev->mutex);
vl_compositor_cleanup(&dev->compositor);
dev->context->destroy(dev->context);
vl_screen_destroy(dev->vscreen);
-
- vlRemoveDataHTAB(device);
FREE(dev);
vlDestroyHTAB();
-
- return VDP_STATUS_OK;
}
/**
if (!vmixer)
return VDP_STATUS_RESOURCES;
- vmixer->device = dev;
+ DeviceReference(&vmixer->device, dev);
pipe_mutex_lock(dev->mutex);
no_handle:
vl_compositor_cleanup_state(&vmixer->cstate);
pipe_mutex_unlock(dev->mutex);
+ DeviceReference(&vmixer->device, NULL);
FREE(vmixer);
return ret;
}
FREE(vmixer->sharpness.filter);
}
pipe_mutex_unlock(vmixer->device->mutex);
+ DeviceReference(&vmixer->device, NULL);
FREE(vmixer);
if (!vlsurface)
return VDP_STATUS_RESOURCES;
- vlsurface->device = dev;
+ DeviceReference(&vlsurface->device, dev);
memset(&res_tmpl, 0, sizeof(res_tmpl));
pipe_resource_reference(&res, NULL);
err_unlock:
pipe_mutex_unlock(dev->mutex);
+ DeviceReference(&vlsurface->device, NULL);
FREE(vlsurface);
return VDP_STATUS_ERROR;
}
pipe_mutex_unlock(vlsurface->device->mutex);
vlRemoveDataHTAB(surface);
+ DeviceReference(&vlsurface->device, NULL);
FREE(vlsurface);
return VDP_STATUS_OK;
if (!pq)
return VDP_STATUS_RESOURCES;
- pq->device = dev;
+ DeviceReference(&pq->device, dev);
pq->drawable = pqt->drawable;
pipe_mutex_lock(dev->mutex);
no_handle:
no_compositor:
+ DeviceReference(&pq->device, NULL);
FREE(pq);
return ret;
}
pipe_mutex_unlock(pq->device->mutex);
vlRemoveDataHTAB(presentation_queue);
+ DeviceReference(&pq->device, NULL);
FREE(pq);
return VDP_STATUS_OK;
goto inv_device;
}
- p_surf->device = dev;
+ DeviceReference(&p_surf->device, dev);
pipe = dev->context;
pipe_mutex_lock(dev->mutex);
p_surf->video_buffer->destroy(p_surf->video_buffer);
inv_device:
+ DeviceReference(&p_surf->device, NULL);
FREE(p_surf);
no_res:
pipe_mutex_unlock(p_surf->device->mutex);
vlRemoveDataHTAB(surface);
+ DeviceReference(&p_surf->device, NULL);
FREE(p_surf);
return VDP_STATUS_OK;
typedef struct
{
+ struct pipe_reference reference;
struct vl_screen *vscreen;
struct pipe_context *context;
struct vl_compositor compositor;
/* Internal function pointers */
VdpGetErrorString vlVdpGetErrorString;
VdpDeviceDestroy vlVdpDeviceDestroy;
+void vlVdpDeviceFree(vlVdpDevice *dev);
VdpGetProcAddress vlVdpGetProcAddress;
VdpGetApiVersion vlVdpGetApiVersion;
VdpGetInformationString vlVdpGetInformationString;
}
}
+static inline void
+DeviceReference(vlVdpDevice **ptr, vlVdpDevice *dev)
+{
+ vlVdpDevice *old_dev = *ptr;
+
+ if (pipe_reference(&(*ptr)->reference, &dev->reference))
+ vlVdpDeviceFree(old_dev);
+ *ptr = dev;
+}
+
#endif /* VDPAU_PRIVATE_H */