static void got_remote_source(OwrMediaSession *session, OwrMediaSource *source, gpointer user_data)
{
    gchar *name = NULL;
    OwrMediaType media_type;

    g_assert(!user_data);

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

    g_print("Got remote source: %s\n", name);

    if (media_type == OWR_MEDIA_TYPE_VIDEO) {
        OwrVideoRenderer *renderer;

        g_print("Creating video renderer\n");
        renderer = owr_video_renderer_new(NULL);
        g_assert(renderer);
        owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(renderer));

        g_print("Connecting source to video renderer\n");
        owr_media_renderer_set_source(OWR_MEDIA_RENDERER(renderer), source);
        remote_video_renderer = OWR_MEDIA_RENDERER(renderer);
    } else if (media_type == OWR_MEDIA_TYPE_AUDIO) {
        OwrAudioRenderer *renderer;

        g_print("Creating audio renderer\n");
        renderer = owr_audio_renderer_new();
        g_assert(renderer);
        owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(renderer));

        g_print("Connecting source to audio renderer\n");
        owr_media_renderer_set_source(OWR_MEDIA_RENDERER(renderer), source);
        remote_audio_renderer = OWR_MEDIA_RENDERER(renderer);
    }

    g_free(name);

    if (media_type == OWR_MEDIA_TYPE_VIDEO)
        remote_video_source = g_object_ref(source);
    else
        remote_audio_source = g_object_ref(source);
}
Exemple #2
0
/**
 * owr_session_force_remote_candidate:
 * @session: The session on which the candidate will be forced.
 * @candidate: (transfer none): the candidate to forcibly set
 *
 * Forces the transport agent to use the given candidate. Calling this function will disable all
 * further ICE processing. Keep-alives will continue to be sent.
 */
void owr_session_force_remote_candidate(OwrSession *session, OwrCandidate *candidate)
{
    GHashTable *args;

    g_return_if_fail(OWR_IS_SESSION(session));
    g_return_if_fail(OWR_IS_CANDIDATE(candidate));

    args = _owr_create_schedule_table(OWR_MESSAGE_ORIGIN(session));
    g_hash_table_insert(args, "session", session);
    g_hash_table_insert(args, "candidate", candidate);
    g_hash_table_insert(args, "forced", GINT_TO_POINTER(TRUE));
    g_object_ref(session);
    g_object_ref(candidate);

    _owr_schedule_with_hash_table((GSourceFunc)add_remote_candidate, args);
}
void owr_window_registry_unregister(OwrWindowRegistry *window_registry,
    const gchar *tag)
{
    GHashTable *args;

    g_return_if_fail(OWR_IS_WINDOW_REGISTRY(window_registry));
    g_return_if_fail(tag);

    args = _owr_create_schedule_table(OWR_MESSAGE_ORIGIN(window_registry));
    g_hash_table_insert(args, "window_registry", window_registry);
    g_hash_table_insert(args, "tag", g_strdup(tag));

    g_object_ref(window_registry);

    _owr_schedule_with_hash_table((GSourceFunc)do_unregister, args);
}
static void tee_pad_removed_cb(GstElement *tee, GstPad *old_pad, gpointer user_data)
{
    OwrMediaSource *media_source = user_data;

    OWR_UNUSED(old_pad);

    /* No sink is left, shutdown */
    if (!tee->numsrcpads) {
        GHashTable *args;

        args = _owr_create_schedule_table(OWR_MESSAGE_ORIGIN(media_source));
        g_hash_table_insert(args, "media_source", media_source);
        g_object_ref(media_source);

        _owr_schedule_with_hash_table((GSourceFunc)shutdown_media_source, args);
    }
}
/**
 * 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 = _owr_create_schedule_table(OWR_MESSAGE_ORIGIN(renderer));
    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 #6
0
/**
 * owr_session_force_candidate_pair:
 * @session: The session on which the candidate will be forced.
 * @local_candidate: (transfer none): the local candidate to forcibly set
 * @remote_candidate: (transfer none): the remote candidate to forcibly set
 *
 * Forces the transport agent to use the given candidate pair. Calling this
 * function will disable all further ICE processing. Keep-alives will continue
 * to be sent.
 */
void owr_session_force_candidate_pair(OwrSession *session, OwrComponentType ctype,
        OwrCandidate *local_candidate, OwrCandidate *remote_candidate)
{
    GHashTable *args;

    g_return_if_fail(OWR_IS_SESSION(session));
    g_return_if_fail(OWR_IS_CANDIDATE(local_candidate));
    g_return_if_fail(OWR_IS_CANDIDATE(remote_candidate));

    args = _owr_create_schedule_table(OWR_MESSAGE_ORIGIN(session));
    g_hash_table_insert(args, "session", session);
    g_hash_table_insert(args, "component-type", GUINT_TO_POINTER(ctype));
    g_hash_table_insert(args, "local-candidate", local_candidate);
    g_hash_table_insert(args, "remote-candidate", remote_candidate);
    g_object_ref(session);
    g_object_ref(local_candidate);
    g_object_ref(remote_candidate);

    _owr_schedule_with_hash_table((GSourceFunc)add_candidate_pair, args);
}
Exemple #7
0
/**
 * owr_session_add_remote_candidate:
 * @session: the session on which the candidate will be added.
 * @candidate: (transfer none): the candidate to add
 *
 * Adds a remote candidate for this session.
 *
 */
void owr_session_add_remote_candidate(OwrSession *session, OwrCandidate *candidate)
{
    GHashTable *args;

    g_return_if_fail(session);
    g_return_if_fail(candidate);

    if (session->priv->rtcp_mux && _owr_candidate_get_component_type(candidate) == OWR_COMPONENT_TYPE_RTCP) {
        g_warning("Trying to adding RTCP component on an rtcp_muxing session. Aborting");
        return;
    }

    args = _owr_create_schedule_table(OWR_MESSAGE_ORIGIN(session));
    g_hash_table_insert(args, "session", session);
    g_hash_table_insert(args, "candidate", candidate);
    g_object_ref(session);
    g_object_ref(candidate);

    _owr_schedule_with_hash_table((GSourceFunc)add_remote_candidate, args);
}
int main(int argc, char **argv)
{
    GOptionContext *options;
    GError *error = NULL;

    options = g_option_context_new(NULL);
    g_option_context_add_main_entries(options, entries, NULL);
    if (!g_option_context_parse(options, &argc, &argv, &error)) {
        g_print("Failed to parse options: %s\n", error->message);
        return 1;
    }

    if (disable_audio && disable_video) {
        g_print("Audio and video disabled. Nothing to do.\n");
        return 0;
    }

    /* PREPARE FOR RECEIVING */

    OwrPayload *receive_payload;

    owr_init(NULL);

    bus = owr_bus_new();
    owr_bus_set_message_callback(bus, (OwrBusMessageCallback) bus_message_print_callback,
        message_origin_name_func, NULL);

    if (!print_messages) {
        g_object_set(bus, "message-type-mask", OWR_MESSAGE_TYPE_ERROR, NULL);
    }

    owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(owr_window_registry_get()));

    recv_transport_agent = owr_transport_agent_new(FALSE);
    g_assert(OWR_IS_TRANSPORT_AGENT(recv_transport_agent));
    owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(recv_transport_agent));

    owr_transport_agent_set_local_port_range(recv_transport_agent, 5120, 5127);
    if (!remote_addr)
        owr_transport_agent_add_local_address(recv_transport_agent, "127.0.0.1");
    else if (local_addr)
        owr_transport_agent_add_local_address(recv_transport_agent, local_addr);

    // SEND
    send_transport_agent = owr_transport_agent_new(TRUE);
    g_assert(OWR_IS_TRANSPORT_AGENT(send_transport_agent));
    owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(send_transport_agent));

    owr_transport_agent_set_local_port_range(send_transport_agent, 5120, 5129);
    if (!remote_addr)
        owr_transport_agent_add_local_address(send_transport_agent, "127.0.0.1");

    if (!disable_video) {
        recv_session_video = owr_media_session_new(FALSE);
        owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(recv_session_video));
        send_session_video = owr_media_session_new(TRUE);
        owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(send_session_video));
    }
    if (!disable_audio) {
        recv_session_audio = owr_media_session_new(FALSE);
        owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(recv_session_audio));
        send_session_audio = owr_media_session_new(TRUE);
        owr_bus_add_message_origin(bus, OWR_MESSAGE_ORIGIN(send_session_audio));
    }

    if (!disable_video) {
        g_signal_connect(recv_session_video, "on-new-candidate", G_CALLBACK(got_candidate), send_session_video);
        g_signal_connect(send_session_video, "on-new-candidate", G_CALLBACK(got_candidate), recv_session_video);
        if (remote_addr) {
            g_signal_connect(recv_session_video, "on-candidate-gathering-done", G_CALLBACK(gathering_done), send_session_video);
            g_signal_connect(send_session_video, "on-candidate-gathering-done", G_CALLBACK(gathering_done), recv_session_video);
	    owr_session_set_local_port(OWR_SESSION(send_session_video), OWR_COMPONENT_TYPE_RTP, 5120);
	    owr_session_set_local_port(OWR_SESSION(send_session_video), OWR_COMPONENT_TYPE_RTCP, 5121);
	    owr_session_set_local_port(OWR_SESSION(recv_session_video), OWR_COMPONENT_TYPE_RTP, 5122);
	    owr_session_set_local_port(OWR_SESSION(recv_session_video), OWR_COMPONENT_TYPE_RTCP, 5123);
        }
    }
    if (!disable_audio) {
        g_signal_connect(recv_session_audio, "on-new-candidate", G_CALLBACK(got_candidate), send_session_audio);
        g_signal_connect(send_session_audio, "on-new-candidate", G_CALLBACK(got_candidate), recv_session_audio);
        if (remote_addr) {
            g_signal_connect(recv_session_audio, "on-candidate-gathering-done", G_CALLBACK(gathering_done), send_session_audio);
            g_signal_connect(send_session_audio, "on-candidate-gathering-done", G_CALLBACK(gathering_done), recv_session_audio);
	    owr_session_set_local_port(OWR_SESSION(send_session_audio), OWR_COMPONENT_TYPE_RTP, 5124);
	    owr_session_set_local_port(OWR_SESSION(send_session_audio), OWR_COMPONENT_TYPE_RTCP, 5125);
	    owr_session_set_local_port(OWR_SESSION(recv_session_audio), OWR_COMPONENT_TYPE_RTP, 5126);
	    owr_session_set_local_port(OWR_SESSION(recv_session_audio), OWR_COMPONENT_TYPE_RTCP, 5127);
        }
    }

    // VIDEO
    if (!disable_video) {
        g_signal_connect(recv_session_video, "on-incoming-source", G_CALLBACK(got_remote_source), NULL);

        receive_payload = owr_video_payload_new(OWR_CODEC_TYPE_VP8, 103, 90000, TRUE, FALSE);
        g_object_set(receive_payload, "rtx-payload-type", 123, NULL);
        if (adaptation)
            g_object_set(receive_payload, "adaptation", TRUE, NULL);

        owr_media_session_add_receive_payload(recv_session_video, receive_payload);
    }

    // AUDIO
    if (!disable_audio) {
        g_signal_connect(recv_session_audio, "on-incoming-source", G_CALLBACK(got_remote_source), NULL);

        receive_payload = owr_audio_payload_new(OWR_CODEC_TYPE_OPUS, 100, 48000, 1);
        owr_media_session_add_receive_payload(recv_session_audio, receive_payload);
    }

    /* PREPARE FOR SENDING */

    if (!uri) {
        owr_get_capture_sources(
                (!disable_video ? OWR_MEDIA_TYPE_VIDEO : 0) | (!disable_audio ? OWR_MEDIA_TYPE_AUDIO : 0),
                got_sources, NULL);
    } else {
        uri_source_agent = owr_uri_source_agent_new(uri);
        g_signal_connect(uri_source_agent, "on-new-source", G_CALLBACK(on_new_source), NULL);
        owr_uri_source_agent_play(uri_source_agent);
    }

    g_timeout_add_seconds(10, (GSourceFunc)dump_cb, NULL);

    owr_run();

    g_free(remote_addr);
    g_free(uri);

    return 0;
}
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;
    }
}