[FFmpeg-devel] [PATCH 2/2] MxPEG decoder
Anatoly Nenashev
anatoly.nenashev
Wed Nov 3 01:21:04 CET 2010
On 02.11.2010 22:08, Michael Niedermayer wrote:
> 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
>
>
>
Removed.
>> +
>> + 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
>
It's moved above.
>
>
>> + 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
>
>
>
Yes. New implementation attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mxg_v6.patch
Type: text/x-patch
Size: 7804 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101103/5aa5d67b/attachment.bin>
More information about the ffmpeg-devel
mailing list