[FFmpeg-devel] [PATCH 2/2] MxPEG decoder
Michael Niedermayer
michaelni
Tue Nov 2 20:08:47 CET 2010
On Tue, Nov 02, 2010 at 06:25:41AM +0300, Anatoly Nenashev wrote:
[...]
> +static int mxg_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> + int ret, size;
> + MXGContext *mxg = s->priv_data;
> +
> + while (!url_feof(s->pb) && !url_ferror(s->pb)) {
> + const uint8_t data = get_byte(s->pb);
> + unsigned int found_frame_end = 0;
> + mxg->state = (mxg->state << 8) | data;
> + mxg->buffer[mxg->current_pos++] = data;
> +
> + if (mxg->state == 0xffd9) {
> + found_frame_end = mxg->current_pos;
> + } else if (mxg->state == 0xffd8) {
> + if (mxg->vop_found) {
> + //emulating frame end
> + found_frame_end = mxg->current_pos - 2;
> + url_fseek(s->pb, -2, SEEK_CUR);
> + } else {
> + mxg->vop_found = 1;
> + }
> + } else if (mxg->state == 0xfffe) {
> + size = get_be16(s->pb);
> + if (url_feof(s->pb) || url_ferror(s->pb))
> + return AVERROR_EOF;
checking for eof after every byte read seems overkill to me
> +
> + if (mxg->current_pos > mxg->current_pos + size)
> + return AVERROR(ENOMEM);
> +
> + mxg->buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size,
> + mxg->current_pos + size);
> + if (!mxg->buffer)
> + return AVERROR(ENOMEM);
> +
> + if (size < 2) {
> + av_log(s, AV_LOG_ERROR, "wrong comment buffer size\n");
> + return AVERROR(EINVAL);
> + }
checking size after using it
> + mxg->buffer[mxg->current_pos++] = size >> 8;
> + mxg->buffer[mxg->current_pos++] = size & 0xff;
> +
> + ret = get_buffer(s->pb, mxg->buffer + mxg->current_pos, size - 2);
> + if (ret < 0)
> + return ret;
> + if (ret >= 16 && !strncmp(mxg->buffer + mxg->current_pos, "MXF", 3)) {
> + mxg->dts = AV_RL64(mxg->buffer + mxg->current_pos + 8);
> + }
> + mxg->current_pos += ret;
> + mxg->state = 0;
> + } else if (mxg->state == 0xffed) {
> + mxg->current_pos -= 2;
> + size = get_be16(s->pb);
> + if (url_feof(s->pb) || url_ferror(s->pb))
> + return AVERROR_EOF;
> + if (size <= 14)
> + return AVERROR(EINVAL);
> + url_fskip(s->pb, 12);
> + if (url_feof(s->pb) || url_ferror(s->pb))
> + return AVERROR_EOF;
> + size -= 14;
> + ret = av_get_packet(s->pb, pkt, size);
> + if (ret < 0)
> + return ret;
> +
> + pkt->stream_index = AUDIO_STREAM_INDEX;
> + mxg->state = 0;
> +
> + return pkt->size;
> + }
> +
> + if (found_frame_end) {
> + mxg->vop_found = 0;
> + mxg->current_pos = 0;
> + ret = av_new_packet(pkt, found_frame_end);
> + if (ret < 0)
> + return ret;
> + memcpy(pkt->data, mxg->buffer, found_frame_end);
avoidable
[...}
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101102/7638f3b2/attachment.pgp>
More information about the ffmpeg-devel
mailing list