FFmpeg: libavformat/rtspenc.c Source File
Go to the documentation of this file. 1 /*
2 * RTSP muxer
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
23
24 #if HAVE_POLL_H
25 #include <poll.h>
26 #endif
38
39
45 };
46
48 {
52 char *sdp;
55
58
59 /* Announce the stream */
61 if (!sdp)
63 /* We create the SDP based on the RTSP AVFormatContext where we
64 * aren't allowed to change the filename field. (We create the SDP
65 * based on the RTSP context since the contexts for the RTP streams
66 * don't exist yet.) In order to specify a custom URL with the actual
67 * peer IP instead of the originally specified hostname, we create
68 * a temporary copy of the AVFormatContext, where the custom URL is set.
69 *
70 * FIXME: Create the SDP without copying the AVFormatContext.
71 * This either requires setting up the RTP stream AVFormatContexts
72 * already here (complicating things immensely) or getting a more
73 * flexible SDP creation interface.
74 */
79 ctx_array[0] = &sdp_ctx;
83 }
86 "Content-Type: application/sdp\r\n",
87 reply,
NULL, sdp, strlen(sdp));
91
92 /* Set up the RTSPStreams for each AVStream */
93 for (
i = 0;
i <
s->nb_streams;
i++) {
95
97 if (!rtsp_st)
100
102
104 /* Note, this must match the relative uri set in the sdp content */
107 }
108
109 return 0;
110 }
111
113 {
117
119 "Range: npt=0.000-\r\n");
124 return 0;
125 }
126
128 {
130
134
139 }
140 return 0;
141 }
142
144 {
147 uint8_t *buf, *ptr;
149 uint8_t *interleave_header, *interleaved_packet;
150
153 ptr = buf;
155 uint32_t packet_len =
AV_RB32(ptr);
157 /* The interleaving header is exactly 4 bytes, which happens to be
158 * the same size as the packet length header from
159 * ffio_open_dyn_packet_buf. So by writing the interleaving header
160 * over these bytes, we get a consecutive interleaved packet
161 * that can be written in one call. */
162 interleaved_packet = interleave_header = ptr;
163 ptr += 4;
165 if (packet_len >
size || packet_len < 2)
166 break;
169 else
171 interleave_header[0] = '$';
172 interleave_header[1] =
id;
173 AV_WB16(interleave_header + 2, packet_len);
175 ptr += packet_len;
177 }
180 }
181
183 {
186 int n;
190
191 while (1) {
193 if (n <= 0)
194 break;
195 if (
p.revents & POLLIN) {
197
198 /* Don't let ff_rtsp_read_reply handle interleaved packets,
199 * since it would block and wait for an RTSP reply on the socket
200 * (which may not be coming any time soon) if it handles
201 * interleaved packets internally. */
209 }
210 /* XXX: parse message */
213 }
214 }
215
220
222 /* ff_write_chained does all the RTP packetization. If using TCP as
223 * transport, rtpctx->pb is only a dyn_packet_buf that queues up the
224 * packets, so we need to send them out on the TCP connection separately.
225 */
229 }
230
232 {
234
235 // If we want to send RTCP_BYE packets, these are sent by av_write_trailer.
236 // Thus call this on all streams before doing the teardown. This is
237 // done within ff_rtsp_undo_setup.
239
241
245 return 0;
246 }
247
259 };
int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, unsigned char **content_ptr, int return_on_interleaved_data, const char *method)
Read a RTSP message from the server, or prepare to read data packets if we're reading data interleave...
void ff_rtsp_close_streams(AVFormatContext *s)
Close and free all streams within the RTSP (de)muxer.
static const AVClass rtsp_muxer_class
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void * transport_priv
RTP/RDT parse context if input, RTP AVFormatContext if output.
int ff_rtsp_send_cmd_with_content(AVFormatContext *s, const char *method, const char *url, const char *headers, RTSPMessageHeader *reply, unsigned char **content_ptr, const unsigned char *send_content, int send_content_length)
Send a command to the RTSP server and wait for the reply.
int ff_rtsp_send_cmd(AVFormatContext *s, const char *method, const char *url, const char *headers, RTSPMessageHeader *reply, unsigned char **content_ptr)
Send a command to the RTSP server and wait for the reply.
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
static int ff_rtsp_averror(enum RTSPStatusCode status_code, int default_averror)
int interleaved_min
interleave IDs; copies of RTSPTransportField->interleaved_min/max for the selected transport.
Describe a single stream, as identified by a single m= line block in the SDP content.
#define AV_LOG_VERBOSE
Detailed information.
int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method, const char *url, const char *headers)
Send a command to the RTSP server without waiting for the reply.
void ff_network_close(void)
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
int nb_rtsp_streams
number of items in the 'rtsp_streams' variable
@ RTSP_STATE_STREAMING
initialized and sending/receiving data
int stream_index
corresponding stream index, if any.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
URLContext * rtsp_hd_out
Additional output handle, used when input and output are done separately, eg for HTTP tunneling.
const FFOutputFormat ff_rtsp_muxer
char control_uri[MAX_URL_SIZE]
some MS RTSP streams contain a URL in the SDP that we need to use for all subsequent RTSP requests,...
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets)
Undo the effect of ff_rtsp_make_setup_request, close the transport_priv and rtp_handle fields.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
int ff_rtsp_tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)
Send buffered packets over TCP.
const char * av_default_item_name(void *ptr)
Return the context name.
AVIOContext * pb
I/O context.
enum RTSPClientState state
indicator of whether we are currently receiving data from the server.
static int rtsp_write_record(AVFormatContext *s)
static int rtsp_write_header(AVFormatContext *s)
static int rtsp_write_close(AVFormatContext *s)
#define RTP_PT_IS_RTCP(x)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const AVOption ff_rtsp_options[]
void ff_rtsp_close_connections(AVFormatContext *s)
Close all connection handles within the RTSP (de)muxer.
Private data for the RTSP demuxer.
enum RTSPLowerTransport lower_transport
the negotiated network layer transport protocol; e.g.
char * url
input or output URL.
struct RTSPStream ** rtsp_streams
streams in this session
#define AV_NOPTS_VALUE
Undefined timestamp value.
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_RB32
int ff_rtsp_skip_packet(AVFormatContext *s)
Skip a RTP/TCP interleaved packet.
int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
Open a write only packetized memory stream with a maximum packet size of 'max_packet_size'.
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
#define i(width, name, range_min, range_max)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
@ RTSP_LOWER_TRANSPORT_TCP
TCP; interleaved in RTSP.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
char control_url[MAX_URL_SIZE]
url for this stream (from SDP)
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr)
Announce the stream to the server and set up the RTSPStream child objects for each media stream.
int64_t av_gettime(void)
Get the current time in microseconds.
static int rtsp_write_packet(AVFormatContext *s, AVPacket *pkt)
This structure stores compressed data.
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.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int ff_rtsp_connect(AVFormatContext *s)
Connect to the RTSP server and set up the individual media streams.
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
Generated on Tue Nov 18 2025 19:23:34 for FFmpeg by
doxygen
1.8.17