2014-10-24 04:31:39 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +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.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
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
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-10-24 04:31:39 +08:00
|
|
|
|
2015-06-06 09:40:08 +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
|
2015-05-16 10:00:41 +08:00
|
|
|
/// 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:
|
|
|
|
VideoFrame(AVFrame* frame);
|
|
|
|
VideoFrame(AVFrame* frame, std::function<void()> freelistCallback);
|
|
|
|
VideoFrame(AVFrame* frame, int w, int h, int fmt, std::function<void()> freelistCallback);
|
|
|
|
~VideoFrame();
|
|
|
|
|
2015-05-16 19:16:41 +08:00
|
|
|
/// Return the size of the original frame
|
|
|
|
QSize getSize();
|
|
|
|
|
2015-05-16 10:00:41 +08:00
|
|
|
/// 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
|
2015-05-16 19:16:41 +08:00
|
|
|
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:
|
2015-05-16 19:16:41 +08:00
|
|
|
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
|