1 /*
2 * Session Announcement Protocol (RFC 2974) demuxer
3 * Copyright (c) 2010 Martin Storsjo
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
32 #if HAVE_POLL_H
33 #include <poll.h>
34 #endif
35
43 };
44
46 {
49 return 0;
50 }
51
53 {
61 return 0;
62 }
63
65 {
67 char host[1024], path[1024], url[1024];
69 int port;
70 int ret, i;
72
75
78 if (port < 0)
79 port = 9875;
80
81 if (!host[0]) {
82 /* Listen for announcements on sap.mcast.net if no host was specified */
83 av_strlcpy(host,
"224.2.127.254",
sizeof(host));
84 }
85
87 port);
91 if (ret)
93
94 while (1) {
95 int addr_type, auth_len;
96 int pos;
97
100 continue;
101 if (ret < 0)
103 recvbuf[ret] = '0円'; /* Null terminate for easier parsing */
104 if (ret < 8) {
106 continue;
107 }
108
109 if ((recvbuf[0] & 0xe0) != 0x20) {
111 "received\n");
112 continue;
113 }
114
115 if (recvbuf[0] & 0x04) {
117 "announcement\n");
118 continue;
119 }
120 addr_type = recvbuf[0] & 0x10;
121 auth_len = recvbuf[1];
123 pos = 4;
124 if (addr_type)
125 pos += 16; /* IPv6 */
126 else
127 pos += 4; /* IPv4 */
128 pos += auth_len * 4;
129 if (pos + 4 >= ret) {
131 continue;
132 }
133 #define MIME "application/sdp"
134 if (strcmp(&recvbuf[pos],
MIME) == 0) {
135 pos += strlen(
MIME) + 1;
136 } else if (strncmp(&recvbuf[pos], "v=0\r\n", 5) == 0) {
137 // Direct SDP without a mime type
138 } else {
140 &recvbuf[pos]);
141 continue;
142 }
143
145 break;
146 }
147
151
153 if (!infmt)
159 }
163
166
168 if (ret < 0)
174 if (!st) {
177 }
181 }
182
183 return 0;
184
187 return ret;
188 }
189
191 {
195 struct pollfd p = {fd, POLLIN, 0};
197
200
201 while (1) {
202 n = poll(&p, 1, 0);
203 if (n <= 0 || !(p.revents & POLLIN))
204 break;
206 if (ret >= 8) {
208 /* Should ideally check the source IP address, too */
209 if (recvbuf[0] & 0x04 && hash == sap->
hash) {
210 /* Stream deletion */
213 }
214 }
215 }
217 if (ret < 0)
218 return ret;
223 if (!st) {
226 }
230 }
231 }
232 return ret;
233 }
234
238 .priv_data_size =
sizeof(
struct SAPState),
244 };
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
static int sap_read_close(AVFormatContext *s)
#define RTP_MAX_PACKET_LENGTH
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVInputFormat ff_sap_demuxer
#define AVIO_FLAG_READ
read-only
void ff_network_close(void)
int ctx_flags
Flags signalling stream properties.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
int ff_network_init(void)
miscellaneous OS support macros and functions.
int id
Format-specific stream ID.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
char * protocol_whitelist
',' separated list of allowed protocols.
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
simple assert() macros that are a bit more flexible than ISO C assert().
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
AVCodecContext * codec
Codec context associated with this stream.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
char filename[1024]
input or output filename
AVFormatContext * sdp_ctx
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
char * av_strdup(const char *s)
Duplicate the string s.
AVIOContext * pb
I/O context.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
This structure contains the data a format has to probe a file.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
static int sap_read_header(AVFormatContext *s)
static int sap_probe(AVProbeData *p)
int ffurl_close(URLContext *h)
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
void * priv_data
Format private data.
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
unbuffered private I/O API
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
This structure stores compressed data.
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...