Miam-Player  0.8.0
A nice music player
VideoRenderer_p.h
Go to the documentation of this file.
1 /******************************************************************************
2  QtAV: Media play library based on Qt and FFmpeg
3  Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
4 
5 * This file is part of QtAV
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ******************************************************************************/
21 
22 #ifndef QAV_VIDEORENDERER_P_H
23 #define QAV_VIDEORENDERER_P_H
24 
26 #include <QtAV/VideoRenderer.h>
27 #include <QtCore/QMutex>
28 #include <QtCore/QRect>
29 #include <QtAV/VideoFrame.h>
30 #include <QtGui/QColor>
31 
32 /*TODO:
33  * Region of Interest(ROI)
34  * use matrix to compute out rect, mapped point etc
35  */
36 QT_BEGIN_NAMESPACE
37 class QObject;
38 class QWidget;
39 QT_END_NAMESPACE
40 namespace QtAV {
41 class Filter;
43 {
44 public:
47  , update_background(true)
48  , renderer_width(480)
49  , renderer_height(320)
50  , source_aspect_ratio(0)
51  , src_width(0)
52  , src_height(0)
53  , aspect_ratio_changed(true) //to set the initial parameters
54  , out_aspect_ratio_mode(VideoRenderer::VideoAspectRatio)
55  , out_aspect_ratio(0)
56  , quality(VideoRenderer::QualityBest)
57  , orientation(0)
58  , preferred_format(VideoFormat::Format_RGB32)
59  , force_preferred(false)
60  , brightness(0)
61  , contrast(0)
62  , hue(0)
63  , saturation(0)
64  , bg_color(0, 0, 0)
65  {
66  //conv.setInFormat(PIX_FMT_YUV420P);
67  //conv.setOutFormat(PIX_FMT_BGR32); //TODO: why not RGB32?
68  }
70  }
71 
72  // return true if video rect changed
73  bool computeOutParameters(qreal outAspectRatio) {
74  qreal rendererAspectRatio = qreal(renderer_width)/qreal(renderer_height);
75  const QRect out_rect0(out_rect);
76  if (out_aspect_ratio_mode == VideoRenderer::RendererAspectRatio) {
77  out_aspect_ratio = rendererAspectRatio;
78  out_rect = QRect(0, 0, renderer_width, renderer_height);
79  return out_rect0 != out_rect;
80  }
81  // dar: displayed aspect ratio in video renderer orientation
82  const qreal dar = (orientation % 180) ? 1.0/outAspectRatio : outAspectRatio;
83  //qDebug("out rect: %f %dx%d ==>", out_aspect_ratio, out_rect.width(), out_rect.height());
84  if (rendererAspectRatio >= dar) { //equals to original video aspect ratio here, also equals to out ratio
85  //renderer is too wide, use renderer's height, horizonal align center
86  const int h = renderer_height;
87  const int w = qRound(dar * qreal(h));
88  out_rect = QRect((renderer_width - w)/2, 0, w, h);
89  } else if (rendererAspectRatio < dar) {
90  //renderer is too high, use renderer's width
91  const int w = renderer_width;
92  const int h = qRound(qreal(w)/dar);
93  out_rect = QRect(0, (renderer_height - h)/2, w, h);
94  }
95  out_aspect_ratio = outAspectRatio;
96  //qDebug("%f %dx%d <<<<<<<<", out_aspect_ratio, out_rect.width(), out_rect.height());
97  return out_rect0 != out_rect;
98  }
99  virtual void setupQuality() {}
100 
101  //draw background when necessary, for example, renderer is resized. Then set to false
103  // width, height: the renderer's size. i.e. size of video frame with the value with borders
104  //TODO: rename to renderer_width/height
105  int renderer_width, renderer_height;
107  int src_width, src_height; //TODO: in_xxx
108  QMutex img_mutex;
109  //for both source, out aspect ratio. because source change may result in out change if mode is VideoAspectRatio
114  //out_rect: the displayed video frame out_rect in the renderer
115  QRect out_rect; //TODO: out_out_rect
116  QRectF roi;
118 
122 
123  qreal brightness, contrast, hue, saturation;
124  QColor bg_color;
125 };
126 
127 } //namespace QtAV
128 #endif // QAV_VIDEORENDERER_P_H
int orientation
Definition: VideoRenderer_p.h:117
VideoFormat::PixelFormat preferred_format
Definition: VideoRenderer_p.h:120
qreal source_aspect_ratio
Definition: VideoRenderer_p.h:106
bool computeOutParameters(qreal outAspectRatio)
Definition: VideoRenderer_p.h:73
QRectF roi
Definition: VideoRenderer_p.h:116
The VideoFormat class Describes the layout of video data.
Definition: VideoFormat.h:39
virtual void setupQuality()
Definition: VideoRenderer_p.h:99
bool update_background
Definition: VideoRenderer_p.h:102
VideoRendererPrivate()
Definition: VideoRenderer_p.h:45
VideoRenderer::OutAspectRatioMode out_aspect_ratio_mode
Definition: VideoRenderer_p.h:111
#define Q_AV_PRIVATE_EXPORT
Definition: QtAV_Global.h:43
qreal saturation
Definition: VideoRenderer_p.h:123
int src_width
Definition: VideoRenderer_p.h:107
Definition: AVOutput_p.h:38
QColor bg_color
Definition: VideoRenderer_p.h:124
OutAspectRatioMode
Definition: VideoRenderer.h:57
PixelFormat
The PixelFormat enum 32 bit rgba format enum name indicates it&#39;s channel layout.
Definition: VideoFormat.h:51
bool force_preferred
Definition: VideoRenderer_p.h:121
Definition: VideoFrame.h:32
VideoRenderer::Quality quality
Definition: VideoRenderer_p.h:113
Definition: VideoRenderer.h:58
Definition: VideoRenderer_p.h:42
QMutex img_mutex
Definition: VideoRenderer_p.h:108
virtual ~VideoRendererPrivate()
Definition: VideoRenderer_p.h:69
bool aspect_ratio_changed
Definition: VideoRenderer_p.h:110
Quality
Definition: VideoRenderer.h:63
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
QRect out_rect
Definition: VideoRenderer_p.h:115
VideoFrame video_frame
Definition: VideoRenderer_p.h:119
int renderer_width
Definition: VideoRenderer_p.h:105
Definition: VideoRenderer.h:51
qreal out_aspect_ratio
Definition: VideoRenderer_p.h:112