forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AVError.cpp
230 lines (203 loc) · 6.13 KB
/
AVError.cpp
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV (from 2013)
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
******************************************************************************/
#include "QtAV/AVError.h"
#include "QtAV/private/AVCompat.h"
#ifndef QT_NO_DEBUG_STREAM
#include <QtCore/qdebug.h>
#endif
namespace QtAV {
namespace
{
class RegisterMetaTypes
{
public:
RegisterMetaTypes()
{
qRegisterMetaType<QtAV::AVError>("QtAV::AVError");
}
} _registerMetaTypes;
}
static AVError::ErrorCode errorFromFFmpeg(int fe)
{
typedef struct {
int ff;
AVError::ErrorCode e;
} err_entry;
static const err_entry err_map[] = {
{ AVERROR_BSF_NOT_FOUND, AVError::FormatError },
#ifdef AVERROR_BUFFER_TOO_SMALL
{ AVERROR_BUFFER_TOO_SMALL, AVError::ResourceError },
#endif //AVERROR_BUFFER_TOO_SMALL
{ AVERROR_DECODER_NOT_FOUND, AVError::CodecError },
{ AVERROR_ENCODER_NOT_FOUND, AVError::CodecError },
{ AVERROR_DEMUXER_NOT_FOUND, AVError::FormatError },
{ AVERROR_MUXER_NOT_FOUND, AVError::FormatError },
{ AVERROR_PROTOCOL_NOT_FOUND, AVError::ResourceError },
{ AVERROR_STREAM_NOT_FOUND, AVError::ResourceError },
{ 0, AVError::UnknowError }
};
for (int i = 0; err_map[i].ff; i) {
if (err_map[i].ff == fe)
return err_map[i].e;
}
return AVError::UnknowError;
}
/*
* correct wrong AVError to a right category by ffmpeg error code
* does nothing if ffmpeg error code is 0
*/
static void correct_error_by_ffmpeg(AVError::ErrorCode *e, int fe)
{
if (!fe || !e)
return;
const AVError::ErrorCode ec = errorFromFFmpeg(fe);
if (*e > ec)
*e = ec;
}
AVError::AVError()
: mError(NoError)
, mFFmpegError(0)
{
}
AVError::AVError(ErrorCode code, int ffmpegError)
: mError(code)
, mFFmpegError(ffmpegError)
{
correct_error_by_ffmpeg(&mError, mFFmpegError);
}
AVError::AVError(ErrorCode code, const QString &detail, int ffmpegError)
: mError(code)
, mFFmpegError(ffmpegError)
, mDetail(detail)
{
correct_error_by_ffmpeg(&mError, mFFmpegError);
}
AVError::AVError(const AVError& other)
: mError(other.mError)
, mFFmpegError(other.mFFmpegError)
, mDetail(other.mDetail)
{
}
AVError& AVError::operator=(const AVError& other)
{
mError = other.mError;
mFFmpegError = other.mFFmpegError;
return *this;
}
bool AVError::operator==(const AVError& other) const
{
return (mError == other.mError && mFFmpegError == other.mFFmpegError);
}
void AVError::setError(ErrorCode ec)
{
mError = ec;
}
AVError::ErrorCode AVError::error() const
{
return mError;
}
QString AVError::string() const
{
QString errStr(mDetail);
if (errStr.isEmpty()) {
switch (mError) {
case NoError:
errStr = QObject::tr("No error");
break;
case OpenError:
errStr = QObject::tr("Open error");
break;
case OpenTimedout:
errStr = QObject::tr("Open timed out");
break;
case ParseStreamTimedOut:
errStr = QObject::tr("Parse stream timed out");
break;
case ParseStreamError:
errStr = QObject::tr("Parse stream error");
break;
case StreamNotFound:
errStr = QObject::tr("Stream not found");
break;
case ReadTimedout:
errStr = QObject::tr("Read packet timed out");
break;
case ReadError:
errStr = QObject::tr("Read error");
break;
case SeekError:
errStr = QObject::tr("Seek error");
break;
case ResourceError:
errStr = QObject::tr("Resource error");
break;
case OpenCodecError:
errStr = QObject::tr("Open codec error");
break;
case CloseCodecError:
errStr = QObject::tr("Close codec error");
break;
case VideoCodecNotFound:
errStr = QObject::tr("Video codec not found");
break;
case AudioCodecNotFound:
errStr = QObject::tr("Audio codec not found");
break;
case SubtitleCodecNotFound:
errStr = QObject::tr("Subtitle codec not found");
break;
case CodecError:
errStr = QObject::tr("Codec error");
break;
case FormatError:
errStr = QObject::tr("Format error");
break;
case NetworkError:
errStr = QObject::tr("Network error");
break;
case AccessDenied:
errStr = QObject::tr("Access denied");
break;
default:
errStr = QObject::tr("Unknow error");
break;
}
}
if (mFFmpegError != 0) {
errStr = QStringLiteral("\n(FFmpeg %1: %2)").arg(mFFmpegError, 0, 16).arg(ffmpegErrorString());
}
return errStr;
}
int AVError::ffmpegErrorCode() const
{
return mFFmpegError;
}
QString AVError::ffmpegErrorString() const
{
if (mFFmpegError == 0)
return QString();
return QString::fromUtf8(av_err2str(mFFmpegError));
}
} //namespace QtAV
#ifndef QT_NO_DEBUG_STREAM
//class QDebug;
QDebug operator<<(QDebug debug, const QtAV::AVError &error)
{
debug << error.string();
return debug;
}
#endif