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

77 lines
2.6 KiB
C
Raw Normal View History

2014-10-24 04:31:39 +08:00
/*
Copyright © 2014-2015 by The qTox Project
2014-10-24 04:31:39 +08:00
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
2014-10-24 04:31:39 +08:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
2014-10-24 04:31:39 +08:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2014-10-24 04:31:39 +08:00
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
2014-10-24 04:31:39 +08:00
*/
#ifndef VIDEOFRAME_H
#define VIDEOFRAME_H
2015-05-14 10:46:28 +08:00
#include <QMutex>
#include <QImage>
#include <functional>
2014-10-24 04:31:39 +08:00
2015-05-14 10:46:28 +08:00
struct AVFrame;
struct AVCodecContext;
struct vpx_image;
2014-10-24 04:31:39 +08:00
2015-05-14 10:46:28 +08:00
/// VideoFrame takes ownership of an AVFrame* and allows fast conversions to other formats
/// Ownership of all video frame buffers is kept by the VideoFrame, even after conversion
/// All references to the frame data become invalid when the VideoFrame is deleted
/// We try to avoid pixel format conversions as much as possible, at the cost of some memory
/// All methods are thread-safe. If provided freelistCallback will be called by the destructor,
/// unless releaseFrame was called in between.
2015-05-14 10:46:28 +08:00
class VideoFrame
2014-10-24 04:31:39 +08:00
{
2015-05-14 10:46:28 +08:00
public:
explicit VideoFrame(AVFrame* frame);
2015-05-14 10:46:28 +08:00
VideoFrame(AVFrame* frame, std::function<void()> freelistCallback);
VideoFrame(AVFrame* frame, int w, int h, int fmt, std::function<void()> freelistCallback);
~VideoFrame();
/// Return the size of the original frame
QSize getSize();
/// Frees all internal buffers and frame data, removes the freelistCallback
2015-05-14 10:46:28 +08:00
/// This makes all converted objects that shares our internal buffers invalid
void releaseFrame();
/// Converts the VideoFrame to a QImage that shares our internal video buffer
QImage toQImage(QSize size = QSize());
2015-05-14 10:46:28 +08:00
/// Converts the VideoFrame to a vpx_image_t that shares our internal video buffer
/// Free it with operator delete, NOT vpx_img_free
vpx_image* toVpxImage();
2014-10-24 04:31:39 +08:00
2015-05-14 10:46:28 +08:00
protected:
bool convertToRGB24(QSize size = QSize());
2015-05-14 10:46:28 +08:00
bool convertToYUV420();
void releaseFrameLockless();
private:
// Disable copy. Use a shared_ptr if you need copies.
VideoFrame(const VideoFrame& other)=delete;
VideoFrame& operator=(const VideoFrame& other)=delete;
private:
std::function<void()> freelistCallback;
QMutex biglock;
AVFrame* frameOther, *frameYUV420, *frameRGB24;
int width, height;
int pixFmt;
};
2014-10-24 04:31:39 +08:00
#endif // VIDEOFRAME_H