avformat: Use ff_check_interrupt
[libav.git] / libavformat / url.h
CommitLineData
5652bb94
AK
1/*
2 *
3 * This file is part of Libav.
4 *
5 * Libav is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * Libav is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with Libav; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20/**
21 * @file
22 * unbuffered private I/O API
23 */
24
25#ifndef AVFORMAT_URL_H
26#define AVFORMAT_URL_H
27
28#include "avio.h"
b8404847
AK
29#include "libavformat/version.h"
30
31#if !FF_API_OLD_AVIO
32#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
5cec8971 33
026e1757 34extern int (*url_interrupt_cb)(void);
c486dade
AK
35
36typedef struct URLContext {
37 const AVClass *av_class; /**< information for av_log(). Set by url_open(). */
38 struct URLProtocol *prot;
39 void *priv_data;
40 char *filename; /**< specified URL */
41 int flags;
42 int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
43 int is_streamed; /**< true if streamed (no seek possible), default = false */
44 int is_connected;
6aa0b98f 45 AVIOInterruptCB interrupt_callback;
c486dade 46} URLContext;
5593f031
AK
47
48typedef struct URLProtocol {
49 const char *name;
50 int (*url_open)( URLContext *h, const char *url, int flags);
51 int (*url_read)( URLContext *h, unsigned char *buf, int size);
52 int (*url_write)(URLContext *h, const unsigned char *buf, int size);
53 int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
54 int (*url_close)(URLContext *h);
55 struct URLProtocol *next;
56 int (*url_read_pause)(URLContext *h, int pause);
57 int64_t (*url_read_seek)(URLContext *h, int stream_index,
58 int64_t timestamp, int flags);
59 int (*url_get_file_handle)(URLContext *h);
60 int priv_data_size;
61 const AVClass *priv_data_class;
62 int flags;
175389c8 63 int (*url_check)(URLContext *h, int mask);
5593f031 64} URLProtocol;
b8404847 65#endif
5652bb94
AK
66
67/**
68 * Create a URLContext for accessing to the resource indicated by
69 * url, but do not initiate the connection yet.
70 *
71 * @param puc pointer to the location where, in case of success, the
72 * function puts the pointer to the created URLContext
73 * @param flags flags which control how the resource indicated by url
74 * is to be opened
75 * @return 0 in case of success, a negative value corresponding to an
76 * AVERROR code in case of failure
77 */
96c1e6d4 78int ffurl_alloc(URLContext **puc, const char *filename, int flags);
5652bb94 79
62eaaeac
AK
80/**
81 * Connect an URLContext that has been allocated by ffurl_alloc
82 */
96c1e6d4 83int ffurl_connect(URLContext *uc);
62eaaeac 84
0589da0a
AK
85/**
86 * Create an URLContext for accessing to the resource indicated by
87 * url, and open it.
88 *
89 * @param puc pointer to the location where, in case of success, the
90 * function puts the pointer to the created URLContext
91 * @param flags flags which control how the resource indicated by url
92 * is to be opened
93 * @return 0 in case of success, a negative value corresponding to an
94 * AVERROR code in case of failure
95 */
96c1e6d4 96int ffurl_open(URLContext **puc, const char *filename, int flags);
0589da0a 97
bc371aca
AK
98/**
99 * Read up to size bytes from the resource accessed by h, and store
100 * the read bytes in buf.
101 *
102 * @return The number of bytes actually read, or a negative value
103 * corresponding to an AVERROR code in case of error. A value of zero
104 * indicates that it is not possible to read more from the accessed
105 * resource (except if the value of the size argument is also zero).
106 */
107int ffurl_read(URLContext *h, unsigned char *buf, int size);
108
dce37564
AK
109/**
110 * Read as many bytes as possible (up to size), calling the
111 * read function multiple times if necessary.
112 * This makes special short-read handling in applications
113 * unnecessary, if the return value is < size then it is
114 * certain there was either an error or the end of file was reached.
115 */
116int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
117
925e908b
AK
118/**
119 * Write size bytes from buf to the resource accessed by h.
120 *
121 * @return the number of bytes actually written, or a negative value
122 * corresponding to an AVERROR code in case of failure
123 */
124int ffurl_write(URLContext *h, const unsigned char *buf, int size);
125
58a48c65
AK
126/**
127 * Change the position that will be used by the next read/write
128 * operation on the resource accessed by h.
129 *
130 * @param pos specifies the new position to set
131 * @param whence specifies how pos should be interpreted, it must be
132 * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
133 * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
134 * (return the filesize of the requested resource, pos is ignored).
135 * @return a negative value corresponding to an AVERROR code in case
136 * of failure, or the resulting file position, measured in bytes from
137 * the beginning of the file. You can use this feature together with
138 * SEEK_CUR to read the current file position.
139 */
140int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);
141
e52a9145
AK
142/**
143 * Close the resource accessed by the URLContext h, and free the
144 * memory used by it.
145 *
146 * @return a negative value if an error condition occurred, 0
147 * otherwise
148 */
149int ffurl_close(URLContext *h);
150
32a97d46
AK
151/**
152 * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
153 * if the operation is not supported by h, or another negative value
154 * corresponding to an AVERROR error code in case of failure.
155 */
156int64_t ffurl_size(URLContext *h);
157
1869ea03
AK
158/**
159 * Return the file descriptor associated with this URL. For RTP, this
160 * will return only the RTP file descriptor, not the RTCP file descriptor.
161 *
162 * @return the file descriptor associated with this URL, or <0 on error.
163 */
164int ffurl_get_file_handle(URLContext *h);
165
8e76a19b
AK
166/**
167 * Register the URLProtocol protocol.
168 *
169 * @param size the size of the URLProtocol struct referenced
170 */
171int ffurl_register_protocol(URLProtocol *protocol, int size);
172
c4a090dd
MS
173/**
174 * Check if the user has requested to interrup a blocking function
175 * associated with cb.
176 */
177int ff_check_interrupt(AVIOInterruptCB *cb);
178
d6bbe761
AK
179/* udp.c */
180int ff_udp_set_remote_url(URLContext *h, const char *uri);
181int ff_udp_get_local_port(URLContext *h);
182
153382e1 183#endif /* AVFORMAT_URL_H */