static void rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
                                      int read_all)
{
    RMContext *rm = s->priv_data;
    ByteIOContext *pb = &s->pb;
    char buf[256];
    uint32_t version;
    int i;
    /* ra type header */
    version = get_be32(pb); /* version */
    if (((version >> 16) & 0xff) == 3) {
        int64_t startpos = url_ftell(pb);
        /* very old version */
        for(i = 0; i < 14; i++)
            get_byte(pb);
        get_str8(pb, s->title, sizeof(s->title));
        get_str8(pb, s->author, sizeof(s->author));
        get_str8(pb, s->copyright, sizeof(s->copyright));
        get_str8(pb, s->comment, sizeof(s->comment));
        if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) {
        // fourcc (should always be "lpcJ")
        get_byte(pb);
        get_str8(pb, buf, sizeof(buf));
        // Skip extra header crap (this should never happen)
        if ((startpos + (version & 0xffff)) > url_ftell(pb))
            url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb));
        st->codec->sample_rate = 8000;
        st->codec->channels = 1;
        st->codec->codec_type = CODEC_TYPE_AUDIO;
        st->codec->codec_id = CODEC_ID_RA_144;
    } else {
        int flavor, sub_packet_h, coded_framesize, sub_packet_size;
        /* old version (4) */
        get_be32(pb); /* .ra4 */
        get_be32(pb); /* data size */
        get_be16(pb); /* version2 */
        get_be32(pb); /* header size */
        flavor= get_be16(pb); /* add codec info / flavor */
        rm->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */
        get_be32(pb); /* ??? */
        get_be32(pb); /* ??? */
        get_be32(pb); /* ??? */
        rm->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */
        st->codec->block_align= get_be16(pb); /* frame size */
        rm->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */
        get_be16(pb); /* ??? */
        if (((version >> 16) & 0xff) == 5) {
            get_be16(pb); get_be16(pb); get_be16(pb); }
        st->codec->sample_rate = get_be16(pb);
        get_be32(pb);
        st->codec->channels = get_be16(pb);
        if (((version >> 16) & 0xff) == 5) {
            get_be32(pb);
            buf[0] = get_byte(pb);
            buf[1] = get_byte(pb);
            buf[2] = get_byte(pb);
            buf[3] = get_byte(pb);
            buf[4] = 0;
        } else {
        get_str8(pb, buf, sizeof(buf)); /* desc */
        get_str8(pb, buf, sizeof(buf)); /* desc */
        st->codec->codec_type = CODEC_TYPE_AUDIO;
        if (!strcmp(buf, "dnet")) {
            st->codec->codec_id = CODEC_ID_AC3;
        } else if (!strcmp(buf, "28_8")) {
            st->codec->codec_id = CODEC_ID_RA_288;
            st->codec->extradata_size= 0;
            rm->audio_framesize = st->codec->block_align;
            st->codec->block_align = coded_framesize;
            rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
        } else if (!strcmp(buf, "cook")) {
            int codecdata_length, i;
            get_be16(pb); get_byte(pb);
            if (((version >> 16) & 0xff) == 5)
                get_byte(pb);
            codecdata_length = get_be32(pb);
            if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
                av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
            st->codec->codec_id = CODEC_ID_COOK;
            st->codec->extradata_size= codecdata_length;
            st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
            for(i = 0; i < codecdata_length; i++)
                ((uint8_t*)st->codec->extradata)[i] = get_byte(pb);
            rm->audio_framesize = st->codec->block_align;
            st->codec->block_align = rm->sub_packet_size;
            rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
        } else {
            st->codec->codec_id = CODEC_ID_NONE;
            pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name),
                    buf);
        if (read_all) {
            get_byte(pb);
            get_byte(pb);
            get_byte(pb);
            get_str8(pb, s->title, sizeof(s->title));
            get_str8(pb, s->author, sizeof(s->author));
            get_str8(pb, s->copyright, sizeof(s->copyright));
            get_str8(pb, s->comment, sizeof(s->comment));
static void rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
                                      int read_all)
{
    RMContext *rm = s->priv_data;
    ByteIOContext *pb = &s->pb;
    char buf[256];
    uint32_t version;
    int i;
    
    version = get_be32(pb); 
    if (((version >> 16) & 0xff) == 3) {
        int64_t startpos = url_ftell(pb);
        
        for(i = 0; i < 14; i++)
            get_byte(pb);
        get_str8(pb, s->title, sizeof(s->title));
        get_str8(pb, s->author, sizeof(s->author));
        get_str8(pb, s->copyright, sizeof(s->copyright));
        get_str8(pb, s->comment, sizeof(s->comment));
        if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) {
        
        get_byte(pb);
        get_str8(pb, buf, sizeof(buf));
        
        if ((startpos + (version & 0xffff)) > url_ftell(pb))
            url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb));
        st->codec->sample_rate = 8000;
        st->codec->channels = 1;
        st->codec->codec_type = CODEC_TYPE_AUDIO;
        st->codec->codec_id = CODEC_ID_RA_144;
    } else {
        int flavor, sub_packet_h, coded_framesize, sub_packet_size;
        
        get_be32(pb); 
        get_be32(pb); 
        get_be16(pb); 
        get_be32(pb); 
        flavor= get_be16(pb); 
        rm->coded_framesize = coded_framesize = get_be32(pb); 
        get_be32(pb); 
        get_be32(pb); 
        get_be32(pb); 
        rm->sub_packet_h = sub_packet_h = get_be16(pb); 
        st->codec->block_align= get_be16(pb); 
        rm->sub_packet_size = sub_packet_size = get_be16(pb); 
        get_be16(pb); 
        if (((version >> 16) & 0xff) == 5) {
            get_be16(pb); get_be16(pb); get_be16(pb); }
        st->codec->sample_rate = get_be16(pb);
        get_be32(pb);
        st->codec->channels = get_be16(pb);
        if (((version >> 16) & 0xff) == 5) {
            get_be32(pb);
            buf[0] = get_byte(pb);
            buf[1] = get_byte(pb);
            buf[2] = get_byte(pb);
            buf[3] = get_byte(pb);
            buf[4] = 0;
        } else {
        get_str8(pb, buf, sizeof(buf)); 
        get_str8(pb, buf, sizeof(buf)); 
        st->codec->codec_type = CODEC_TYPE_AUDIO;
        if (!strcmp(buf, "dnet")) {
            st->codec->codec_id = CODEC_ID_AC3;
        } else if (!strcmp(buf, "28_8")) {
            st->codec->codec_id = CODEC_ID_RA_288;
            st->codec->extradata_size= 0;
            rm->audio_framesize = st->codec->block_align;
            st->codec->block_align = coded_framesize;
            rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
        } else if (!strcmp(buf, "cook")) {
            int codecdata_length, i;
            get_be16(pb); get_byte(pb);
            if (((version >> 16) & 0xff) == 5)
                get_byte(pb);
            codecdata_length = get_be32(pb);
            if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
                av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
            st->codec->codec_id = CODEC_ID_COOK;
            st->codec->extradata_size= codecdata_length;
            st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
            for(i = 0; i < codecdata_length; i++)
                ((uint8_t*)st->codec->extradata)[i] = get_byte(pb);
            rm->audio_framesize = st->codec->block_align;
            st->codec->block_align = rm->sub_packet_size;
            rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h);
        } else {
            st->codec->codec_id = CODEC_ID_NONE;
            pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name),
                    buf);
        if (read_all) {
            get_byte(pb);
            get_byte(pb);
            get_byte(pb);
            get_str8(pb, s->title, sizeof(s->title));
            get_str8(pb, s->author, sizeof(s->author));
            get_str8(pb, s->copyright, sizeof(s->copyright));
            get_str8(pb, s->comment, sizeof(s->comment));
static void FUNC_0(AVFormatContext *VAR_0, AVStream *VAR_1,
                                      int VAR_2)
{
    RMContext *rm = VAR_0->priv_data;
    ByteIOContext *pb = &VAR_0->pb;
    char VAR_3[256];
    uint32_t version;
    int VAR_10;
    
    version = get_be32(pb); 
    if (((version >> 16) & 0xff) == 3) {
        int64_t startpos = url_ftell(pb);
        
        for(VAR_10 = 0; VAR_10 < 14; VAR_10++)
            get_byte(pb);
        get_str8(pb, VAR_0->title, sizeof(VAR_0->title));
        get_str8(pb, VAR_0->author, sizeof(VAR_0->author));
        get_str8(pb, VAR_0->copyright, sizeof(VAR_0->copyright));
        get_str8(pb, VAR_0->comment, sizeof(VAR_0->comment));
        if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) {
        
        get_byte(pb);
        get_str8(pb, VAR_3, sizeof(VAR_3));
        
        if ((startpos + (version & 0xffff)) > url_ftell(pb))
            url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb));
        VAR_1->codec->sample_rate = 8000;
        VAR_1->codec->channels = 1;
        VAR_1->codec->codec_type = CODEC_TYPE_AUDIO;
        VAR_1->codec->codec_id = CODEC_ID_RA_144;
    } else {
        int VAR_5, VAR_6, VAR_7, VAR_8;
        
        get_be32(pb); 
        get_be32(pb); 
        get_be16(pb); 
        get_be32(pb); 
        VAR_5= get_be16(pb); 
        rm->VAR_7 = VAR_7 = get_be32(pb); 
        get_be32(pb); 
        get_be32(pb); 
        get_be32(pb); 
        rm->VAR_6 = VAR_6 = get_be16(pb); 
        VAR_1->codec->block_align= get_be16(pb); 
        rm->VAR_8 = VAR_8 = get_be16(pb); 
        get_be16(pb); 
        if (((version >> 16) & 0xff) == 5) {
            get_be16(pb); get_be16(pb); get_be16(pb); }
        VAR_1->codec->sample_rate = get_be16(pb);
        get_be32(pb);
        VAR_1->codec->channels = get_be16(pb);
        if (((version >> 16) & 0xff) == 5) {
            get_be32(pb);
            VAR_3[0] = get_byte(pb);
            VAR_3[1] = get_byte(pb);
            VAR_3[2] = get_byte(pb);
            VAR_3[3] = get_byte(pb);
            VAR_3[4] = 0;
        } else {
        get_str8(pb, VAR_3, sizeof(VAR_3)); 
        get_str8(pb, VAR_3, sizeof(VAR_3)); 
        VAR_1->codec->codec_type = CODEC_TYPE_AUDIO;
        if (!strcmp(VAR_3, "dnet")) {
            VAR_1->codec->codec_id = CODEC_ID_AC3;
        } else if (!strcmp(VAR_3, "28_8")) {
            VAR_1->codec->codec_id = CODEC_ID_RA_288;
            VAR_1->codec->extradata_size= 0;
            rm->audio_framesize = VAR_1->codec->block_align;
            VAR_1->codec->block_align = VAR_7;
            rm->audiobuf = av_malloc(rm->audio_framesize * VAR_6);
        } else if (!strcmp(VAR_3, "cook")) {
            int VAR_9, VAR_10;
            get_be16(pb); get_byte(pb);
            if (((version >> 16) & 0xff) == 5)
                get_byte(pb);
            VAR_9 = get_be32(pb);
            if(VAR_9 + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)VAR_9){
                av_log(VAR_0, AV_LOG_ERROR, "VAR_9 too large\n");
            VAR_1->codec->codec_id = CODEC_ID_COOK;
            VAR_1->codec->extradata_size= VAR_9;
            VAR_1->codec->extradata= av_mallocz(VAR_1->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
            for(VAR_10 = 0; VAR_10 < VAR_9; VAR_10++)
                ((uint8_t*)VAR_1->codec->extradata)[VAR_10] = get_byte(pb);
            rm->audio_framesize = VAR_1->codec->block_align;
            VAR_1->codec->block_align = rm->VAR_8;
            rm->audiobuf = av_malloc(rm->audio_framesize * VAR_6);
        } else {
            VAR_1->codec->codec_id = CODEC_ID_NONE;
            pstrcpy(VAR_1->codec->codec_name, sizeof(VAR_1->codec->codec_name),
                    VAR_3);
        if (VAR_2) {
            get_byte(pb);
            get_byte(pb);
            get_byte(pb);
            get_str8(pb, VAR_0->title, sizeof(VAR_0->title));
            get_str8(pb, VAR_0->author, sizeof(VAR_0->author));
            get_str8(pb, VAR_0->copyright, sizeof(VAR_0->copyright));
            get_str8(pb, VAR_0->comment, sizeof(VAR_0->comment));
static void FUNC_0(AVFormatContext *VAR_0, AVStream *VAR_1,
int VAR_2)
{ RMContext *rm = VAR_0->priv_data; ByteIOContext *pb = &VAR_0->pb; char VAR_3[256]; uint32_t version; int VAR_10; version = get_be32(pb); if (((version >> 16) & 0xff) == 3) { int64_t startpos = url_ftell(pb); for(VAR_10 = 0; VAR_10 < 14; VAR_10++) get_byte(pb); get_str8(pb, VAR_0->title, sizeof(VAR_0->title)); get_str8(pb, VAR_0->author, sizeof(VAR_0->author)); get_str8(pb, VAR_0->copyright, sizeof(VAR_0->copyright)); get_str8(pb, VAR_0->comment, sizeof(VAR_0->comment)); if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) { get_byte(pb); get_str8(pb, VAR_3, sizeof(VAR_3)); if ((startpos + (version & 0xffff)) > url_ftell(pb))
url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb)); VAR_1->codec->sample_rate = 8000; VAR_1->codec->channels = 1; VAR_1->codec->codec_type = CODEC_TYPE_AUDIO; VAR_1->codec->codec_id = CODEC_ID_RA_144; } else { int VAR_5, VAR_6, VAR_7, VAR_8; get_be32(pb); get_be32(pb); get_be16(pb); get_be32(pb); VAR_5= get_be16(pb); rm->VAR_7 = VAR_7 = get_be32(pb); get_be32(pb); get_be32(pb); get_be32(pb); rm->VAR_6 = VAR_6 = get_be16(pb); VAR_1->codec->block_align= get_be16(pb); rm->VAR_8 = VAR_8 = get_be16(pb); get_be16(pb); if (((version >> 16) & 0xff) == 5) { get_be16(pb); get_be16(pb); get_be16(pb); } VAR_1->codec->sample_rate = get_be16(pb); get_be32(pb); VAR_1->codec->channels = get_be16(pb); if (((version >> 16) & 0xff) == 5) { get_be32(pb); VAR_3[0] = get_byte(pb); VAR_3[1] = get_byte(pb); VAR_3[2] = get_byte(pb); VAR_3[3] = get_byte(pb); VAR_3[4] = 0; } else { get_str8(pb, VAR_3, sizeof(VAR_3)); get_str8(pb, VAR_3, sizeof(VAR_3)); VAR_1->codec->codec_type = CODEC_TYPE_AUDIO; if (!strcmp(VAR_3, "dnet")) { VAR_1->codec->codec_id = CODEC_ID_AC3; } else if (!strcmp(VAR_3, "28_8")) { VAR_1->codec->codec_id = CODEC_ID_RA_288; VAR_1->codec->extradata_size= 0; rm->audio_framesize = VAR_1->codec->block_align; VAR_1->codec->block_align = VAR_7; rm->audiobuf = av_malloc(rm->audio_framesize * VAR_6); } else if (!strcmp(VAR_3, "cook")) { int VAR_9, VAR_10; get_be16(pb); get_byte(pb); if (((version >> 16) & 0xff) == 5)
get_byte(pb); VAR_9 = get_be32(pb); if(VAR_9 + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)VAR_9){ av_log(VAR_0, AV_LOG_ERROR, "VAR_9 too large\n"); VAR_1->codec->codec_id = CODEC_ID_COOK; VAR_1->codec->extradata_size= VAR_9; VAR_1->codec->extradata= av_mallocz(VAR_1->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); for(VAR_10 = 0; VAR_10 < VAR_9; VAR_10++) ((uint8_t*)VAR_1->codec->extradata)[VAR_10] = get_byte(pb); rm->audio_framesize = VAR_1->codec->block_align; VAR_1->codec->block_align = rm->VAR_8; rm->audiobuf = av_malloc(rm->audio_framesize * VAR_6); } else { VAR_1->codec->codec_id = CODEC_ID_NONE; pstrcpy(VAR_1->codec->codec_name, sizeof(VAR_1->codec->codec_name),
VAR_3); if (VAR_2) { get_byte(pb); get_byte(pb); get_byte(pb); get_str8(pb, VAR_0->title, sizeof(VAR_0->title)); get_str8(pb, VAR_0->author, sizeof(VAR_0->author)); get_str8(pb, VAR_0->copyright, sizeof(VAR_0->copyright)); get_str8(pb, VAR_0->comment, sizeof(VAR_0->comment));