bool GMPVideoDecoderChild::Alloc(size_t aSize, Shmem::SharedMemory::SharedMemoryType aType, Shmem* aMem) { MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current()); bool rv; #ifndef SHMEM_ALLOC_IN_CHILD ++mNeedShmemIntrCount; rv = CallNeedShmem(aSize, aMem); --mNeedShmemIntrCount; if (mPendingDecodeComplete && mNeedShmemIntrCount == 0) { mPendingDecodeComplete = false; mPlugin->GMPMessageLoop()->PostTask( NewRunnableMethod(this, &GMPVideoDecoderChild::RecvDecodingComplete)); } #else #ifdef GMP_SAFE_SHMEM rv = AllocShmem(aSize, aType, aMem); #else rv = AllocUnsafeShmem(aSize, aType, aMem); #endif #endif return rv; }
void TestSysVShmemParent::Main() { Shmem mem; Shmem unsafe; size_t size = 12345; if (!AllocShmem(size, SharedMemory::TYPE_SYSV, &mem)) fail("can't alloc shmem"); if (!AllocUnsafeShmem(size, SharedMemory::TYPE_SYSV, &unsafe)) fail("can't alloc shmem"); if (0 > mem.GetSysVID()) fail("invalid shmem ID"); if (0 > unsafe.GetSysVID()) fail("invalid shmem ID"); if (mem.Size<char>() != size) fail("shmem is wrong size: expected %lu, got %lu", size, mem.Size<char>()); if (unsafe.Size<char>() != size) fail("shmem is wrong size: expected %lu, got %lu", size, unsafe.Size<char>()); char* ptr = mem.get<char>(); memcpy(ptr, "Hello!", sizeof("Hello!")); char* unsafeptr = unsafe.get<char>(); memcpy(unsafeptr, "Hello!", sizeof("Hello!")); Shmem unsafecopy = unsafe; if (!SendGive(mem, unsafe, size)) fail("can't send Give()"); // uncomment the following line for a (nondeterministic) surprise! //char c1 = *ptr; (void)c1; // uncomment the following line for a deterministic surprise! //char c2 = *mem.get<char>(); (void)c2; // unsafe shmem gets rid of those checks char uc1 = *unsafeptr; (void)uc1; char uc2 = *unsafecopy.get<char>(); (void)uc2; }
SharedImage* ImageContainerChild::AllocateSharedImageFor(Image* image) { NS_ABORT_IF_FALSE(InImageBridgeChildThread(), "Should be in ImageBridgeChild thread."); if (!image) { return nullptr; } if (image->GetFormat() == PLANAR_YCBCR ) { PlanarYCbCrImage *planarYCbCrImage = static_cast<PlanarYCbCrImage*>(image); const PlanarYCbCrImage::Data *data = planarYCbCrImage->GetData(); NS_ASSERTION(data, "Must be able to retrieve yuv data from image!"); if (!data) { return nullptr; } SharedMemory::SharedMemoryType shmType = OptimalShmemType(); size_t size = ShmemYCbCrImage::ComputeMinBufferSize(data->mYSize, data->mCbCrSize); Shmem shmem; if (!AllocUnsafeShmem(size, shmType, &shmem)) { return nullptr; } ShmemYCbCrImage::InitializeBufferInfo(shmem.get<uint8_t>(), data->mYSize, data->mCbCrSize); ShmemYCbCrImage shmemImage(shmem); if (!shmemImage.IsValid()) { NS_WARNING("Failed to properly allocate image data!"); DeallocShmem(shmem); return nullptr; } ++mActiveImageCount; return new SharedImage(YCbCrImage(shmem, 0, data->GetPictureRect())); } else { NS_RUNTIMEABORT("TODO: Only YCbCrImage is supported here right now."); } return nullptr; }
SharedImage* ImageContainerChild::CreateSharedImageFromData(Image* image) { NS_ABORT_IF_FALSE(InImageBridgeChildThread(), "Should be in ImageBridgeChild thread."); if (!image) { return nullptr; } if (image->GetFormat() == PLANAR_YCBCR ) { PlanarYCbCrImage *planarYCbCrImage = static_cast<PlanarYCbCrImage*>(image); const PlanarYCbCrImage::Data *data = planarYCbCrImage->GetData(); NS_ASSERTION(data, "Must be able to retrieve yuv data from image!"); if (!data) { return nullptr; } SharedMemory::SharedMemoryType shmType = OptimalShmemType(); size_t size = ShmemYCbCrImage::ComputeMinBufferSize(data->mYSize, data->mCbCrSize); Shmem shmem; if (!AllocUnsafeShmem(size, shmType, &shmem)) { return nullptr; } ShmemYCbCrImage::InitializeBufferInfo(shmem.get<uint8_t>(), data->mYSize, data->mCbCrSize); ShmemYCbCrImage shmemImage(shmem); if (!shmemImage.IsValid() || shmem.Size<uint8_t>() < size) { DeallocShmem(shmem); return nullptr; } for (int i = 0; i < data->mYSize.height; i++) { memcpy(shmemImage.GetYData() + i * shmemImage.GetYStride(), data->mYChannel + i * data->mYStride, data->mYSize.width); } for (int i = 0; i < data->mCbCrSize.height; i++) { memcpy(shmemImage.GetCbData() + i * shmemImage.GetCbCrStride(), data->mCbChannel + i * data->mCbCrStride, data->mCbCrSize.width); memcpy(shmemImage.GetCrData() + i * shmemImage.GetCbCrStride(), data->mCrChannel + i * data->mCbCrStride, data->mCbCrSize.width); } ++mActiveImageCount; SharedImage* result = new SharedImage(YCbCrImage(shmem, 0, data->GetPictureRect())); return result; #ifdef MOZ_WIDGET_GONK } else if (image->GetFormat() == GONK_IO_SURFACE) { GonkIOSurfaceImage* gonkImage = static_cast<GonkIOSurfaceImage*>(image); SharedImage* result = new SharedImage(gonkImage->GetSurfaceDescriptor()); return result; } else if (image->GetFormat() == GRALLOC_PLANAR_YCBCR) { GrallocPlanarYCbCrImage* GrallocImage = static_cast<GrallocPlanarYCbCrImage*>(image); SharedImage* result = new SharedImage(GrallocImage->GetSurfaceDescriptor()); return result; #endif } else { NS_RUNTIMEABORT("TODO: Only YCbCrImage is supported here right now."); } return nullptr; }