[FFmpeg-devel] [PATCH] OpenAL 1.1 Capture Support

Stefano Sabatini stefano.sabatini-lala at poste.it
Sat Jun 18 14:52:45 CEST 2011


On date Friday 2011-06-17 22:21:42 -0400, Jonathan Baldwin encoded:
> >> Sorry for the delay, I was kind of busy.
> ++;
> 
> > Please verify that this is correctly rendered in the man page (the
> > last time I checked, multi-tables are not correctly displayed), in
> > this case the previous approach would be just fine.
> 
> Apparently upstream texi2pod.pl (gcc) does, but the output doesn't
> look to pleasant IMHO anyways. Wasted a few hours messing with it, and
> decided it was easier to avoid multi-tables. Changed to a plain old
> two-column @table.
> 
> > Note: it would be useful to list the available supported devices,
> > e.g. with a list option which returns AVERROR_EXIT (no need to do it
> > in this patch though).
> 
> Regarding the list option,
> 
> Can something like
> $ ffmpeg -f openal -list_devices
> be achieved, or is
> $ ffmpeg -f openal -list_devices 1
> or even
> $ ffmpeg -f openal -list_devices 1 ''
> the best I can get?
> 
> I found AV_OPT_TYPE_FLAGS, is this relevant, and how would I use it?

Yes, I confirm there is no way to set a boolean, the only way is
throug -list_devices 1 or by abusing the filename like it is done in
vfwcap ("list" provided as filename will cause the device to list the
available devices, but I don't like that solution).

[...]
> +static int read_header(AVFormatContext* ctx, AVFormatParameters *ap)
> +{
> +    static const ALCenum sample_formats[2][2] = {
> +        {AL_FORMAT_MONO8,AL_FORMAT_STEREO8},
> +        {AL_FORMAT_MONO16,AL_FORMAT_STEREO16}
> +    };
> +    al_data *ad = ctx->priv_data;
> +    int error=0;
> +    const char *error_msg;
> +    AVStream *st = NULL;
> +    AVCodecContext *codec = NULL;
> +    
> +    ad->sample_format = sample_formats[ad->sample_size/8-1][ad->channels-1];
> +
> +    /* Open device for capture */
> +    ad->device = alcCaptureOpenDevice(
> +                     ctx->filename[0] ? ctx->filename : 0,
> +                     ad->sample_rate,
> +                     ad->sample_format,
> +                     ad->sample_rate /* Maximum 1 second of sample data to be read at once */
> +                 );
> +
> +    /* Did we fail? */
> +    if(error=al_get_error(ad->device, &error_msg)) goto fail;
> +
> +    /* Create stream */
> +    if(! (st=av_new_stream(ctx, 0))) {
> +        error=AVERROR (ENOMEM);
> +        goto fail;
> +    }
> +
> +    /* We work in microseconds */
> +    av_set_pts_info(st, 64, 1, 1000000);
> +
> +    /* Set codec parameters */
> +    codec = st->codec;
> +    codec->codec_type = AVMEDIA_TYPE_AUDIO;
> +    codec->sample_rate = ad->sample_rate;
> +    codec->channels = get_al_format_info(ad->sample_format)->channels;
> +    codec->codec_id = get_al_format_info(ad->sample_format)->codec_id;
> +
> +    /* This is needed to read the audio data */
> +    ad->sample_step = (av_get_bits_per_sample(get_al_format_info(ad->sample_format)->codec_id) *
> +                       get_al_format_info(ad->sample_format)->channels) / 8;
> +
> +    /* Finally, start the capture process */
> +    alcCaptureStart(ad->device);
> +
> +    return 0;
> +
> +    /* Handle failure */
> +fail:
> +    if(ad->device)
> +        alcCaptureCloseDevice(ad->device);
> +
> +    if(error_msg)
> +        av_log(ctx, AV_LOG_ERROR, "Error: %s\n", error_msg);
> +

> +    /* An EINVAL error here is probably due to an invalid OpenAL capture device name */
> +    if(error==AVERROR (EINVAL)) {
> +        av_log(ctx, AV_LOG_ERROR, "Did you use a valid OpenAL capture device name?\n");
> +        print_al_capture_devices();
> +    }

I fear this message will get tedious if the "guess" is wrong, I'd
prefer just the list_device option (explicit and perfectly predicible,
no need for wild guesses or supposing that a device name can't be
named "list" or like another arbitrary string).

[...]

No more comments from me. I suppose the device has been tested and
works.
-- 
FFmpeg = Fundamentalist and Fast Murdering Problematic Enigmatic Game


More information about the ffmpeg-devel mailing list