static void got_sources(GList *sources, gpointer user_data)
{
    OwrMediaSource *source = NULL;
    static gboolean have_video = FALSE, have_audio = FALSE;

    g_assert(sources);

    while (sources && (source = sources->data)) {
        OwrMediaType media_type;
        OwrSourceType source_type;

        g_assert(OWR_IS_MEDIA_SOURCE(source));

        g_object_get(source, "type", &source_type, "media-type", &media_type, NULL);

        if (!disable_video && !have_video && media_type == OWR_MEDIA_TYPE_VIDEO && source_type == OWR_SOURCE_TYPE_CAPTURE) {
            OwrVideoRenderer *renderer;
            OwrPayload *payload;

            have_video = TRUE;

            payload = owr_video_payload_new(OWR_CODEC_TYPE_VP8, 103, 90000, TRUE, FALSE);
            g_object_set(payload, "width", 1280, "height", 720, "framerate", 30.0, NULL);
            g_object_set(payload, "rtx-payload-type", 123, NULL);

            owr_media_session_set_send_payload(send_session_video, payload);

            owr_media_session_set_send_source(send_session_video, source);

            owr_transport_agent_add_session(send_transport_agent, OWR_SESSION(send_session_video));

            g_print("Displaying self-view\n");

            renderer = owr_video_renderer_new(NULL);
            g_assert(renderer);
            g_object_set(renderer, "width", 1280, "height", 720, "max-framerate", 30.0, NULL);
            owr_media_renderer_set_source(OWR_MEDIA_RENDERER(renderer), source);
            video_renderer = OWR_MEDIA_RENDERER(renderer);
            video_source = g_object_ref(source);
        } else if (!disable_audio && !have_audio && media_type == OWR_MEDIA_TYPE_AUDIO && source_type == OWR_SOURCE_TYPE_CAPTURE) {
            OwrPayload *payload;

            have_audio = TRUE;

            payload = owr_audio_payload_new(OWR_CODEC_TYPE_OPUS, 100, 48000, 1);
            owr_media_session_set_send_payload(send_session_audio, payload);

            owr_media_session_set_send_source(send_session_audio, source);

            owr_transport_agent_add_session(send_transport_agent, OWR_SESSION(send_session_audio));
            audio_source = g_object_ref(source);
        }

        if ((disable_video || have_video) && (disable_audio || have_audio))
            break;

        sources = sources->next;
    }
}
void _owr_local_media_source_set_capture_device_index(OwrLocalMediaSource *source, guint index)
{
    OwrSourceType source_type = -1;
    g_return_if_fail(OWR_IS_MEDIA_SOURCE(source));
    g_object_get(source, "type", &source_type, NULL);
    g_return_if_fail(source_type == OWR_SOURCE_TYPE_CAPTURE);
    source->priv->device_index = index;
}
/**
 * _owr_media_source_release_source:
 * @media_source:
 * @source: (transfer none):
 *
 */
void _owr_media_source_release_source(OwrMediaSource *media_source, GstElement *source)
{
    g_return_if_fail(OWR_IS_MEDIA_SOURCE(media_source));
    g_return_if_fail(GST_IS_ELEMENT(source));

    g_mutex_lock(&media_source->lock);
    OWR_MEDIA_SOURCE_GET_CLASS(media_source)->release_source(media_source, source);
    g_mutex_unlock(&media_source->lock);
}
/**
 * _owr_media_source_set_source_tee:
 * @media_source:
 * @tee: (transfer none):
 *
 */
void _owr_media_source_set_source_tee(OwrMediaSource *media_source, GstElement *tee)
{
    g_return_if_fail(OWR_IS_MEDIA_SOURCE(media_source));
    g_return_if_fail(!tee || GST_IS_ELEMENT(tee));

    if (media_source->priv->source_tee) {
        gst_object_unref(media_source->priv->source_tee);
    }
    media_source->priv->source_tee = tee ? gst_object_ref(tee) : NULL;
}
/**
 * _owr_media_source_set_source_bin:
 * @media_source:
 * @bin: (transfer none):
 *
 */
void _owr_media_source_set_source_bin(OwrMediaSource *media_source, GstElement *bin)
{
    g_return_if_fail(OWR_IS_MEDIA_SOURCE(media_source));
    g_return_if_fail(!bin || GST_IS_ELEMENT(bin));

    if (media_source->priv->source_bin) {
        gst_element_set_state(media_source->priv->source_bin, GST_STATE_NULL);
        gst_object_unref(media_source->priv->source_bin);
    }
    media_source->priv->source_bin = bin ? gst_object_ref(bin) : NULL;
}
static gboolean set_source(GHashTable *args)
{
    OwrMediaRenderer *renderer;
    OwrMediaSource *source;
    OwrMediaRendererPrivate *priv;

    g_return_val_if_fail(args, G_SOURCE_REMOVE);

    renderer = g_hash_table_lookup(args, "renderer");
    source = g_hash_table_lookup(args, "source");

    g_return_val_if_fail(OWR_IS_MEDIA_RENDERER(renderer), G_SOURCE_REMOVE);
    g_return_val_if_fail(!source || OWR_IS_MEDIA_SOURCE(source), G_SOURCE_REMOVE);

    priv = renderer->priv;

    g_mutex_lock(&priv->media_renderer_lock);

    if (source == priv->source) {
        g_mutex_unlock(&priv->media_renderer_lock);
        goto end;
    }

    if (priv->source) {
        _owr_media_source_release_source(priv->source, priv->src);
        gst_element_set_state(priv->src, GST_STATE_NULL);
        gst_bin_remove(GST_BIN(priv->pipeline), priv->src);
        priv->src = NULL;
        g_object_unref(priv->source);
        priv->source = NULL;
    }

    if (!source) {
        /* Shut down the pipeline if we have no source */
        gst_element_set_state(priv->pipeline, GST_STATE_NULL);
        OWR_POST_EVENT(renderer, RENDERER_STOPPED, NULL);
        g_mutex_unlock(&priv->media_renderer_lock);
        goto end;
    }

    priv->source = g_object_ref(source);

    _owr_media_renderer_reconfigure_element(renderer);
    maybe_start_renderer(renderer);

    g_mutex_unlock(&priv->media_renderer_lock);

end:
    g_object_unref(renderer);
    if (source)
        g_object_unref(source);
    g_hash_table_unref(args);
    return G_SOURCE_REMOVE;
}
/**
 * _owr_media_source_request_source:
 * @media_source:
 * @caps: (transfer none):
 *
 * Returns: (transfer full):
 *
 */
GstElement *_owr_media_source_request_source(OwrMediaSource *media_source, GstCaps *caps)
{
    GstElement *source;

    g_return_val_if_fail(OWR_IS_MEDIA_SOURCE(media_source), NULL);

    g_mutex_lock(&media_source->lock);
    source = OWR_MEDIA_SOURCE_GET_CLASS(media_source)->request_source(media_source, caps);
    g_mutex_unlock(&media_source->lock);

    return source;
}
gchar * owr_media_source_get_dot_data(OwrMediaSource *source)
{
    g_return_val_if_fail(OWR_IS_MEDIA_SOURCE(source), NULL);

    if (!source->priv->source_bin)
        return g_strdup("");

#if GST_CHECK_VERSION(1, 5, 0)
    return gst_debug_bin_to_dot_data(GST_BIN(source->priv->source_bin), GST_DEBUG_GRAPH_SHOW_ALL);
#else
    return g_strdup("");
#endif
}
Exemple #9
0
static void got_sources(GList *sources, gpointer user_data)
{
    OwrMediaSource *source = NULL;
    static gboolean have_video = FALSE, have_audio = FALSE;
    g_assert(sources);

    g_print("Got sources!\n");

    while(sources && (source = sources->data)) {
        OwrMediaType media_type;
        OwrSourceType source_type;

        g_assert(OWR_IS_MEDIA_SOURCE(source));

        g_object_get(source, "type", &source_type, "media-type", &media_type, NULL);

        if (!have_video && media_type == OWR_MEDIA_TYPE_VIDEO && source_type == OWR_SOURCE_TYPE_CAPTURE) {
            OwrVideoRenderer *renderer;

            have_video = TRUE;

            renderer = owr_video_renderer_new(NULL);
            g_assert(renderer);

            g_object_set(renderer, "width", 1280, "height", 720, "max-framerate", 30.0, NULL);
            owr_media_renderer_set_source(OWR_MEDIA_RENDERER(renderer), source);
            video_renderer = OWR_MEDIA_RENDERER(renderer);
            video_source = source;
        } else if (!have_audio && media_type == OWR_MEDIA_TYPE_AUDIO && source_type == OWR_SOURCE_TYPE_CAPTURE) {
            OwrAudioRenderer *renderer;

            have_audio = TRUE;

            renderer = owr_audio_renderer_new();
            g_assert(renderer);

            owr_media_renderer_set_source(OWR_MEDIA_RENDERER(renderer), source);
            audio_renderer = OWR_MEDIA_RENDERER(renderer);
            audio_source = source;
        }

        if (have_video && have_audio)
            break;

        sources = sources->next;
    }

    g_timeout_add(5000, dump_pipeline, NULL);
}
/**
 * owr_media_renderer_set_source:
 * @renderer:
 * @source: (transfer none) (allow-none):
 *
 * Returns:
 */
void owr_media_renderer_set_source(OwrMediaRenderer *renderer, OwrMediaSource *source)
{
    GHashTable *args;

    g_return_if_fail(OWR_IS_MEDIA_RENDERER(renderer));
    g_return_if_fail(!source || OWR_IS_MEDIA_SOURCE(source));

    args = g_hash_table_new(g_str_hash, g_str_equal);
    g_hash_table_insert(args, "renderer", renderer);
    g_hash_table_insert(args, "source", source);

    g_object_ref(renderer);
    if (source)
        g_object_ref(source);

    _owr_schedule_with_hash_table((GSourceFunc)set_source, args);
}
Exemple #11
0
static void got_sources(GList *sources, gpointer user_data)
{
    OwrMediaSource *source = NULL;
    g_assert(sources);

    while(sources && (source = sources->data)) {
        gchar *name = NULL;
        OwrMediaType media_type;
        OwrSourceType source_type;

        g_assert(OWR_IS_MEDIA_SOURCE(source));

        g_object_get(source, "name", &name, "type", &source_type, "media-type", &media_type, NULL);

        g_print("[%s/%s] %s\n", media_type == OWR_MEDIA_TYPE_AUDIO ? "audio" : "video",
            source_type == OWR_SOURCE_TYPE_CAPTURE ? "capture" : source_type == OWR_SOURCE_TYPE_TEST ? "test" : "unknown",
            name);

        sources = sources->next;
    }

    owr_quit();
}
static void got_sources(GList *sources, gpointer user_data)
{
    OwrMediaSource *source = NULL;
    static gboolean have_video = FALSE, have_audio = FALSE;

    g_assert(sources);

    while (sources && (source = sources->data)) {
        OwrMediaType media_type;
        OwrSourceType source_type;

        g_assert(OWR_IS_MEDIA_SOURCE(source));

        g_object_get(source, "type", &source_type, "media-type", &media_type, NULL);

        if (remote_addr) {
            owr_transport_agent_add_helper_server(send_transport_agent, OWR_HELPER_SERVER_TYPE_STUN,
                "stun.services.mozilla.com", 3478, NULL, NULL);
            owr_transport_agent_add_helper_server(recv_transport_agent, OWR_HELPER_SERVER_TYPE_STUN,
                "stun.services.mozilla.com", 3478, NULL, NULL);
        }

        if (!disable_video && !have_video && media_type == OWR_MEDIA_TYPE_VIDEO) {
            OwrVideoRenderer *renderer;
            OwrPayload *payload;

            have_video = TRUE;

            owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(source));

            payload = owr_video_payload_new(OWR_CODEC_TYPE_VP8, 103, 90000, TRUE, FALSE);
            g_object_set(payload, "width", 640, "height", 480, "framerate", 30.0, NULL);
            g_object_set(payload, "rtx-payload-type", 123, NULL);
            if (adaptation)
                g_object_set(payload, "adaptation", TRUE, NULL);

            owr_media_session_set_send_payload(send_session_video, payload);

            owr_media_session_set_send_source(send_session_video, source);

            owr_transport_agent_add_session(recv_transport_agent, OWR_SESSION(recv_session_video));
            owr_transport_agent_add_session(send_transport_agent, OWR_SESSION(send_session_video));

            g_print("Displaying self-view\n");

            renderer = owr_video_renderer_new(NULL);
            g_assert(renderer);
            owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(renderer));

            g_object_set(renderer, "width", 640, "height", 480, "max-framerate", 30.0, NULL);
            owr_media_renderer_set_source(OWR_MEDIA_RENDERER(renderer), source);
            video_renderer = OWR_MEDIA_RENDERER(renderer);
            video_source = g_object_ref(source);
        } else if (!disable_audio && !have_audio && media_type == OWR_MEDIA_TYPE_AUDIO) {
            OwrPayload *payload;

            have_audio = TRUE;

            owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(source));

            payload = owr_audio_payload_new(OWR_CODEC_TYPE_OPUS, 100, 48000, 1);
            owr_media_session_set_send_payload(send_session_audio, payload);

            owr_media_session_set_send_source(send_session_audio, source);

            owr_transport_agent_add_session(recv_transport_agent, OWR_SESSION(recv_session_audio));
            owr_transport_agent_add_session(send_transport_agent, OWR_SESSION(send_session_audio));
            audio_source = g_object_ref(source);
        }

        if ((disable_video || have_video) && (disable_audio || have_audio))
            break;

        sources = sources->next;
    }
}
void _owr_media_source_set_codec(OwrMediaSource *media_source, OwrCodecType codec_type)
{
    g_return_if_fail(OWR_IS_MEDIA_SOURCE(media_source));
    /* an enum is an int type so we can use atomic assignment */
    g_atomic_int_set(&media_source->priv->codec_type, codec_type);
}
OwrCodecType _owr_media_source_get_codec(OwrMediaSource *media_source)
{
    g_return_val_if_fail(OWR_IS_MEDIA_SOURCE(media_source), OWR_CODEC_TYPE_NONE);
    return media_source->priv->codec_type;
}
/**
 * _owr_media_source_get_source_tee:
 * @media_source:
 *
 * Returns: (transfer full):
 *
 */
GstElement *_owr_media_source_get_source_tee(OwrMediaSource *media_source)
{
    g_return_val_if_fail(OWR_IS_MEDIA_SOURCE(media_source), NULL);

    return media_source->priv->source_tee ? gst_object_ref(media_source->priv->source_tee) : NULL;
}