mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
style(corevideosource): Small style fixes
This commit is contained in:
parent
9cfd678c26
commit
ef641ce6d3
|
@ -17,11 +17,11 @@
|
|||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavutil/imgutils.h>
|
||||
}
|
||||
|
||||
#include "corevideosource.h"
|
||||
#include "videoframe.h"
|
||||
|
||||
|
@ -39,15 +39,13 @@ void CoreVideoSource::pushFrame(const vpx_image_t* vpxframe)
|
|||
QMutexLocker locker(&biglock);
|
||||
|
||||
std::shared_ptr<VideoFrame> vframe;
|
||||
AVFrame* avframe;
|
||||
uint8_t* buf;
|
||||
int width = vpxframe->d_w, height = vpxframe->d_h;
|
||||
int dstStride, srcStride, minStride;
|
||||
int width = vpxframe->d_w;
|
||||
int height = vpxframe->d_h;
|
||||
|
||||
if (subscribers <= 0)
|
||||
return;
|
||||
|
||||
avframe = av_frame_alloc();
|
||||
AVFrame* avframe = av_frame_alloc();
|
||||
if (!avframe)
|
||||
return;
|
||||
avframe->width = width;
|
||||
|
@ -55,29 +53,35 @@ void CoreVideoSource::pushFrame(const vpx_image_t* vpxframe)
|
|||
avframe->format = AV_PIX_FMT_YUV420P;
|
||||
|
||||
int imgBufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, width, height, 1);
|
||||
buf = (uint8_t*)av_malloc(imgBufferSize);
|
||||
uint8_t* buf = (uint8_t*)av_malloc(imgBufferSize);
|
||||
if (!buf)
|
||||
{
|
||||
av_frame_free(&avframe);
|
||||
return;
|
||||
}
|
||||
avframe->opaque = buf;
|
||||
|
||||
uint8_t** data = avframe->data;
|
||||
int* linesize = avframe->linesize;
|
||||
av_image_fill_arrays(data, linesize, buf, AV_PIX_FMT_YUV420P, width, height, 1);
|
||||
|
||||
dstStride=avframe->linesize[0], srcStride=vpxframe->stride[0], minStride=std::min(dstStride, srcStride);
|
||||
for (int i=0; i<height; i++)
|
||||
memcpy(avframe->data[0]+dstStride*i, vpxframe->planes[0]+srcStride*i, minStride);
|
||||
dstStride=avframe->linesize[1], srcStride=vpxframe->stride[1], minStride=std::min(dstStride, srcStride);
|
||||
for (int i=0; i<height/2; i++)
|
||||
memcpy(avframe->data[1]+dstStride*i, vpxframe->planes[1]+srcStride*i, minStride);
|
||||
dstStride=avframe->linesize[2], srcStride=vpxframe->stride[2], minStride=std::min(dstStride, srcStride);
|
||||
for (int i=0; i<height/2; i++)
|
||||
memcpy(avframe->data[2]+dstStride*i, vpxframe->planes[2]+srcStride*i, minStride);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int dstStride = avframe->linesize[i];
|
||||
int srcStride = vpxframe->stride[i];
|
||||
int minStride = std::min(dstStride, srcStride);
|
||||
int size = (i == 0) ? height : height / 2;
|
||||
|
||||
for (int j = 0; j < size; j++)
|
||||
{
|
||||
uint8_t *dst = avframe->data[i] + dstStride * j;
|
||||
uint8_t *src = vpxframe->planes[i] + srcStride * j;
|
||||
memcpy(dst, src, minStride);
|
||||
}
|
||||
}
|
||||
|
||||
vframe = std::make_shared<VideoFrame>(avframe);
|
||||
|
||||
av_free(buf);
|
||||
emit frameAvailable(vframe);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user