File indexing completed on 2025-01-19 03:57:06

0001 /*********************************************************
0002  * Copyright (C) 2020, Val Doroshchuk <valbok@gmail.com> *
0003  *                                                       *
0004  * This file is part of QtAVPlayer.                      *
0005  * Free Qt Media Player based on FFmpeg.                 *
0006  *********************************************************/
0007 
0008 #include "qavvideobuffer_cpu_p.h"
0009 
0010 extern "C" {
0011 #include <libavutil/imgutils.h>
0012 #include <libavutil/frame.h>
0013 }
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 QAVVideoFrame::MapData QAVVideoBuffer_CPU::map()
0018 {
0019     QAVVideoFrame::MapData mapData;
0020     auto frame = m_frame.frame();
0021     if (frame->format == AV_PIX_FMT_NONE)
0022         return mapData;
0023 
0024     mapData.size = av_image_get_buffer_size(AVPixelFormat(frame->format), frame->width, frame->height, 1);
0025     mapData.format = AVPixelFormat(frame->format);
0026 
0027     for (int i = 0; i < 4; ++i) {
0028         if (!frame->linesize[i])
0029             break;
0030 
0031         mapData.bytesPerLine[i] = frame->linesize[i];
0032         mapData.data[i] = static_cast<uchar *>(frame->data[i]);
0033     }
0034 
0035     return mapData;
0036 }
0037 
0038 QT_END_NAMESPACE