+static AMF_RESULT amf_set_property_buffer(AMFSurface *object, const wchar_t *name, AMFBuffer *val)
+{
+ AMF_RESULT res;
+ AMFVariantStruct var;
+ res = AMFVariantInit(&var);
+ if (res == AMF_OK) {
+ AMFGuid guid_AMFInterface = IID_AMFInterface();
+ AMFInterface *amf_interface;
+ res = val->pVtbl->QueryInterface(val, &guid_AMFInterface, (void**)&amf_interface);
+
+ if (res == AMF_OK) {
+ res = AMFVariantAssignInterface(&var, amf_interface);
+ amf_interface->pVtbl->Release(amf_interface);
+ }
+ if (res == AMF_OK) {
+ res = object->pVtbl->SetProperty(object, name, var);
+ }
+ AMFVariantClear(&var);
+ }
+ return res;
+}
+
+static AMF_RESULT amf_get_property_buffer(AMFData *object, const wchar_t *name, AMFBuffer **val)
+{
+ AMF_RESULT res;
+ AMFVariantStruct var;
+ res = AMFVariantInit(&var);
+ if (res == AMF_OK) {
+ res = object->pVtbl->GetProperty(object, name, &var);
+ if (res == AMF_OK) {
+ if (var.type == AMF_VARIANT_INTERFACE) {
+ AMFGuid guid_AMFBuffer = IID_AMFBuffer();
+ AMFInterface *amf_interface = AMFVariantInterface(&var);
+ res = amf_interface->pVtbl->QueryInterface(amf_interface, &guid_AMFBuffer, (void**)val);
+ } else {
+ res = AMF_INVALID_DATA_TYPE;
+ }
+ }
+ AMFVariantClear(&var);
+ }
+ return res;
+}
+
+static AMFBuffer *amf_create_buffer_with_frame_ref(const AVFrame *frame, AMFContext *context)
+{
+ AVFrame *frame_ref;
+ AMFBuffer *frame_ref_storage_buffer = NULL;
+ AMF_RESULT res;
+
+ res = context->pVtbl->AllocBuffer(context, AMF_MEMORY_HOST, sizeof(frame_ref), &frame_ref_storage_buffer);
+ if (res == AMF_OK) {
+ frame_ref = av_frame_clone(frame);
+ if (frame_ref) {
+ memcpy(frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), &frame_ref, sizeof(frame_ref));
+ } else {
+ frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+ frame_ref_storage_buffer = NULL;
+ }
+ }
+ return frame_ref_storage_buffer;
+}
+
+static void amf_release_buffer_with_frame_ref(AMFBuffer *frame_ref_storage_buffer)
+{
+ AVFrame *frame_ref;
+ memcpy(&frame_ref, frame_ref_storage_buffer->pVtbl->GetNative(frame_ref_storage_buffer), sizeof(frame_ref));
+ av_frame_free(&frame_ref);
+ frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
+}