Changeset 273


Ignore:
Timestamp:
04/17/07 14:10:51 (17 years ago)
Author:
r2d
Message:
  • added return codes for mpc_demux_decode
  • refill buffer only if bit level is too low
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpc/branches/r2d/libmpcdec/mpc_demux.c

    r271 r273  
    364364}
    365365
    366 void mpc_demux_decode(mpc_demux * d, mpc_frame_info * i)
     366mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i)
    367367{
    368368        mpc_bits_reader r;
     
    382382                                if (memcmp(b.key, "SE", 2) == 0) { // end block
    383383                                        i->bits = -1;
    384                                         return;
     384                                        return MPC_STATUS_OK;
    385385                                }
    386386                                mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0);
     
    392392                        i->is_key_frame = MPC_TRUE;
    393393                }
    394                 // FIXME : this is not good if block size > buffer size
    395                 mpc_demux_fill(d, (d->block_bits >> 3) + 1, 0);
     394                if (d->buffer + d->bytes_total - d->bits_reader.buff <= MAX_FRAME_SIZE)
     395                        mpc_demux_fill(d, (d->block_bits >> 3) + 1, 0);
    396396                r = d->bits_reader;
    397397                mpc_decoder_decode_frame(d->d, &d->bits_reader, i);
     
    399399                d->block_frames--;
    400400                if (d->block_bits < 0 || (d->block_frames == 0 && d->block_bits > 7)) {
    401                         // an error occured, stop decoding
    402                         // FIXME : return an error code.
    403401                        i->bits = -1; // we pretend it's end of file
     402                        return MPC_STATUS_INVALIDSV;
    404403                }
    405404        } else {
     
    413412                mpc_decoder_decode_frame(d->d, &d->bits_reader, i);
    414413                if (d->block_bits != ((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count) {
    415                         // an error occured, stop decoding
    416                         // FIXME : return an error code.
    417414                        i->bits = -1; // we pretend it's end of file
     415                        return MPC_STATUS_INVALIDSV;
    418416                }
    419417        }
    420418        if (d->buffer + d->bytes_total < d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3)) {
    421                 // we're reading outside the buffer bytes, this is an error !
    422                 // FIXME : return an error code.
    423419                i->bits = -1; // we pretend it's end of file
    424         }
     420                return MPC_STATUS_INVALIDSV;
     421        }
     422        return MPC_STATUS_OK;
    425423}
    426424
Note: See TracChangeset for help on using the changeset viewer.