summaryrefslogtreecommitdiffstats
path: root/src/app/xineEngine.h
blob: d152a96d9d02de51c82acebc88061d2766d049be (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// (C) 2005 Max Howell ([email protected])
// See COPYING file for licensing information

#ifndef CODEINE_VIDEOWINDOW_H
#define CODEINE_VIDEOWINDOW_H

#include "../codeine.h"
#include <tqtimer.h>
#include <tqwidget.h>
#include <kurl.h>
#include <stdint.h>
#include <vector>
#include <xine.h>


typedef struct xine_s xine_t;
typedef struct xine_stream_s xine_stream_t;
typedef struct xine_video_port_s xine_video_port_t;
typedef struct xine_audio_port_s xine_audio_port_t;
typedef struct xine_event_queue_s xine_event_queue_t;
typedef struct xine_post_s xine_post_t;
typedef struct xine_osd_s xine_osd_t;

namespace Engine {
   typedef std::vector<int16_t> Scope;
}


namespace Codeine
{
   /** Functions declared here are defined in:
    *    xineEngine.cpp
    *    videoWindow.cpp
    */
   class VideoWindow : public TQWidget
   {
   TQ_OBJECT

      enum PosTimeLength { Pos, Time, Length };

      static VideoWindow *s_instance;
      static bool s_logarithmicVolume;

      VideoWindow( const VideoWindow& ); //disable
      VideoWindow &operator=( const VideoWindow& ); //disable

      friend class TheStream;
      friend VideoWindow* const engine();
      friend VideoWindow* const videoWindow();

   public:
      VideoWindow( TQWidget *parent );
     ~VideoWindow();

      bool init();
      void exit();

      bool load( const KURL &url );
      bool play( uint = 0 );

      uint position() const { return posTimeLength( Pos ); }
      uint time() const { return posTimeLength( Time ); }
      uint length() const { return posTimeLength( Length ); }

      uint volume() const;

      const Engine::Scope &scope();
      Engine::State state() const;

      operator xine_t*() const { return m_xine; }
      operator xine_stream_t*() const { return m_stream; }

   public slots:
      void pause();
      void record();
      void seek( uint );
      void stop();

      ///special slot, see implementation to facilitate understanding
      void setStreamParameter( int );

   signals:
      void stateChanged( Engine::State );
      void statusMessage( const TQString& );
      void titleChanged( const TQString& );
      void channelsChanged( const TQStringList& );

   private:
      static void xineEventListener( void*, const xine_event_t* );

      uint posTimeLength( PosTimeLength ) const;
      void showErrorMessage();

      virtual void customEvent( TQCustomEvent* );
      virtual void timerEvent( TQTimerEvent* );

      void eject();

      void announceStateChange() { emit stateChanged( state() ); }

      xine_osd_t         *m_osd;
      xine_stream_t      *m_stream;
      xine_event_queue_t *m_eventQueue;
      xine_video_port_t  *m_videoPort;
      xine_audio_port_t  *m_audioPort;
      xine_post_t        *m_scope;
      xine_t             *m_xine;

      int64_t m_current_vpts;

      KURL m_url;

   public:
      TQString fileFilter() const;

   public slots:
      void toggleDVDMenu();
      void showOSD( const TQString& );

   /// Stuff to do with video and the video window/widget
   private:
      static void destSizeCallBack( void*, int, int, double, int*, int*, double* );
      static void frameOutputCallBack( void*, int, int, double, int*, int*, int*, int*, double*, int*, int* );
      static int makeVolumeLogarithmic(int volume);

      void initVideo();
      void cleanUpVideo();

   public:
      static const uint CURSOR_HIDE_TIMEOUT = 2000;

      virtual TQSize sizeHint() const;
      virtual TQSize minimumSizeHint() const;

      void *x11Visual() const;
      void becomePreferredSize();
      TQImage captureFrame() const;

      enum { ExposeEvent = 3000 };

   public slots:
      void resetZoom();

   private slots:
      void hideCursor();

   private:
      virtual void contextMenuEvent( TQContextMenuEvent* );
      virtual bool event( TQEvent* );
      virtual bool x11Event( XEvent* );

      double m_displayRatio;
      TQTimer m_timer;
   };

   //global function for general use by Codeine
   //videoWindow() is const for Xlib-thread-safety reasons
   inline VideoWindow* const videoWindow() { return VideoWindow::s_instance; }
   inline VideoWindow* const engine() { return VideoWindow::s_instance; }
}

#endif