From: Michal Sojka Date: Sat, 28 Nov 2009 18:26:09 +0000 (+0100) Subject: Reworked assignment of FRSH contract parameters X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/ffmpeg.git/commitdiff_plain/914345eda9d70ff0452d832d8ed37181c72ea431 Reworked assignment of FRSH contract parameters Now we can specify also deadline. The assigned values differ for RTCP and RTP streams because RCP needs much less bandwidth. Sending was changed to sync. When async was used, the packets would be queued and delivered with delay, which is not what we want. In future, we might add an endpoint parameter to specify the size of queue and use async again. --- diff --git a/libavformat/frsh.c b/libavformat/frsh.c index 90e6f6020..d4fae188a 100644 --- a/libavformat/frsh.c +++ b/libavformat/frsh.c @@ -36,8 +36,6 @@ #include #include -long int avformat_frsh_budget, avformat_frsh_period; - typedef struct { int frsh_fd; int ttl; @@ -54,7 +52,7 @@ typedef struct { frsh_send_endpoint_protocol_info_t send_pinfo; frsh_contract_t contract; frsh_contract_label_t label; - frsh_rel_time_t budget, period; + frsh_rel_time_t budget, period, deadline; } FRSHContext; #define FRSH_TX_BUF_SIZE 32768 @@ -91,8 +89,6 @@ frsh_output_socket_create(FRSHContext *s) addr_len = sizeof(addr); /* set params for contract */ - frsh_network_bytes_to_budget(FRSH_NETPF_FWP, avformat_frsh_budget, &s->budget); - s->period = fosa_msec_to_rel_time(avformat_frsh_period); s->send_pinfo.body = NULL; frsh_fd = frsh_send_endpoint_create(FRSH_NETPF_FWP, @@ -123,6 +119,11 @@ frsh_output_socket_create(FRSHContext *s) //if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label"); if (ret) return -1; + if (frsh_rel_time_to_nsec(s->deadline) > 0) { + ret = frsh_contract_set_timing_reqs(&s->contract, false, &s->deadline); + if (ret) return -1; + } + ret = frsh_contract_negotiate(&s->contract, &s->vres); //if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate"); if (ret) return -1; @@ -260,6 +261,15 @@ static int frsh_open(URLContext *h, const char *uri, int flags) "contract_label", p)) { s->label[0]=0; } + if (find_info_tag(buf, sizeof(buf), "budget", p)) { + frsh_network_bytes_to_budget(FRSH_NETPF_FWP, strtol(buf, NULL, 10), &s->budget); + } + if (find_info_tag(buf, sizeof(buf), "period", p)) { + s->period=frsh_msec_to_rel_time(strtol(buf, NULL, 10)); + } + if (find_info_tag(buf, sizeof(buf), "deadline", p)) { + s->deadline=frsh_msec_to_rel_time(strtol(buf, NULL, 10)); + } } /* fill the dest addr */ @@ -336,7 +346,7 @@ static int frsh_write(URLContext *h, uint8_t *buf, int size) FRSHContext *s = h->priv_data; int ret; - ret = frsh_send_async(s->sepoint, buf, size); + ret = frsh_send_sync(s->sepoint, buf, size); return ret; } @@ -347,6 +357,7 @@ static int frsh_close(URLContext *h) frsh_send_endpoint_unbind(s->sepoint); ret = frsh_contract_cancel(s->vres); + frsh_contract_destroy(s->contract); return ret; } diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 727c79961..a18bf5585 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +int frsh_rtp_budget=0, frsh_rtp_period_ms=0, frsh_rtp_deadline_ms=0; + /** * @file libavformat/rtpproto.c * RTP protocol @@ -109,7 +111,7 @@ static void build_udp_url(char *buf, int buf_size, const char *hostname, int port, int local_port, int ttl, int max_packet_size, - const char *label) + const char *label, int budget, int period_ms, int deadline_ms) { snprintf(buf, buf_size, URL_PROTO"://%s:%d", hostname, port); if (local_port >= 0) @@ -120,6 +122,12 @@ static void build_udp_url(char *buf, int buf_size, url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size); if (label) url_add_option(buf, buf_size, "contract_label=%s", label); + if (budget >=0) + url_add_option(buf, buf_size, "budget=%d", budget); + if (period_ms >=0) + url_add_option(buf, buf_size, "period=%d", period_ms); + if (deadline_ms >=0) + url_add_option(buf, buf_size, "deadline=%d", deadline_ms); } /** @@ -167,7 +175,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags) } build_udp_url(buf, sizeof(buf), - hostname, port, local_port, ttl, max_packet_size, "RTP"); + hostname, port, local_port, ttl, max_packet_size, "RTP", + frsh_rtp_budget, frsh_rtp_period_ms, frsh_rtp_deadline_ms); if (url_open(&s->rtp_hd, buf, flags) < 0) goto fail; local_port = udp_get_local_port(s->rtp_hd); @@ -176,7 +185,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags) /* well, should suppress localport in path */ build_udp_url(buf, sizeof(buf), - hostname, port + 1, local_port + 1, ttl, max_packet_size, "RTCP"); + hostname, port + 1, local_port + 1, ttl, max_packet_size, "RTCP", + 1000, 100*1000, 0); if (url_open(&s->rtcp_hd, buf, flags) < 0) goto fail;