[FFmpeg-devel] [PATCH] RTMP client support for lavf

Michael Niedermayer michaelni
Thu Jul 30 22:29:49 CEST 2009


On Thu, Jul 30, 2009 at 09:16:22AM +0300, Kostya wrote:
[...]
> +static int get_packet(URLContext *s, int for_header)
> +{
> +    RTMPContext *rt = s->priv_data;
> +    int ret;
> +
> +    for(;;) {
> +        RTMPPacket rpkt;
> +        int has_data = 0;
> +        if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt,
> +                                       rt->chunk_size, rt->prev_pkt[0])) != 0) {
> +            if (ret > 0) {
> +                return AVERROR(EAGAIN);
> +            } else {
> +                return AVERROR(EIO);
> +            }
> +        }
> +
> +        ret = rtmp_parse_result(s, rt, &rpkt);
> +        if (ret < 0) {//serious error in packet
> +            ff_rtmp_packet_destroy(&rpkt);
> +            return -1;
> +        }
> +        if (for_header && rt->state == STATE_PLAYING) {
> +            ff_rtmp_packet_destroy(&rpkt);
> +            return 0;
> +        }
> +        if (!rpkt.data_size) {
> +            ff_rtmp_packet_destroy(&rpkt);
> +            continue;
> +        }
> +        if (rpkt.type == RTMP_PT_VIDEO || rpkt.type == RTMP_PT_AUDIO ||
> +            rpkt.type == RTMP_PT_NOTIFY) {
> +            uint8_t *p;
> +            uint32_t ts = rpkt.timestamp;
> +
> +            if (rpkt.type == RTMP_PT_VIDEO) {
> +                rt->video_ts += rpkt.timestamp;
> +                ts = rt->video_ts;
> +            } else if (rpkt.type == RTMP_PT_AUDIO) {
> +                rt->audio_ts += rpkt.timestamp;
> +                ts = rt->audio_ts;
> +            }
> +            // generate packet header and put data into buffer for FLV demuxer
> +            rt->flv_off  = 0;
> +            rt->flv_size = rpkt.data_size + 15;
> +            rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size);
> +            bytestream_put_byte(&p, rpkt.type);
> +            bytestream_put_be24(&p, rpkt.data_size);
> +            bytestream_put_be24(&p, ts);
> +            bytestream_put_byte(&p, ts >> 24);
> +            bytestream_put_be24(&p, 0);
> +            bytestream_put_buffer(&p, rpkt.data, rpkt.data_size);
> +            bytestream_put_be32(&p, 0);

> +            has_data = 1;
> +        } else if (rpkt.type == RTMP_PT_METADATA) {
> +            // we got raw FLV data, make it available for FLV demuxer
> +            rt->flv_off  = 0;
> +            rt->flv_size = rpkt.data_size;
> +            rt->flv_data = av_realloc(rt->flv_data, rt->flv_size);
> +            memcpy(rt->flv_data, rpkt.data, rpkt.data_size);
> +            has_data = 1;
> +        }
> +        ff_rtmp_packet_destroy(&rpkt);
> +        if (has_data)
> +            break;
> +    }
> +    return 0;

            ff_rtmp_packet_destroy(&rpkt);
            return 0;
        }else if ...
            ...
            ff_rtmp_packet_destroy(&rpkt);
            return 0;
        }

2 lines less ...

besides this the patch isnt looking bad ...

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090730/376f79e6/attachment.pgp>



More information about the ffmpeg-devel mailing list