GstFlowReturn GStreamerReader::AllocateVideoBufferFull(GstPad* aPad, guint64 aOffset, guint aSize, GstCaps* aCaps, GstBuffer** aBuf, nsRefPtr<PlanarYCbCrImage>& aImage) { /* allocate an image using the container */ ImageContainer* container = mDecoder->GetImageContainer(); if (container == nullptr) { return GST_FLOW_ERROR; } nsRefPtr<PlanarYCbCrImage> image = container->CreateImage(ImageFormat::PLANAR_YCBCR).downcast<PlanarYCbCrImage>(); /* prepare a GstBuffer pointing to the underlying PlanarYCbCrImage buffer */ GstBuffer* buf = GST_BUFFER(gst_moz_video_buffer_new()); GST_BUFFER_SIZE(buf) = aSize; /* allocate the actual YUV buffer */ GST_BUFFER_DATA(buf) = image->AllocateAndGetNewBuffer(aSize); aImage = image; /* create a GstMozVideoBufferData to hold the image */ GstMozVideoBufferData* bufferdata = new GstMozVideoBufferData(image); /* Attach bufferdata to our GstMozVideoBuffer, it will take care to free it */ gst_moz_video_buffer_set_data(GST_MOZ_VIDEO_BUFFER(buf), bufferdata); *aBuf = buf; return GST_FLOW_OK; }
void moz_gfx_memory_reset(MozGfxMemory *mem) { if (mem->image) mem->image->Release(); ImageContainer* container = ((MozGfxMemoryAllocator*) mem->memory.allocator)->reader->GetImageContainer(); mem->image = reinterpret_cast<PlanarYCbCrImage*>(container->CreateImage(ImageFormat::PLANAR_YCBCR).take()); mem->data = mem->image->AllocateAndGetNewBuffer(mem->memory.size); }
GstFlowReturn GStreamerReader::AllocateVideoBufferFull(GstPad* aPad, guint64 aOffset, guint aSize, GstCaps* aCaps, GstBuffer** aBuf, nsRefPtr<PlanarYCbCrImage>& aImage) { /* allocate an image using the container */ ImageContainer* container = mDecoder->GetImageContainer(); ImageFormat format = PLANAR_YCBCR; PlanarYCbCrImage* img = reinterpret_cast<PlanarYCbCrImage*>(container->CreateImage(&format, 1).get()); nsRefPtr<PlanarYCbCrImage> image = dont_AddRef(img); /* prepare a GstBuffer pointing to the underlying PlanarYCbCrImage buffer */ GstBuffer* buf = gst_buffer_new(); GST_BUFFER_SIZE(buf) = aSize; /* allocate the actual YUV buffer */ GST_BUFFER_DATA(buf) = image->AllocateAndGetNewBuffer(aSize); aImage = image; #if GST_VERSION_MICRO >= 36 /* create a GBoxed handle to hold the image */ BufferData* data = new BufferData(image); /* store it in a GValue so we can put it in a GstStructure */ GValue value = {0,}; g_value_init(&value, buffer_data_get_type()); g_value_take_boxed(&value, data); /* store the value in the structure */ GstStructure* structure = gst_structure_new("moz-reader-data", nullptr); gst_structure_take_value(structure, "image", &value); /* and attach the structure to the buffer */ gst_buffer_set_qdata(buf, g_quark_from_string("moz-reader-data"), structure); #endif *aBuf = buf; return GST_FLOW_OK; }