SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
datvideorender.h
Go to the documentation of this file.
1 // Copyright (C) 2018 F4HKW //
3 // for F4EXB / SDRAngel //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef DATVIDEORENDER_H
20 #define DATVIDEORENDER_H
21 
22 #include <QEvent>
23 #include <QIODevice>
24 #include <QThread>
25 #include <QWidget>
26 
27 #include "datvideostream.h"
28 #include "gui/tvscreen.h"
29 
30 extern "C"
31 {
32 #include "libavcodec/avcodec.h"
33 #include "libavformat/avformat.h"
34 
35 #include <libavutil/channel_layout.h>
36 #include <libavutil/common.h>
37 #include <libavutil/imgutils.h>
38 #include <libavutil/mathematics.h>
39 #include <libavutil/opt.h>
40 #include <libavutil/samplefmt.h>
41 
42 #include "libswscale/swscale.h"
43 }
44 
45 class AudioFifo;
46 
48 {
49  int PID;
50  int CodecID;
51 
52  bool OK_Data;
56 
57  QString Program;
58  QString Stream;
59 
60  int Width;
61  int Height;
62  int BitRate;
63  int Channels;
64 
66 
68  {
69  PID = -1;
70  CodecID = -1;
71  Program = "";
72  Stream = "";
73  Width = -1;
74  Height = -1;
75  BitRate = -1;
76  Channels = -1;
77  CodecDescription = "";
78  OK_Data = false;
79  OK_Decoding = false;
80  OK_TransportStream = false;
81  OK_VideoStream = false;
82  }
83 };
84 
85 class DATVideoRender : public TVScreen
86 {
87  Q_OBJECT
88 
89  public:
90  explicit DATVideoRender(QWidget *parent);
91  ~DATVideoRender();
92 
93  void SetFullScreen(bool blnFullScreen);
94 
95  bool OpenStream(DATVideostream *objDevice);
96  bool RenderStream();
97  bool CloseStream(QIODevice *objDevice);
98 
99  void setAudioFIFO(AudioFifo *fifo) { m_audioFifo = fifo; }
100  int getVideoStreamIndex() const { return m_videoStreamIndex; }
101  int getAudioStreamIndex() const { return m_audioStreamIndex; }
102 
103  void setAudioMute(bool audioMute) { m_audioMute = audioMute; }
104  void setVideoMute(bool videoMute) { m_videoMute = videoMute; }
105  void setAudioVolume(int audioVolume);
106 
107  bool getAudioDecodeOK() const { return m_audioDecodeOK; }
108  bool getVideoDecodeOK() const { return m_videoDecodeOK; }
109 
110  struct DataTSMetaData2 MetaData;
111 
112  private:
113  QWidget *m_parentWidget;
114  Qt::WindowFlags m_originalWindowFlags;
116 
117  bool m_running;
119 
121  bool m_isOpen;
122 
123  SwsContext *m_swsCtx;
124  AVFormatContext *m_formatCtx;
125  AVCodecContext *m_videoDecoderCtx;
126  AVCodecContext *m_audioDecoderCtx;
127  AVFrame *m_frame;
129  struct SwrContext* m_audioSWR;
131  static const int m_audioFifoBufferSize = 16000;
132  int16_t m_audioFifoBuffer[m_audioFifoBufferSize*2]; // 2 channels
138 
139  uint8_t *m_pbytDecodedData[4];
140  int m_pintDecodedLineSize[4];
141 
145 
148 
151 
152  bool InitializeFFMPEG();
153  bool PreprocessStream();
154  void ResetMetaData();
155 
156  int new_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt);
157  void setResampler();
158 
159  protected:
160  virtual bool eventFilter(QObject *obj, QEvent *event);
161 
162  signals:
163  void onMetaDataChanged(DataTSMetaData2 *metaData);
164 };
165 
166 //To run Video Rendering with a dedicated thread
167 class DATVideoRenderThread : public QThread
168 {
169  public:
171  {
172  m_renderer = nullptr;
173  m_stream = nullptr;
174  m_renderingVideo = false;
175  }
176 
178  {
179  m_renderer = renderer;
180  m_stream = stream;
181  m_renderingVideo = false;
182  }
183 
185  {
186  m_renderer = renderer;
187  m_stream = stream;
188  m_renderingVideo = false;
189  }
190 
191  void run()
192  {
193  if (m_renderingVideo)
194  {
195  return;
196  }
197 
198  if ((m_renderer == nullptr) || (m_stream == nullptr))
199  {
200  return;
201  }
202 
203  m_renderingVideo = m_renderer->OpenStream(m_stream);
204 
205  if (!m_renderingVideo)
206  {
207  return;
208  }
209 
210  while ((m_renderer->RenderStream()) && (m_renderingVideo == true))
211  {
212  }
213 
214  m_renderer->CloseStream(m_stream);
215  m_renderingVideo = false;
216  }
217 
219  {
220  m_renderingVideo = false;
221  }
222 
223  private:
227 };
228 
229 #endif // DATVIDEORENDER_H
short int16_t
Definition: rtptypes_win.h:43
SwsContext * m_swsCtx
AudioFifo * m_audioFifo
bool m_isFFMPEGInitialized
QString CodecDescription
AVCodecContext * m_videoDecoderCtx
bool m_updateAudioResampler
int getVideoStreamIndex() const
bool getAudioDecodeOK() const
DATVideoRender * m_renderer
unsigned char uint8_t
Definition: rtptypes_win.h:42
AVCodecContext * m_audioDecoderCtx
void setAudioMute(bool audioMute)
Qt::WindowFlags m_originalWindowFlags
void setAudioFIFO(AudioFifo *fifo)
QWidget * m_parentWidget
bool getVideoDecodeOK() const
void setVideoMute(bool videoMute)
DATVideoRenderThread(DATVideoRender *renderer, DATVideostream *stream)
void setStreamAndRenderer(DATVideoRender *renderer, DATVideostream *stream)
AVFrame * m_frame
AVFormatContext * m_formatCtx
DATVideostream * m_stream
struct SwrContext * m_audioSWR
int getAudioStreamIndex() const