简体   繁体   English

YUV缓冲区的内存分配以转换为RGB

[英]Memory allocation for YUV buffer to convert into RGB

I'm facing issue on few android devices while copying the data from DecodeFrame2() 从DecodeFrame2()复制数据时,我在几个Android设备上都遇到问题

This is my code: 这是我的代码:

uint8_t* m_yuvData[3];
SBufferInfo yuvDataInfo;
memset(&yuvDataInfo, 0, sizeof(SBufferInfo));
m_yuvData[0] = NULL;
m_yuvData[1] = NULL;
m_yuvData[2] = NULL;
DECODING_STATE decodingState = m_decoder->DecodeFrame2(bufferData, bufferDataSize, m_yuvData, &yuvDataInfo);

if(yuvDataInfo.iBufferStatus == 1)
{
        int yStride = yuvDataInfo->UsrData.sSystemBuffer.iStride[0];
        int uvStride = yuvDataInfo->UsrData.sSystemBuffer.iStride[1];
        uint32_t width = yuvDataInfo->UsrData.sSystemBuffer.iWidth;
       uint32_t height = yuvDataInfo->UsrData.sSystemBuffer.iHeight;
       size_t yDataSize = (width * height) + (height * yStride);
       size_t uvDataSize = (((width * height) / 4) + (height * uvStride));
        size_t requiredSize = yDataSize + (2 * uvDataSize);
        uint8_t* yuvBufferedData = (uint8_t*)malloc(requiredSize);
        // when i move yuvData[0] to another location i am getting crash.
         memcpy(yuvBufferedData, yuvData[0], yDataSize);
         memcpy(yuvBufferedData + yDataSize, yuvData[1], uvDataSize);
        memcpy(yuvBufferedData + yDataSize + uvDataSize, yuvData[2], uvDataSize);
  }

The above code snippet is working on high end android devices. 上面的代码段适用于高端android设备。 but on few android devices after processing first frame, second frame onwards i am getting crash in first memcpy() statement. 但是在处理了第一帧,第二帧之后的少数Android设备上,我在第一个memcpy()语句中崩溃了。

What is wrong in this code? 该代码有什么问题? and how to calculate the buffer size from the output of DecodeFrame2(). 以及如何根据DecodeFrame2()的输出计算缓冲区大小。 If i process alternative frames(instead of 30, just 15 frames alternative ones), it is copying fine. 如果我处理替代帧(而不是30帧,而仅处理15帧替代帧),则复制正常。

Please help me to fix this? 请帮我解决这个问题?

基于上述公式,yDataSize和uvDataSize非常大,此问题已通过修改大小来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM