[1cff17]: src / org / esb / hive / job / ProcessUnit.cpp  Maximize  Restore  History

Download this file

201 lines (163 with data), 5.4 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
#include "ProcessUnit.h"
#include "org/esb/av/Frame.h"
#include "org/esb/av/FrameFormat.h"
#include "org/esb/av/FrameConverter.h"
#include "org/esb/util/Log.h"
using namespace org::esb::hive::job;
using namespace org::esb::av;
bool toDebug=false;
ProcessUnit::ProcessUnit(){
_decoder=NULL;
_encoder=NULL;
codec=NULL;
_target_stream=0;
_source_stream=0;
_frame_group=0;
id=0;
}
ProcessUnit::~ProcessUnit(){
/*
if(_decoder!=NULL)
delete _decoder;
if(_encoder!=NULL)
delete _encoder;
if(codec!=NULL)
delete codec;
*/
// _decoder=NULL;
// _encoder=NULL;
// _target_stream=0;
// _input_packets.clear();
// _output_packets.clear();
}
void ProcessUnit::process(){
int insize=0, outsize=0;
if(_decoder!=NULL)
_decoder->open();
if(_encoder!=NULL)
_encoder->open();
if(toDebug)
logdebug("Codex openned");
FrameFormat in_format;
in_format.pixel_format=(PixelFormat)_decoder->getPixelFormat();//PIX_FMT_YUV420P;
in_format.height=_decoder->getHeight();
in_format.width=_decoder->getWidth();
in_format.channels=_decoder->getChannels();
in_format.samplerate=_decoder->getSampleRate();
if(toDebug)
logdebug("Input Formater created");
FrameFormat out_format;
out_format.pixel_format=(PixelFormat)_encoder->getPixelFormat();//PIX_FMT_YUV420P;
out_format.height=_encoder->getHeight();
out_format.width=_encoder->getWidth();
out_format.channels=_encoder->getChannels();
out_format.samplerate=_encoder->getSampleRate();
if(toDebug)
logdebug("Output Formater created");
// cout << "Create Formater:\twidth:"<<format.width<<"\theight"<<format.height<<endl;
FrameConverter conv(in_format,out_format);
if(toDebug)
logdebug("Converter created");
// cout << "start decoding encoding"<<endl;
list< boost::shared_ptr<Packet> >::iterator it;
multiset<boost::shared_ptr<Frame>, PtsComparator > pts_list;
multiset<boost::shared_ptr<Packet>, PtsPacketComparator > pts_packets;
int a=0;
int counter=0;
for(it=_input_packets.begin();it!=_input_packets.end();it++){
if(toDebug)
logdebug("Loop");
boost::shared_ptr<Packet> p=*it;
insize+=p->packet->size;
if(p->isKeyFrame()){
cout <<"KeyFrame\t";
}
// if(tmp._buffer==0)continue;
// boost::shared_ptr<Frame> fr(new Frame(tmp));
// pts_list.insert(fr);
cout <<"PacketPts:"<<p->packet->pts<<"\tPacketDts:"<<p->packet->dts<<"\t";
// cout <<"\tFramePts:"<<tmp.getPts()<<"\tFrameDts:"<<tmp.getDts();
// cout <<"\tFrame*Pts:"<<fr->getPts()<<"\tFrame*Dts:"<<fr->getDts();
// cout << endl;
Frame tmp=_decoder->decode(*p);
if(toDebug)
logdebug("Frame Decoded");
if(_frame_count>=counter&&tmp.pict_type==FF_I_TYPE){
break;
}
if(tmp._buffer==0){
continue;
}
if(toDebug)
logdebug("Frame Buffer > 0");
// fr->setPts(++a);
// fr->setDts(AV_NOPTS_VALUE);
Frame f=conv.convert(tmp);
if(toDebug)
logdebug("Frame Converted");
f.setPts(f.getDts());
// f.setPts(++a);
// tmp.setDts(AV_NOPTS_VALUE);
Packet ret=_encoder->encode(f);
if(toDebug)
logdebug("Frame Encoded");
boost::shared_ptr<Packet> pEnc(new Packet(ret));
if(toDebug)
logdebug("Packet Created");
// pEnc->packet->dts=AV_NOPTS_VALUE;
outsize+=pEnc->packet->size;
_output_packets.push_back(pEnc);
if(toDebug)
logdebug("Packet Added");
// cout <<"FramePts:"<<f.pts<<"\tFrameDts:"<<f.dts;
// cout <<"\tPacketPts:"<<pEnc->packet->pts<<"\tPacketDts:"<<pEnc->packet->dts<<endl;
// pts_packets.insert(p);
}
// cout <<"ListSize:"<<_input_packets.size()<<"\tSetSize:"<<pts_list.size()<<endl;
// multiset<boost::shared_ptr<Frame>, PtsComparator>::iterator pts_it;
/*
multiset<boost::shared_ptr<Packet>, PtsPacketComparator>::iterator packet_it;
a=0;
for(packet_it=pts_packets.begin();packet_it!=pts_packets.end();packet_it++){
boost::shared_ptr<Packet> p=*packet_it;
insize+=p->packet->size;
Frame tmp=_decoder->decode(*p);
if(tmp._buffer==0)continue;
boost::shared_ptr<Frame> fr(new Frame(tmp));
// fr->setDts(++a);
pts_list.insert(fr);
tmp.setPts(++a);
tmp.setDts(AV_NOPTS_VALUE);
Frame f=conv.convert(tmp);
Packet ret=_encoder->encode(f);
boost::shared_ptr<Packet> pEnc(new Packet(ret));
outsize+=pEnc->packet->size;
_output_packets.push_back(pEnc);
}
*/
/*
a=0;
for(pts_it=pts_list.begin();pts_it!=pts_list.end();pts_it++){
boost::shared_ptr<Frame> tmp=*pts_it;
tmp->setPts(++a);
// tmp->setDts(AV_NOPTS_VALUE);
Frame f=conv.convert(*tmp);
// f.dts=f.pts;
Packet ret=_encoder->encode(*tmp);
boost::shared_ptr<Packet> pEnc(new Packet(ret));
outsize+=pEnc->packet->size;
pEnc->packet->dts=AV_NOPTS_VALUE;
_output_packets.push_back(pEnc);
// cout <<"FramePts:"<<f.pts<<"\tFrameDts:"<<f.dts;
cout <<"\tPacketPts:"<<pEnc->packet->pts<<"\tPacketDts:"<<pEnc->packet->dts<<endl;
// cout << "Frame*Pts:"<<tmp->pts<<"\tPacketPts:"<<ret.packet->pts<<"Packet*Pts"<<pEnc->packet->pts<<endl;
}
*/
logdebug("InputSize:"<<insize<<"OutputSize:"<<outsize);
if(_decoder!=NULL)
delete _decoder;
if(_encoder!=NULL)
delete _encoder;
_decoder=0;
_encoder=0;
}