forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQPainterRenderer.cpp
79 lines (67 loc) · 3.23 KB
/
QPainterRenderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include <QtAV/QPainterRenderer.h>
#include <QtAV/private/QPainterRenderer_p.h>
#include <QtAV/FilterContext.h>
#include <QtAV/OSDFilter.h>
namespace QtAV {
QPainterRenderer::QPainterRenderer()
:VideoRenderer(*new QPainterRendererPrivate())
{
DPTR_D(QPainterRenderer);
d.filter_context = FilterContext::create(FilterContext::QtPainter);
setOSDFilter(new OSDFilterQPainter());
}
QPainterRenderer::QPainterRenderer(QPainterRendererPrivate &d)
:VideoRenderer(d)
{
d.filter_context = FilterContext::create(FilterContext::QtPainter);
setOSDFilter(new OSDFilterQPainter());
}
bool QPainterRenderer::isSupported(VideoFormat::PixelFormat pixfmt) const
{
return VideoFormat::isRGB(pixfmt);
}
int QPainterRenderer::filterContextType() const
{
return FilterContext::QtPainter;
}
bool QPainterRenderer::prepareFrame(const VideoFrame &frame)
{
DPTR_D(QPainterRenderer);
/*
* QImage constructed from memory do not deep copy the data, data should be available throughout
* image's lifetime and not be modified. painting image happens in main thread, we must ensure the
* image data is not changed if not use the original frame size, so we need the lock.
* In addition, the data passed by ref, so even if we lock, the original data may changed in decoder
* (ImageConverter), so we need a copy of this data(not deep copy) to ensure the image's data not changes before it
* is painted.
* But if we use the fixed original frame size, the data address and size always the same, so we can
* avoid the lock and use the ref data directly and safely
*/
//if (!d.scale_in_renderer) {
/*if lock is required, do not use locker in if() scope, it will unlock outside the scope*/
QMutexLocker locker(&d.img_mutex);
Q_UNUSED(locker);
//If use d.data.data() it will eat more cpu, deep copy?
d.video_frame = frame;
// DO NOT use frameData().data() because it's temp ptr while QImage does not deep copy the data
d.image = QImage((uchar*)frame.bits(), frame.width(), frame.height(), frame.imageFormat());
//Format_RGB32 is fast. see document
return true;
}
} //namespace QtAV