Commit 925e908b authored by Anton Khirnov's avatar Anton Khirnov

avio: make url_write() internal.

parent dce37564
......@@ -188,6 +188,10 @@ int url_read_complete(URLContext *h, unsigned char *buf, int size)
{
return ffurl_read_complete(h, buf, size);
}
int url_write(URLContext *h, const unsigned char *buf, int size)
{
return ffurl_write(h, buf, size);
}
#endif
#define URL_SCHEME_CHARS \
......@@ -280,7 +284,7 @@ int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
}
int url_write(URLContext *h, const unsigned char *buf, int size)
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
{
if (!(h->flags & (URL_WRONLY | URL_RDWR)))
return AVERROR(EIO);
......
......@@ -107,16 +107,9 @@ attribute_deprecated int url_connect(URLContext *h);
attribute_deprecated int url_open(URLContext **h, const char *url, int flags);
attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size);
attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size);
attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size);
#endif
/**
* Write size bytes from buf to the resource accessed by h.
*
* @return the number of bytes actually written, or a negative value
* corresponding to an AVERROR code in case of failure
*/
int url_write(URLContext *h, const unsigned char *buf, int size);
/**
* Passing this as the "whence" parameter to a seek function causes it to
* return the filesize without seeking anywhere. Supporting this is optional.
......
......@@ -846,7 +846,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
if (ffio_init_context(*s, buffer, buffer_size,
(h->flags & URL_WRONLY || h->flags & URL_RDWR), h,
ffurl_read, url_write, url_seek) < 0) {
ffurl_read, ffurl_write, url_seek) < 0) {
av_free(buffer);
av_freep(s);
return AVERROR(EIO);
......
......@@ -35,7 +35,7 @@ typedef struct {
static int gopher_write(URLContext *h, const uint8_t *buf, int size)
{
GopherContext *s = h->priv_data;
return url_write(s->hd, buf, size);
return ffurl_write(s->hd, buf, size);
}
static int gopher_connect(URLContext *h, const char *path)
......
......@@ -333,7 +333,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
authstr ? authstr : "");
av_freep(&authstr);
if (url_write(s->hd, s->buffer, strlen(s->buffer)) < 0)
if (ffurl_write(s->hd, s->buffer, strlen(s->buffer)) < 0)
return AVERROR(EIO);
/* init input buffer */
......@@ -427,7 +427,7 @@ static int http_write(URLContext *h, const uint8_t *buf, int size)
if (s->chunksize == -1) {
/* non-chunked data is sent without any special encoding */
return url_write(s->hd, buf, size);
return ffurl_write(s->hd, buf, size);
}
/* silently ignore zero-size data since chunk encoding that would
......@@ -436,9 +436,9 @@ static int http_write(URLContext *h, const uint8_t *buf, int size)
/* upload data using chunked encoding */
snprintf(temp, sizeof(temp), "%x\r\n", size);
if ((ret = url_write(s->hd, temp, strlen(temp))) < 0 ||
(ret = url_write(s->hd, buf, size)) < 0 ||
(ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
if ((ret = ffurl_write(s->hd, temp, strlen(temp))) < 0 ||
(ret = ffurl_write(s->hd, buf, size)) < 0 ||
(ret = ffurl_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
return ret;
}
return size;
......@@ -452,7 +452,7 @@ static int http_close(URLContext *h)
/* signal end of chunked encoding if used */
if ((h->flags & URL_WRONLY) && s->chunksize != -1) {
ret = url_write(s->hd, footer, sizeof(footer) - 1);
ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
ret = ret > 0 ? 0 : ret;
}
......
......@@ -68,7 +68,7 @@ static int md5_close(URLContext *h)
err = ffurl_open(&out, filename, URL_WRONLY);
if (err)
return err;
err = url_write(out, buf, i*2+1);
err = ffurl_write(out, buf, i*2+1);
url_close(out);
} else {
if (fwrite(buf, 1, i*2+1, stdout) < i*2+1)
......
......@@ -139,7 +139,7 @@ static int send_command_packet(MMSTContext *mmst)
memset(mms->write_out_ptr, 0, exact_length - len);
// write it out.
write_result= url_write(mms->mms_hd, mms->out_buffer, exact_length);
write_result= ffurl_write(mms->mms_hd, mms->out_buffer, exact_length);
if(write_result != exact_length) {
av_log(NULL, AV_LOG_ERROR,
"Failed to write data of length %d: %d (%s)\n",
......
......@@ -215,15 +215,15 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
}
prev_pkt[pkt->channel_id].extra = pkt->extra;
url_write(h, pkt_hdr, p-pkt_hdr);
ffurl_write(h, pkt_hdr, p-pkt_hdr);
size = p - pkt_hdr + pkt->data_size;
while (off < pkt->data_size) {
int towrite = FFMIN(chunk_size, pkt->data_size - off);
url_write(h, pkt->data + off, towrite);
ffurl_write(h, pkt->data + off, towrite);
off += towrite;
if (off < pkt->data_size) {
uint8_t marker = 0xC0 | pkt->channel_id;
url_write(h, &marker, 1);
ffurl_write(h, &marker, 1);
size++;
}
}
......
......@@ -486,7 +486,7 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
tosend[i] = av_lfg_get(&rnd) >> 24;
client_pos = rtmp_handshake_imprint_with_digest(tosend + 1);
url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1);
ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1);
i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1);
if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) {
av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
......@@ -532,9 +532,9 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32);
// write reply back to the server
url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE);
ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE);
} else {
url_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE);
ffurl_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE);
}
return 0;
......
......@@ -25,6 +25,7 @@
#include "libavcodec/get_bits.h"
#include "avformat.h"
#include "mpegts.h"
#include "url.h"
#include <unistd.h>
#include <strings.h>
......@@ -325,8 +326,8 @@ int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)
if ((len > 0) && buf) {
int result;
av_dlog(s->ic, "sending %d bytes of RR\n", len);
result= url_write(s->rtp_ctx, buf, len);
av_dlog(s->ic, "result from url_write: %d\n", result);
result= ffurl_write(s->rtp_ctx, buf, len);
av_dlog(s->ic, "result from ffurl_write: %d\n", result);
av_free(buf);
}
return 0;
......@@ -351,7 +352,7 @@ void rtp_send_punch_packets(URLContext* rtp_handle)
avio_flush(pb);
len = avio_close_dyn_buf(pb, &buf);
if ((len > 0) && buf)
url_write(rtp_handle, buf, len);
ffurl_write(rtp_handle, buf, len);
av_free(buf);
/* Send a minimal RTCP RR */
......@@ -366,7 +367,7 @@ void rtp_send_punch_packets(URLContext* rtp_handle)
avio_flush(pb);
len = avio_close_dyn_buf(pb, &buf);
if ((len > 0) && buf)
url_write(rtp_handle, buf, len);
ffurl_write(rtp_handle, buf, len);
av_free(buf);
}
......
......@@ -297,7 +297,7 @@ static int rtp_write(URLContext *h, const uint8_t *buf, int size)
hd = s->rtp_hd;
}
ret = url_write(hd, buf, size);
ret = ffurl_write(hd, buf, size);
#if 0
{
struct timespec ts;
......
......@@ -983,14 +983,14 @@ static int ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,
av_dlog(s, "Sending:\n%s--\n", buf);
url_write(rt->rtsp_hd_out, out_buf, strlen(out_buf));
ffurl_write(rt->rtsp_hd_out, out_buf, strlen(out_buf));
if (send_content_length > 0 && send_content) {
if (rt->control_transport == RTSP_MODE_TUNNEL) {
av_log(s, AV_LOG_ERROR, "tunneling of RTSP requests "
"with content data not supported\n");
return AVERROR_PATCHWELCOME;
}
url_write(rt->rtsp_hd_out, send_content, send_content_length);
ffurl_write(rt->rtsp_hd_out, send_content, send_content_length);
}
rt->last_cmd_time = av_gettime();
......
......@@ -32,6 +32,7 @@
#include "avio_internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h"
#include "url.h"
#define SDP_MAX_SIZE 16384
......@@ -158,7 +159,7 @@ static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)
interleave_header[0] = '$';
interleave_header[1] = id;
AV_WB16(interleave_header + 2, packet_len);
url_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len);
ffurl_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len);
ptr += packet_len;
size -= packet_len;
}
......
......@@ -54,7 +54,7 @@ static int sap_write_close(AVFormatContext *s)
if (sap->last_time && sap->ann && sap->ann_fd) {
sap->ann[0] |= 4; /* Session deletion*/
url_write(sap->ann_fd, sap->ann, sap->ann_size);
ffurl_write(sap->ann_fd, sap->ann, sap->ann_size);
}
av_freep(&sap->ann);
......@@ -239,7 +239,7 @@ static int sap_write_packet(AVFormatContext *s, AVPacket *pkt)
int64_t now = av_gettime();
if (!sap->last_time || now - sap->last_time > 5000000) {
int ret = url_write(sap->ann_fd, sap->ann, sap->ann_size);
int ret = ffurl_write(sap->ann_fd, sap->ann, sap->ann_size);
/* Don't abort even if we get "Destination unreachable" */
if (ret < 0 && ret != AVERROR(ECONNREFUSED))
return ret;
......
......@@ -78,4 +78,12 @@ int ffurl_read(URLContext *h, unsigned char *buf, int size);
*/
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
/**
* Write size bytes from buf to the resource accessed by h.
*
* @return the number of bytes actually written, or a negative value
* corresponding to an AVERROR code in case of failure
*/
int ffurl_write(URLContext *h, const unsigned char *buf, int size);
#endif //AVFORMAT_URL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment