Mercurial > libavformat.hg
comparison rtmpproto.c @ 5411:1f27e6bd85c3 libavformat
Move "app" string into RTMP protocol context.
Patch by Sergiy (com.gmail@piratfm)
author | kostya |
---|---|
date | Thu, 03 Dec 2009 15:47:00 +0000 |
parents | b7ef0aa415d0 |
children | 95bc775d22ff |
comparison
equal
deleted
inserted
replaced
5410:f66e3c131106 | 5411:1f27e6bd85c3 |
---|---|
57 URLContext* stream; ///< TCP stream used in interactions with RTMP server | 57 URLContext* stream; ///< TCP stream used in interactions with RTMP server |
58 RTMPPacket prev_pkt[2][RTMP_CHANNELS]; ///< packet history used when reading and sending packets | 58 RTMPPacket prev_pkt[2][RTMP_CHANNELS]; ///< packet history used when reading and sending packets |
59 int chunk_size; ///< size of the chunks RTMP packets are divided into | 59 int chunk_size; ///< size of the chunks RTMP packets are divided into |
60 int is_input; ///< input/output flag | 60 int is_input; ///< input/output flag |
61 char playpath[256]; ///< path to filename to play (with possible "mp4:" prefix) | 61 char playpath[256]; ///< path to filename to play (with possible "mp4:" prefix) |
62 char app[128]; ///< application | |
62 ClientState state; ///< current state | 63 ClientState state; ///< current state |
63 int main_channel_id; ///< an additional channel ID which is used for some invocations | 64 int main_channel_id; ///< an additional channel ID which is used for some invocations |
64 uint8_t* flv_data; ///< buffer with data for demuxer | 65 uint8_t* flv_data; ///< buffer with data for demuxer |
65 int flv_size; ///< current buffer size | 66 int flv_size; ///< current buffer size |
66 int flv_off; ///< number of bytes read from current buffer | 67 int flv_off; ///< number of bytes read from current buffer |
91 | 92 |
92 /** | 93 /** |
93 * Generates 'connect' call and sends it to the server. | 94 * Generates 'connect' call and sends it to the server. |
94 */ | 95 */ |
95 static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto, | 96 static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto, |
96 const char *host, int port, const char *app) | 97 const char *host, int port) |
97 { | 98 { |
98 RTMPPacket pkt; | 99 RTMPPacket pkt; |
99 uint8_t ver[32], *p; | 100 uint8_t ver[32], *p; |
100 char tcurl[512]; | 101 char tcurl[512]; |
101 | 102 |
102 ff_rtmp_packet_create(&pkt, RTMP_VIDEO_CHANNEL, RTMP_PT_INVOKE, 0, 4096); | 103 ff_rtmp_packet_create(&pkt, RTMP_VIDEO_CHANNEL, RTMP_PT_INVOKE, 0, 4096); |
103 p = pkt.data; | 104 p = pkt.data; |
104 | 105 |
105 snprintf(tcurl, sizeof(tcurl), "%s://%s:%d/%s", proto, host, port, app); | 106 snprintf(tcurl, sizeof(tcurl), "%s://%s:%d/%s", proto, host, port, rt->app); |
106 ff_amf_write_string(&p, "connect"); | 107 ff_amf_write_string(&p, "connect"); |
107 ff_amf_write_number(&p, 1.0); | 108 ff_amf_write_number(&p, 1.0); |
108 ff_amf_write_object_start(&p); | 109 ff_amf_write_object_start(&p); |
109 ff_amf_write_field_name(&p, "app"); | 110 ff_amf_write_field_name(&p, "app"); |
110 ff_amf_write_string(&p, app); | 111 ff_amf_write_string(&p, rt->app); |
111 | 112 |
112 snprintf(ver, sizeof(ver), "%s %d,%d,%d,%d", RTMP_CLIENT_PLATFORM, RTMP_CLIENT_VER1, | 113 snprintf(ver, sizeof(ver), "%s %d,%d,%d,%d", RTMP_CLIENT_PLATFORM, RTMP_CLIENT_VER1, |
113 RTMP_CLIENT_VER2, RTMP_CLIENT_VER3, RTMP_CLIENT_VER4); | 114 RTMP_CLIENT_VER2, RTMP_CLIENT_VER3, RTMP_CLIENT_VER4); |
114 ff_amf_write_field_name(&p, "flashVer"); | 115 ff_amf_write_field_name(&p, "flashVer"); |
115 ff_amf_write_string(&p, ver); | 116 ff_amf_write_string(&p, ver); |
561 * may be prefixed with "mp4:") | 562 * may be prefixed with "mp4:") |
562 */ | 563 */ |
563 static int rtmp_open(URLContext *s, const char *uri, int flags) | 564 static int rtmp_open(URLContext *s, const char *uri, int flags) |
564 { | 565 { |
565 RTMPContext *rt; | 566 RTMPContext *rt; |
566 char proto[8], hostname[256], path[1024], app[128], *fname; | 567 char proto[8], hostname[256], path[1024], *fname; |
567 uint8_t buf[2048]; | 568 uint8_t buf[2048]; |
568 int port; | 569 int port; |
569 int ret; | 570 int ret; |
570 | 571 |
571 rt = av_mallocz(sizeof(RTMPContext)); | 572 rt = av_mallocz(sizeof(RTMPContext)); |
597 rt->chunk_size = 128; | 598 rt->chunk_size = 128; |
598 rt->state = STATE_HANDSHAKED; | 599 rt->state = STATE_HANDSHAKED; |
599 //extract "app" part from path | 600 //extract "app" part from path |
600 if (!strncmp(path, "/ondemand/", 10)) { | 601 if (!strncmp(path, "/ondemand/", 10)) { |
601 fname = path + 10; | 602 fname = path + 10; |
602 memcpy(app, "ondemand", 9); | 603 memcpy(rt->app, "ondemand", 9); |
603 } else { | 604 } else { |
604 char *p = strchr(path + 1, '/'); | 605 char *p = strchr(path + 1, '/'); |
605 if (!p) { | 606 if (!p) { |
606 fname = path + 1; | 607 fname = path + 1; |
607 app[0] = '\0'; | 608 rt->app[0] = '\0'; |
608 } else { | 609 } else { |
609 char *c = strchr(p + 1, ':'); | 610 char *c = strchr(p + 1, ':'); |
610 fname = strchr(p + 1, '/'); | 611 fname = strchr(p + 1, '/'); |
611 if (!fname || c < fname) { | 612 if (!fname || c < fname) { |
612 fname = p + 1; | 613 fname = p + 1; |
613 av_strlcpy(app, path + 1, p - path); | 614 av_strlcpy(rt->app, path + 1, p - path); |
614 } else { | 615 } else { |
615 fname++; | 616 fname++; |
616 av_strlcpy(app, path + 1, fname - path - 1); | 617 av_strlcpy(rt->app, path + 1, fname - path - 1); |
617 } | 618 } |
618 } | 619 } |
619 } | 620 } |
620 if (!strchr(fname, ':') && | 621 if (!strchr(fname, ':') && |
621 (!strcmp(fname + strlen(fname) - 4, ".f4v") || | 622 (!strcmp(fname + strlen(fname) - 4, ".f4v") || |
625 rt->playpath[0] = 0; | 626 rt->playpath[0] = 0; |
626 } | 627 } |
627 strncat(rt->playpath, fname, sizeof(rt->playpath) - 5); | 628 strncat(rt->playpath, fname, sizeof(rt->playpath) - 5); |
628 | 629 |
629 av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", | 630 av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", |
630 proto, path, app, rt->playpath); | 631 proto, path, rt->app, rt->playpath); |
631 gen_connect(s, rt, proto, hostname, port, app); | 632 gen_connect(s, rt, proto, hostname, port); |
632 | 633 |
633 do { | 634 do { |
634 ret = get_packet(s, 1); | 635 ret = get_packet(s, 1); |
635 } while (ret == EAGAIN); | 636 } while (ret == EAGAIN); |
636 if (ret < 0) | 637 if (ret < 0) |