Commit afd302fa authored by Ronald S. Bultje's avatar Ronald S. Bultje Committed by Benoit Fouet

Split out the packet parsing from the main function body in rmdec.c

into its own function
Patch by Ronald S. Bultje: rsbultje gmail com
Original thread: Re: [FFmpeg-devel] [PATCH 2/6] rmdec.c: ff_rm_parse_frame()
Date: 11/05/2007 09:23 PM

Originally committed as revision 10961 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 7e4b1611
......@@ -535,68 +535,17 @@ static int rm_assemble_video_frame(AVFormatContext *s, RMContext *rm, AVPacket *
return 1;
}
static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
static int
ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len, AVPacket *pkt,
int *seq, int *flags, int64_t *timestamp)
{
RMContext *rm = s->priv_data;
ByteIOContext *pb = &s->pb;
AVStream *st;
int i, len, j;
int64_t timestamp, pos;
uint8_t *ptr;
int flags;
if (rm->audio_pkt_cnt) {
// If there are queued audio packet return them first
st = s->streams[rm->audio_stream_num];
if (st->codec->codec_id == CODEC_ID_AAC)
av_get_packet(pb, pkt, rm->sub_packet_lengths[rm->sub_packet_cnt - rm->audio_pkt_cnt]);
else {
av_new_packet(pkt, st->codec->block_align);
memcpy(pkt->data, rm->audiobuf + st->codec->block_align *
(rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
st->codec->block_align);
}
rm->audio_pkt_cnt--;
pkt->flags = 0;
pkt->stream_index = rm->audio_stream_num;
} else if (rm->old_format) {
st = s->streams[0];
if (st->codec->codec_id == CODEC_ID_RA_288) {
int x, y;
for (y = 0; y < rm->sub_packet_h; y++)
for (x = 0; x < rm->sub_packet_h/2; x++)
if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0)
return AVERROR(EIO);
rm->audio_stream_num = 0;
rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1;
// Release first audio packet
av_new_packet(pkt, st->codec->block_align);
memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe
pkt->stream_index = 0;
} else {
/* just read raw bytes */
len = RAW_PACKET_SIZE;
len= av_get_packet(pb, pkt, len);
pkt->stream_index = 0;
if (len <= 0) {
return AVERROR(EIO);
}
pkt->size = len;
}
} else {
int seq=1;
resync:
len=sync(s, &timestamp, &flags, &i, &pos);
if(len<0)
return AVERROR(EIO);
st = s->streams[i];
RMContext *rm = s->priv_data;
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
rm->current_stream= st->id;
if(rm_assemble_video_frame(s, rm, pkt, len) == 1)
goto resync;//got partial frame
return -1; //got partial frame
} else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
if ((st->codec->codec_id == CODEC_ID_RA_288) ||
(st->codec->codec_id == CODEC_ID_COOK) ||
......@@ -608,10 +557,10 @@ resync:
int y = rm->sub_packet_cnt;
int w = rm->audio_framesize;
if (flags & 2)
if (*flags & 2)
y = rm->sub_packet_cnt = 0;
if (!y)
rm->audiotimestamp = timestamp;
rm->audiotimestamp = *timestamp;
switch(st->codec->codec_id) {
case CODEC_ID_RA_288:
......@@ -626,7 +575,7 @@ resync:
}
if (++(rm->sub_packet_cnt) < h)
goto resync;
return -1;
else {
rm->sub_packet_cnt = 0;
rm->audio_stream_num = st->index;
......@@ -634,8 +583,8 @@ resync:
// Release first audio packet
av_new_packet(pkt, st->codec->block_align);
memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
timestamp = rm->audiotimestamp;
flags = 2; // Mark first packet as keyframe
*timestamp = rm->audiotimestamp;
*flags = 2; // Mark first packet as keyframe
}
} else if (st->codec->codec_id == CODEC_ID_AAC) {
int x;
......@@ -647,7 +596,7 @@ resync:
// Release first audio packet
rm->audio_pkt_cnt = rm->sub_packet_cnt - 1;
av_get_packet(pb, pkt, rm->sub_packet_lengths[0]);
flags = 2; // Mark first packet as keyframe
*flags = 2; // Mark first packet as keyframe
}
} else
av_get_packet(pb, pkt, len);
......@@ -655,10 +604,10 @@ resync:
} else
av_get_packet(pb, pkt, len);
if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
if( (st->discard >= AVDISCARD_NONKEY && !(*flags&2))
|| st->discard >= AVDISCARD_ALL){
av_free_packet(pkt);
goto resync;
return -1;
}
pkt->stream_index = st->index;
......@@ -667,17 +616,84 @@ resync:
if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
if(st->codec->codec_id == CODEC_ID_RV20){
int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);
av_log(NULL, AV_LOG_DEBUG, "%d %"PRId64" %d\n", timestamp, timestamp*512LL/25, seq);
av_log(NULL, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *timestamp, *timestamp*512LL/25, seq);
seq |= (timestamp&~0x3FFF);
if(seq - timestamp > 0x2000) seq -= 0x4000;
if(seq - timestamp < -0x2000) seq += 0x4000;
seq |= (*timestamp&~0x3FFF);
if(seq - *timestamp > 0x2000) seq -= 0x4000;
if(seq - *timestamp < -0x2000) seq += 0x4000;
}
}
#endif
pkt->pts= timestamp;
if(flags&2){
pkt->pts= *timestamp;
if (*flags & 2)
pkt->flags |= PKT_FLAG_KEY;
return 0;
}
static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
{
RMContext *rm = s->priv_data;
ByteIOContext *pb = &s->pb;
AVStream *st;
int i, len, j;
int64_t timestamp, pos;
uint8_t *ptr;
int flags;
if (rm->audio_pkt_cnt) {
// If there are queued audio packet return them first
st = s->streams[rm->audio_stream_num];
if (st->codec->codec_id == CODEC_ID_AAC)
av_get_packet(pb, pkt, rm->sub_packet_lengths[rm->sub_packet_cnt - rm->audio_pkt_cnt]);
else {
av_new_packet(pkt, st->codec->block_align);
memcpy(pkt->data, rm->audiobuf + st->codec->block_align *
(rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
st->codec->block_align);
}
rm->audio_pkt_cnt--;
pkt->flags = 0;
pkt->stream_index = rm->audio_stream_num;
} else if (rm->old_format) {
st = s->streams[0];
if (st->codec->codec_id == CODEC_ID_RA_288) {
int x, y;
for (y = 0; y < rm->sub_packet_h; y++)
for (x = 0; x < rm->sub_packet_h/2; x++)
if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0)
return AVERROR(EIO);
rm->audio_stream_num = 0;
rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1;
// Release first audio packet
av_new_packet(pkt, st->codec->block_align);
memcpy(pkt->data, rm->audiobuf, st->codec->block_align);
pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe
pkt->stream_index = 0;
} else {
/* just read raw bytes */
len = RAW_PACKET_SIZE;
len= av_get_packet(pb, pkt, len);
pkt->stream_index = 0;
if (len <= 0) {
return AVERROR(EIO);
}
pkt->size = len;
}
} else {
int seq=1;
resync:
len=sync(s, &timestamp, &flags, &i, &pos);
if(len<0)
return AVERROR(EIO);
st = s->streams[i];
if (ff_rm_parse_packet (s, st, len, pkt, &seq, &flags, &timestamp) < 0)
goto resync;
if(flags&2){
if((seq&0x7F) == 1)
av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment