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/>.
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <libavcodec/avcodec.h>
|
#include <libavcodec/avcodec.h>
|
||||||
#include <libavutil/imgutils.h>
|
#include <libavutil/imgutils.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "corevideosource.h"
|
#include "corevideosource.h"
|
||||||
#include "videoframe.h"
|
#include "videoframe.h"
|
||||||
|
|
||||||
|
@ -39,15 +39,13 @@ void CoreVideoSource::pushFrame(const vpx_image_t* vpxframe)
|
||||||
QMutexLocker locker(&biglock);
|
QMutexLocker locker(&biglock);
|
||||||
|
|
||||||
std::shared_ptr<VideoFrame> vframe;
|
std::shared_ptr<VideoFrame> vframe;
|
||||||
AVFrame* avframe;
|
int width = vpxframe->d_w;
|
||||||
uint8_t* buf;
|
int height = vpxframe->d_h;
|
||||||
int width = vpxframe->d_w, height = vpxframe->d_h;
|
|
||||||
int dstStride, srcStride, minStride;
|
|
||||||
|
|
||||||
if (subscribers <= 0)
|
if (subscribers <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
avframe = av_frame_alloc();
|
AVFrame* avframe = av_frame_alloc();
|
||||||
if (!avframe)
|
if (!avframe)
|
||||||
return;
|
return;
|
||||||
avframe->width = width;
|
avframe->width = width;
|
||||||
|
@ -55,29 +53,35 @@ void CoreVideoSource::pushFrame(const vpx_image_t* vpxframe)
|
||||||
avframe->format = AV_PIX_FMT_YUV420P;
|
avframe->format = AV_PIX_FMT_YUV420P;
|
||||||
|
|
||||||
int imgBufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, width, height, 1);
|
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)
|
if (!buf)
|
||||||
{
|
{
|
||||||
av_frame_free(&avframe);
|
av_frame_free(&avframe);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
avframe->opaque = buf;
|
|
||||||
|
|
||||||
uint8_t** data = avframe->data;
|
uint8_t** data = avframe->data;
|
||||||
int* linesize = avframe->linesize;
|
int* linesize = avframe->linesize;
|
||||||
av_image_fill_arrays(data, linesize, buf, AV_PIX_FMT_YUV420P, width, height, 1);
|
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 < 3; i++)
|
||||||
for (int i=0; i<height; i++)
|
{
|
||||||
memcpy(avframe->data[0]+dstStride*i, vpxframe->planes[0]+srcStride*i, minStride);
|
int dstStride = avframe->linesize[i];
|
||||||
dstStride=avframe->linesize[1], srcStride=vpxframe->stride[1], minStride=std::min(dstStride, srcStride);
|
int srcStride = vpxframe->stride[i];
|
||||||
for (int i=0; i<height/2; i++)
|
int minStride = std::min(dstStride, srcStride);
|
||||||
memcpy(avframe->data[1]+dstStride*i, vpxframe->planes[1]+srcStride*i, minStride);
|
int size = (i == 0) ? height : height / 2;
|
||||||
dstStride=avframe->linesize[2], srcStride=vpxframe->stride[2], minStride=std::min(dstStride, srcStride);
|
|
||||||
for (int i=0; i<height/2; i++)
|
for (int j = 0; j < size; j++)
|
||||||
memcpy(avframe->data[2]+dstStride*i, vpxframe->planes[2]+srcStride*i, minStride);
|
{
|
||||||
|
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);
|
vframe = std::make_shared<VideoFrame>(avframe);
|
||||||
|
|
||||||
|
av_free(buf);
|
||||||
emit frameAvailable(vframe);
|
emit frameAvailable(vframe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user