1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(video): rename ToxAVFrame to ToxYUVFrame and add documentation

This commit is contained in:
initramfs 2016-07-23 06:28:42 +08:00
parent 6d18c109e8
commit f85a299e75
No known key found for this signature in database
GPG Key ID: 78B8BDF87E9EF0AF
3 changed files with 17 additions and 8 deletions

View File

@ -361,7 +361,7 @@ void CoreAV::sendCallVideo(uint32_t callId, std::shared_ptr<VideoFrame> vframe)
} }
// This frame shares vframe's buffers, we don't call vpx_img_free but just delete it // This frame shares vframe's buffers, we don't call vpx_img_free but just delete it
ToxAVFrame frame = vframe->toToxAVFrame(); ToxYUVFrame frame = vframe->toToxAVFrame();
if(frame.width == 0 || frame.height == 0) if(frame.width == 0 || frame.height == 0)
{ {

View File

@ -185,7 +185,7 @@ QImage VideoFrame::toQImage(QSize frameSize)
return toGenericObject(frameSize, AV_PIX_FMT_RGB24, false, converter, QImage {}); return toGenericObject(frameSize, AV_PIX_FMT_RGB24, false, converter, QImage {});
} }
ToxAVFrame VideoFrame::toToxAVFrame(QSize frameSize) ToxYUVFrame VideoFrame::toToxAVFrame(QSize frameSize)
{ {
if(frameSize.width() == 0 && frameSize.height() == 0) if(frameSize.width() == 0 && frameSize.height() == 0)
{ {
@ -193,9 +193,9 @@ ToxAVFrame VideoFrame::toToxAVFrame(QSize frameSize)
} }
// Converter function (constructs ToxAVFrame out of AVFrame*) // Converter function (constructs ToxAVFrame out of AVFrame*)
const std::function<ToxAVFrame(AVFrame* const)> converter = [&](AVFrame* const frame) const std::function<ToxYUVFrame(AVFrame* const)> converter = [&](AVFrame* const frame)
{ {
ToxAVFrame ret ToxYUVFrame ret
{ {
static_cast<std::uint16_t>(frameSize.width()), static_cast<std::uint16_t>(frameSize.width()),
static_cast<std::uint16_t>(frameSize.height()), static_cast<std::uint16_t>(frameSize.height()),
@ -205,7 +205,7 @@ ToxAVFrame VideoFrame::toToxAVFrame(QSize frameSize)
return ret; return ret;
}; };
return toGenericObject(frameSize, AV_PIX_FMT_YUV420P, true, converter, ToxAVFrame {0, 0, nullptr, nullptr, nullptr}); return toGenericObject(frameSize, AV_PIX_FMT_YUV420P, true, converter, ToxYUVFrame {0, 0, nullptr, nullptr, nullptr});
} }
AVFrame* VideoFrame::retrieveAVFrame(const QSize& dimensions, const int pixelFormat, const bool requireAligned) AVFrame* VideoFrame::retrieveAVFrame(const QSize& dimensions, const int pixelFormat, const bool requireAligned)

View File

@ -37,9 +37,18 @@ extern "C"{
#include <unordered_map> #include <unordered_map>
/** /**
* @brief A simple structure to represent a ToxAV frame. * @brief A simple structure to represent a ToxYUV video frame (corresponds to a frame encoded
* under format: AV_PIX_FMT_YUV420P [FFmpeg] or VPX_IMG_FMT_I420 [WebM]).
*
* This structure exists for convenience and code clarity when ferrying YUV420 frames from one
* source to another. The buffers pointed to by the struct should not be owned by the struct nor
* should they be freed from the struct, instead this struct functions only as a simple alias to a
* more complicated frame container like AVFrame.
*
* The creation of this structure was done to replace existing code which mis-used vpx_image
* structs when passing frame data to toxcore.
*/ */
struct ToxAVFrame struct ToxYUVFrame
{ {
public: public:
const std::uint16_t width; const std::uint16_t width;
@ -217,7 +226,7 @@ public:
* @return a ToxAVFrame structure that represents this VideoFrame, sharing it's buffers or an * @return a ToxAVFrame structure that represents this VideoFrame, sharing it's buffers or an
* empty structure if this VideoFrame is no longer valid. * empty structure if this VideoFrame is no longer valid.
*/ */
ToxAVFrame toToxAVFrame(QSize frameSize = {0, 0}); ToxYUVFrame toToxAVFrame(QSize frameSize = {0, 0});
/** /**
* @brief Data alignment parameter used to populate AVFrame buffers. * @brief Data alignment parameter used to populate AVFrame buffers.