summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/phonon/qt7/quicktimevideoplayer.h
blob: bf4f216450541e7fc593fd26400928e801da7ac7 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*  This file is part of the KDE project.

    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).

    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 or 3 of the License.

    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, see <http://www.gnu.org/licenses/>.
*/

#ifndef Phonon_QT7_QUICKTIMEVIDEOPLAYER_H
#define Phonon_QT7_QUICKTIMEVIDEOPLAYER_H

#include "backendheader.h"

#include <QtGui/qmacdefines_mac.h>
#import <QTKit/QTDataReference.h>
#import <QTKit/QTMovie.h>

#include <phonon/mediasource.h>
#include <Carbon/Carbon.h>
#include <QtCore/QString>
#include <QtOpenGL/QGLPixelBuffer>
#include "videoframe.h"

QT_BEGIN_NAMESPACE

class QGLContext;

namespace Phonon
{
namespace QT7
{
    class QuickTimeStreamReader;
	class VideoRenderWidgetQTMovieView;

    class QuickTimeVideoPlayer : QObject
    {
        public:
            enum StateEnum {
                Playing = 0x1,
                Paused = 0x2,
                NoMedia = 0x4,
            };
            Q_DECLARE_FLAGS(State, StateEnum);

            QuickTimeVideoPlayer();
            virtual ~QuickTimeVideoPlayer();

            void setMediaSource(const MediaSource &source);
            MediaSource mediaSource() const;
            void unsetVideo();

            void play();
            void pause();
            void seek(quint64 milliseconds);

            bool videoFrameChanged();
            CVOpenGLTextureRef currentFrameAsCVTexture();
            GLuint currentFrameAsGLTexture();
			void *currentFrameAsCIImage();
            QImage currentFrameAsQImage();
            void releaseImageCache();
            QRect videoRect() const;

            quint64 duration() const;
            quint64 currentTime() const;
            long timeScale() const;
            float staticFps();
            QString currentTimeString();

            void setColors(qreal brightness = 0, qreal contrast = 1, qreal hue = 0, qreal saturation = 1);
            void setMasterVolume(float volume);
            void setRelativeVolume(float volume);
            void setVolume(float masterVolume, float relativeVolume);
            void setMute(bool mute);
            void enableAudio(bool enable);
            bool audioEnabled();
            bool setAudioDevice(int id);
            void setPlaybackRate(float rate);
            QTMovie *qtMovie() const;

            float playbackRate() const;
            float prefferedPlaybackRate() const;

            QuickTimeVideoPlayer::State state() const;

            bool hasAudio() const;
            bool hasVideo() const;
            bool hasMovie() const;
            bool canPlayMedia() const;
            bool isPlaying() const;
            bool isSeekable() const;
            bool isDrmProtected() const;
            bool isDrmAuthorized() const;

            bool preRollMovie(qint64 startTime = 0);
            float percentageLoaded();
            quint64 timeLoaded();

            static QString timeToString(quint64 ms);

			// Help functions when drawing to more that one widget in cocoa 64:
			void *m_primaryRenderingTarget;
            void setPrimaryRenderingTarget(NSObject *target);

			void *primaryRenderingCIImage();
			void setPrimaryRenderingCIImage(void *ciImage);

        private:
            QTMovie *m_QTMovie;
            State m_state;
            QGLPixelBuffer *m_QImagePixelBuffer;

            CVOpenGLTextureRef m_cachedCVTextureRef;
            QImage m_cachedQImage;

            bool m_playbackRateSat;
            bool m_isDrmProtected;
            bool m_isDrmAuthorized;
            bool m_mute;
            bool m_audioEnabled;
            bool m_hasVideo;
            float m_masterVolume;
            float m_relativeVolume;
            float m_playbackRate;
            float m_staticFps;
            quint64 m_currentTime;
            MediaSource m_mediaSource;

			void *m_primaryRenderingCIImage;
			qreal m_brightness;
			qreal m_contrast;
			qreal m_hue;
			qreal m_saturation;

#ifdef QUICKTIME_C_API_AVAILABLE
            QTVisualContextRef m_visualContext;
#endif
            VideoFrame m_currentFrame;
            QuickTimeStreamReader *m_streamReader;

            void createVisualContext();
            void openMovieFromCurrentMediaSource();
            void openMovieFromDataRef(QTDataReference *dataRef);
            void openMovieFromFile();
            void openMovieFromUrl();
            void openMovieFromStream();
            void openMovieFromData(QByteArray *data, char *fileType);
            void openMovieFromDataGuessType(QByteArray *data);
			QString mediaSourcePath();
			bool codecExistsAccordingToSuffix(const QString &fileName);

            void setError(NSError *error);
            bool errorOccured();
            void readProtection();
            void calculateStaticFps();
            void checkIfVideoAwailable();
            bool movieNotLoaded();
            void waitStatePlayable();
    };

    Q_DECLARE_OPERATORS_FOR_FLAGS(QuickTimeVideoPlayer::State);

}} // namespace Phonon::QT7

QT_END_NAMESPACE

#endif // Phonon_QT7_QUICKTIMEVIDEOPLAYER_H