static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    RMContext *rm = s->priv_data;
    AVStream *st;
    ByteIOContext *pb = &s->pb;
    unsigned int tag, v;
    int tag_size, size, codec_data_size, i;
    int64_t codec_pos;
    unsigned int h263_hack_version, start_time, duration;
    char buf[128];
    int flags = 0;
    tag = get_le32(pb);
    if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
        /* very old .ra format */
        return rm_read_header_old(s, ap);
    } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
        return AVERROR_IO;
    get_be32(pb); /* header size */
    get_be16(pb);
    get_be32(pb);
    get_be32(pb); /* number of headers */
    for(;;) {
        if (url_feof(pb))
            goto fail;
        tag = get_le32(pb);
        tag_size = get_be32(pb);
        get_be16(pb);
#if 0
        printf("tag=%c%c%c%c (%08x) size=%d\n",
               (tag) & 0xff,
               (tag >> 8) & 0xff,
               (tag >> 16) & 0xff,
               (tag >> 24) & 0xff,
               tag,
               tag_size);
#endif
        if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
            goto fail;
        switch(tag) {
        case MKTAG('P', 'R', 'O', 'P'):
            /* file header */
            get_be32(pb); /* max bit rate */
            get_be32(pb); /* avg bit rate */
            get_be32(pb); /* max packet size */
            get_be32(pb); /* avg packet size */
            get_be32(pb); /* nb packets */
            get_be32(pb); /* duration */
            get_be32(pb); /* preroll */
            get_be32(pb); /* index offset */
            get_be32(pb); /* data offset */
            get_be16(pb); /* nb streams */
            flags = get_be16(pb); /* flags */
            break;
        case MKTAG('C', 'O', 'N', 'T'):
            get_str(pb, s->title, sizeof(s->title));
            get_str(pb, s->author, sizeof(s->author));
            get_str(pb, s->copyright, sizeof(s->copyright));
            get_str(pb, s->comment, sizeof(s->comment));
            break;
        case MKTAG('M', 'D', 'P', 'R'):
            st = av_new_stream(s, 0);
            if (!st)
                goto fail;
            st->id = get_be16(pb);
            get_be32(pb); /* max bit rate */
            st->codec->bit_rate = get_be32(pb); /* bit rate */
            get_be32(pb); /* max packet size */
            get_be32(pb); /* avg packet size */
            start_time = get_be32(pb); /* start time */
            get_be32(pb); /* preroll */
            duration = get_be32(pb); /* duration */
            st->start_time = start_time;
            st->duration = duration;
            get_str8(pb, buf, sizeof(buf)); /* desc */
            get_str8(pb, buf, sizeof(buf)); /* mimetype */
            codec_data_size = get_be32(pb);
            codec_pos = url_ftell(pb);
            st->codec->codec_type = CODEC_TYPE_DATA;
            av_set_pts_info(st, 64, 1, 1000);
            v = get_be32(pb);
            if (v == MKTAG(0xfd, 'a', 'r', '.')) {
                /* ra type header */
                rm_read_audio_stream_info(s, st, 0);
            } else {
                int fps, fps2;
                if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
                fail1:
                    av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
                    goto skip;
                st->codec->codec_tag = get_le32(pb);
//                av_log(NULL, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0'));
                if (   st->codec->codec_tag != MKTAG('R', 'V', '1', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '2', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '3', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '4', '0'))
                    goto fail1;
                st->codec->width = get_be16(pb);
                st->codec->height = get_be16(pb);
                st->codec->time_base.num= 1;
                fps= get_be16(pb);
                st->codec->codec_type = CODEC_TYPE_VIDEO;
                get_be32(pb);
                fps2= get_be16(pb);
                get_be16(pb);
                st->codec->extradata_size= codec_data_size - (url_ftell(pb) - codec_pos);
                st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
                get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
//                av_log(NULL, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2);
                st->codec->time_base.den = fps * st->codec->time_base.num;
                /* modification of h263 codec version (!) */
#ifdef WORDS_BIGENDIAN
                h263_hack_version = ((uint32_t*)st->codec->extradata)[1];
#else
                h263_hack_version = bswap_32(((uint32_t*)st->codec->extradata)[1]);
#endif
                st->codec->sub_id = h263_hack_version;
                switch((h263_hack_version>>28)){
                case 1: st->codec->codec_id = CODEC_ID_RV10; break;
                case 2: st->codec->codec_id = CODEC_ID_RV20; break;
                case 3: st->codec->codec_id = CODEC_ID_RV30; break;
                case 4: st->codec->codec_id = CODEC_ID_RV40; break;
                default: goto fail1;
skip:
            /* skip codec info */
            size = url_ftell(pb) - codec_pos;
            url_fskip(pb, codec_data_size - size);
            break;
        case MKTAG('D', 'A', 'T', 'A'):
            goto header_end;
        default:
            /* unknown tag: skip it */
            url_fskip(pb, tag_size - 10);
            break;
 header_end:
    rm->nb_packets = get_be32(pb); /* number of packets */
    if (!rm->nb_packets && (flags & 4))
        rm->nb_packets = 3600 * 25;
    get_be32(pb); /* next data header */
    return 0;
 fail:
    for(i=0;i<s->nb_streams;i++) {
        av_free(s->streams[i]);
    return AVERROR_IO;
static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    RMContext *rm = s->priv_data;
    AVStream *st;
    ByteIOContext *pb = &s->pb;
    unsigned int tag, v;
    int tag_size, size, codec_data_size, i;
    int64_t codec_pos;
    unsigned int h263_hack_version, start_time, duration;
    char buf[128];
    int flags = 0;
    tag = get_le32(pb);
    if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
        
        return rm_read_header_old(s, ap);
    } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
        return AVERROR_IO;
    get_be32(pb); 
    get_be16(pb);
    get_be32(pb);
    get_be32(pb); 
    for(;;) {
        if (url_feof(pb))
            goto fail;
        tag = get_le32(pb);
        tag_size = get_be32(pb);
        get_be16(pb);
#if 0
        printf("tag=%c%c%c%c (%08x) size=%d\n",
               (tag) & 0xff,
               (tag >> 8) & 0xff,
               (tag >> 16) & 0xff,
               (tag >> 24) & 0xff,
               tag,
               tag_size);
#endif
        if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
            goto fail;
        switch(tag) {
        case MKTAG('P', 'R', 'O', 'P'):
            
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be16(pb); 
            flags = get_be16(pb); 
            break;
        case MKTAG('C', 'O', 'N', 'T'):
            get_str(pb, s->title, sizeof(s->title));
            get_str(pb, s->author, sizeof(s->author));
            get_str(pb, s->copyright, sizeof(s->copyright));
            get_str(pb, s->comment, sizeof(s->comment));
            break;
        case MKTAG('M', 'D', 'P', 'R'):
            st = av_new_stream(s, 0);
            if (!st)
                goto fail;
            st->id = get_be16(pb);
            get_be32(pb); 
            st->codec->bit_rate = get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            start_time = get_be32(pb); 
            get_be32(pb); 
            duration = get_be32(pb); 
            st->start_time = start_time;
            st->duration = duration;
            get_str8(pb, buf, sizeof(buf)); 
            get_str8(pb, buf, sizeof(buf)); 
            codec_data_size = get_be32(pb);
            codec_pos = url_ftell(pb);
            st->codec->codec_type = CODEC_TYPE_DATA;
            av_set_pts_info(st, 64, 1, 1000);
            v = get_be32(pb);
            if (v == MKTAG(0xfd, 'a', 'r', '.')) {
                
                rm_read_audio_stream_info(s, st, 0);
            } else {
                int fps, fps2;
                if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
                fail1:
                    av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
                    goto skip;
                st->codec->codec_tag = get_le32(pb);

                if (   st->codec->codec_tag != MKTAG('R', 'V', '1', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '2', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '3', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '4', '0'))
                    goto fail1;
                st->codec->width = get_be16(pb);
                st->codec->height = get_be16(pb);
                st->codec->time_base.num= 1;
                fps= get_be16(pb);
                st->codec->codec_type = CODEC_TYPE_VIDEO;
                get_be32(pb);
                fps2= get_be16(pb);
                get_be16(pb);
                st->codec->extradata_size= codec_data_size - (url_ftell(pb) - codec_pos);
                st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
                get_buffer(pb, st->codec->extradata, st->codec->extradata_size);

                st->codec->time_base.den = fps * st->codec->time_base.num;
                
#ifdef WORDS_BIGENDIAN
                h263_hack_version = ((uint32_t*)st->codec->extradata)[1];
#else
                h263_hack_version = bswap_32(((uint32_t*)st->codec->extradata)[1]);
#endif
                st->codec->sub_id = h263_hack_version;
                switch((h263_hack_version>>28)){
                case 1: st->codec->codec_id = CODEC_ID_RV10; break;
                case 2: st->codec->codec_id = CODEC_ID_RV20; break;
                case 3: st->codec->codec_id = CODEC_ID_RV30; break;
                case 4: st->codec->codec_id = CODEC_ID_RV40; break;
                default: goto fail1;
skip:
            
            size = url_ftell(pb) - codec_pos;
            url_fskip(pb, codec_data_size - size);
            break;
        case MKTAG('D', 'A', 'T', 'A'):
            goto header_end;
        default:
            
            url_fskip(pb, tag_size - 10);
            break;
 header_end:
    rm->nb_packets = get_be32(pb); 
    if (!rm->nb_packets && (flags & 4))
        rm->nb_packets = 3600 * 25;
    get_be32(pb); 
    return 0;
 fail:
    for(i=0;i<s->nb_streams;i++) {
        av_free(s->streams[i]);
    return AVERROR_IO;
static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)
{
    RMContext *rm = VAR_0->priv_data;
    AVStream *st;
    ByteIOContext *pb = &VAR_0->pb;
    unsigned int VAR_2, VAR_3;
    int VAR_4, VAR_5, VAR_6, VAR_7;
    int64_t codec_pos;
    unsigned int VAR_8, VAR_9, VAR_10;
    char VAR_11[128];
    int VAR_12 = 0;
    VAR_2 = get_le32(pb);
    if (VAR_2 == MKTAG('.', 'r', 'a', 0xfd)) {
        
        return rm_read_header_old(VAR_0, VAR_1);
    } else if (VAR_2 != MKTAG('.', 'R', 'M', 'F')) {
        return AVERROR_IO;
    get_be32(pb); 
    get_be16(pb);
    get_be32(pb);
    get_be32(pb); 
    for(;;) {
        if (url_feof(pb))
            goto fail;
        VAR_2 = get_le32(pb);
        VAR_4 = get_be32(pb);
        get_be16(pb);
#if 0
        printf("VAR_2=%c%c%c%c (%08x) VAR_5=%d\n",
               (VAR_2) & 0xff,
               (VAR_2 >> 8) & 0xff,
               (VAR_2 >> 16) & 0xff,
               (VAR_2 >> 24) & 0xff,
               VAR_2,
               VAR_4);
#endif
        if (VAR_4 < 10 && VAR_2 != MKTAG('D', 'A', 'T', 'A'))
            goto fail;
        switch(VAR_2) {
        case MKTAG('P', 'R', 'O', 'P'):
            
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            get_be16(pb); 
            VAR_12 = get_be16(pb); 
            break;
        case MKTAG('C', 'O', 'N', 'T'):
            get_str(pb, VAR_0->title, sizeof(VAR_0->title));
            get_str(pb, VAR_0->author, sizeof(VAR_0->author));
            get_str(pb, VAR_0->copyright, sizeof(VAR_0->copyright));
            get_str(pb, VAR_0->comment, sizeof(VAR_0->comment));
            break;
        case MKTAG('M', 'D', 'P', 'R'):
            st = av_new_stream(VAR_0, 0);
            if (!st)
                goto fail;
            st->id = get_be16(pb);
            get_be32(pb); 
            st->codec->bit_rate = get_be32(pb); 
            get_be32(pb); 
            get_be32(pb); 
            VAR_9 = get_be32(pb); 
            get_be32(pb); 
            VAR_10 = get_be32(pb); 
            st->VAR_9 = VAR_9;
            st->VAR_10 = VAR_10;
            get_str8(pb, VAR_11, sizeof(VAR_11)); 
            get_str8(pb, VAR_11, sizeof(VAR_11)); 
            VAR_6 = get_be32(pb);
            codec_pos = url_ftell(pb);
            st->codec->codec_type = CODEC_TYPE_DATA;
            av_set_pts_info(st, 64, 1, 1000);
            VAR_3 = get_be32(pb);
            if (VAR_3 == MKTAG(0xfd, 'a', 'r', '.')) {
                
                rm_read_audio_stream_info(VAR_0, st, 0);
            } else {
                int VAR_13, VAR_14;
                if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
                fail1:
                    av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
                    goto skip;
                st->codec->codec_tag = get_le32(pb);

                if (   st->codec->codec_tag != MKTAG('R', 'V', '1', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '2', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '3', '0')
                    && st->codec->codec_tag != MKTAG('R', 'V', '4', '0'))
                    goto fail1;
                st->codec->width = get_be16(pb);
                st->codec->height = get_be16(pb);
                st->codec->time_base.num= 1;
                VAR_13= get_be16(pb);
                st->codec->codec_type = CODEC_TYPE_VIDEO;
                get_be32(pb);
                VAR_14= get_be16(pb);
                get_be16(pb);
                st->codec->extradata_size= VAR_6 - (url_ftell(pb) - codec_pos);
                st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
                get_buffer(pb, st->codec->extradata, st->codec->extradata_size);

                st->codec->time_base.den = VAR_13 * st->codec->time_base.num;
                
#ifdef WORDS_BIGENDIAN
                VAR_8 = ((uint32_t*)st->codec->extradata)[1];
#else
                VAR_8 = bswap_32(((uint32_t*)st->codec->extradata)[1]);
#endif
                st->codec->sub_id = VAR_8;
                switch((VAR_8>>28)){
                case 1: st->codec->codec_id = CODEC_ID_RV10; break;
                case 2: st->codec->codec_id = CODEC_ID_RV20; break;
                case 3: st->codec->codec_id = CODEC_ID_RV30; break;
                case 4: st->codec->codec_id = CODEC_ID_RV40; break;
                default: goto fail1;
skip:
            
            VAR_5 = url_ftell(pb) - codec_pos;
            url_fskip(pb, VAR_6 - VAR_5);
            break;
        case MKTAG('D', 'A', 'T', 'A'):
            goto header_end;
        default:
            
            url_fskip(pb, VAR_4 - 10);
            break;
 header_end:
    rm->nb_packets = get_be32(pb); 
    if (!rm->nb_packets && (VAR_12 & 4))
        rm->nb_packets = 3600 * 25;
    get_be32(pb); 
    return 0;
 fail:
    for(VAR_7=0;VAR_7<VAR_0->nb_streams;VAR_7++) {
        av_free(VAR_0->streams[VAR_7]);
    return AVERROR_IO;
static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)
{ RMContext *rm = VAR_0->priv_data; AVStream *st; ByteIOContext *pb = &VAR_0->pb; unsigned int VAR_2, VAR_3; int VAR_4, VAR_5, VAR_6, VAR_7; int64_t codec_pos; unsigned int VAR_8, VAR_9, VAR_10; char VAR_11[128]; int VAR_12 = 0; VAR_2 = get_le32(pb); if (VAR_2 == MKTAG('.', 'r', 'a', 0xfd)) { return rm_read_header_old(VAR_0, VAR_1); } else if (VAR_2 != MKTAG('.', 'R', 'M', 'F')) { return AVERROR_IO; get_be32(pb); get_be16(pb); get_be32(pb); get_be32(pb); for(;;) { if (url_feof(pb))
goto fail; VAR_2 = get_le32(pb); VAR_4 = get_be32(pb); get_be16(pb); #if 0
printf("VAR_2=%c%c%c%c (%08x) VAR_5=%d\n",
(VAR_2) & 0xff,
(VAR_2 >> 8) & 0xff,
(VAR_2 >> 16) & 0xff,
(VAR_2 >> 24) & 0xff,
VAR_2,
VAR_4); #endif
if (VAR_4 < 10 && VAR_2 != MKTAG('D', 'A', 'T', 'A'))
goto fail; switch(VAR_2) { case MKTAG('P', 'R', 'O', 'P'):
get_be32(pb); get_be32(pb); get_be32(pb); get_be32(pb); get_be32(pb); get_be32(pb); get_be32(pb); get_be32(pb); get_be32(pb); get_be16(pb); VAR_12 = get_be16(pb); break; case MKTAG('C', 'O', 'N', 'T'):
get_str(pb, VAR_0->title, sizeof(VAR_0->title)); get_str(pb, VAR_0->author, sizeof(VAR_0->author)); get_str(pb, VAR_0->copyright, sizeof(VAR_0->copyright)); get_str(pb, VAR_0->comment, sizeof(VAR_0->comment)); break; case MKTAG('M', 'D', 'P', 'R'):
st = av_new_stream(VAR_0, 0); if (!st)
goto fail; st->id = get_be16(pb); get_be32(pb); st->codec->bit_rate = get_be32(pb); get_be32(pb); get_be32(pb); VAR_9 = get_be32(pb); get_be32(pb); VAR_10 = get_be32(pb); st->VAR_9 = VAR_9; st->VAR_10 = VAR_10; get_str8(pb, VAR_11, sizeof(VAR_11)); get_str8(pb, VAR_11, sizeof(VAR_11)); VAR_6 = get_be32(pb); codec_pos = url_ftell(pb); st->codec->codec_type = CODEC_TYPE_DATA; av_set_pts_info(st, 64, 1, 1000); VAR_3 = get_be32(pb); if (VAR_3 == MKTAG(0xfd, 'a', 'r', '.')) { rm_read_audio_stream_info(VAR_0, st, 0); } else { int VAR_13, VAR_14; if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) { fail1:
av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n"); goto skip; st->codec->codec_tag = get_le32(pb); if (   st->codec->codec_tag != MKTAG('R', 'V', '1', '0')
&& st->codec->codec_tag != MKTAG('R', 'V', '2', '0')
&& st->codec->codec_tag != MKTAG('R', 'V', '3', '0')
&& st->codec->codec_tag != MKTAG('R', 'V', '4', '0'))
goto fail1; st->codec->width = get_be16(pb); st->codec->height = get_be16(pb); st->codec->time_base.num= 1; VAR_13= get_be16(pb); st->codec->codec_type = CODEC_TYPE_VIDEO; get_be32(pb); VAR_14= get_be16(pb); get_be16(pb); st->codec->extradata_size= VAR_6 - (url_ftell(pb) - codec_pos); st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); get_buffer(pb, st->codec->extradata, st->codec->extradata_size); st->codec->time_base.den = VAR_13 * st->codec->time_base.num; #ifdef WORDS_BIGENDIAN
VAR_8 = ((uint32_t*)st->codec->extradata)[1]; #else
VAR_8 = bswap_32(((uint32_t*)st->codec->extradata)[1]); #endif
st->codec->sub_id = VAR_8; switch((VAR_8>>28)){ case 1: st->codec->codec_id = CODEC_ID_RV10; break; case 2: st->codec->codec_id = CODEC_ID_RV20; break; case 3: st->codec->codec_id = CODEC_ID_RV30; break; case 4: st->codec->codec_id = CODEC_ID_RV40; break; default: goto fail1; skip:
VAR_5 = url_ftell(pb) - codec_pos; url_fskip(pb, VAR_6 - VAR_5); break; case MKTAG('D', 'A', 'T', 'A'):
goto header_end; default:
url_fskip(pb, VAR_4 - 10); break; header_end:
rm->nb_packets = get_be32(pb); if (!rm->nb_packets && (VAR_12 & 4))
rm->nb_packets = 3600 * 25; get_be32(pb); return 0; fail:
for(VAR_7=0;VAR_7<VAR_0->nb_streams;VAR_7++) { av_free(VAR_0->streams[VAR_7]); return AVERROR_IO;