Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemoryAlignment: Fixes #10810

Merged
merged 4 commits into from
Oct 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ void CActiveAESink::GenerateNoise()
nb_floats *= m_sampleOfSilence.pkt->config.channels;
size_t size = nb_floats*sizeof(float);

float *noise = (float*)_aligned_malloc(size, 16);
float *noise = (float*)_aligned_malloc(size, 32);
if (!noise)
throw std::bad_alloc();

Expand Down
15 changes: 8 additions & 7 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoPPFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include "DVDVideoPPFFmpeg.h"
#include "utils/log.h"
#include "cores/FFmpeg.h"
#ifdef TARGET_POSIX
#include "linux/XMemUtils.h"
#endif

extern "C" {
#include "libavutil/mem.h"
}

CDVDVideoPPFFmpeg::CDVDVideoPPFFmpeg():
m_sType("")
Expand Down Expand Up @@ -57,7 +58,7 @@ void CDVDVideoPPFFmpeg::Dispose()
{
if( m_FrameBuffer.data[i] )
{
_aligned_free(m_FrameBuffer.data[i]);
av_free(&(m_FrameBuffer.data[i]));
m_FrameBuffer.data[i] = NULL;
m_FrameBuffer.iLineSize[i] = 0;
}
Expand Down Expand Up @@ -185,9 +186,9 @@ bool CDVDVideoPPFFmpeg::CheckFrameBuffer(const DVDVideoPicture* pSource)
m_FrameBuffer.iWidth = pSource->iWidth;
m_FrameBuffer.iHeight = pSource->iHeight;

m_FrameBuffer.data[0] = (uint8_t*)_aligned_malloc(m_FrameBuffer.iLineSize[0] * m_FrameBuffer.iHeight , 16);
m_FrameBuffer.data[1] = (uint8_t*)_aligned_malloc(m_FrameBuffer.iLineSize[1] * m_FrameBuffer.iHeight/2, 16);
m_FrameBuffer.data[2] = (uint8_t*)_aligned_malloc(m_FrameBuffer.iLineSize[2] * m_FrameBuffer.iHeight/2, 16);
m_FrameBuffer.data[0] = (uint8_t*)av_malloc(m_FrameBuffer.iLineSize[0] * m_FrameBuffer.iHeight);
m_FrameBuffer.data[1] = (uint8_t*)av_malloc(m_FrameBuffer.iLineSize[1] * m_FrameBuffer.iHeight/2);
m_FrameBuffer.data[2] = (uint8_t*)av_malloc(m_FrameBuffer.iLineSize[2] * m_FrameBuffer.iHeight/2);

if( !m_FrameBuffer.data[0] || !m_FrameBuffer.data[1] || !m_FrameBuffer.data[2])
{
Expand Down
2 changes: 1 addition & 1 deletion xbmc/guilib/FFmpegImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ bool CFFmpegImage::DecodeFrame(AVFrame* frame, unsigned int width, unsigned int

bool needsCopy = false;
int pixelsSize = pitch * height;
bool aligned = (((uintptr_t)(const void *)(pixels)) % (16) == 0);
bool aligned = (((uintptr_t)(const void *)(pixels)) % (32) == 0);

This comment was marked as spam.

if (!aligned)
CLog::Log(LOGDEBUG, "Alignment of external buffer is not suitable for ffmpeg intrinsics - please fix your malloc");

Expand Down
2 changes: 1 addition & 1 deletion xbmc/guilib/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void CBaseTexture::Allocate(unsigned int width, unsigned int height, unsigned in
if (GetPitch() * GetRows() > 0)
{
size_t size = GetPitch() * GetRows();
m_pixels = (unsigned char*) _aligned_malloc(size, 16);
m_pixels = (unsigned char*) _aligned_malloc(size, 32);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


if (m_pixels == nullptr)
{
Expand Down
15 changes: 8 additions & 7 deletions xbmc/pictures/Picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

extern "C" {
#include "libswscale/swscale.h"
#include "libavutil/mem.h"
}

using namespace XFILE;
Expand Down Expand Up @@ -176,7 +177,7 @@ bool CPicture::ResizeTexture(const std::string &image, uint8_t *pixels, uint32_t
// create a buffer large enough for the resulting image
GetScale(width, height, dest_width, dest_height);

uint8_t *buffer = new uint8_t[dest_width * dest_height * sizeof(uint32_t)];
uint8_t *buffer = (uint8_t*) av_malloc(dest_width * dest_height * sizeof(uint32_t));
if (buffer == NULL)
{
result = NULL;
Expand All @@ -186,14 +187,14 @@ bool CPicture::ResizeTexture(const std::string &image, uint8_t *pixels, uint32_t

if (!ScaleImage(pixels, width, height, pitch, buffer, dest_width, dest_height, dest_width * sizeof(uint32_t), scalingAlgorithm))
{
delete[] buffer;
av_free(&buffer);
result = NULL;
result_size = 0;
return false;
}

bool success = GetThumbnailFromSurface(buffer, dest_width, dest_height, dest_width * sizeof(uint32_t), image, result, result_size);
delete[] buffer;
av_free(&buffer);

if (!success)
{
Expand Down Expand Up @@ -245,7 +246,7 @@ bool CPicture::CacheTexture(uint8_t *pixels, uint32_t width, uint32_t height, ui

// create a buffer large enough for the resulting image
GetScale(width, height, dest_width, dest_height);
uint32_t *buffer = new uint32_t[dest_width * dest_height];
uint32_t *buffer = (uint32_t*) av_malloc(dest_width * dest_height);
if (buffer)
{
if (ScaleImage(pixels, width, height, pitch,
Expand All @@ -257,7 +258,7 @@ bool CPicture::CacheTexture(uint8_t *pixels, uint32_t width, uint32_t height, ui
success = CreateThumbnailFromSurface((unsigned char*)buffer, dest_width, dest_height, dest_width * 4, dest);
}
}
delete[] buffer;
av_free(&buffer);
}
return success;
}
Expand Down Expand Up @@ -297,7 +298,7 @@ bool CPicture::CreateTiledThumb(const std::vector<std::string> &files, const std
GetScale(texture->GetWidth(), texture->GetHeight(), width, height);

// scale appropriately
uint32_t *scaled = new uint32_t[width * height];
uint32_t *scaled = (uint32_t*) av_malloc(width * height);
if (ScaleImage(texture->GetPixels(), texture->GetWidth(), texture->GetHeight(), texture->GetPitch(),
(uint8_t *)scaled, width, height, width * 4))
{
Expand All @@ -317,7 +318,7 @@ bool CPicture::CreateTiledThumb(const std::vector<std::string> &files, const std
}
}
}
delete[] scaled;
av_free(&scaled);
}
delete texture;
}
Expand Down