forked from h4tr3d/avcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodecparameters.cpp
169 lines (133 loc) · 3.32 KB
/
codecparameters.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
#include "codecparameters.h"
#include "codeccontext.h"
namespace av {
CodecParametersView::CodecParametersView(AVCodecParameters *codecpar)
: FFWrapperPtr<AVCodecParameters>(codecpar)
{
}
bool CodecParametersView::isValid() const
{
return !isNull();
}
void CodecParametersView::copyFrom(CodecParametersView src, OptionalErrorCode ec)
{
clear_if(ec);
if (!m_raw) {
throws_if(ec, Errors::Unallocated);
return;
}
if (!src.m_raw) {
throws_if(ec, Errors::Unallocated);
return;
}
auto const ret = avcodec_parameters_copy(m_raw, src.m_raw);
if (ret) {
throws_if(ec, ret, ffmpeg_category());
}
}
void CodecParametersView::copyTo(CodecParametersView dst, OptionalErrorCode ec) const
{
clear_if(ec);
if (!m_raw) {
throws_if(ec, Errors::Unallocated);
return;
}
if (!dst.m_raw) {
throws_if(ec, Errors::Unallocated);
return;
}
auto const ret = avcodec_parameters_copy(dst.m_raw, m_raw);
if (ret) {
throws_if(ec, ret, ffmpeg_category());
}
}
void CodecParametersView::copyFrom(const CodecContext2 &src, OptionalErrorCode ec)
{
clear_if(ec);
if (!m_raw) {
throws_if(ec, Errors::Unallocated);
return;
}
if (!src.raw()) {
throws_if(ec, Errors::Unallocated);
return;
}
auto const ret = avcodec_parameters_from_context(m_raw, src.raw());
if (ret) {
throws_if(ec, ret, ffmpeg_category());
}
}
void CodecParametersView::copyTo(CodecContext2 &dst, OptionalErrorCode ec) const
{
clear_if(ec);
if (!m_raw) {
throws_if(ec, Errors::Unallocated);
return;
}
if (!dst.raw()) {
throws_if(ec, Errors::Unallocated);
return;
}
auto const ret = avcodec_parameters_to_context(dst.raw(), m_raw);
if (ret) {
throws_if(ec, ret, ffmpeg_category());
}
}
int CodecParametersView::getAudioFrameDuration(int frame_bytes) const
{
if (!m_raw)
return 0;
return av_get_audio_frame_duration2(const_cast<AVCodecParameters*>(m_raw), frame_bytes);
}
AVMediaType CodecParametersView::codecType() const
{
return m_raw ? m_raw->codec_type : AVMEDIA_TYPE_UNKNOWN;
}
void CodecParametersView::codecType(AVMediaType codec_type)
{
if (m_raw)
m_raw->codec_type = codec_type;
}
AVMediaType CodecParametersView::mediaType() const
{
return codecType();
}
void CodecParametersView::mediaType(AVMediaType media_type)
{
codecType(media_type);
}
AVCodecID CodecParametersView::codecId() const
{
return m_raw ? m_raw->codec_id : AV_CODEC_ID_NONE;
}
void CodecParametersView::codecId(AVCodecID codec_id)
{
if (m_raw)
m_raw->codec_id = codec_id;
}
Codec CodecParametersView::encodingCodec() const
{
return m_raw ? findEncodingCodec(m_raw->codec_id) : Codec();
}
Codec CodecParametersView::decodingCodec() const
{
return m_raw ? findDecodingCodec(m_raw->codec_id) : Codec();
}
uint32_t CodecParametersView::codecTag() const
{
return m_raw ? m_raw->codec_tag : 0u;
}
void CodecParametersView::codecTag(uint32_t codec_tag)
{
if (m_raw)
m_raw->codec_tag = codec_tag;
}
CodecParameters::CodecParameters()
: CodecParametersView(avcodec_parameters_alloc())
{
}
CodecParameters::~CodecParameters()
{
avcodec_parameters_free(&m_raw);
}
} // namespace av