⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 riff.c.svn-base

📁 mediastreamer2是开源的网络传输媒体流的库
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
    put_tag(pb, tag);    put_le32(pb, 0);    return url_ftell(pb);}void end_tag(ByteIOContext *pb, offset_t start){    offset_t pos;    pos = url_ftell(pb);    url_fseek(pb, start - 4, SEEK_SET);    put_le32(pb, (uint32_t)(pos - start));    url_fseek(pb, pos, SEEK_SET);}/* WAVEFORMATEX header *//* returns the size or -1 on error */int put_wav_header(ByteIOContext *pb, AVCodecContext *enc){    int bps, blkalign, bytespersec;    int hdrsize = 18;    if(!enc->codec_tag || enc->codec_tag > 0xffff)        return -1;    put_le16(pb, enc->codec_tag);    put_le16(pb, enc->channels);    put_le32(pb, enc->sample_rate);    if (enc->codec_id == CODEC_ID_PCM_U8 ||        enc->codec_id == CODEC_ID_PCM_ALAW ||        enc->codec_id == CODEC_ID_PCM_MULAW) {        bps = 8;    } else if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {        bps = 0;    } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV || enc->codec_id == CODEC_ID_ADPCM_MS || enc->codec_id == CODEC_ID_ADPCM_G726 || enc->codec_id == CODEC_ID_ADPCM_YAMAHA) { //        bps = 4;    } else if (enc->codec_id == CODEC_ID_PCM_S24LE) {        bps = 24;    } else if (enc->codec_id == CODEC_ID_PCM_S32LE) {        bps = 32;    } else {        bps = 16;    }    if(bps != enc->bits_per_sample && enc->bits_per_sample){        av_log(enc, AV_LOG_WARNING, "requested bits_per_sample (%d) and actually stored (%d) differ\n", enc->bits_per_sample, bps);    }    if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {        blkalign = enc->frame_size; //this is wrong, but it seems many demuxers do not work if this is set correctly        //blkalign = 144 * enc->bit_rate/enc->sample_rate;    } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { //        blkalign = 1;    } else if (enc->block_align != 0) { /* specified by the codec */        blkalign = enc->block_align;    } else        blkalign = enc->channels*bps >> 3;    if (enc->codec_id == CODEC_ID_PCM_U8 ||        enc->codec_id == CODEC_ID_PCM_S24LE ||        enc->codec_id == CODEC_ID_PCM_S32LE ||        enc->codec_id == CODEC_ID_PCM_S16LE) {        bytespersec = enc->sample_rate * blkalign;    } else {        bytespersec = enc->bit_rate / 8;    }    put_le32(pb, bytespersec); /* bytes per second */    put_le16(pb, blkalign); /* block align */    put_le16(pb, bps); /* bits per sample */    if (enc->codec_id == CODEC_ID_MP3) {        put_le16(pb, 12); /* wav_extra_size */        hdrsize += 12;        put_le16(pb, 1); /* wID */        put_le32(pb, 2); /* fdwFlags */        put_le16(pb, 1152); /* nBlockSize */        put_le16(pb, 1); /* nFramesPerBlock */        put_le16(pb, 1393); /* nCodecDelay */    } else if (enc->codec_id == CODEC_ID_MP2) {        put_le16(pb, 22); /* wav_extra_size */        hdrsize += 22;        put_le16(pb, 2);  /* fwHeadLayer */        put_le32(pb, enc->bit_rate); /* dwHeadBitrate */        put_le16(pb, enc->channels == 2 ? 1 : 8); /* fwHeadMode */        put_le16(pb, 0);  /* fwHeadModeExt */        put_le16(pb, 1);  /* wHeadEmphasis */        put_le16(pb, 16); /* fwHeadFlags */        put_le32(pb, 0);  /* dwPTSLow */        put_le32(pb, 0);  /* dwPTSHigh */    } else if (enc->codec_id == CODEC_ID_GSM_MS) {        put_le16(pb, 2); /* wav_extra_size */        hdrsize += 2;        put_le16(pb, enc->frame_size); /* wSamplesPerBlock */    } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {        put_le16(pb, 2); /* wav_extra_size */        hdrsize += 2;        put_le16(pb, enc->frame_size); /* wSamplesPerBlock */    } else if(enc->extradata_size){        put_le16(pb, enc->extradata_size);        put_buffer(pb, enc->extradata, enc->extradata_size);        hdrsize += enc->extradata_size;        if(hdrsize&1){            hdrsize++;            put_byte(pb, 0);        }    } else {        hdrsize -= 2;    }    return hdrsize;}/* BITMAPINFOHEADER header */void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf){    put_le32(pb, 40 + enc->extradata_size); /* size */    put_le32(pb, enc->width);    put_le32(pb, enc->height);    put_le16(pb, 1); /* planes */    put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */    /* compression type */    put_le32(pb, enc->codec_tag);    put_le32(pb, enc->width * enc->height * 3);    put_le32(pb, 0);    put_le32(pb, 0);    put_le32(pb, 0);    put_le32(pb, 0);    put_buffer(pb, enc->extradata, enc->extradata_size);    if (enc->extradata_size & 1)        put_byte(pb, 0);}#endif //CONFIG_MUXERS#ifdef CONFIG_DEMUXERS/* We could be given one of the three possible structures here: * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure * is an expansion of the previous one with the fields added * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and * WAVEFORMATEX adds 'WORD  cbSize' and basically makes itself * an openended structure. */void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size){    int id;    id = get_le16(pb);    codec->codec_type = CODEC_TYPE_AUDIO;    codec->codec_tag = id;    codec->channels = get_le16(pb);    codec->sample_rate = get_le32(pb);    codec->bit_rate = get_le32(pb) * 8;    codec->block_align = get_le16(pb);    if (size == 14) {  /* We're dealing with plain vanilla WAVEFORMAT */        codec->bits_per_sample = 8;    }else        codec->bits_per_sample = get_le16(pb);    if (size >= 18) {  /* We're obviously dealing with WAVEFORMATEX */        int cbSize = get_le16(pb); /* cbSize */        size -= 18;        cbSize = FFMIN(size, cbSize);        if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */            codec->bits_per_sample = get_le16(pb);            get_le32(pb); /* dwChannelMask */            id = get_le32(pb); /* 4 first bytes of GUID */            url_fskip(pb, 12); /* skip end of GUID */            cbSize -= 22;            size -= 22;        }        codec->extradata_size = cbSize;        if (cbSize > 0) {            codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);            get_buffer(pb, codec->extradata, codec->extradata_size);            size -= cbSize;        }        /* It is possible for the chunk to contain garbage at the end */        if (size > 0)            url_fskip(pb, size);    }    codec->codec_id = wav_codec_get_id(id, codec->bits_per_sample);}int wav_codec_get_id(unsigned int tag, int bps){    int id;    id = codec_get_id(codec_wav_tags, tag);    if (id <= 0)        return id;    /* handle specific u8 codec */    if (id == CODEC_ID_PCM_S16LE && bps == 8)        id = CODEC_ID_PCM_U8;    if (id == CODEC_ID_PCM_S16LE && bps == 24)        id = CODEC_ID_PCM_S24LE;    if (id == CODEC_ID_PCM_S16LE && bps == 32)        id = CODEC_ID_PCM_S32LE;    if (id == CODEC_ID_ADPCM_IMA_WAV && bps == 8)        id = CODEC_ID_PCM_ZORK;    return id;}#endif // CONFIG_DEMUXERSvoid ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale){    int gcd;    *au_ssize= stream->block_align;    if(stream->frame_size && stream->sample_rate){        *au_scale=stream->frame_size;        *au_rate= stream->sample_rate;    }else if(stream->codec_type == CODEC_TYPE_VIDEO){        *au_scale= stream->time_base.num;        *au_rate = stream->time_base.den;    }else{        *au_scale= stream->block_align ? stream->block_align*8 : 8;        *au_rate = stream->bit_rate;    }    gcd= ff_gcd(*au_scale, *au_rate);    *au_scale /= gcd;    *au_rate /= gcd;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -