static gboolean gst_ffmpegaudioresample_set_caps (GstBaseTransform * trans, GstCaps * incaps, GstCaps * outcaps) { GstFFMpegAudioResample *resample = GST_FFMPEGAUDIORESAMPLE (trans); GstStructure *instructure = gst_caps_get_structure (incaps, 0); GstStructure *outstructure = gst_caps_get_structure (outcaps, 0); GST_LOG_OBJECT (resample, "incaps:%" GST_PTR_FORMAT, incaps); GST_LOG_OBJECT (resample, "outcaps:%" GST_PTR_FORMAT, outcaps); if (!gst_structure_get_int (instructure, "channels", &resample->in_channels)) return FALSE; if (!gst_structure_get_int (instructure, "rate", &resample->in_rate)) return FALSE; if (!gst_structure_get_int (outstructure, "channels", &resample->out_channels)) return FALSE; if (!gst_structure_get_int (outstructure, "rate", &resample->out_rate)) return FALSE; resample->res = audio_resample_init (resample->out_channels, resample->in_channels, resample->out_rate, resample->in_rate); if (resample->res == NULL) return FALSE; return TRUE; }
// --------------------------------------------------------------------------------- static PyObject * ResamplerNew( PyTypeObject *type, PyObject *args, PyObject *kwds ) { ReSampleContext *cResCtx; PyResamplerObject* cRes; int iFromSRate, iFromChannels, iToSRate, iToChannels; if (!PyArg_ParseTuple(args, "(ii)(ii):Resampler", &iFromSRate, &iFromChannels, &iToSRate, &iToChannels )) return NULL; // try to init resampler cResCtx= audio_resample_init( iToChannels, iFromChannels, iToSRate, iFromSRate ); if(!cResCtx) { PyErr_Format(g_cErr, "Can't create resampler, bad parameters combination" ); return NULL; } cRes= (PyResamplerObject* )type->tp_alloc(type, 0); if( !cRes ) { audio_resample_close( cResCtx ); return NULL; } cRes->resample_ctx= cResCtx; return (PyObject*)cRes; }
LAVCAudioProvider::LAVCAudioProvider(wxString _filename, VideoProvider *vpro) : lavcfile(NULL), codecContext(NULL), rsct(NULL), buffer(NULL) { try { #if 0 /* since seeking currently is likely to be horribly broken with two * providers accessing the same stream, this is disabled for now. */ LAVCVideoProvider *vpro_lavc = dynamic_cast<LAVCVideoProvider *>(vpro); if (vpro_lavc) { lavcfile = vpro->lavcfile->AddRef(); filename = vpro_lavc->GetFilename(); } else { #endif lavcfile = LAVCFile::Create(_filename); filename = _filename; #if 0 } #endif audStream = -1; for (int i = 0; i < lavcfile->fctx->nb_streams; i++) { codecContext = lavcfile->fctx->streams[i]->codec; if (codecContext->codec_type == CODEC_TYPE_AUDIO) { stream = lavcfile->fctx->streams[i]; audStream = i; break; } } if (audStream == -1) throw _T("Could not find an audio stream"); AVCodec *codec = avcodec_find_decoder(codecContext->codec_id); if (!codec) throw _T("Could not find a suitable audio decoder"); if (avcodec_open(codecContext, codec) < 0) throw _T("Failed to open audio decoder"); /* aegisub currently supports mono only, so always resample */ sample_rate = Options.AsInt(_T("Audio Sample Rate")); if (!sample_rate) sample_rate = codecContext->sample_rate; channels = 1; bytes_per_sample = 2; rsct = audio_resample_init(1, codecContext->channels, sample_rate, codecContext->sample_rate); if (!rsct) throw _T("Failed to initialize resampling"); resample_ratio = (float)sample_rate / (float)codecContext->sample_rate; double length = (double)stream->duration * av_q2d(stream->time_base); num_samples = (__int64)(length * sample_rate); buffer = (int16_t *)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); if (!buffer) throw _T("Out of memory"); } catch (...) { Destroy(); throw; } }