[b7a122]: src / org / esb / av / Packet.cpp  Maximize  Restore  History

Download this file

291 lines (252 with data), 7.2 kB

  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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include "Packet.h"
#include "AV.h"
#include "org/esb/util/Log.h"
#include <iostream>
using namespace std;
using namespace org::esb::av;
Packet::Packet() {
// cout << "Packet()"<<endl;
isCopy = false;
packetPtr = boost::shared_ptr<AVPacket > (new AVPacket());
packet = packetPtr.get();
av_init_packet(packet);
callDestruct = false;
packet->data = NULL;
// data=0;
packet->size = 0;
_time_base.num = 0;
_time_base.den = 0;
_pict_type = 0;
}
/**
* constructor to build an internal Packet directly from an AVPacket
*/
Packet::Packet(AVPacket * p) {
//cout << "Packet::Packet(AVPacket * p)"<<endl;
packetPtr = boost::shared_ptr<AVPacket > (new AVPacket());
packetPtr->pts = p->pts;
packetPtr->dts = p->dts;
packetPtr->pos = p->pos;
packetPtr->size = p->size;
packetPtr->duration = p->duration;
packetPtr->convergence_duration = p->convergence_duration;
packetPtr->flags = p->flags;
packetPtr->priv = p->priv;
packetPtr->stream_index = p->stream_index;
_pict_type = 0;
if (av_dup_packet(p) == 0) {
// packetPtr->data = static_cast<uint8_t*>(av_malloc(p->size + FF_INPUT_BUFFER_PADDING_SIZE));
// memcpy(packetPtr->data, p->data, p->size);
// memset(packetPtr->data + packetPtr->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
packetPtr->data = p->data;
}
packetPtr->destruct = av_destruct_packet;
callDestruct = false;
/**
* this must be removed in the near future, because this packet field will be hidden in the future
*/
packet = packetPtr.get();
}
Packet::Packet(const Packet & p) {
//cout << "Packet(const Packet & p)"<<endl;
// callDestruct=false;
packetPtr = boost::shared_ptr<AVPacket > (new AVPacket());
packet = packetPtr.get();
// _time_base.num=p._time_base.num;
// _time_base.den=p._time_base.num;
_time_base = p._time_base;
_pict_type = p._pict_type;
_ptsTimeStamp = p._ptsTimeStamp;
_dtsTimeStamp = p._dtsTimeStamp;
_duration=p._duration;
//_time_base=p.getTimeBase();
av_init_packet(packet);
packet->data = 0;
packet->pts = p.packet->pts;
packet->dts = p.packet->dts;
if (p.packet->size > 0) {
// packet->data = new uint8_t[p.packet->size];
packet->data = new uint8_t[p.packet->size + FF_INPUT_BUFFER_PADDING_SIZE];
// memset(packet->data, 0, packet->size + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(packet->data, p.packet->data, p.packet->size);
memset(packet->data + p.packet->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
packet->destruct = av_destruct_packet;
}
packet->size = p.packet->size;
packet->stream_index = p.packet->stream_index;
packet->flags = p.packet->flags;
packet->duration = p.packet->duration;
packet->destruct = p.packet->destruct;
packet->priv = p.packet->priv;
packet->pos = p.packet->pos;
callDestruct = true;
}
Packet Packet::operator=(Packet & p) {
cout << "Packet::operator=" << endl;
packetPtr = boost::shared_ptr<AVPacket > (new AVPacket());
packet = packetPtr.get();
// packet=new AVPacket();
av_init_packet(packet);
packet->pts = p.packet->pts;
packet->dts = p.packet->dts;
_pict_type = p._pict_type;
_ptsTimeStamp = p._ptsTimeStamp;
_dtsTimeStamp = p._dtsTimeStamp;
_duration=p._duration;
packet->data = 0;
packet->data = new uint8_t[p.packet->size];
// packet->data = new uint8_t[p.packet->size + FF_INPUT_BUFFER_PADDING_SIZE ];
// memset(packet->data, 0, packet->size + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(packet->data, p.packet->data, p.packet->size);
packet->size = p.packet->size;
packet->stream_index = p.packet->stream_index;
packet->flags = p.packet->flags;
packet->duration = p.packet->duration;
packet->destruct = p.packet->destruct;
packet->priv = p.packet->priv;
packet->pos = p.packet->pos;
callDestruct = true;
return *this;
}
Packet::Packet(int s) {
// logdebug("Packet(int s)"<<this);
isCopy = false;
_time_base.num = 0;
_time_base.den = 0;
_pict_type = 0;
packetPtr = boost::shared_ptr<AVPacket > (new AVPacket());
packet = packetPtr.get();
av_init_packet(packet);
packet->size = s;
if (s > 0) {
//packet->data = new uint8_t[s];
packet->data = new uint8_t[s + FF_INPUT_BUFFER_PADDING_SIZE];
// packet->data = static_cast<uint8_t*>(av_malloc(s + FF_INPUT_BUFFER_PADDING_SIZE));
memset(packet->data, 0, s + FF_INPUT_BUFFER_PADDING_SIZE);
//memset(packet->data, 0, s);
callDestruct = true;
} else {
// logerror("Try to Allocate Packet buffer <0")
packet->data = NULL;
callDestruct = false;
}
}
Packet::~Packet() {
// logdebug("delete Packet"<<this);
// av_free_packet(packetPtr.get());
if (callDestruct) {
if (packet->data)
delete [] packet->data;
} else
av_free_packet(packet);
packet->data = NULL;
// delete packet;
// packet=0;
}
uint8_t * Packet::getData() {
return packet->data;
}
int Packet::getSize() {
return packet->size;
}
void Packet::setPts(int64_t ts) {
packet->pts = ts;
}
void Packet::setDts(int64_t ts) {
packet->dts = ts;
}
long long int Packet::getPts() {
return packet->pts;
}
long long int Packet::getDts() {
return packet->dts;
}
int Packet::getFlags() {
return packet->flags;
}
void Packet::setFlags(int f) {
packet->flags = f;
}
unsigned int Packet::getStreamIndex() {
return packet->stream_index;
}
void Packet::setStreamIndex(int idx) {
packet->stream_index = idx;
}
int Packet::getDuration() {
return packet->duration;
}
void Packet::setDuration(int d) {
packet->duration = d;
}
bool Packet::isKeyFrame() {
return packet->flags & PKT_FLAG_KEY;
}
void * Packet::getPriv() {
return packet->priv;
}
int64_t Packet::getPosition() {
return packet->pos;
}
AVPacket* Packet::getAVPacket() {
return packetPtr.get();
}
void Packet::setTimeBase(AVRational t) {
_time_base = t;
}
void Packet::setTimeBase(int num, int den) {
_time_base.num = num;
_time_base.den = den;
}
AVRational Packet::getTimeBase() {
return _time_base;
}
void Packet::setKeyPacket(bool key) {
if (key)
packet->flags |= PKT_FLAG_KEY;
}
void Packet::setPtsTimeStamp(TimeStamp t) {
_ptsTimeStamp = t;
}
void Packet::setDtsTimeStamp(TimeStamp t) {
_dtsTimeStamp = t;
}
TimeStamp Packet::getPtsTimeStamp() {
return _ptsTimeStamp;
}
TimeStamp Packet::getDtsTimeStamp() {
return _dtsTimeStamp;
}
void Packet::setTimeDuration(TimeStamp d) {
_duration = d;
}
TimeStamp Packet::getTimeDuration() {
return _duration;
}
std::string Packet::toString() {
std::ostringstream oss;
oss << "P->S:" << getSize() <<
":Pts:" << getPts() <<
":Dts:" << getDts() <<
":Index:" << getStreamIndex() <<
":Dur:" << getDuration() <<
":Pos:" << getPosition() <<
":TBase:" << getTimeBase().num << "/" << getTimeBase().den <<
":F:" << getFlags() <<
":KF" << isKeyFrame();
std::string type;
switch (_pict_type) {
case FF_I_TYPE: type = "I";
break;
case FF_B_TYPE: type = "B";
break;
case FF_BI_TYPE: type = "BI";
break;
case FF_P_TYPE: type = "P";
break;
default:type = "U";
break;
}
oss << ":T=" << type;
return std::string(oss.str());
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks