forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAVPlayerPrivate.h
145 lines (126 loc) · 4.68 KB
/
AVPlayerPrivate.h
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
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2014 Wang Bin <[email protected]>
* This file is part of QtAV
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 of the License, or (at your option) any later version.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_AVPLAYER_PRIVATE_H
#define QTAV_AVPLAYER_PRIVATE_H
#include <limits>
#include "QtAV/AVDemuxer.h"
#include "QtAV/AVPlayer.h"
#include "AudioThread.h"
#include "VideoThread.h"
#include "AVDemuxThread.h"
#include "utils/Logger.h"
namespace QtAV {
static const qint64 kInvalidPosition = std::numeric_limits<qint64>::max();
class AVPlayer::Private
{
public:
Private();
~Private();
void initStatistics();
bool setupAudioThread(AVPlayer *player);
bool setupVideoThread(AVPlayer *player);
//TODO: addAVOutput()
template<class Out>
void setAVOutput(Out *&pOut, Out *pNew, AVThread *thread) {
Out *old = pOut;
bool delete_old = false;
if (pOut == pNew) {
qDebug("output not changed: %p", pOut);
if (thread && thread->output() == pNew) {//avthread already set that output
qDebug("avthread already set that output");
return;
}
} else {
pOut = pNew;
delete_old = true;
}
if (!thread) {
qDebug("avthread not ready. can not set output.");
//no avthread, we can delete it safely
//AVOutput must be allocated in heap. Just like QObject's children.
if (delete_old) {
delete old;
old = 0;
}
return;
}
//FIXME: what if isPaused()==false but pause(true) in another thread?
//bool need_lock = isPlaying() && !thread->isPaused();
//if (need_lock)
// thread->lock();
qDebug("set AVThread output");
thread->setOutput(pOut);
if (pOut) {
pOut->setStatistics(&statistics);
//if (need_lock)
// thread->unlock(); //??why here?
}
//now the old avoutput is not used by avthread, we can delete it safely
//AVOutput must be allocated in heap. Just like QObject's children.
if (delete_old) {
delete old;
old = 0;
}
}
bool auto_load;
bool async_load;
// can be QString, QIODevice*
QVariant current_source, pendding_source;
bool loaded; // for current source
bool relative_time_mode;
AVFormatContext *fmt_ctx; //changed when reading a packet
qint64 media_start_pts; // read from media stream
qint64 media_end;
/*
* unit: s. 0~1. stream's start time/duration(). or last position/duration() if change to new stream
* auto set to 0 if stop(). to stream start time if load()
*
* -1: used by play() to get current playing position
*/
qint64 last_position; //last_pos
bool reset_state;
qint64 start_position, stop_position;
int repeat_max, repeat_current;
int timer_id; //notify position change and check AB repeat range. active when playing
//the following things are required and must be set not null
AVDemuxer demuxer;
AVDemuxThread *read_thread;
AVClock *clock;
VideoRenderer *vo; //list? // TODO: remove
AudioOutput *ao; // TODO: remove
AudioDecoder *adec;
VideoDecoder *vdec;
AudioThread *athread;
VideoThread *vthread;
VideoCapture *vcapture;
Statistics statistics;
qreal speed;
bool ao_enabled;
OutputSet *vos, *aos;
QVector<VideoDecoderId> vc_ids;
QVector<AudioOutputId> ao_ids;
int brightness, contrast, saturation;
QVariantHash ac_opt, vc_opt;
bool seeking;
qint64 seek_target; // relative time if relativeTimeMode is true
qint64 interrupt_timeout;
bool mute;
// timerEvent interval in ms. can divide 1000. depends on media duration, fps etc.
int notify_interval;
};
} //namespace QtAV
#endif // QTAV_AVPLAYER_PRIVATE_H