00180 {
00181
if (writeOnly || state != OPEN)
00182
return NULL;
00183
00184
if (( (this->currentFrameNumber > this->
endFrameNumber) && (
endFrameNumber!=0) )) {
00185
close(
true);
00186 state=STREAMEOF;
00187
return NULL;
00188 }
00189
00190
00191 AU *au =
new AU();
00192
Frame *frm = NULL;
00193 Frame::FrameType type = Frame::NN_VOP;
00194
00195
00196
00197
if(es->
isVisualStream()) {
00198
00199 u32 code = 2000;
00200
int i = 0;
00201
00202 u8 *data =
new u8[MAX_FRAME_SIZE];
00203
00204
do {
00205 data[i] = buffered_getc();
00206 code = (code << 8) | data[i];
00207 i++;
00208
if ((i==4) && code == VOP_START_CODE) code = 0;
00209 }
while ((code != VOP_START_CODE) && (i < maxFrameSize) && state != CLOSED);
00210
00211
if (code == VOP_START_CODE) {
00212 goBack(4);
00213 i -= 4;
00214 au->size = i;
00215 au->payload =
new u8[i];
00216 memcpy(au->payload, data, i);
00217
delete [] data;
00218 dprintf_full(
"BufferedMPGStreamReader::getFrame() read %d bytes of video frame\n", i);
00219 }
00220
00221
if (au->size == 0) {
00222 state = STREAMEOF;
00223
delete au;
00224
return NULL;
00225 }
00226
00227 au->prio = IO_NETWORK_HIGHEST_PRIORITY;
00228 au->duration = es->
getVOPTimeIncrement();
00229 au->cts = currentFrameNumber * es->
getVOPTimeIncrement();
00230 au->dts = currentFrameNumber * es->
getVOPTimeIncrement();
00231 au->sampleFlags = 0;
00232
if (code != VOP_START_CODE)
00233 au->err = SA_EOF;
00234
else
00235 au->err = SA_OK;
00236
00237 }
00238
00239
if(es->
isAudioStream()) {
00240
00241 u32 code = 2000;
00242
int i = 0;
00243
00244
00245
if (framesSeen == 0) {
00246
int ch = 0;
00247 au->payload =
new u8[1024];
00248
do {
00249 ch = buffered_getc();
00250 au->payload[i] = ch;
00251 i++;
00252 code = (code << 8) | ch;
00253 }
00254
while ((code>>21) != 0x000007FF );
00255 au->size = i;
00256 }
else {
00257 au->payload =
new u8[MAX_FRAME_SIZE];
00258 au->size = buffered_copy(au->payload, maxFrameSize);
00259 }
00260
00261 dprintf_full(
"BufferedMPGStreamReader::getFrame() read %d bytes of audio frame\n", au->size);
00262
00263 au->cts = DTS;
00264 au->dts = DTS;
00265 au->duration = 0;
00266 au->sampleFlags = 0;
00267 au->err = SA_OK;
00268
00269 DTS += es->
getVOPTimeIncrement();
00270 }
00271
00272
00273
if(es->
isVisualStream())
00274 frm =
new CompressedVideoFrame(type, ((VideoESInfo*)es)->getWidth(), ((VideoESInfo*)es)->getHeight());
00275
else if(es->isAudioStream())
00276 frm=
new CompressedAudioFrame(type);
00277
else
00278 frm =
new CompressedVideoFrame(type, 0, 0);
00279 frm->
setAU(au);
00280 frm->
setMediaTimeScale(es->getMediaTimeScale());
00281 framesSeen++;
00282 currentFrameNumber++;
00283
00284
00285
#ifdef _POSIX_PRIORITY_SCHEDULING
00286
sched_yield();
00287
#else
00288
00289
#ifdef WIN32
00290
#ifndef WINCE
00291
sched_yield();
00292
#else
00293
Sleep(1);
00294
#endif
00295
#endif
00296
#endif
00297
00298
return frm;
00299 }