~morphis/media-hub/fix-hybris-dep

« back to all changes in this revision

Viewing changes to src/core/media/gstreamer/bus.h

  • Committer: CI Train Bot
  • Author(s): Jim Hodapp
  • Date: 2015-06-04 14:18:19 UTC
  • mfrom: (140.1.7 media-hub)
  • Revision ID: ci-train-bot@canonical.com-20150604141819-y9m1y1d4og1lk3y4
Handle a wider array of GStreamer errors so that .ogv files are reported as failing to play. Fixes: #1458040
Approved by: PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
277
277
 
278
278
        auto thiz = static_cast<Bus*>(data);
279
279
        Message message(msg);
280
 
        thiz->on_new_message(message);
281
 
 
282
 
        return GST_BUS_DROP;
283
 
    }
284
 
 
285
 
    Bus(GstBus* bus) : bus(bus)
 
280
        if (message.type == GST_MESSAGE_TAG || message.type == GST_MESSAGE_ASYNC_DONE)
 
281
            thiz->on_new_message(message);
 
282
 
 
283
        return GST_BUS_PASS;
 
284
    }
 
285
 
 
286
    static gboolean bus_watch_handler(
 
287
            GstBus* bus,
 
288
            GstMessage* msg,
 
289
            gpointer data)
 
290
    {
 
291
        (void) bus;
 
292
 
 
293
        auto thiz = static_cast<Bus*>(data);
 
294
        Message message(msg);
 
295
        thiz->on_new_message_async(message);
 
296
 
 
297
        return true;
 
298
    }
 
299
 
 
300
    Bus(GstBus* bus) : bus(bus), bus_watch_id(0)
 
301
    {
 
302
        set_bus(bus);
 
303
    }
 
304
 
 
305
    ~Bus()
 
306
    {
 
307
        g_source_remove(bus_watch_id);
 
308
        gst_object_unref(bus);
 
309
    }
 
310
 
 
311
    void set_bus(GstBus* bus)
286
312
    {
287
313
        if (!bus)
288
314
            throw std::runtime_error("Cannot create Bus instance if underlying instance is NULL.");
292
318
                    Bus::sync_handler,
293
319
                    this,
294
320
                    nullptr);
295
 
    }
296
321
 
297
 
    ~Bus()
298
 
    {
299
 
        gst_object_unref(bus);
 
322
        // Use a watch for most messages instead of the sync handler so that our context is not
 
323
        // the same as the streaming thread, which can cause deadlocks in GStreamer
 
324
        // if, for example, attempting to change the pipeline state from this context.
 
325
        bus_watch_id = gst_bus_add_watch(
 
326
                            bus,
 
327
                            Bus::bus_watch_handler,
 
328
                            this);
300
329
    }
301
330
 
302
331
    GstBus* bus;
303
332
    core::Signal<Message> on_new_message;
 
333
    core::Signal<Message> on_new_message_async;
 
334
    guint bus_watch_id;
304
335
};
305
336
}
306
337