static GstFlowReturn
gst_ffmpegaudioresample_transform (GstBaseTransform * trans, GstBuffer * inbuf,
    GstBuffer * outbuf)
{
  GstFFMpegAudioResample *resample = GST_FFMPEGAUDIORESAMPLE (trans);
  gint nbsamples;
  gint ret;

  gst_buffer_copy_metadata (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS);
  nbsamples = GST_BUFFER_SIZE (inbuf) / (2 * resample->in_channels);

  GST_LOG_OBJECT (resample, "input buffer duration:%" GST_TIME_FORMAT,
      GST_TIME_ARGS (GST_BUFFER_DURATION (inbuf)));

  GST_DEBUG_OBJECT (resample,
      "audio_resample(ctx, output:%p [size:%d], input:%p [size:%d], nbsamples:%d",
      GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf),
      GST_BUFFER_DATA (inbuf), GST_BUFFER_SIZE (inbuf), nbsamples);

  ret = audio_resample (resample->res, (short *) GST_BUFFER_DATA (outbuf),
      (short *) GST_BUFFER_DATA (inbuf), nbsamples);

  GST_DEBUG_OBJECT (resample, "audio_resample returned %d", ret);

  GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale (ret, GST_SECOND,
      resample->out_rate);
  GST_BUFFER_SIZE (outbuf) = ret * 2 * resample->out_channels;

  GST_LOG_OBJECT (resample, "Output buffer duration:%" GST_TIME_FORMAT,
      GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)));

  return GST_FLOW_OK;
}
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;

  /* FIXME : Allow configuring the various resampling properties */
#define TAPS 16
  resample->res =
      av_audio_resample_init (resample->out_channels, resample->in_channels,
      resample->out_rate, resample->in_rate,
      AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16, TAPS, 10, 0, 0.8);
  if (resample->res == NULL)
    return FALSE;

  return TRUE;
}
Пример #3
0
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 void
gst_ffmpegaudioresample_finalize (GObject * object)
{
  GstFFMpegAudioResample *resample = GST_FFMPEGAUDIORESAMPLE (object);

  if (resample->res != NULL)
    audio_resample_close (resample->res);

  G_OBJECT_CLASS (parent_class)->finalize (object);
}