headunit.h
1 #ifndef HEADUNITPLAYER_H
2 #define HEADUNITPLAYER_H
3 
4 #include <QObject>
5 #include <QString>
6 #include <QPoint>
7 #include <QGst/Pipeline>
8 #include <QGst/Message>
9 #include <QVariant>
10 #include <QGst/Utils/ApplicationSource>
11 #include <gst/gst.h>
12 #include <gst/app/gstappsrc.h>
13 
14 #include "hu_uti.h"
15 #include "hu_aap.h"
16 #include "glib_utils.h"
17 #include "usbconnectionlistener.h"
18 
19 class Headunit;
20 
21 class DesktopEventCallbacks : public IHUConnectionThreadEventCallbacks {
22 
23 private:
24  Headunit * headunit;
25 public:
27  headunit = hu;
28  }
29  virtual int MediaPacket(int chan, uint64_t timestamp, const byte * buf, int len) override;
30  virtual int MediaStart(int chan) override;
31  virtual int MediaStop(int chan) override;
32  virtual void MediaSetupComplete(int chan) override;
33  virtual void DisconnectionOrError() override;
34  virtual void CustomizeOutputChannel(int chan, HU::ChannelDescriptor::OutputStreamChannel& streamChannel) override;
35  virtual void AudioFocusRequest(int chan, const HU::AudioFocusRequest& request) override;
36  virtual void VideoFocusRequest(int chan, const HU::VideoFocusRequest& request) override;
37 
38  void VideoFocusHappened(bool hasFocus, bool unrequested);
39 
40  std::atomic<bool> connected;
41  std::atomic<bool> videoFocus;
42  std::atomic<bool> audioFocus;
43 };
44 
45 class Headunit : public QObject
46 {
47  Q_OBJECT
48  Q_PROPERTY(int outputWidth READ outputWidth WRITE setOutputWidth NOTIFY outputResized)
49  Q_PROPERTY(int outputHeight READ outputHeight WRITE setOutputHeight NOTIFY outputResized)
50 public:
51  Headunit(const QGst::ElementPtr & sink);
52  ~Headunit();
53  int startHU();
54  void stop();
55  void exit();
56  void setGstState(QString state);
57  void setUsbConnectionListener(UsbConnectionListener *m_connectionListener);
58  void setOutputWidth(const int a);
59  void setOutputHeight(const int a);
60  const int outputWidth();
61  const int outputHeight();
62  GstElement *mic_pipeline = nullptr;
63  GstElement *mic_sink = nullptr;
64  GstElement *aud_pipeline = nullptr;
65  GstAppSrc *aud_src = nullptr;
66  GstElement *au1_pipeline = nullptr;
67  GstAppSrc *au1_src = nullptr;
68  GstElement *vid_pipeline = nullptr;
69  GstAppSrc *vid_src = nullptr;
70  IHUAnyThreadInterface* g_hu = nullptr;
71 signals:
72  void outputResized();
73  void deviceConnected(QVariantMap notification);
74 public slots:
75  bool mouseDown(QPoint point);
76  bool mouseMove(QPoint point);
77  bool mouseUp(QPoint point);
78  bool keyEvent(QString key);
79  void slotDeviceAdded(const QString &dev);
80  void slotAndroidDeviceAdded(const QString &dev);
81  void slotDeviceRemoved(const QString &dev);
82  void slotDeviceChanged(const QString &dev);
83 private:
84  QGst::ElementPtr m_videoSink;
85  HUServer *headunit;
86  DesktopEventCallbacks callbacks;
87  HU::TouchInfo::TOUCH_ACTION lastAction = HU::TouchInfo::TOUCH_ACTION_RELEASE;
88  UsbConnectionListener *connectionListener;
89  int videoWidth = 800;
90  int videoHeight = 480;
91  int m_outputWidth = 800;
92  int m_outputHeight = 480;
93  int initGst();
94  void read_mic_data(GstElement * sink);
95  static gboolean bus_callback(GstBus *bus, GstMessage *message, gpointer *ptr);
96  void touchEvent(HU::TouchInfo::TOUCH_ACTION action, QPoint *point);
97  static uint64_t get_cur_timestamp();
98  bool huStarted = false;
99  byte ep_in_addr = -2;
100  byte ep_out_addr = -2;
101 };
102 #endif // HEADUNITPLAYER_H
Definition: headunit.h:21
Definition: headunit.h:45
Definition: usbconnectionlistener.h:29