Bug 1077299 - allocate blob buffer to CreateMemoryFile(). r=roc

This commit is contained in:
Alfredo Yang 2014-10-14 01:00:00 +02:00
parent 8c6c28c754
commit c369ec4dd4

View File

@ -445,16 +445,18 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(uint8_t* aData, uint32_t aLeng
uint8_t* aData, uint8_t* aData,
uint32_t aLength, uint32_t aLength,
const nsAString& aMimeType) const nsAString& aMimeType)
: mPhotoDataLength(aLength)
{ {
mCallbacks.SwapElements(aCallbacks); mCallbacks.SwapElements(aCallbacks);
mPhoto.AppendElements(aData, aLength); mPhotoData = (uint8_t*) moz_malloc(aLength);
memcpy(mPhotoData, aData, mPhotoDataLength);
mMimeType = aMimeType; mMimeType = aMimeType;
} }
NS_IMETHOD Run() NS_IMETHOD Run()
{ {
nsRefPtr<dom::File> blob = nsRefPtr<dom::File> blob =
dom::File::CreateMemoryFile(nullptr, mPhoto.Elements(), mPhoto.Length(), mMimeType); dom::File::CreateMemoryFile(nullptr, mPhotoData, mPhotoDataLength, mMimeType);
uint32_t callbackCounts = mCallbacks.Length(); uint32_t callbackCounts = mCallbacks.Length();
for (uint8_t i = 0; i < callbackCounts; i++) { for (uint8_t i = 0; i < callbackCounts; i++) {
nsRefPtr<dom::File> tempBlob = blob; nsRefPtr<dom::File> tempBlob = blob;
@ -466,8 +468,9 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(uint8_t* aData, uint32_t aLeng
} }
nsTArray<nsRefPtr<PhotoCallback>> mCallbacks; nsTArray<nsRefPtr<PhotoCallback>> mCallbacks;
nsTArray<uint8_t> mPhoto; uint8_t* mPhotoData;
nsString mMimeType; nsString mMimeType;
uint32_t mPhotoDataLength;
}; };
// All elements in mPhotoCallbacks will be swapped in GenerateBlobRunnable // All elements in mPhotoCallbacks will be swapped in GenerateBlobRunnable