lavd/pulse_audio_enc: cosmetics
authorLukasz Marek <lukasz.m.luki2@gmail.com>
Thu, 17 Apr 2014 23:10:20 +0000 (01:10 +0200)
committerLukasz Marek <lukasz.m.luki2@gmail.com>
Thu, 17 Apr 2014 23:42:17 +0000 (01:42 +0200)
libavdevice/pulse_audio_enc.c

index fa2a7cb0c5520e9d6ec6a84ea8e2709b8b02e2e4..885a1fb15a3fc6c2c301eff92c0d497d0bcec3db 100644 (file)
@@ -35,8 +35,8 @@ typedef struct PulseData {
     const char *device;
     pa_simple *pa;
     int64_t timestamp;
     const char *device;
     pa_simple *pa;
     int64_t timestamp;
-    int buffer_size;
-    int buffer_duration;
+    int buffer_size;               /**< Buffer size in bytes */
+    int buffer_duration;           /**< Buffer size in ms, recalculated to buffer_size */
 } PulseData;
 
 static av_cold int pulse_write_header(AVFormatContext *h)
 } PulseData;
 
 static av_cold int pulse_write_header(AVFormatContext *h)
@@ -44,8 +44,8 @@ static av_cold int pulse_write_header(AVFormatContext *h)
     PulseData *s = h->priv_data;
     AVStream *st = NULL;
     int ret;
     PulseData *s = h->priv_data;
     AVStream *st = NULL;
     int ret;
-    pa_sample_spec ss;
-    pa_buffer_attr attr = { -1, -1, -1, -1, -1 };
+    pa_sample_spec sample_spec;
+    pa_buffer_attr buffer_attributes = { -1, -1, -1, -1, -1 };
     const char *stream_name = s->stream_name;
 
     if (h->nb_streams != 1 || h->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
     const char *stream_name = s->stream_name;
 
     if (h->nb_streams != 1 || h->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
@@ -66,26 +66,30 @@ static av_cold int pulse_write_header(AVFormatContext *h)
         bytes *= st->codec->channels * st->codec->sample_rate *
                  av_get_bytes_per_sample(st->codec->sample_fmt);
         bytes /= 1000;
         bytes *= st->codec->channels * st->codec->sample_rate *
                  av_get_bytes_per_sample(st->codec->sample_fmt);
         bytes /= 1000;
-        attr.tlength = FFMAX(s->buffer_size, av_clip64(bytes, 0, UINT32_MAX - 1));
+        buffer_attributes.tlength = FFMAX(s->buffer_size, av_clip64(bytes, 0, UINT32_MAX - 1));
         av_log(s, AV_LOG_DEBUG,
                "Buffer duration: %ums recalculated into %"PRId64" bytes buffer.\n",
                s->buffer_duration, bytes);
         av_log(s, AV_LOG_DEBUG,
                "Buffer duration: %ums recalculated into %"PRId64" bytes buffer.\n",
                s->buffer_duration, bytes);
-        av_log(s, AV_LOG_DEBUG, "Real buffer length is %u bytes\n", attr.tlength);
+        av_log(s, AV_LOG_DEBUG, "Real buffer length is %u bytes\n", buffer_attributes.tlength);
     } else if (s->buffer_size)
     } else if (s->buffer_size)
-        attr.tlength = s->buffer_size;
+        buffer_attributes.tlength = s->buffer_size;
 
 
-    ss.format = ff_codec_id_to_pulse_format(st->codec->codec_id);
-    ss.rate = st->codec->sample_rate;
-    ss.channels = st->codec->channels;
+    sample_spec.format = ff_codec_id_to_pulse_format(st->codec->codec_id);
+    sample_spec.rate = st->codec->sample_rate;
+    sample_spec.channels = st->codec->channels;
+    if (!pa_sample_spec_valid(&sample_spec)) {
+        av_log(s, AV_LOG_ERROR, "Invalid sample spec.\n");
+        return AVERROR(EINVAL);
+    }
 
     s->pa = pa_simple_new(s->server,                 // Server
                           s->name,                   // Application name
                           PA_STREAM_PLAYBACK,
                           s->device,                 // Device
                           stream_name,               // Description of a stream
 
     s->pa = pa_simple_new(s->server,                 // Server
                           s->name,                   // Application name
                           PA_STREAM_PLAYBACK,
                           s->device,                 // Device
                           stream_name,               // Description of a stream
-                          &ss,                       // Sample format
+                          &sample_spec,              // Sample format
                           NULL,                      // Use default channel map
                           NULL,                      // Use default channel map
-                          &attr,                     // Buffering attributes
+                          &buffer_attributes,        // Buffering attributes
                           &ret);                     // Result
 
     if (!s->pa) {
                           &ret);                     // Result
 
     if (!s->pa) {
@@ -175,19 +179,18 @@ static int pulse_get_device_list(AVFormatContext *h, AVDeviceInfoList *device_li
 
 #define OFFSET(a) offsetof(PulseData, a)
 #define E AV_OPT_FLAG_ENCODING_PARAM
 
 #define OFFSET(a) offsetof(PulseData, a)
 #define E AV_OPT_FLAG_ENCODING_PARAM
-
 static const AVOption options[] = {
 static const AVOption options[] = {
-    { "server",        "set PulseAudio server",  OFFSET(server),      AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
-    { "name",          "set application name",   OFFSET(name),        AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT},  0, 0, E },
-    { "stream_name",   "set stream description", OFFSET(stream_name), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
-    { "device",        "set device name",        OFFSET(device),      AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
-    { "buffer_size",   "set buffer size in bytes", OFFSET(buffer_size), AV_OPT_TYPE_INT,  {.i64 = 0}, 0, INT_MAX, E },
-    { "buffer_duration", "set buffer duration in millisecs", OFFSET(buffer_duration), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
+    { "server",          "set PulseAudio server",            OFFSET(server),          AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
+    { "name",            "set application name",             OFFSET(name),            AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT},  0, 0, E },
+    { "stream_name",     "set stream description",           OFFSET(stream_name),     AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
+    { "device",          "set device name",                  OFFSET(device),          AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
+    { "buffer_size",     "set buffer size in bytes",         OFFSET(buffer_size),     AV_OPT_TYPE_INT,    {.i64 = 0}, 0, INT_MAX, E },
+    { "buffer_duration", "set buffer duration in millisecs", OFFSET(buffer_duration), AV_OPT_TYPE_INT,    {.i64 = 0}, 0, INT_MAX, E },
     { NULL }
 };
 
 static const AVClass pulse_muxer_class = {
     { NULL }
 };
 
 static const AVClass pulse_muxer_class = {
-    .class_name     = "Pulse muxer",
+    .class_name     = "PulseAudio muxer",
     .item_name      = av_default_item_name,
     .option         = options,
     .version        = LIBAVUTIL_VERSION_INT,
     .item_name      = av_default_item_name,
     .option         = options,
     .version        = LIBAVUTIL_VERSION_INT,
@@ -195,17 +198,17 @@ static const AVClass pulse_muxer_class = {
 };
 
 AVOutputFormat ff_pulse_muxer = {
 };
 
 AVOutputFormat ff_pulse_muxer = {
-    .name           = "pulse",
-    .long_name      = NULL_IF_CONFIG_SMALL("Pulse audio output"),
-    .priv_data_size = sizeof(PulseData),
-    .audio_codec    = AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE),
-    .video_codec    = AV_CODEC_ID_NONE,
-    .write_header   = pulse_write_header,
-    .write_packet   = pulse_write_packet,
-    .write_uncoded_frame = pulse_write_frame,
-    .write_trailer  = pulse_write_trailer,
+    .name                 = "pulse",
+    .long_name            = NULL_IF_CONFIG_SMALL("Pulse audio output"),
+    .priv_data_size       = sizeof(PulseData),
+    .audio_codec          = AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE),
+    .video_codec          = AV_CODEC_ID_NONE,
+    .write_header         = pulse_write_header,
+    .write_packet         = pulse_write_packet,
+    .write_uncoded_frame  = pulse_write_frame,
+    .write_trailer        = pulse_write_trailer,
     .get_output_timestamp = pulse_get_output_timestamp,
     .get_output_timestamp = pulse_get_output_timestamp,
-    .get_device_list = pulse_get_device_list,
-    .flags          = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH,
-    .priv_class     = &pulse_muxer_class,
+    .get_device_list      = pulse_get_device_list,
+    .flags                = AVFMT_NOFILE | AVFMT_ALLOW_FLUSH,
+    .priv_class           = &pulse_muxer_class,
 };
 };