[FFmpeg-devel] [PATCH] rmdec.c: merge old/new packet reading code
Kostya
kostya.shishkov
Tue Mar 10 07:26:27 CET 2009
On Mon, Mar 09, 2009 at 09:42:59PM -0400, Ronald S. Bultje wrote:
> Hi again,
>
> On Mon, Mar 9, 2009 at 6:37 PM, Ronald S. Bultje <rsbultje at gmail.com> wrote:
> > The move of the resync onto above the retrieve_cache() code isn't
> > strictly necessary (it could be below, directly after the "} else {"),
> > but is partly in preparation for the next patch which moves the cache
> > reading out of ff_rm_parse_packet() (which will return a positive
> > non-zero integer, and thus any non-zero return value in
> > ff_rm_parse_packet() will go back to resync => magic).
>
> attached is a newer version that properly checks for EOF so that
> old_format actually stops at the end of a file.
>
> Ronald
> Index: ffmpeg-svn/libavformat/rmdec.c
> ===================================================================
> --- ffmpeg-svn.orig/libavformat/rmdec.c 2009-03-09 18:02:40.000000000 -0400
> +++ ffmpeg-svn/libavformat/rmdec.c 2009-03-09 21:32:49.000000000 -0400
> @@ -691,57 +691,38 @@
> static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
> {
> RMDemuxContext *rm = s->priv_data;
> - ByteIOContext *pb = s->pb;
> AVStream *st;
> - int i, len;
> + int i, len, seq = 1;
> int64_t timestamp, pos;
> int flags;
>
> +resync:
do{
> if (rm->audio_pkt_cnt) {
> // If there are queued audio packet return them first
> st = s->streams[rm->audio_stream_num];
> ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
> - } else if (rm->old_format) {
> - RMStream *ast;
> + } else {
> + if (rm->old_format) {
> + RMStream *ast;
>
> - st = s->streams[0];
> - ast = st->priv_data;
> - if (st->codec->codec_id == CODEC_ID_RA_288) {
> - int x, y;
> -
> - for (y = 0; y < ast->sub_packet_h; y++)
> - for (x = 0; x < ast->sub_packet_h/2; x++)
> - if (get_buffer(pb, ast->pkt.data+x*2*ast->audio_framesize+y*ast->coded_framesize, ast->coded_framesize) <= 0)
> - return AVERROR(EIO);
> - rm->audio_stream_num = 0;
> - rm->audio_pkt_cnt = ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - 1;
> - // Release first audio packet
> - av_new_packet(pkt, st->codec->block_align);
> - memcpy(pkt->data, ast->pkt.data, st->codec->block_align); //FIXME avoid this
> - 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;
> - }
> - rm_ac3_swap_bytes(st, pkt);
> + st = s->streams[0];
> + ast = st->priv_data;
> + timestamp = AV_NOPTS_VALUE;
> + len = ast->audio_framesize ?
> + ast->coded_framesize * ast->sub_packet_h / 2 : RAW_PACKET_SIZE;
> + flags = (seq == 1) ? 2 : 0;
> } else {
> - int seq=1;
> -resync:
> len=sync(s, ×tamp, &flags, &i, &pos);
> - if(len<0)
> - return AVERROR(EIO);
> st = s->streams[i];
> + }
> +
> + if(len<0 || url_feof(s->pb))
> + return AVERROR(EIO);
>
> if (ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
> &seq, &flags, ×tamp) < 0)
> goto resync;
> + }
} while(ff_rm_parse_packet (...) < 0);
I like goto's but this one is rather unneeded (and is not that qualified to
be called resync now).
> if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
> || st->discard >= AVDISCARD_ALL){
And you can move discarding logic into the loop without need for emptying
cache inside it.
> @@ -755,7 +736,6 @@
>
> if((flags&2) && (seq&0x7F) == 1)
> av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
> - }
>
> return 0;
> }
More information about the ffmpeg-devel
mailing list