On Tue, 25 Oct 2011 18:59:10 -0700, Luca Barbato <[email protected]> wrote:
> +static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> + PulseData *pd = s->priv_data;
> + int res;
> + pa_usec_t latency;
> + uint64_t frame_duration =
> + (pd->frame_size*1000000LL)/(pd->sample_rate * pd->channels);
> +
> + if (av_new_packet(pkt, pd->frame_size) < 0) {
> + return AVERROR(ENOMEM);
> + }
> +
> + if ((pa_simple_read(pd->s, pkt->data, pkt->size, &res)) < 0) {
> + av_log(s, AV_LOG_ERROR, "pa_simple_read failed: %s\n",
> + pa_strerror(res));
> + av_free_packet(pkt);
> + return AVERROR(EIO);
> + }
> +
> + if ((latency = pa_simple_get_latency(pd->s, &res)) == (pa_usec_t) -1) {
> + av_log(s, AV_LOG_ERROR, "pa_simple_get_latency() failed: %s\n",
> + pa_strerror(res));
> + return AVERROR(EIO);
> + }
> +
> + if (pd->pts == AV_NOPTS_VALUE) {
> + pd->pts = -latency;
I find this a bit suspicious. If, as you said on IRC, pulseaudio buffers
the data so it is continuous and nothing is dropped, then pts of the
next frame should be just pts of the previous + frame duration.
> + }
> +
> + pd->pts += frame_duration;
> +
> + pkt->pts = pd->pts;
> +
> + return 0;
> +}
> +
> +static av_cold int pulse_close(AVFormatContext *s)
> +{
> + PulseData *pd = s->priv_data;
> + pa_simple_free(pd->s);
> + return 0;
> +}
> +
> +#define OFFSET(a) offsetof(PulseData, a)
> +#define D AV_OPT_FLAG_DECODING_PARAM
> +
> +static const AVOption options[] = {
> + { "server", "pulse server name",
> + OFFSET(server), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0,
> D },
> + { "name", "application name",
> + OFFSET(name), AV_OPT_TYPE_STRING, {.str = "libav"}, 0, 0,
> D },
> + { "stream_name", "stream description",
> + OFFSET(stream_name), AV_OPT_TYPE_STRING, {.str = "record"}, 0, 0,
> D },
> + { "sample_rate", "",
> + OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1,
> INT_MAX, D },
> + { "channels", "",
> + OFFSET(channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1,
> INT_MAX, D },
> + { "frame_size", "",
> + OFFSET(frame_size), AV_OPT_TYPE_INT, {.dbl = 1024}, 1,
> INT_MAX, D },
You might mention that it's in bytes, not seconds or whatever.
And I agree with Justin that long lines are more readable here.
--
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel