int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)

{

    AVStream *st;

    MOVStreamContext *sc;

    int j, pseudo_stream_id;



    if (c->fc->nb_streams < 1)

        return 0;

    st = c->fc->streams[c->fc->nb_streams-1];

    sc = st->priv_data;



    for (pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) {

        //Parsing Sample description table

        enum AVCodecID id;

        int dref_id = 1;

        MOVAtom a = { AV_RL32("stsd") };

        int64_t start_pos = avio_tell(pb);

        int size = avio_rb32(pb); /* size */

        uint32_t format = avio_rl32(pb); /* data format */



        if (size >= 16) {

            avio_rb32(pb); /* reserved */

            avio_rb16(pb); /* reserved */

            dref_id = avio_rb16(pb);

        }



        if (st->codec->codec_tag &&

            st->codec->codec_tag != format &&

            (c->fc->video_codec_id ? ff_codec_get_id(ff_codec_movvideo_tags, format) != c->fc->video_codec_id

                                   : st->codec->codec_tag != MKTAG('j','p','e','g'))

           ){

            /* Multiple fourcc, we skip JPEG. This is not correct, we should

             * export it as a separate AVStream but this needs a few changes

             * in the MOV demuxer, patch welcome. */

        multiple_stsd:

            av_log(c->fc, AV_LOG_WARNING, "multiple fourcc not supported\n");

            avio_skip(pb, size - (avio_tell(pb) - start_pos));

            continue;

        }

        /* we cannot demux concatenated h264 streams because of different extradata */

        if (st->codec->codec_tag && st->codec->codec_tag == AV_RL32("avc1"))

            goto multiple_stsd;

        sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id;

        sc->dref_id= dref_id;



        st->codec->codec_tag = format;

        id = ff_codec_get_id(ff_codec_movaudio_tags, format);

        if (id<=0 && ((format&0xFFFF) == 'm'+('s'<<8) || (format&0xFFFF) == 'T'+('S'<<8)))

            id = ff_codec_get_id(ff_codec_wav_tags, av_bswap32(format)&0xFFFF);



        if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) {

            st->codec->codec_type = AVMEDIA_TYPE_AUDIO;

        } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO && /* do not overwrite codec type */

                   format && format != MKTAG('m','p','4','s')) { /* skip old asf mpeg4 tag */

            id = ff_codec_get_id(ff_codec_movvideo_tags, format);

            if (id <= 0)

                id = ff_codec_get_id(ff_codec_bmp_tags, format);

            if (id > 0)

                st->codec->codec_type = AVMEDIA_TYPE_VIDEO;

            else if (st->codec->codec_type == AVMEDIA_TYPE_DATA){

                id = ff_codec_get_id(ff_codec_movsubtitle_tags, format);

                if (id > 0)

                    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

            }

        }



        av_dlog(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size,

                (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,

                (format >> 24) & 0xff, st->codec->codec_type);



        if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {

            unsigned int color_depth, len;

            int color_greyscale;

            int color_table_id;



            st->codec->codec_id = id;

            avio_rb16(pb); /* version */

            avio_rb16(pb); /* revision level */

            avio_rb32(pb); /* vendor */

            avio_rb32(pb); /* temporal quality */

            avio_rb32(pb); /* spatial quality */



            st->codec->width = avio_rb16(pb); /* width */

            st->codec->height = avio_rb16(pb); /* height */



            avio_rb32(pb); /* horiz resolution */

            avio_rb32(pb); /* vert resolution */

            avio_rb32(pb); /* data size, always 0 */

            avio_rb16(pb); /* frames per samples */



            len = avio_r8(pb); /* codec name, pascal string */

            if (len > 31)

                len = 31;

            mov_read_mac_string(c, pb, len, st->codec->codec_name, 32);

            if (len < 31)

                avio_skip(pb, 31 - len);

            /* codec_tag YV12 triggers an UV swap in rawdec.c */

            if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))

                st->codec->codec_tag=MKTAG('I', '4', '2', '0');



            st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */

            color_table_id = avio_rb16(pb); /* colortable id */

            av_dlog(c->fc, "depth %d, ctab id %d\n",

                   st->codec->bits_per_coded_sample, color_table_id);

            /* figure out the palette situation */

            color_depth = st->codec->bits_per_coded_sample & 0x1F;

            color_greyscale = st->codec->bits_per_coded_sample & 0x20;



            /* if the depth is 2, 4, or 8 bpp, file is palettized */

            if ((color_depth == 2) || (color_depth == 4) ||

                (color_depth == 8)) {

                /* for palette traversal */

                unsigned int color_start, color_count, color_end;

                unsigned char r, g, b;



                if (color_greyscale) {

                    int color_index, color_dec;

                    /* compute the greyscale palette */

                    st->codec->bits_per_coded_sample = color_depth;

                    color_count = 1 << color_depth;

                    color_index = 255;

                    color_dec = 256 / (color_count - 1);

                    for (j = 0; j < color_count; j++) {

                        r = g = b = color_index;

                        sc->palette[j] =

                            (r << 16) | (g << 8) | (b);

                        color_index -= color_dec;

                        if (color_index < 0)

                            color_index = 0;

                    }

                } else if (color_table_id) {

                    const uint8_t *color_table;

                    /* if flag bit 3 is set, use the default palette */

                    color_count = 1 << color_depth;

                    if (color_depth == 2)

                        color_table = ff_qt_default_palette_4;

                    else if (color_depth == 4)

                        color_table = ff_qt_default_palette_16;

                    else

                        color_table = ff_qt_default_palette_256;



                    for (j = 0; j < color_count; j++) {

                        r = color_table[j * 3 + 0];

                        g = color_table[j * 3 + 1];

                        b = color_table[j * 3 + 2];

                        sc->palette[j] =

                            (r << 16) | (g << 8) | (b);

                    }

                } else {

                    /* load the palette from the file */

                    color_start = avio_rb32(pb);

                    color_count = avio_rb16(pb);

                    color_end = avio_rb16(pb);

                    if ((color_start <= 255) &&

                        (color_end <= 255)) {

                        for (j = color_start; j <= color_end; j++) {

                            /* each R, G, or B component is 16 bits;

                             * only use the top 8 bits; skip alpha bytes

                             * up front */

                            avio_r8(pb);

                            avio_r8(pb);

                            r = avio_r8(pb);

                            avio_r8(pb);

                            g = avio_r8(pb);

                            avio_r8(pb);

                            b = avio_r8(pb);

                            avio_r8(pb);

                            sc->palette[j] =

                                (r << 16) | (g << 8) | (b);

                        }

                    }

                }

                sc->has_palette = 1;

            }

        } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) {

            int bits_per_sample, flags;

            uint16_t version = avio_rb16(pb);



            st->codec->codec_id = id;

            avio_rb16(pb); /* revision level */

            avio_rb32(pb); /* vendor */



            st->codec->channels = avio_rb16(pb);             /* channel count */

            av_dlog(c->fc, "audio channels %d\n", st->codec->channels);

            st->codec->bits_per_coded_sample = avio_rb16(pb);      /* sample size */



            sc->audio_cid = avio_rb16(pb);

            avio_rb16(pb); /* packet size = 0 */



            st->codec->sample_rate = ((avio_rb32(pb) >> 16));



            //Read QT version 1 fields. In version 0 these do not exist.

            av_dlog(c->fc, "version =%d, isom =%d\n",version,c->isom);

            if (!c->isom) {

                if (version==1) {

                    sc->samples_per_frame = avio_rb32(pb);

                    avio_rb32(pb); /* bytes per packet */

                    sc->bytes_per_frame = avio_rb32(pb);

                    avio_rb32(pb); /* bytes per sample */

                } else if (version==2) {

                    avio_rb32(pb); /* sizeof struct only */

                    st->codec->sample_rate = av_int2double(avio_rb64(pb)); /* float 64 */

                    st->codec->channels = avio_rb32(pb);

                    avio_rb32(pb); /* always 0x7F000000 */

                    st->codec->bits_per_coded_sample = avio_rb32(pb); /* bits per channel if sound is uncompressed */

                    flags = avio_rb32(pb); /* lpcm format specific flag */

                    sc->bytes_per_frame = avio_rb32(pb); /* bytes per audio packet if constant */

                    sc->samples_per_frame = avio_rb32(pb); /* lpcm frames per audio packet if constant */

                    if (format == MKTAG('l','p','c','m'))

                        st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags);

                }

            }



            switch (st->codec->codec_id) {

            case AV_CODEC_ID_PCM_S8:

            case AV_CODEC_ID_PCM_U8:

                if (st->codec->bits_per_coded_sample == 16)

                    st->codec->codec_id = AV_CODEC_ID_PCM_S16BE;

                break;

            case AV_CODEC_ID_PCM_S16LE:

            case AV_CODEC_ID_PCM_S16BE:

                if (st->codec->bits_per_coded_sample == 8)

                    st->codec->codec_id = AV_CODEC_ID_PCM_S8;

                else if (st->codec->bits_per_coded_sample == 24)

                    st->codec->codec_id =

                        st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ?

                        AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE;

                break;

            /* set values for old format before stsd version 1 appeared */

            case AV_CODEC_ID_MACE3:

                sc->samples_per_frame = 6;

                sc->bytes_per_frame = 2*st->codec->channels;

                break;

            case AV_CODEC_ID_MACE6:

                sc->samples_per_frame = 6;

                sc->bytes_per_frame = 1*st->codec->channels;

                break;

            case AV_CODEC_ID_ADPCM_IMA_QT:

                sc->samples_per_frame = 64;

                sc->bytes_per_frame = 34*st->codec->channels;

                break;

            case AV_CODEC_ID_GSM:

                sc->samples_per_frame = 160;

                sc->bytes_per_frame = 33;

                break;

            default:

                break;

            }



            bits_per_sample = av_get_bits_per_sample(st->codec->codec_id);

            if (bits_per_sample) {

                st->codec->bits_per_coded_sample = bits_per_sample;

                sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;

            }

        } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){

            // ttxt stsd contains display flags, justification, background

            // color, fonts, and default styles, so fake an atom to read it

            MOVAtom fake_atom = { .size = size - (avio_tell(pb) - start_pos) };

            if (format != AV_RL32("mp4s")) // mp4s contains a regular esds atom

                mov_read_glbl(c, pb, fake_atom);

            st->codec->codec_id= id;

            st->codec->width = sc->width;

            st->codec->height = sc->height;

        } else {

            /* other codec type, just skip (rtp, mp4s, tmcd ...) */

            avio_skip(pb, size - (avio_tell(pb) - start_pos));

        }

        /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */

        a.size = size - (avio_tell(pb) - start_pos);

        if (a.size > 8) {

            int ret;

            if ((ret = mov_read_default(c, pb, a)) < 0)

                return ret;

        } else if (a.size > 0)

            avio_skip(pb, a.size);

    }



    if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1)

        st->codec->sample_rate= sc->time_scale;



    /* special codec parameters handling */

    switch (st->codec->codec_id) {

#if CONFIG_DV_DEMUXER

    case AV_CODEC_ID_DVAUDIO:

        c->dv_fctx = avformat_alloc_context();

        c->dv_demux = avpriv_dv_init_demux(c->dv_fctx);

        if (!c->dv_demux) {

            av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n");

            return AVERROR(ENOMEM);

        }

        sc->dv_audio_container = 1;

        st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;

        break;

#endif

    /* no ifdef since parameters are always those */

    case AV_CODEC_ID_QCELP:

        // force sample rate for qcelp when not stored in mov

        if (st->codec->codec_tag != MKTAG('Q','c','l','p'))

            st->codec->sample_rate = 8000;

        st->codec->channels= 1; /* really needed */

        break;

    case AV_CODEC_ID_AMR_NB:

        st->codec->channels= 1; /* really needed */

        /* force sample rate for amr, stsd in 3gp does not store sample rate */

        st->codec->sample_rate = 8000;

        break;

    case AV_CODEC_ID_AMR_WB:

        st->codec->channels    = 1;

        st->codec->sample_rate = 16000;

        break;

    case AV_CODEC_ID_MP2:

    case AV_CODEC_ID_MP3:

        st->codec->codec_type = AVMEDIA_TYPE_AUDIO; /* force type after stsd for m1a hdlr */

        st->need_parsing = AVSTREAM_PARSE_FULL;

        break;

    case AV_CODEC_ID_GSM:

    case AV_CODEC_ID_ADPCM_MS:

    case AV_CODEC_ID_ADPCM_IMA_WAV:

    case AV_CODEC_ID_ILBC:

        st->codec->block_align = sc->bytes_per_frame;

        break;

    case AV_CODEC_ID_ALAC:

        if (st->codec->extradata_size == 36) {

            st->codec->channels   = AV_RB8 (st->codec->extradata+21);

            st->codec->sample_rate = AV_RB32(st->codec->extradata+32);

        }

        break;

    case AV_CODEC_ID_VC1:

        st->need_parsing = AVSTREAM_PARSE_FULL;

        break;

    default:

        break;

    }



    return 0;

}

int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)

{

    AVStream *st;

    MOVStreamContext *sc;

    int j, pseudo_stream_id;



    if (c->fc->nb_streams < 1)

        return 0;

    st = c->fc->streams[c->fc->nb_streams-1];

    sc = st->priv_data;



    for (pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) {

        

        enum AVCodecID id;

        int dref_id = 1;

        MOVAtom a = { AV_RL32("stsd") };

        int64_t start_pos = avio_tell(pb);

        int size = avio_rb32(pb); 

        uint32_t format = avio_rl32(pb); 



        if (size >= 16) {

            avio_rb32(pb); 

            avio_rb16(pb); 

            dref_id = avio_rb16(pb);

        }



        if (st->codec->codec_tag &&

            st->codec->codec_tag != format &&

            (c->fc->video_codec_id ? ff_codec_get_id(ff_codec_movvideo_tags, format) != c->fc->video_codec_id

                                   : st->codec->codec_tag != MKTAG('j','p','e','g'))

           ){

            





        multiple_stsd:

            av_log(c->fc, AV_LOG_WARNING, "multiple fourcc not supported\n");

            avio_skip(pb, size - (avio_tell(pb) - start_pos));

            continue;

        }

        

        if (st->codec->codec_tag && st->codec->codec_tag == AV_RL32("avc1"))

            goto multiple_stsd;

        sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id;

        sc->dref_id= dref_id;



        st->codec->codec_tag = format;

        id = ff_codec_get_id(ff_codec_movaudio_tags, format);

        if (id<=0 && ((format&0xFFFF) == 'm'+('s'<<8) || (format&0xFFFF) == 'T'+('S'<<8)))

            id = ff_codec_get_id(ff_codec_wav_tags, av_bswap32(format)&0xFFFF);



        if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) {

            st->codec->codec_type = AVMEDIA_TYPE_AUDIO;

        } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO && 

                   format && format != MKTAG('m','p','4','s')) { 

            id = ff_codec_get_id(ff_codec_movvideo_tags, format);

            if (id <= 0)

                id = ff_codec_get_id(ff_codec_bmp_tags, format);

            if (id > 0)

                st->codec->codec_type = AVMEDIA_TYPE_VIDEO;

            else if (st->codec->codec_type == AVMEDIA_TYPE_DATA){

                id = ff_codec_get_id(ff_codec_movsubtitle_tags, format);

                if (id > 0)

                    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

            }

        }



        av_dlog(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size,

                (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,

                (format >> 24) & 0xff, st->codec->codec_type);



        if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {

            unsigned int color_depth, len;

            int color_greyscale;

            int color_table_id;



            st->codec->codec_id = id;

            avio_rb16(pb); 

            avio_rb16(pb); 

            avio_rb32(pb); 

            avio_rb32(pb); 

            avio_rb32(pb); 



            st->codec->width = avio_rb16(pb); 

            st->codec->height = avio_rb16(pb); 



            avio_rb32(pb); 

            avio_rb32(pb); 

            avio_rb32(pb); 

            avio_rb16(pb); 



            len = avio_r8(pb); 

            if (len > 31)

                len = 31;

            mov_read_mac_string(c, pb, len, st->codec->codec_name, 32);

            if (len < 31)

                avio_skip(pb, 31 - len);

            

            if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))

                st->codec->codec_tag=MKTAG('I', '4', '2', '0');



            st->codec->bits_per_coded_sample = avio_rb16(pb); 

            color_table_id = avio_rb16(pb); 

            av_dlog(c->fc, "depth %d, ctab id %d\n",

                   st->codec->bits_per_coded_sample, color_table_id);

            

            color_depth = st->codec->bits_per_coded_sample & 0x1F;

            color_greyscale = st->codec->bits_per_coded_sample & 0x20;



            

            if ((color_depth == 2) || (color_depth == 4) ||

                (color_depth == 8)) {

                

                unsigned int color_start, color_count, color_end;

                unsigned char r, g, b;



                if (color_greyscale) {

                    int color_index, color_dec;

                    

                    st->codec->bits_per_coded_sample = color_depth;

                    color_count = 1 << color_depth;

                    color_index = 255;

                    color_dec = 256 / (color_count - 1);

                    for (j = 0; j < color_count; j++) {

                        r = g = b = color_index;

                        sc->palette[j] =

                            (r << 16) | (g << 8) | (b);

                        color_index -= color_dec;

                        if (color_index < 0)

                            color_index = 0;

                    }

                } else if (color_table_id) {

                    const uint8_t *color_table;

                    

                    color_count = 1 << color_depth;

                    if (color_depth == 2)

                        color_table = ff_qt_default_palette_4;

                    else if (color_depth == 4)

                        color_table = ff_qt_default_palette_16;

                    else

                        color_table = ff_qt_default_palette_256;



                    for (j = 0; j < color_count; j++) {

                        r = color_table[j * 3 + 0];

                        g = color_table[j * 3 + 1];

                        b = color_table[j * 3 + 2];

                        sc->palette[j] =

                            (r << 16) | (g << 8) | (b);

                    }

                } else {

                    

                    color_start = avio_rb32(pb);

                    color_count = avio_rb16(pb);

                    color_end = avio_rb16(pb);

                    if ((color_start <= 255) &&

                        (color_end <= 255)) {

                        for (j = color_start; j <= color_end; j++) {

                            





                            avio_r8(pb);

                            avio_r8(pb);

                            r = avio_r8(pb);

                            avio_r8(pb);

                            g = avio_r8(pb);

                            avio_r8(pb);

                            b = avio_r8(pb);

                            avio_r8(pb);

                            sc->palette[j] =

                                (r << 16) | (g << 8) | (b);

                        }

                    }

                }

                sc->has_palette = 1;

            }

        } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) {

            int bits_per_sample, flags;

            uint16_t version = avio_rb16(pb);



            st->codec->codec_id = id;

            avio_rb16(pb); 

            avio_rb32(pb); 



            st->codec->channels = avio_rb16(pb);             

            av_dlog(c->fc, "audio channels %d\n", st->codec->channels);

            st->codec->bits_per_coded_sample = avio_rb16(pb);      



            sc->audio_cid = avio_rb16(pb);

            avio_rb16(pb); 



            st->codec->sample_rate = ((avio_rb32(pb) >> 16));



            

            av_dlog(c->fc, "version =%d, isom =%d\n",version,c->isom);

            if (!c->isom) {

                if (version==1) {

                    sc->samples_per_frame = avio_rb32(pb);

                    avio_rb32(pb); 

                    sc->bytes_per_frame = avio_rb32(pb);

                    avio_rb32(pb); 

                } else if (version==2) {

                    avio_rb32(pb); 

                    st->codec->sample_rate = av_int2double(avio_rb64(pb)); 

                    st->codec->channels = avio_rb32(pb);

                    avio_rb32(pb); 

                    st->codec->bits_per_coded_sample = avio_rb32(pb); 

                    flags = avio_rb32(pb); 

                    sc->bytes_per_frame = avio_rb32(pb); 

                    sc->samples_per_frame = avio_rb32(pb); 

                    if (format == MKTAG('l','p','c','m'))

                        st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags);

                }

            }



            switch (st->codec->codec_id) {

            case AV_CODEC_ID_PCM_S8:

            case AV_CODEC_ID_PCM_U8:

                if (st->codec->bits_per_coded_sample == 16)

                    st->codec->codec_id = AV_CODEC_ID_PCM_S16BE;

                break;

            case AV_CODEC_ID_PCM_S16LE:

            case AV_CODEC_ID_PCM_S16BE:

                if (st->codec->bits_per_coded_sample == 8)

                    st->codec->codec_id = AV_CODEC_ID_PCM_S8;

                else if (st->codec->bits_per_coded_sample == 24)

                    st->codec->codec_id =

                        st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ?

                        AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE;

                break;

            

            case AV_CODEC_ID_MACE3:

                sc->samples_per_frame = 6;

                sc->bytes_per_frame = 2*st->codec->channels;

                break;

            case AV_CODEC_ID_MACE6:

                sc->samples_per_frame = 6;

                sc->bytes_per_frame = 1*st->codec->channels;

                break;

            case AV_CODEC_ID_ADPCM_IMA_QT:

                sc->samples_per_frame = 64;

                sc->bytes_per_frame = 34*st->codec->channels;

                break;

            case AV_CODEC_ID_GSM:

                sc->samples_per_frame = 160;

                sc->bytes_per_frame = 33;

                break;

            default:

                break;

            }



            bits_per_sample = av_get_bits_per_sample(st->codec->codec_id);

            if (bits_per_sample) {

                st->codec->bits_per_coded_sample = bits_per_sample;

                sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;

            }

        } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){

            

            

            MOVAtom fake_atom = { .size = size - (avio_tell(pb) - start_pos) };

            if (format != AV_RL32("mp4s")) 

                mov_read_glbl(c, pb, fake_atom);

            st->codec->codec_id= id;

            st->codec->width = sc->width;

            st->codec->height = sc->height;

        } else {

            

            avio_skip(pb, size - (avio_tell(pb) - start_pos));

        }

        

        a.size = size - (avio_tell(pb) - start_pos);

        if (a.size > 8) {

            int ret;

            if ((ret = mov_read_default(c, pb, a)) < 0)

                return ret;

        } else if (a.size > 0)

            avio_skip(pb, a.size);

    }



    if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1)

        st->codec->sample_rate= sc->time_scale;



    

    switch (st->codec->codec_id) {

#if CONFIG_DV_DEMUXER

    case AV_CODEC_ID_DVAUDIO:

        c->dv_fctx = avformat_alloc_context();

        c->dv_demux = avpriv_dv_init_demux(c->dv_fctx);

        if (!c->dv_demux) {

            av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n");

            return AVERROR(ENOMEM);

        }

        sc->dv_audio_container = 1;

        st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;

        break;

#endif

    

    case AV_CODEC_ID_QCELP:

        

        if (st->codec->codec_tag != MKTAG('Q','c','l','p'))

            st->codec->sample_rate = 8000;

        st->codec->channels= 1; 

        break;

    case AV_CODEC_ID_AMR_NB:

        st->codec->channels= 1; 

        

        st->codec->sample_rate = 8000;

        break;

    case AV_CODEC_ID_AMR_WB:

        st->codec->channels    = 1;

        st->codec->sample_rate = 16000;

        break;

    case AV_CODEC_ID_MP2:

    case AV_CODEC_ID_MP3:

        st->codec->codec_type = AVMEDIA_TYPE_AUDIO; 

        st->need_parsing = AVSTREAM_PARSE_FULL;

        break;

    case AV_CODEC_ID_GSM:

    case AV_CODEC_ID_ADPCM_MS:

    case AV_CODEC_ID_ADPCM_IMA_WAV:

    case AV_CODEC_ID_ILBC:

        st->codec->block_align = sc->bytes_per_frame;

        break;

    case AV_CODEC_ID_ALAC:

        if (st->codec->extradata_size == 36) {

            st->codec->channels   = AV_RB8 (st->codec->extradata+21);

            st->codec->sample_rate = AV_RB32(st->codec->extradata+32);

        }

        break;

    case AV_CODEC_ID_VC1:

        st->need_parsing = AVSTREAM_PARSE_FULL;

        break;

    default:

        break;

    }



    return 0;

}

int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, int VAR_2)

{

    AVStream *st;

    MOVStreamContext *sc;

    int VAR_3, VAR_4;



    if (VAR_0->fc->nb_streams < 1)

        return 0;

    st = VAR_0->fc->streams[VAR_0->fc->nb_streams-1];

    sc = st->priv_data;



    for (VAR_4=0; VAR_4<VAR_2; VAR_4++) {

        

        enum AVCodecID VAR_5;

        int VAR_6 = 1;

        MOVAtom a = { AV_RL32("stsd") };

        int64_t start_pos = avio_tell(VAR_1);

        int VAR_7 = avio_rb32(VAR_1); 

        uint32_t format = avio_rl32(VAR_1); 



        if (VAR_7 >= 16) {

            avio_rb32(VAR_1); 

            avio_rb16(VAR_1); 

            VAR_6 = avio_rb16(VAR_1);

        }



        if (st->codec->codec_tag &&

            st->codec->codec_tag != format &&

            (VAR_0->fc->video_codec_id ? ff_codec_get_id(ff_codec_movvideo_tags, format) != VAR_0->fc->video_codec_id

                                   : st->codec->codec_tag != MKTAG('VAR_3','p','e','VAR_16'))

           ){

            





        multiple_stsd:

            av_log(VAR_0->fc, AV_LOG_WARNING, "multiple fourcc not supported\n");

            avio_skip(VAR_1, VAR_7 - (avio_tell(VAR_1) - start_pos));

            continue;

        }

        

        if (st->codec->codec_tag && st->codec->codec_tag == AV_RL32("avc1"))

            goto multiple_stsd;

        sc->VAR_4 = st->codec->codec_tag ? -1 : VAR_4;

        sc->VAR_6= VAR_6;



        st->codec->codec_tag = format;

        VAR_5 = ff_codec_get_id(ff_codec_movaudio_tags, format);

        if (VAR_5<=0 && ((format&0xFFFF) == 'm'+('s'<<8) || (format&0xFFFF) == 'T'+('S'<<8)))

            VAR_5 = ff_codec_get_id(ff_codec_wav_tags, av_bswap32(format)&0xFFFF);



        if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && VAR_5 > 0) {

            st->codec->codec_type = AVMEDIA_TYPE_AUDIO;

        } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO && 

                   format && format != MKTAG('m','p','4','s')) { 

            VAR_5 = ff_codec_get_id(ff_codec_movvideo_tags, format);

            if (VAR_5 <= 0)

                VAR_5 = ff_codec_get_id(ff_codec_bmp_tags, format);

            if (VAR_5 > 0)

                st->codec->codec_type = AVMEDIA_TYPE_VIDEO;

            else if (st->codec->codec_type == AVMEDIA_TYPE_DATA){

                VAR_5 = ff_codec_get_id(ff_codec_movsubtitle_tags, format);

                if (VAR_5 > 0)

                    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

            }

        }



        av_dlog(VAR_0->fc, "VAR_7=%d 4CC= %VAR_0%VAR_0%VAR_0%VAR_0 codec_type=%d\n", VAR_7,

                (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,

                (format >> 24) & 0xff, st->codec->codec_type);



        if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {

            unsigned int VAR_8, VAR_9;

            int VAR_10;

            int VAR_11;



            st->codec->codec_id = VAR_5;

            avio_rb16(VAR_1); 

            avio_rb16(VAR_1); 

            avio_rb32(VAR_1); 

            avio_rb32(VAR_1); 

            avio_rb32(VAR_1); 



            st->codec->width = avio_rb16(VAR_1); 

            st->codec->height = avio_rb16(VAR_1); 



            avio_rb32(VAR_1); 

            avio_rb32(VAR_1); 

            avio_rb32(VAR_1); 

            avio_rb16(VAR_1); 



            VAR_9 = avio_r8(VAR_1); 

            if (VAR_9 > 31)

                VAR_9 = 31;

            mov_read_mac_string(VAR_0, VAR_1, VAR_9, st->codec->codec_name, 32);

            if (VAR_9 < 31)

                avio_skip(VAR_1, 31 - VAR_9);

            

            if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))

                st->codec->codec_tag=MKTAG('I', '4', '2', '0');



            st->codec->bits_per_coded_sample = avio_rb16(VAR_1); 

            VAR_11 = avio_rb16(VAR_1); 

            av_dlog(VAR_0->fc, "depth %d, ctab VAR_5 %d\n",

                   st->codec->bits_per_coded_sample, VAR_11);

            

            VAR_8 = st->codec->bits_per_coded_sample & 0x1F;

            VAR_10 = st->codec->bits_per_coded_sample & 0x20;



            

            if ((VAR_8 == 2) || (VAR_8 == 4) ||

                (VAR_8 == 8)) {

                

                unsigned int VAR_12, VAR_13, VAR_14;

                unsigned char VAR_15, VAR_16, VAR_17;



                if (VAR_10) {

                    int VAR_18, VAR_19;

                    

                    st->codec->bits_per_coded_sample = VAR_8;

                    VAR_13 = 1 << VAR_8;

                    VAR_18 = 255;

                    VAR_19 = 256 / (VAR_13 - 1);

                    for (VAR_3 = 0; VAR_3 < VAR_13; VAR_3++) {

                        VAR_15 = VAR_16 = VAR_17 = VAR_18;

                        sc->palette[VAR_3] =

                            (VAR_15 << 16) | (VAR_16 << 8) | (VAR_17);

                        VAR_18 -= VAR_19;

                        if (VAR_18 < 0)

                            VAR_18 = 0;

                    }

                } else if (VAR_11) {

                    const uint8_t *VAR_20;

                    

                    VAR_13 = 1 << VAR_8;

                    if (VAR_8 == 2)

                        VAR_20 = ff_qt_default_palette_4;

                    else if (VAR_8 == 4)

                        VAR_20 = ff_qt_default_palette_16;

                    else

                        VAR_20 = ff_qt_default_palette_256;



                    for (VAR_3 = 0; VAR_3 < VAR_13; VAR_3++) {

                        VAR_15 = VAR_20[VAR_3 * 3 + 0];

                        VAR_16 = VAR_20[VAR_3 * 3 + 1];

                        VAR_17 = VAR_20[VAR_3 * 3 + 2];

                        sc->palette[VAR_3] =

                            (VAR_15 << 16) | (VAR_16 << 8) | (VAR_17);

                    }

                } else {

                    

                    VAR_12 = avio_rb32(VAR_1);

                    VAR_13 = avio_rb16(VAR_1);

                    VAR_14 = avio_rb16(VAR_1);

                    if ((VAR_12 <= 255) &&

                        (VAR_14 <= 255)) {

                        for (VAR_3 = VAR_12; VAR_3 <= VAR_14; VAR_3++) {

                            





                            avio_r8(VAR_1);

                            avio_r8(VAR_1);

                            VAR_15 = avio_r8(VAR_1);

                            avio_r8(VAR_1);

                            VAR_16 = avio_r8(VAR_1);

                            avio_r8(VAR_1);

                            VAR_17 = avio_r8(VAR_1);

                            avio_r8(VAR_1);

                            sc->palette[VAR_3] =

                                (VAR_15 << 16) | (VAR_16 << 8) | (VAR_17);

                        }

                    }

                }

                sc->has_palette = 1;

            }

        } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) {

            int VAR_21, VAR_22;

            uint16_t version = avio_rb16(VAR_1);



            st->codec->codec_id = VAR_5;

            avio_rb16(VAR_1); 

            avio_rb32(VAR_1); 



            st->codec->channels = avio_rb16(VAR_1);             

            av_dlog(VAR_0->fc, "audio channels %d\n", st->codec->channels);

            st->codec->bits_per_coded_sample = avio_rb16(VAR_1);      



            sc->audio_cid = avio_rb16(VAR_1);

            avio_rb16(VAR_1); 



            st->codec->sample_rate = ((avio_rb32(VAR_1) >> 16));



            

            av_dlog(VAR_0->fc, "version =%d, isom =%d\n",version,VAR_0->isom);

            if (!VAR_0->isom) {

                if (version==1) {

                    sc->samples_per_frame = avio_rb32(VAR_1);

                    avio_rb32(VAR_1); 

                    sc->bytes_per_frame = avio_rb32(VAR_1);

                    avio_rb32(VAR_1); 

                } else if (version==2) {

                    avio_rb32(VAR_1); 

                    st->codec->sample_rate = av_int2double(avio_rb64(VAR_1)); 

                    st->codec->channels = avio_rb32(VAR_1);

                    avio_rb32(VAR_1); 

                    st->codec->bits_per_coded_sample = avio_rb32(VAR_1); 

                    VAR_22 = avio_rb32(VAR_1); 

                    sc->bytes_per_frame = avio_rb32(VAR_1); 

                    sc->samples_per_frame = avio_rb32(VAR_1); 

                    if (format == MKTAG('l','p','VAR_0','m'))

                        st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, VAR_22);

                }

            }



            switch (st->codec->codec_id) {

            case AV_CODEC_ID_PCM_S8:

            case AV_CODEC_ID_PCM_U8:

                if (st->codec->bits_per_coded_sample == 16)

                    st->codec->codec_id = AV_CODEC_ID_PCM_S16BE;

                break;

            case AV_CODEC_ID_PCM_S16LE:

            case AV_CODEC_ID_PCM_S16BE:

                if (st->codec->bits_per_coded_sample == 8)

                    st->codec->codec_id = AV_CODEC_ID_PCM_S8;

                else if (st->codec->bits_per_coded_sample == 24)

                    st->codec->codec_id =

                        st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ?

                        AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE;

                break;

            

            case AV_CODEC_ID_MACE3:

                sc->samples_per_frame = 6;

                sc->bytes_per_frame = 2*st->codec->channels;

                break;

            case AV_CODEC_ID_MACE6:

                sc->samples_per_frame = 6;

                sc->bytes_per_frame = 1*st->codec->channels;

                break;

            case AV_CODEC_ID_ADPCM_IMA_QT:

                sc->samples_per_frame = 64;

                sc->bytes_per_frame = 34*st->codec->channels;

                break;

            case AV_CODEC_ID_GSM:

                sc->samples_per_frame = 160;

                sc->bytes_per_frame = 33;

                break;

            default:

                break;

            }



            VAR_21 = av_get_bits_per_sample(st->codec->codec_id);

            if (VAR_21) {

                st->codec->bits_per_coded_sample = VAR_21;

                sc->sample_size = (VAR_21 >> 3) * st->codec->channels;

            }

        } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){

            

            

            MOVAtom fake_atom = { .VAR_7 = VAR_7 - (avio_tell(VAR_1) - start_pos) };

            if (format != AV_RL32("mp4s")) 

                mov_read_glbl(VAR_0, VAR_1, fake_atom);

            st->codec->codec_id= VAR_5;

            st->codec->width = sc->width;

            st->codec->height = sc->height;

        } else {

            

            avio_skip(VAR_1, VAR_7 - (avio_tell(VAR_1) - start_pos));

        }

        

        a.VAR_7 = VAR_7 - (avio_tell(VAR_1) - start_pos);

        if (a.VAR_7 > 8) {

            int VAR_23;

            if ((VAR_23 = mov_read_default(VAR_0, VAR_1, a)) < 0)

                return VAR_23;

        } else if (a.VAR_7 > 0)

            avio_skip(VAR_1, a.VAR_7);

    }



    if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1)

        st->codec->sample_rate= sc->time_scale;



    

    switch (st->codec->codec_id) {

#if CONFIG_DV_DEMUXER

    case AV_CODEC_ID_DVAUDIO:

        VAR_0->dv_fctx = avformat_alloc_context();

        VAR_0->dv_demux = avpriv_dv_init_demux(VAR_0->dv_fctx);

        if (!VAR_0->dv_demux) {

            av_log(VAR_0->fc, AV_LOG_ERROR, "dv demux context init error\n");

            return AVERROR(ENOMEM);

        }

        sc->dv_audio_container = 1;

        st->codec->codec_id = AV_CODEC_ID_PCM_S16LE;

        break;

#endif

    

    case AV_CODEC_ID_QCELP:

        

        if (st->codec->codec_tag != MKTAG('Q','VAR_0','l','p'))

            st->codec->sample_rate = 8000;

        st->codec->channels= 1; 

        break;

    case AV_CODEC_ID_AMR_NB:

        st->codec->channels= 1; 

        

        st->codec->sample_rate = 8000;

        break;

    case AV_CODEC_ID_AMR_WB:

        st->codec->channels    = 1;

        st->codec->sample_rate = 16000;

        break;

    case AV_CODEC_ID_MP2:

    case AV_CODEC_ID_MP3:

        st->codec->codec_type = AVMEDIA_TYPE_AUDIO; 

        st->need_parsing = AVSTREAM_PARSE_FULL;

        break;

    case AV_CODEC_ID_GSM:

    case AV_CODEC_ID_ADPCM_MS:

    case AV_CODEC_ID_ADPCM_IMA_WAV:

    case AV_CODEC_ID_ILBC:

        st->codec->block_align = sc->bytes_per_frame;

        break;

    case AV_CODEC_ID_ALAC:

        if (st->codec->extradata_size == 36) {

            st->codec->channels   = AV_RB8 (st->codec->extradata+21);

            st->codec->sample_rate = AV_RB32(st->codec->extradata+32);

        }

        break;

    case AV_CODEC_ID_VC1:

        st->need_parsing = AVSTREAM_PARSE_FULL;

        break;

    default:

        break;

    }



    return 0;

}

int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, int VAR_2)
{ AVStream *st; MOVStreamContext *sc; int VAR_3, VAR_4; if (VAR_0->fc->nb_streams < 1)
return 0; st = VAR_0->fc->streams[VAR_0->fc->nb_streams-1]; sc = st->priv_data; for (VAR_4=0; VAR_4<VAR_2; VAR_4++) { enum AVCodecID VAR_5; int VAR_6 = 1; MOVAtom a = { AV_RL32("stsd") }; int64_t start_pos = avio_tell(VAR_1); int VAR_7 = avio_rb32(VAR_1); uint32_t format = avio_rl32(VAR_1); if (VAR_7 >= 16) { avio_rb32(VAR_1); avio_rb16(VAR_1); VAR_6 = avio_rb16(VAR_1); } if (st->codec->codec_tag &&
st->codec->codec_tag != format &&
(VAR_0->fc->video_codec_id ? ff_codec_get_id(ff_codec_movvideo_tags, format) != VAR_0->fc->video_codec_id
: st->codec->codec_tag != MKTAG('VAR_3','p','e','VAR_16'))
){ multiple_stsd:
av_log(VAR_0->fc, AV_LOG_WARNING, "multiple fourcc not supported\n"); avio_skip(VAR_1, VAR_7 - (avio_tell(VAR_1) - start_pos)); continue; } if (st->codec->codec_tag && st->codec->codec_tag == AV_RL32("avc1"))
goto multiple_stsd; sc->VAR_4 = st->codec->codec_tag ? -1 : VAR_4; sc->VAR_6= VAR_6; st->codec->codec_tag = format; VAR_5 = ff_codec_get_id(ff_codec_movaudio_tags, format); if (VAR_5<=0 && ((format&0xFFFF) == 'm'+('s'<<8) || (format&0xFFFF) == 'T'+('S'<<8)))
VAR_5 = ff_codec_get_id(ff_codec_wav_tags, av_bswap32(format)&0xFFFF); if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && VAR_5 > 0) { st->codec->codec_type = AVMEDIA_TYPE_AUDIO; } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO && format && format != MKTAG('m','p','4','s')) { VAR_5 = ff_codec_get_id(ff_codec_movvideo_tags, format); if (VAR_5 <= 0)
VAR_5 = ff_codec_get_id(ff_codec_bmp_tags, format); if (VAR_5 > 0)
st->codec->codec_type = AVMEDIA_TYPE_VIDEO; else if (st->codec->codec_type == AVMEDIA_TYPE_DATA){ VAR_5 = ff_codec_get_id(ff_codec_movsubtitle_tags, format); if (VAR_5 > 0)
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; } } av_dlog(VAR_0->fc, "VAR_7=%d 4CC= %VAR_0%VAR_0%VAR_0%VAR_0 codec_type=%d\n", VAR_7,
(format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,
(format >> 24) & 0xff, st->codec->codec_type); if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) { unsigned int VAR_8, VAR_9; int VAR_10; int VAR_11; st->codec->codec_id = VAR_5; avio_rb16(VAR_1); avio_rb16(VAR_1); avio_rb32(VAR_1); avio_rb32(VAR_1); avio_rb32(VAR_1); st->codec->width = avio_rb16(VAR_1); st->codec->height = avio_rb16(VAR_1); avio_rb32(VAR_1); avio_rb32(VAR_1); avio_rb32(VAR_1); avio_rb16(VAR_1); VAR_9 = avio_r8(VAR_1); if (VAR_9 > 31)
VAR_9 = 31; mov_read_mac_string(VAR_0, VAR_1, VAR_9, st->codec->codec_name, 32); if (VAR_9 < 31)
avio_skip(VAR_1, 31 - VAR_9); if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))
st->codec->codec_tag=MKTAG('I', '4', '2', '0'); st->codec->bits_per_coded_sample = avio_rb16(VAR_1); VAR_11 = avio_rb16(VAR_1); av_dlog(VAR_0->fc, "depth %d, ctab VAR_5 %d\n",
st->codec->bits_per_coded_sample, VAR_11); VAR_8 = st->codec->bits_per_coded_sample & 0x1F; VAR_10 = st->codec->bits_per_coded_sample & 0x20; if ((VAR_8 == 2) || (VAR_8 == 4) ||
(VAR_8 == 8)) { unsigned int VAR_12, VAR_13, VAR_14; unsigned char VAR_15, VAR_16, VAR_17; if (VAR_10) { int VAR_18, VAR_19; st->codec->bits_per_coded_sample = VAR_8; VAR_13 = 1 << VAR_8; VAR_18 = 255; VAR_19 = 256 / (VAR_13 - 1); for (VAR_3 = 0; VAR_3 < VAR_13; VAR_3++) { VAR_15 = VAR_16 = VAR_17 = VAR_18; sc->palette[VAR_3] =
(VAR_15 << 16) | (VAR_16 << 8) | (VAR_17); VAR_18 -= VAR_19; if (VAR_18 < 0)
VAR_18 = 0; } } else if (VAR_11) { const uint8_t *VAR_20; VAR_13 = 1 << VAR_8; if (VAR_8 == 2)
VAR_20 = ff_qt_default_palette_4; else if (VAR_8 == 4)
VAR_20 = ff_qt_default_palette_16; else
VAR_20 = ff_qt_default_palette_256; for (VAR_3 = 0; VAR_3 < VAR_13; VAR_3++) { VAR_15 = VAR_20[VAR_3 * 3 + 0]; VAR_16 = VAR_20[VAR_3 * 3 + 1]; VAR_17 = VAR_20[VAR_3 * 3 + 2]; sc->palette[VAR_3] =
(VAR_15 << 16) | (VAR_16 << 8) | (VAR_17); } } else { VAR_12 = avio_rb32(VAR_1); VAR_13 = avio_rb16(VAR_1); VAR_14 = avio_rb16(VAR_1); if ((VAR_12 <= 255) &&
(VAR_14 <= 255)) { for (VAR_3 = VAR_12; VAR_3 <= VAR_14; VAR_3++) { avio_r8(VAR_1); avio_r8(VAR_1); VAR_15 = avio_r8(VAR_1); avio_r8(VAR_1); VAR_16 = avio_r8(VAR_1); avio_r8(VAR_1); VAR_17 = avio_r8(VAR_1); avio_r8(VAR_1); sc->palette[VAR_3] =
(VAR_15 << 16) | (VAR_16 << 8) | (VAR_17); } } } sc->has_palette = 1; } } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) { int VAR_21, VAR_22; uint16_t version = avio_rb16(VAR_1); st->codec->codec_id = VAR_5; avio_rb16(VAR_1); avio_rb32(VAR_1); st->codec->channels = avio_rb16(VAR_1); av_dlog(VAR_0->fc, "audio channels %d\n", st->codec->channels); st->codec->bits_per_coded_sample = avio_rb16(VAR_1); sc->audio_cid = avio_rb16(VAR_1); avio_rb16(VAR_1); st->codec->sample_rate = ((avio_rb32(VAR_1) >> 16)); av_dlog(VAR_0->fc, "version =%d, isom =%d\n",version,VAR_0->isom); if (!VAR_0->isom) { if (version==1) { sc->samples_per_frame = avio_rb32(VAR_1); avio_rb32(VAR_1); sc->bytes_per_frame = avio_rb32(VAR_1); avio_rb32(VAR_1); } else if (version==2) { avio_rb32(VAR_1); st->codec->sample_rate = av_int2double(avio_rb64(VAR_1)); st->codec->channels = avio_rb32(VAR_1); avio_rb32(VAR_1); st->codec->bits_per_coded_sample = avio_rb32(VAR_1); VAR_22 = avio_rb32(VAR_1); sc->bytes_per_frame = avio_rb32(VAR_1); sc->samples_per_frame = avio_rb32(VAR_1); if (format == MKTAG('l','p','VAR_0','m'))
st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, VAR_22); } } switch (st->codec->codec_id) { case AV_CODEC_ID_PCM_S8:
case AV_CODEC_ID_PCM_U8:
if (st->codec->bits_per_coded_sample == 16)
st->codec->codec_id = AV_CODEC_ID_PCM_S16BE; break; case AV_CODEC_ID_PCM_S16LE:
case AV_CODEC_ID_PCM_S16BE:
if (st->codec->bits_per_coded_sample == 8)
st->codec->codec_id = AV_CODEC_ID_PCM_S8; else if (st->codec->bits_per_coded_sample == 24)
st->codec->codec_id =
st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ?
AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE; break; case AV_CODEC_ID_MACE3:
sc->samples_per_frame = 6; sc->bytes_per_frame = 2*st->codec->channels; break; case AV_CODEC_ID_MACE6:
sc->samples_per_frame = 6; sc->bytes_per_frame = 1*st->codec->channels; break; case AV_CODEC_ID_ADPCM_IMA_QT:
sc->samples_per_frame = 64; sc->bytes_per_frame = 34*st->codec->channels; break; case AV_CODEC_ID_GSM:
sc->samples_per_frame = 160; sc->bytes_per_frame = 33; break; default:
break; } VAR_21 = av_get_bits_per_sample(st->codec->codec_id); if (VAR_21) { st->codec->bits_per_coded_sample = VAR_21; sc->sample_size = (VAR_21 >> 3) * st->codec->channels; } } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){ MOVAtom fake_atom = { .VAR_7 = VAR_7 - (avio_tell(VAR_1) - start_pos) }; if (format != AV_RL32("mp4s"))
mov_read_glbl(VAR_0, VAR_1, fake_atom); st->codec->codec_id= VAR_5; st->codec->width = sc->width; st->codec->height = sc->height; } else { avio_skip(VAR_1, VAR_7 - (avio_tell(VAR_1) - start_pos)); } a.VAR_7 = VAR_7 - (avio_tell(VAR_1) - start_pos); if (a.VAR_7 > 8) { int VAR_23; if ((VAR_23 = mov_read_default(VAR_0, VAR_1, a)) < 0)
return VAR_23; } else if (a.VAR_7 > 0) avio_skip(VAR_1, a.VAR_7); } if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1)
st->codec->sample_rate= sc->time_scale; switch (st->codec->codec_id) { #if CONFIG_DV_DEMUXER
case AV_CODEC_ID_DVAUDIO:
VAR_0->dv_fctx = avformat_alloc_context(); VAR_0->dv_demux = avpriv_dv_init_demux(VAR_0->dv_fctx); if (!VAR_0->dv_demux) { av_log(VAR_0->fc, AV_LOG_ERROR, "dv demux context init error\n"); return AVERROR(ENOMEM); } sc->dv_audio_container = 1; st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; break; #endif
case AV_CODEC_ID_QCELP:
if (st->codec->codec_tag != MKTAG('Q','VAR_0','l','p'))
st->codec->sample_rate = 8000; st->codec->channels= 1; break; case AV_CODEC_ID_AMR_NB:
st->codec->channels= 1; st->codec->sample_rate = 8000; break; case AV_CODEC_ID_AMR_WB:
st->codec->channels    = 1; st->codec->sample_rate = 16000; break; case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MP3:
st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->need_parsing = AVSTREAM_PARSE_FULL; break; case AV_CODEC_ID_GSM:
case AV_CODEC_ID_ADPCM_MS:
case AV_CODEC_ID_ADPCM_IMA_WAV:
case AV_CODEC_ID_ILBC:
st->codec->block_align = sc->bytes_per_frame; break; case AV_CODEC_ID_ALAC:
if (st->codec->extradata_size == 36) { st->codec->channels   = AV_RB8 (st->codec->extradata+21); st->codec->sample_rate = AV_RB32(st->codec->extradata+32); } break; case AV_CODEC_ID_VC1:
st->need_parsing = AVSTREAM_PARSE_FULL; break; default:
break; } return 0; }