Bug 1427150 - Don't get some default sink info based on the pa_sink_info build-time size. r?padenot draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 27 Dec 2017 17:31:57 +0900
changeset 714623 d9fbc8a131613a8c2813176fbb380b68d5f30a53
parent 714615 7d40443e6aa01ea63eb243df98dcb9243cadc14e
child 744636 d01fe36513f64a8618af12f8befcfbd223d11b1c
push id93977
push userbmo:mh+mozilla@glandium.org
push dateWed, 27 Dec 2017 08:57:12 +0000
reviewerspadenot
bugs1427150
milestone59.0a1
Bug 1427150 - Don't get some default sink info based on the pa_sink_info build-time size. r?padenot The build-time pa_sink_info might not have the same size as the at run time. This especially becomes a problem when the struct is larger at build-time, since we copy its content for the default sink info. However, we don't need most of the data in there, so create a new struct holding what we do need, and copy that. This new struct has a constant size across versions of pulseaudio.
media/libcubeb/src/cubeb_pulse.c
--- a/media/libcubeb/src/cubeb_pulse.c
+++ b/media/libcubeb/src/cubeb_pulse.c
@@ -92,22 +92,28 @@ LIBPULSE_API_VISIT(MAKE_TYPEDEF);
 #endif
 
 #if PA_CHECK_VERSION(2, 0, 0)
 static int has_pulse_v2 = 0;
 #endif
 
 static struct cubeb_ops const pulse_ops;
 
+struct cubeb_default_sink_info {
+  pa_channel_map channel_map;
+  uint32_t sample_spec_rate;
+  pa_sink_flags_t flags;
+};
+
 struct cubeb {
   struct cubeb_ops const * ops;
   void * libpulse;
   pa_threaded_mainloop * mainloop;
   pa_context * context;
-  pa_sink_info * default_sink_info;
+  struct cubeb_default_sink_info * default_sink_info;
   char * context_name;
   int error;
   cubeb_device_collection_changed_callback collection_changed_callback;
   void * collection_changed_user_ptr;
   cubeb_strings * device_ids;
 };
 
 struct cubeb_stream {
@@ -153,18 +159,20 @@ intern_device_id(cubeb * ctx, char const
 
 static void
 sink_info_callback(pa_context * context, const pa_sink_info * info, int eol, void * u)
 {
   (void)context;
   cubeb * ctx = u;
   if (!eol) {
     free(ctx->default_sink_info);
-    ctx->default_sink_info = malloc(sizeof(pa_sink_info));
-    memcpy(ctx->default_sink_info, info, sizeof(pa_sink_info));
+    ctx->default_sink_info = malloc(sizeof(struct cubeb_default_sink_info));
+    memcpy(&ctx->default_sink_info->channel_map, &info->channel_map, sizeof(pa_channel_map));
+    ctx->default_sink_info->sample_spec_rate = info->sample_spec.rate;
+    ctx->default_sink_info->flags = info->flags;
   }
   WRAP(pa_threaded_mainloop_signal)(ctx->mainloop, 0);
 }
 
 static void
 server_info_callback(pa_context * context, const pa_server_info * info, void * u)
 {
   pa_operation * o;
@@ -694,17 +702,17 @@ static int
 pulse_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate)
 {
   assert(ctx && rate);
   (void)ctx;
 
   if (!ctx->default_sink_info)
     return CUBEB_ERROR;
 
-  *rate = ctx->default_sink_info->sample_spec.rate;
+  *rate = ctx->default_sink_info->sample_spec_rate;
 
   return CUBEB_OK;
 }
 
 static int
 pulse_get_preferred_channel_layout(cubeb * ctx, cubeb_channel_layout * layout)
 {
   assert(ctx && layout);