这篇教程C++ swr_alloc_set_opts函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中swr_alloc_set_opts函数的典型用法代码示例。如果您正苦于以下问题:C++ swr_alloc_set_opts函数的具体用法?C++ swr_alloc_set_opts怎么用?C++ swr_alloc_set_opts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了swr_alloc_set_opts函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: audio_decode_frame/** ZSL* 虽然名字叫 decode,其实并不解码,只是从 is->sampq 里拿出 af(audioframe,Frame类型)* 把 af->frame(AVFrame类型)里的 data 经过 swr_convert() 之后,存入 is->audio_buf* 返回存入的大小(即 resample 之后的大小)**/int audio_decode_frame(VideoState *is) { int resampled_data_size,out_size; Frame *af; af = frame_queue_peek_readable(&is->sampq); frame_queue_next(&is->sampq); if (!is->swr_ctx) { is->swr_ctx = swr_alloc_set_opts(NULL, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_S16, is->audio_ctx->sample_rate, av_get_default_channel_layout(is->audio_ctx->channels), is->audio_ctx->sample_fmt, is->audio_ctx->sample_rate, 0, NULL); swr_init(is->swr_ctx); } const uint8_t **in = (const uint8_t **)af->frame->extended_data; uint8_t **out = &is->audio_buf; //out_size = av_samples_get_buffer_size(NULL, 2, af->frame->nb_samples, AV_SAMPLE_FMT_S16, 1); out_size = 2 * 1152 * 2; if (out_size < 0) { /*比如 af->frame->nb_samples==0 的时候,这必须要处理一下,不然一会儿 av_fast_malloc() 就出问题了 */ av_log(NULL, AV_LOG_ERROR, "av_samples_get_buffer_size() failed/n"); return -1; } int len2; av_fast_malloc(&is->audio_buf, &is->audio_buf_size, out_size); len2 = swr_convert(is->swr_ctx, out, af->frame->nb_samples, in, af->frame->nb_samples); resampled_data_size = len2 * 2 * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16); return resampled_data_size;}
开发者ID:shileiz,项目名称:notes,代码行数:33,
示例2: memsetvoid MediaThread::Pcm::save(const AVFrame *frame, double stamp){ stamp_ = stamp;#if 0 memset(buf_, 0, 4096); data_len_ = 4096;#else if (!swr_) { // 总是输出 2, s16, 32000 ... swr_ = swr_alloc_set_opts(0, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_S16, 32000, frame->channel_layout, (AVSampleFormat)frame->format, frame->sample_rate, 0, 0); ch_ = 2; samplerate_ = 32000; bitsize_ = 16; swr_init(swr_); } size_t out_size = frame->nb_samples * 2 * 2; // samples * bytes per sample * channels if (buf_len_ < out_size) { buf_ = (unsigned char*)realloc(buf_, out_size); buf_len_ = out_size; } int samples = swr_convert(swr_, &buf_, frame->nb_samples, (const uint8_t**)frame->extended_data, frame->nb_samples); data_len_ = samples * 2 * 2; // samples * bytes per sample * channels#endif}
开发者ID:sunkwei,项目名称:zmovie,代码行数:32,
示例3: swr_alloc_set_optsvoid Parser::InitResampler(){ swr_ctx = swr_alloc_set_opts(NULL, av_get_default_channel_layout(cdc_ctx_out->channels), cdc_ctx_out->sample_fmt, cdc_ctx_out->sample_rate, channelLayoutIn, (AVSampleFormat)sampleFormatIn, sampleRateIn, 0,0); if(!swr_ctx) throw ContextCreatorException() << errno_code(MIR_ERR_ALLOC_SWR_CONTEXT); // set options av_opt_set_int(swr_ctx, "in_channel_layout", channelLayoutIn, 0); av_opt_set_int(swr_ctx, "in_sample_rate", sampleRateIn, 0); av_opt_set_int(swr_ctx, "in_bit_rate", bitRateIn, 0); av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", (AVSampleFormat)sampleFormatIn, 0); av_opt_set_int(swr_ctx, "out_channel_layout", cdc_ctx_out->channel_layout, 0); av_opt_set_int(swr_ctx, "out_sample_rate", cdc_ctx_out->sample_rate, 0); av_opt_set_int(swr_ctx, "out_bit_rate", cdc_ctx_out->bit_rate, 0); av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", cdc_ctx_out->sample_fmt, 0); if (swr_init(swr_ctx) < 0) throw ContextCreatorException() << errno_code(MIR_ERR_INIT_SWR_CONTEXT);}
开发者ID:josekleber,项目名称:captura,代码行数:28,
示例4: renderopen// 函数实现void* renderopen(void *surface, AVRational frate, int pixfmt, int w, int h, int64_t ch_layout, AVSampleFormat sndfmt, int srate){ WAVEFORMATEX wfx = {0}; RENDER *render = (RENDER*)malloc(sizeof(RENDER)); memset(render, 0, sizeof(RENDER)); render->hRenderWnd = (HWND)surface; // save hwnd // init for audio wfx.cbSize = sizeof(wfx); wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.wBitsPerSample = 16; // 16bit wfx.nSamplesPerSec = 44100; // 44.1k wfx.nChannels = 2; // stereo wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8; wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; waveOutOpen(&(render->hWaveOut), WAVE_MAPPER, &wfx, (DWORD_PTR)waveOutProc, (DWORD)render, CALLBACK_FUNCTION); waveOutPause(render->hWaveOut); wavqueue_create(&(render->WavQueue), render->hWaveOut, ((int64_t)44100 * 4 * frate.den / frate.num) & ~0x3); /* allocate & init swr context */ render->pSWRContext = swr_alloc_set_opts(NULL, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_S16, 44100, ch_layout, sndfmt, srate, 0, NULL); swr_init(render->pSWRContext); // init for video render->nVideoWidth = w; render->nVideoHeight = h; render->nRenderWidth = GetSystemMetrics(SM_CXSCREEN); render->nRenderHeight= GetSystemMetrics(SM_CYSCREEN); render->nRenderNewW = render->nRenderWidth; render->nRenderNewH = render->nRenderHeight; render->PixelFormat = (PixelFormat)pixfmt; // create sws context render->pSWSContext = sws_getContext( render->nVideoWidth, render->nVideoHeight, render->PixelFormat, render->nRenderWidth, render->nRenderHeight, PIX_FMT_RGB32, SWS_BILINEAR, 0, 0, 0); render->iFrameTick = 1000 * frate.den / frate.num; render->iSleepTick = render->iFrameTick; // create dc & bitmaps render->hRenderDC = GetDC(render->hRenderWnd); render->hBufferDC = CreateCompatibleDC(render->hRenderDC); // create bmp queue bmpqueue_create(&(render->BmpQueue), render->hBufferDC, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), 32); render->nRenderStatus = 0; pthread_create(&(render->hVideoThread), NULL, VideoRenderThreadProc, render); return render;}
开发者ID:wnpllrzodiac,项目名称:ffplayer-android,代码行数:61,
示例5: av_get_channel_layout_nb_channelsEC_U32 AudioWaveScale::Init(MediaCtxInfo* pMediaInfo, AudioPCMBuffer *pFirstFrame){ if (EC_NULL == pMediaInfo) return Audio_Render_Err_InitFail; EC_S32 out_sample_rate = pMediaInfo->m_nSampleRate; EC_S64 out_channel_layout = AV_CH_LAYOUT_STEREO; EC_S32 out_channels = av_get_channel_layout_nb_channels(out_channel_layout); AVSampleFormat out_sample_fmt = AV_SAMPLE_FMT_S16; AVCodecContext *pCodecCtx = (AVCodecContext*)(pMediaInfo->m_pAudioCodecInfo); EC_S64 in_channel_layout = av_get_default_channel_layout(pCodecCtx->channels); EC_S32 in_sample_rate = pCodecCtx->sample_rate; AVSampleFormat in_sample_fmt = pCodecCtx->sample_fmt; m_nOutChannels = out_channels; m_nOutSampleFormat = out_sample_fmt; m_pWaveScaleContext = swr_alloc(); m_pWaveScaleContext = swr_alloc_set_opts(m_pWaveScaleContext, out_channel_layout, out_sample_fmt, out_sample_rate, in_channel_layout, in_sample_fmt, in_sample_rate, 0, NULL); EC_S32 nRet = swr_init(m_pWaveScaleContext); if (nRet < 0) return Audio_Render_Err_InitFail; m_pScaleOutbuffer = (uint8_t *)av_malloc(MAX_AUDIO_FRAME_SIZE * 2); if (m_pScaleOutbuffer == EC_NULL) return EC_Err_Memory_Low; return Audio_Render_Err_None;}
开发者ID:brooksgod,项目名称:SuPlayer,代码行数:34,
示例6: config_outputstatic int config_output(AVFilterLink *outlink){ int ret; AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0]; AConvertContext *aconvert = ctx->priv; char buf1[64], buf2[64]; /* if not specified in args, use the format and layout of the output */ if (aconvert->out_sample_fmt == AV_SAMPLE_FMT_NONE) aconvert->out_sample_fmt = outlink->format; if (aconvert->out_chlayout == 0) aconvert->out_chlayout = outlink->channel_layout; aconvert->swr = swr_alloc_set_opts(aconvert->swr, aconvert->out_chlayout, aconvert->out_sample_fmt, inlink->sample_rate, inlink->channel_layout, inlink->format, inlink->sample_rate, 0, ctx); if (!aconvert->swr) return AVERROR(ENOMEM); ret = swr_init(aconvert->swr); if (ret < 0) return ret; av_get_channel_layout_string(buf1, sizeof(buf1), -1, inlink ->channel_layout); av_get_channel_layout_string(buf2, sizeof(buf2), -1, outlink->channel_layout); av_log(ctx, AV_LOG_VERBOSE, "fmt:%s cl:%s -> fmt:%s cl:%s/n", av_get_sample_fmt_name(inlink ->format), buf1, av_get_sample_fmt_name(outlink->format), buf2); return 0;}
开发者ID:MyungSinKim,项目名称:FFMpeg-for-ANDROID-with-NDK,代码行数:35,
示例7: av_get_bytes_per_sampleCAudioReader::CAudioReader(CAudioSource *source, AudioTrack *info){ m_Source = source; m_Info = info; m_MediaInfo = info->m_Media; m_DestSampleRate = source->m_SampleRate; m_DestChannels = source->m_Channels; m_DestPacketBytes = source->m_PacketBytes; if (m_MediaInfo->m_IsPlanar) { m_SourceChannels = m_MediaInfo->m_nChannel; m_SourcePacketBytes = av_get_bytes_per_sample((enum AVSampleFormat)m_MediaInfo->m_SampleFormat); } else { m_SourceChannels = 1; m_SourcePacketBytes = m_MediaInfo->m_nChannel * av_get_bytes_per_sample((enum AVSampleFormat)m_MediaInfo->m_SampleFormat); } m_SourceSampleRate = m_MediaInfo->m_SampleRate; for(int i = 0; i < m_SourceChannels; i++) { m_hFiles[i] = CreateFile(m_MediaInfo->m_AudioTmpFile[i], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); } if ( (m_MediaInfo->m_SampleRate != m_Source->m_SampleRate) || (m_MediaInfo->m_nChannel != m_Source->m_Channels) || (m_MediaInfo->m_SampleFormat != m_Source->m_SampleFormat) || (m_MediaInfo->m_channel_layout != m_Source->m_Layout) ) { swr_context = swr_alloc_set_opts(NULL, m_Source->m_Layout, (AVSampleFormat)source->m_SampleFormat, m_Source->m_SampleRate, m_MediaInfo->m_channel_layout, (AVSampleFormat)m_MediaInfo->m_SampleFormat, m_MediaInfo->m_SampleRate, 0, NULL); swr_init(swr_context); for(int i = 0; i < m_SourceChannels; i++) { m_ReadBuffer[i] = (uint8_t *)MemoryAlloc(m_SourceSampleRate * m_SourcePacketBytes); } for(int i = 0; i < m_DestChannels; i++) { m_ResampleBuffer[i] = (uint8_t *)MemoryAlloc(m_DestSampleRate * m_DestPacketBytes * 2); } } ResetStartStop();}
开发者ID:amikey,项目名称:vmeisoft-video-convertor-and-editor,代码行数:59,
示例8: audio_convertstatic void audio_convert(dtaudio_decoder_t *decoder, AVFrame * dst, AVFrame * src){ int nb_sample; int dst_buf_size; int out_channels; //for audio post processor //struct SwsContext *m_sws_ctx = NULL; struct SwrContext *m_swr_ctx = NULL; //ResampleContext *m_resample_ctx=NULL; enum AVSampleFormat src_fmt = avctxp->sample_fmt; enum AVSampleFormat dst_fmt = AV_SAMPLE_FMT_S16; dst->linesize[0] = src->linesize[0]; *dst = *src; dst->data[0] = NULL; out_channels = decoder->para.dst_channels; nb_sample = frame->nb_samples; dst_buf_size = nb_sample * av_get_bytes_per_sample(dst_fmt) * out_channels; dst->data[0] = (uint8_t *) av_malloc(dst_buf_size); avcodec_fill_audio_frame(dst, out_channels, dst_fmt, dst->data[0], dst_buf_size, 0); dt_debug(TAG, "SRCFMT:%d dst_fmt:%d /n", src_fmt, dst_fmt); /* resample toAV_SAMPLE_FMT_S16 */ if (src_fmt != dst_fmt || out_channels != decoder->para.channels) { if (!m_swr_ctx) { uint64_t in_channel_layout = av_get_default_channel_layout(avctxp->channels); uint64_t out_channel_layout = av_get_default_channel_layout(out_channels); m_swr_ctx = swr_alloc_set_opts(NULL, out_channel_layout, dst_fmt, avctxp->sample_rate, in_channel_layout, src_fmt, avctxp->sample_rate, 0, NULL); swr_init(m_swr_ctx); } uint8_t **out = (uint8_t **) & dst->data; const uint8_t **in = (const uint8_t **) src->extended_data; if (m_swr_ctx) { int ret, out_count; out_count = nb_sample; ret = swr_convert(m_swr_ctx, out, out_count, in, nb_sample); if (ret < 0) { //set audio mute memset(dst->data[0], 0, dst_buf_size); printf("audio convert failed, set mute data/n"); } } } else { // no need to convert ,just copy memcpy(dst->data[0], src->data[0], src->linesize[0]); } //free context if (m_swr_ctx != NULL) { swr_free(&m_swr_ctx); } //if(m_resample_ctx!=NULL) // audio_resample_close(m_resample_ctx);}
开发者ID:peterfuture,项目名称:dtplayer_c,代码行数:56,
示例9: codec_SimpleAT3::SimpleAT3() : codec_(0), codecCtx_(0), swrCtx_(0) { frame_ = av_frame_alloc(); codec_ = avcodec_find_decoder(AV_CODEC_ID_ATRAC3P); if (!codec_) { // Eh, we shouldn't even have managed to compile. But meh. ERROR_LOG(ME, "This version of FFMPEG does not support AV_CODEC_ID_ATRAC3P (Atrac3+). Update your submodule."); return; } codecCtx_ = avcodec_alloc_context3(codec_); if (!codecCtx_) { ERROR_LOG(ME, "Failed to allocate a codec context"); return; } codecCtx_->channels = 2; codecCtx_->channel_layout = AV_CH_LAYOUT_STEREO; AVDictionary *opts = 0; av_dict_set(&opts, "channels", "2", 0); av_dict_set(&opts, "sample_rate", "44100", 0); if (avcodec_open2(codecCtx_, codec_, &opts) < 0) { ERROR_LOG(ME, "Failed to open codec"); return; } av_dict_free(&opts); // Initializing the sample rate convert. We only really use it to convert float output // into int. int wanted_channels = 2; int64_t wanted_channel_layout = av_get_default_channel_layout(wanted_channels); int64_t dec_channel_layout = av_get_default_channel_layout(2); swrCtx_ = swr_alloc_set_opts( swrCtx_, wanted_channel_layout, AV_SAMPLE_FMT_S16, codecCtx_->sample_rate, dec_channel_layout, codecCtx_->sample_fmt, codecCtx_->sample_rate, 0, NULL); if (!swrCtx_ || swr_init(swrCtx_) < 0) { ERROR_LOG(ME, "swr_init: Failed to initialize the resampling context"); avcodec_close(codecCtx_); codec_ = 0; return; }}
开发者ID:A671DR218,项目名称:ppsspp,代码行数:56,
示例10: swr_alloc_set_opts /** * Initialize the audio resampler based on the input and output codec settings. * If the input and output sample formats differ, a conversion is required * libswresample takes care of this, but requires initialization. */ int AudioDecoder::init_resampler(AVCodecContext *input_codec_context, AVCodecContext *output_codec_context) { int error; /** * Create a resampler context for the conversion. * Set the conversion parameters. * Default channel layouts based on the number of channels * are assumed for simplicity (they are sometimes not detected * properly by the demuxer and/or decoder). */ resample_context = swr_alloc_set_opts(NULL, av_get_default_channel_layout(output_codec_context->channels), output_codec_context->sample_fmt, output_codec_context->sample_rate, av_get_default_channel_layout(input_codec_context->channels), input_codec_context->sample_fmt, input_codec_context->sample_rate, 0, NULL); if (!resample_context) { ELOG_WARN( "Could not allocate resample context/n"); return AVERROR(ENOMEM); } /** * Perform a sanity check so that the number of converted samples is * not greater than the number of samples to be converted. * If the sample rates differ, this case has to be handled differently */ ELOG_DEBUG( "audio input sample_rate = %d, out %d", input_codec_context->sample_rate, output_codec_context->sample_rate); /** Open the resampler with the specified parameters. */ if ((error = swr_init(resample_context)) < 0) { ELOG_WARN( "Could not open resample context"); swr_free(&resample_context); return error; } /** Open the resampler with the specified parameters. */ if ((error = swr_init(resample_context)) < 0) { ELOG_DEBUG( "Could not open resample context"); swr_free(&resample_context); return error; } ELOG_DEBUG( "swr_init done"); return 0; }
开发者ID:fanchuanster,项目名称:erizo_externalinput,代码行数:59,
示例11: swr_freevoid XAudioStream::setSpeed(float speed){ if(m_speed == speed || speed <= 0.0f) return; m_speed = speed; swr_free(&m_pSwrContext); m_pSwrContext = swr_alloc(); if(m_pSwrContext == NULL) return; if(m_pAudioCodecCtx->channel_layout == 0) { swr_alloc_set_opts(m_pSwrContext,av_get_default_channel_layout(XEG.getAudioChannelSum()),getSampleFormat(),XEG.getAudioSampleRate() * m_speed, av_get_default_channel_layout(m_pAudioCodecCtx->channels),m_pAudioCodecCtx->sample_fmt,m_pAudioCodecCtx->sample_rate,0,NULL); }else { swr_alloc_set_opts(m_pSwrContext,av_get_default_channel_layout(XEG.getAudioChannelSum()),getSampleFormat(),XEG.getAudioSampleRate() * m_speed, m_pAudioCodecCtx->channel_layout,m_pAudioCodecCtx->sample_fmt,m_pAudioCodecCtx->sample_rate,0,NULL); } if(swr_init(m_pSwrContext) < 0) { LogStr("swr_init() fail"); return; }}
开发者ID:xiajiaonly,项目名称:XEffect2D,代码行数:22,
示例12: openAudioStream kxMovieError openAudioStream(size_t audioStream) { AVCodecContext *codecCtx = _formatCtx->streams[audioStream]->codec; SwrContext *swrContext = NULL; AVCodec *codec = avcodec_find_decoder(codecCtx->codec_id); if(!codec) return kxMovieErrorCodecNotFound; if (avcodec_open2(codecCtx, codec, NULL) < 0) return kxMovieErrorOpenCodec; if (!audioCodecIsSupported(codecCtx)) { swrContext = swr_alloc_set_opts(NULL, av_get_default_channel_layout(codecCtx->channels), AV_SAMPLE_FMT_S16, codecCtx->sample_rate, av_get_default_channel_layout(codecCtx->channels), codecCtx->sample_fmt, codecCtx->sample_rate, 0, NULL); if (!swrContext || swr_init(swrContext)) { if (swrContext) swr_free(&swrContext); avcodec_close(codecCtx); return kxMovieErroReSampler; } } _audioFrame = av_frame_alloc(); if (!_audioFrame) { if (swrContext) swr_free(&swrContext); avcodec_close(codecCtx); return kxMovieErrorAllocateFrame; } _audioStream = audioStream; _audioCodecCtx = codecCtx; _swrContext = swrContext; return kxMovieErrorNone; }
开发者ID:lgdiy1982,项目名称:SDLAudioPlayer,代码行数:50,
示例13: AudioResamplingint AudioResampling(AVCodecContext * audio_dec_ctx, AVFrame * pAudioDecodeFrame, enum AVSampleFormat out_sample_fmt, int out_channels, int out_sample_rate, uint8_t* out_buf){ struct SwrContext * swr_ctx = 0; swr_ctx = swr_alloc_set_opts(swr_ctx,audio_dec_ctx->channel_layout,out_sample_fmt,out_sample_rate, audio_dec_ctx->channel_layout,audio_dec_ctx->sample_fmt,audio_dec_ctx->sample_rate,0,0); int ret = 0; int dst_linesize = 0; int resampled_data_size = av_samples_get_buffer_size(&dst_linesize, out_channels,audio_dec_ctx->frame_size,audio_dec_ctx->sample_fmt, 1); uint8_t *dst_data = (uint8_t*)av_malloc(resampled_data_size); if ((ret = swr_init(swr_ctx)) < 0) { printf("Failed to initialize the resampling context/n"); return -1; } if (swr_ctx){ ret = swr_convert(swr_ctx, &dst_data, dst_linesize, (const uint8_t **)pAudioDecodeFrame->data, pAudioDecodeFrame->nb_samples); resampled_data_size = av_samples_get_buffer_size(&dst_linesize,out_channels,ret,out_sample_fmt,1); if (ret < 0) { printf("swr_convert error /n"); return -1; } if (resampled_data_size < 0) { printf("av_samples_get_buffer_size error /n"); return -1; } } else{ printf("swr_ctx null error /n"); return -1; } memcpy(out_buf, dst_data, resampled_data_size); if (dst_data) { av_free(dst_data); } if (swr_ctx) { swr_free(&swr_ctx); } return resampled_data_size;}
开发者ID:ShengQiangLiu,项目名称:sdl_ffmpeg_player,代码行数:50,
示例14: render_audiovoid render_audio(void *hrender, AVFrame *audio){ RENDER *render = (RENDER*)hrender; int sampnum = 0; DWORD apts = (DWORD)audio->pts; if (!render->adev) return; do { if (render->nAdevBufAvail == 0) { adev_request(render->adev, &render->pAdevHdrCur); apts += render->nFramePeriod * render->nRenderSpeedCur / 100; render->nAdevBufAvail = (int )render->pAdevHdrCur->size; render->pAdevBufCur = (BYTE*)render->pAdevHdrCur->data; } if (render->nRenderSpeedCur != render->nRenderSpeedNew) { render->nRenderSpeedCur = render->nRenderSpeedNew; // set vdev frame rate int framerate = (render->FrameRate.num * render->nRenderSpeedCur) / (render->FrameRate.den * 100); vdev_setfrate(render->vdev, framerate > 1 ? framerate : 1); //++ allocate & init swr context if (render->pSWRContext) { swr_free(&render->pSWRContext); } int samprate = 44100 * 100 / render->nRenderSpeedCur; render->pSWRContext = swr_alloc_set_opts(NULL, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_S16, samprate, render->nChanLayout, render->SampleFormat, render->nSampleRate, 0, NULL); swr_init(render->pSWRContext); //-- allocate & init swr context } //++ do resample audio data ++// sampnum = swr_convert(render->pSWRContext, (uint8_t**)&render->pAdevBufCur, render->nAdevBufAvail / 4, (const uint8_t**)audio->extended_data, audio->nb_samples); audio->extended_data = NULL; audio->nb_samples = 0; render->nAdevBufAvail -= sampnum * 4; render->pAdevBufCur += sampnum * 4; //-- do resample audio data --// if (render->nAdevBufAvail == 0) { adev_post(render->adev, apts); } } while (sampnum > 0);}
开发者ID:chenhongliang2008,项目名称:ffplayer,代码行数:48,
示例15: swr_alloc_set_optsSwr::Swr(std::int64_t out_ch_layout, AVSampleFormat out_sample_fmt, int out_sample_rate, std::int64_t in_ch_layout, AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void* log_ctx){ this->context = swr_alloc_set_opts(nullptr, out_ch_layout, out_sample_fmt, out_sample_rate, in_ch_layout, in_sample_fmt, in_sample_rate, log_offset, log_ctx); if (this->context == nullptr) { throw std::bad_alloc(); } assert(this->context != nullptr); swr_init(this->context);}
开发者ID:CaptainHayashi,项目名称:playslave-plusplus,代码行数:16,
示例16: init_swrvoid init_swr(){ uint64_t out_channel_layout=AV_CH_LAYOUT_STEREO; //nb_samples: AAC-1024 MP3-1152 out_sample_rate=pCodecCtx->sample_rate; out_channels=av_get_channel_layout_nb_channels(out_channel_layout); out_buffer=(uint8_t *)av_malloc(MAX_AUDIO_FRAME_SIZE*out_channels); //FIX:Some Codec's Context Information is missing int in_channel_layout=av_get_default_channel_layout(pCodecCtx->channels); //Swr au_convert_ctx = swr_alloc(); swr_alloc_set_opts(au_convert_ctx,out_channel_layout, out_sample_fmt, out_sample_rate, in_channel_layout, pCodecCtx->sample_fmt , pCodecCtx->sample_rate,0, NULL); if(swr_init(au_convert_ctx)<0){ au_convert_ctx=NULL; } createBufferQueueAudioPlayer(2,out_sample_rate); }
开发者ID:4455jkjh,项目名称:music_player,代码行数:18,
|