Mercurial > pidgin
comparison libpurple/protocols/jabber/jingle.c @ 23825:c984acc6c392
Added the "media" attribute to the Jingle description element according
to changes to XEP-0167.
author | Mike Ruprecht <maiku@soc.pidgin.im> |
---|---|
date | Fri, 06 Jun 2008 20:28:20 +0000 |
parents | bfaad8393463 |
children | b5a00ddb7077 |
comparison
equal
deleted
inserted
replaced
23824:bfaad8393463 | 23825:c984acc6c392 |
---|---|
30 #ifdef USE_VV | 30 #ifdef USE_VV |
31 | 31 |
32 #include <gst/farsight/fs-candidate.h> | 32 #include <gst/farsight/fs-candidate.h> |
33 | 33 |
34 #define JINGLE "urn:xmpp:tmp:jingle" | 34 #define JINGLE "urn:xmpp:tmp:jingle" |
35 #define JINGLE_AUDIO "urn:xmpp:tmp:jingle:apps:audio-rtp" | 35 #define JINGLE_RTP "urn:xmpp:tmp:jingle:apps:rtp" |
36 #define JINGLE_VIDEO "urn:xmpp:tmp:jingle:apps:video-rtp" | 36 #define JINGLE_RTP_INFO "urn:xmpp:tmp:jingle:apps:rtp:info" |
37 #define TRANSPORT_ICEUDP "urn:xmpp:tmp:jingle:transports:ice-udp" | 37 #define TRANSPORT_ICEUDP "urn:xmpp:tmp:jingle:transports:ice-udp" |
38 | 38 |
39 typedef struct { | 39 typedef struct { |
40 char *id; | 40 char *id; |
41 JabberStream *js; | 41 JabberStream *js; |
52 JingleSession *session; | 52 JingleSession *session; |
53 gchar *creator; | 53 gchar *creator; |
54 gchar *sender; | 54 gchar *sender; |
55 gchar *transport_type; | 55 gchar *transport_type; |
56 gchar *type; | 56 gchar *type; |
57 gchar *subtype; | |
57 } JingleSessionContent; | 58 } JingleSessionContent; |
58 | 59 |
59 static void | 60 static void |
60 jabber_jingle_session_content_create_internal(JingleSession *session, | 61 jabber_jingle_session_content_create_internal(JingleSession *session, |
61 const gchar *name, | 62 const gchar *name, |
62 const gchar *creator, | 63 const gchar *creator, |
63 const gchar *sender, | 64 const gchar *sender, |
64 const gchar *transport_type, | 65 const gchar *transport_type, |
65 const gchar *type) | 66 const gchar *type, |
67 const gchar *subtype) | |
66 { | 68 { |
67 JingleSessionContent *content = g_new0(JingleSessionContent, 1); | 69 JingleSessionContent *content = g_new0(JingleSessionContent, 1); |
68 content->session = session; | 70 content->session = session; |
69 content->name = g_strdup(name); | 71 content->name = g_strdup(name); |
70 content->creator = g_strdup(creator); | 72 content->creator = g_strdup(creator); |
71 content->sender = g_strdup(sender); | 73 content->sender = g_strdup(sender); |
72 content->transport_type = g_strdup(transport_type); | 74 content->transport_type = g_strdup(transport_type); |
73 content->type = g_strdup(type); | 75 content->type = g_strdup(type); |
76 content->subtype = g_strdup(subtype); | |
74 | 77 |
75 if (!session->contents) { | 78 if (!session->contents) { |
76 purple_debug_info("jingle", "Creating hash table for contents\n"); | 79 purple_debug_info("jingle", "Creating hash table for contents\n"); |
77 session->contents = g_hash_table_new(g_str_hash, g_str_equal); | 80 session->contents = g_hash_table_new(g_str_hash, g_str_equal); |
78 } | 81 } |
90 g_free(content->name); | 93 g_free(content->name); |
91 g_free(content->creator); | 94 g_free(content->creator); |
92 g_free(content->sender); | 95 g_free(content->sender); |
93 g_free(content->transport_type); | 96 g_free(content->transport_type); |
94 g_free(content->type); | 97 g_free(content->type); |
98 g_free(content->subtype); | |
95 g_free(content); | 99 g_free(content); |
96 } | 100 } |
97 | 101 |
98 static const gchar * | 102 static const gchar * |
99 jabber_jingle_session_content_get_name(const JingleSessionContent *jsc) | 103 jabber_jingle_session_content_get_name(const JingleSessionContent *jsc) |
144 const gchar *type) | 148 const gchar *type) |
145 { | 149 { |
146 return !strcmp(jabber_jingle_session_content_get_type(jsc), type); | 150 return !strcmp(jabber_jingle_session_content_get_type(jsc), type); |
147 } | 151 } |
148 | 152 |
153 static gchar * | |
154 jabber_jingle_session_content_get_subtype(const JingleSessionContent *jsc) | |
155 { | |
156 return jsc->subtype; | |
157 } | |
158 | |
149 static gboolean | 159 static gboolean |
150 jabber_jingle_session_content_is_vv(const JingleSessionContent *jsc) | 160 jabber_jingle_session_content_is_vv_type(const JingleSessionContent *jsc, |
151 { | 161 const gchar *media_type) |
152 return jabber_jingle_session_content_is_type(jsc, JINGLE_AUDIO) || | 162 { |
153 jabber_jingle_session_content_is_type(jsc, JINGLE_VIDEO); | 163 return jabber_jingle_session_content_is_type(jsc, JINGLE_RTP) && |
164 !strcmp(jabber_jingle_session_content_get_subtype(jsc), | |
165 media_type); | |
154 } | 166 } |
155 | 167 |
156 static void | 168 static void |
157 jabber_jingle_session_content_set_sender(JingleSessionContent *jsc, | 169 jabber_jingle_session_content_set_sender(JingleSessionContent *jsc, |
158 const char *sender) | 170 const char *sender) |
282 { | 294 { |
283 GList *codecs = NULL; | 295 GList *codecs = NULL; |
284 xmlnode *codec_element = NULL; | 296 xmlnode *codec_element = NULL; |
285 const char *encoding_name,*id, *clock_rate; | 297 const char *encoding_name,*id, *clock_rate; |
286 FsCodec *codec; | 298 FsCodec *codec; |
287 FsMediaType type = !strcmp(xmlnode_get_namespace(description), JINGLE_VIDEO) ? | 299 const gchar *media = xmlnode_get_attrib(description, "media"); |
288 FS_MEDIA_TYPE_VIDEO : FS_MEDIA_TYPE_AUDIO; | 300 FsMediaType type = !strcmp(media, "video") ? FS_MEDIA_TYPE_VIDEO : |
301 !strcmp(media, "audio") ? FS_MEDIA_TYPE_AUDIO : | |
302 FS_MEDIA_TYPE_APPLICATION; | |
289 | 303 |
290 for (codec_element = xmlnode_get_child(description, "payload-type") ; | 304 for (codec_element = xmlnode_get_child(description, "payload-type") ; |
291 codec_element ; | 305 codec_element ; |
292 codec_element = xmlnode_get_next_twin(codec_element)) { | 306 codec_element = xmlnode_get_next_twin(codec_element)) { |
293 encoding_name = xmlnode_get_attrib(codec_element, "name"); | 307 encoding_name = xmlnode_get_attrib(codec_element, "name"); |
427 | 441 |
428 static xmlnode * | 442 static xmlnode * |
429 jabber_jingle_session_add_description_vv(const JingleSessionContent *jsc, | 443 jabber_jingle_session_add_description_vv(const JingleSessionContent *jsc, |
430 xmlnode *description) | 444 xmlnode *description) |
431 { | 445 { |
446 xmlnode_set_attrib(description, "media", | |
447 jabber_jingle_session_content_get_subtype(jsc)); | |
432 xmlnode_set_attrib(description, "profile", "RTP/AVP"); | 448 xmlnode_set_attrib(description, "profile", "RTP/AVP"); |
433 return description; | 449 return description; |
434 } | 450 } |
435 | 451 |
436 static xmlnode * | 452 static xmlnode * |
439 { | 455 { |
440 xmlnode *description = xmlnode_new_child(content, "description"); | 456 xmlnode *description = xmlnode_new_child(content, "description"); |
441 xmlnode_set_namespace(description, | 457 xmlnode_set_namespace(description, |
442 jabber_jingle_session_content_get_type(jsc)); | 458 jabber_jingle_session_content_get_type(jsc)); |
443 | 459 |
444 if (jabber_jingle_session_content_is_vv(jsc)) | 460 if (jabber_jingle_session_content_is_type(jsc, JINGLE_RTP)) |
445 return jabber_jingle_session_add_description_vv(jsc, description); | 461 return jabber_jingle_session_add_description_vv(jsc, description); |
446 else | 462 else |
447 return description; | 463 return description; |
448 } | 464 } |
449 | 465 |
644 for (; contents; contents = contents->next) { | 660 for (; contents; contents = contents->next) { |
645 JingleSessionContent *jsc = contents->data; | 661 JingleSessionContent *jsc = contents->data; |
646 xmlnode *content = jabber_jingle_session_add_content(jsc, jingle); | 662 xmlnode *content = jabber_jingle_session_add_content(jsc, jingle); |
647 xmlnode *description = jabber_jingle_session_add_description(jsc, content); | 663 xmlnode *description = jabber_jingle_session_add_description(jsc, content); |
648 xmlnode *transport = jabber_jingle_session_add_transport(jsc, content); | 664 xmlnode *transport = jabber_jingle_session_add_transport(jsc, content); |
649 if (jabber_jingle_session_content_is_vv(jsc)) | 665 if (jabber_jingle_session_content_is_type(jsc, JINGLE_RTP)) |
650 jabber_jingle_session_add_payload_types(jsc, description); | 666 jabber_jingle_session_add_payload_types(jsc, description); |
651 if (jabber_jingle_session_content_is_transport_type(jsc, TRANSPORT_ICEUDP)) | 667 if (jabber_jingle_session_content_is_transport_type(jsc, TRANSPORT_ICEUDP)) |
652 jabber_jingle_session_add_candidate_iceudp(transport, local, remote); | 668 jabber_jingle_session_add_candidate_iceudp(transport, local, remote); |
653 } | 669 } |
654 | 670 |
662 JabberIq *request = jabber_jingle_session_create_iq(session); | 678 JabberIq *request = jabber_jingle_session_create_iq(session); |
663 xmlnode *jingle = | 679 xmlnode *jingle = |
664 jabber_jingle_session_add_jingle(session, request, | 680 jabber_jingle_session_add_jingle(session, request, |
665 "session-info"); | 681 "session-info"); |
666 xmlnode *info = xmlnode_new_child(jingle, type); | 682 xmlnode *info = xmlnode_new_child(jingle, type); |
667 xmlnode_set_namespace(info, JINGLE_AUDIO ":info"); | 683 xmlnode_set_namespace(info, JINGLE_RTP_INFO); |
668 return request; | 684 return request; |
669 } | 685 } |
670 | 686 |
671 static JabberIq * | 687 static JabberIq * |
672 jabber_jingle_session_create_session_initiate(const JingleSession *session) | 688 jabber_jingle_session_create_session_initiate(const JingleSession *session) |
679 | 695 |
680 for (; contents; contents = contents->next) { | 696 for (; contents; contents = contents->next) { |
681 JingleSessionContent *jsc = contents->data; | 697 JingleSessionContent *jsc = contents->data; |
682 xmlnode *content = jabber_jingle_session_add_content(jsc, jingle); | 698 xmlnode *content = jabber_jingle_session_add_content(jsc, jingle); |
683 xmlnode *description = jabber_jingle_session_add_description(jsc, content); | 699 xmlnode *description = jabber_jingle_session_add_description(jsc, content); |
684 if (jabber_jingle_session_content_is_vv(jsc)) | 700 if (jabber_jingle_session_content_is_type(jsc, JINGLE_RTP)) |
685 jabber_jingle_session_add_payload_types(jsc, description); | 701 jabber_jingle_session_add_payload_types(jsc, description); |
686 jabber_jingle_session_add_transport(jsc, content); | 702 jabber_jingle_session_add_transport(jsc, content); |
687 } | 703 } |
688 | 704 |
689 return request; | 705 return request; |
808 strcpy(sender, "responder"); | 824 strcpy(sender, "responder"); |
809 else | 825 else |
810 strcpy(sender, "both"); | 826 strcpy(sender, "both"); |
811 jabber_jingle_session_content_create_internal(session, | 827 jabber_jingle_session_content_create_internal(session, |
812 "audio-content", "initiator", sender, | 828 "audio-content", "initiator", sender, |
813 TRANSPORT_ICEUDP, JINGLE_AUDIO); | 829 TRANSPORT_ICEUDP, JINGLE_RTP, "audio"); |
814 } | 830 } |
815 if (type & PURPLE_MEDIA_VIDEO) { | 831 if (type & PURPLE_MEDIA_VIDEO) { |
816 if (type == PURPLE_MEDIA_SEND_VIDEO) | 832 if (type == PURPLE_MEDIA_SEND_VIDEO) |
817 strcpy(sender, "initiator"); | 833 strcpy(sender, "initiator"); |
818 else if (type == PURPLE_MEDIA_RECV_VIDEO) | 834 else if (type == PURPLE_MEDIA_RECV_VIDEO) |
819 strcpy(sender, "responder"); | 835 strcpy(sender, "responder"); |
820 else | 836 else |
821 strcpy(sender, "both"); | 837 strcpy(sender, "both"); |
822 jabber_jingle_session_content_create_internal(session, | 838 jabber_jingle_session_content_create_internal(session, |
823 "video-content", "initiator", sender, | 839 "video-content", "initiator", sender, |
824 TRANSPORT_ICEUDP, JINGLE_VIDEO); | 840 TRANSPORT_ICEUDP, JINGLE_RTP, "video"); |
825 } | 841 } |
826 } | 842 } |
827 | 843 |
828 static void | 844 static void |
829 jabber_jingle_session_content_create_parse(JingleSession *session, | 845 jabber_jingle_session_content_create_parse(JingleSession *session, |
832 xmlnode *description = xmlnode_get_child(content, "description"); | 848 xmlnode *description = xmlnode_get_child(content, "description"); |
833 xmlnode *transport = xmlnode_get_child(content, "transport"); | 849 xmlnode *transport = xmlnode_get_child(content, "transport"); |
834 | 850 |
835 const gchar *creator = xmlnode_get_attrib(content, "creator"); | 851 const gchar *creator = xmlnode_get_attrib(content, "creator"); |
836 const gchar *sender = xmlnode_get_attrib(content, "sender"); | 852 const gchar *sender = xmlnode_get_attrib(content, "sender"); |
853 const gchar *subtype = xmlnode_get_attrib(description, "media"); | |
837 | 854 |
838 jabber_jingle_session_content_create_internal(session, | 855 jabber_jingle_session_content_create_internal(session, |
839 xmlnode_get_attrib(content, "name"), | 856 xmlnode_get_attrib(content, "name"), |
840 creator ? creator : "initiator", | 857 creator ? creator : "initiator", |
841 sender ? sender : "both", | 858 sender ? sender : "both", |
842 xmlnode_get_namespace(transport), | 859 xmlnode_get_namespace(transport), |
843 xmlnode_get_namespace(description)); | 860 xmlnode_get_namespace(description), |
861 subtype); | |
844 } | 862 } |
845 | 863 |
846 /* callback called when new local transport candidate(s) are available on the | 864 /* callback called when new local transport candidate(s) are available on the |
847 Farsight stream */ | 865 Farsight stream */ |
848 static void | 866 static void |
909 for (; contents; contents = contents->next) { | 927 for (; contents; contents = contents->next) { |
910 JingleSessionContent *jsc = contents->data; | 928 JingleSessionContent *jsc = contents->data; |
911 gboolean result = FALSE; | 929 gboolean result = FALSE; |
912 | 930 |
913 /* these will need to be changed to "nice" once the libnice transmitter is finished */ | 931 /* these will need to be changed to "nice" once the libnice transmitter is finished */ |
914 if (jabber_jingle_session_content_is_type(jsc, JINGLE_AUDIO)) { | 932 if (jabber_jingle_session_content_is_vv_type(jsc, "audio")) { |
915 result = purple_media_add_stream(media, "audio-content", remote_jid, | 933 result = purple_media_add_stream(media, "audio-content", remote_jid, |
916 PURPLE_MEDIA_AUDIO, "rawudp"); | 934 PURPLE_MEDIA_AUDIO, "rawudp"); |
917 purple_debug_info("jingle", "Created Jingle audio session\n"); | 935 purple_debug_info("jingle", "Created Jingle audio session\n"); |
918 } | 936 } |
919 else if (jabber_jingle_session_content_is_type(jsc, JINGLE_VIDEO)) { | 937 else if (jabber_jingle_session_content_is_vv_type(jsc, "video")) { |
920 result = purple_media_add_stream(media, "video-content", remote_jid, | 938 result = purple_media_add_stream(media, "video-content", remote_jid, |
921 PURPLE_MEDIA_VIDEO, "rawudp"); | 939 PURPLE_MEDIA_VIDEO, "rawudp"); |
922 purple_debug_info("jingle", "Created Jingle video session\n"); | 940 purple_debug_info("jingle", "Created Jingle video session\n"); |
923 } | 941 } |
924 | 942 |