annotate rtspenc.c @ 5777:afceb57d364c libavformat

Add doxygen documentation for ff_url_split
author mstorsjo
date Mon, 08 Mar 2010 09:07:41 +0000
parents 7c7fe75728dd
children 4410bccf6a8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
1 /*
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
2 * RTSP muxer
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
3 * Copyright (c) 2010 Martin Storsjo
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
4 *
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
5 * This file is part of FFmpeg.
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
6 *
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
11 *
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
15 * Lesser General Public License for more details.
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
16 *
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
20 */
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
21
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
22 #include "avformat.h"
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
23
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
24 #include <sys/time.h>
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
25 #if HAVE_SYS_SELECT_H
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
26 #include <sys/select.h>
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
27 #endif
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
28 #include "network.h"
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
29 #include "rtsp.h"
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
30
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
31 static int rtsp_write_record(AVFormatContext *s)
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
32 {
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
33 RTSPState *rt = s->priv_data;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
34 RTSPMessageHeader reply1, *reply = &reply1;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
35 char cmd[1024];
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
36
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
37 snprintf(cmd, sizeof(cmd),
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
38 "RECORD %s RTSP/1.0\r\n"
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
39 "Range: npt=%0.3f-\r\n",
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
40 s->filename,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
41 (double) 0);
5697
484fceabfad2 Prefix non-static RTSP functions with ff_.
rbultje
parents: 5695
diff changeset
42 ff_rtsp_send_cmd(s, cmd, reply, NULL);
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
43 if (reply->status_code != RTSP_STATUS_OK)
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
44 return -1;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
45 rt->state = RTSP_STATE_STREAMING;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
46 return 0;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
47 }
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
48
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
49 static int rtsp_write_header(AVFormatContext *s)
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
50 {
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
51 RTSPState *rt = s->priv_data;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
52 int ret;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
53
5697
484fceabfad2 Prefix non-static RTSP functions with ff_.
rbultje
parents: 5695
diff changeset
54 ret = ff_rtsp_connect(s);
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
55 if (ret)
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
56 return ret;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
57
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
58 if (rtsp_write_record(s) < 0) {
5697
484fceabfad2 Prefix non-static RTSP functions with ff_.
rbultje
parents: 5695
diff changeset
59 ff_rtsp_close_streams(s);
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
60 url_close(rt->rtsp_hd);
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
61 return AVERROR_INVALIDDATA;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
62 }
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
63 return 0;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
64 }
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
65
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
66 static int rtsp_write_packet(AVFormatContext *s, AVPacket *pkt)
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
67 {
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
68 RTSPState *rt = s->priv_data;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
69 RTSPStream *rtsp_st;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
70 fd_set rfds;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
71 int n, tcp_fd;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
72 struct timeval tv;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
73 AVFormatContext *rtpctx;
5721
82b0dc4f052a RTSP muxer: Use a local copy of the AVPacket for sending to the chained muxer
mstorsjo
parents: 5697
diff changeset
74 AVPacket local_pkt;
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
75
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
76 FD_ZERO(&rfds);
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
77 tcp_fd = url_get_file_handle(rt->rtsp_hd);
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
78 FD_SET(tcp_fd, &rfds);
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
79
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
80 tv.tv_sec = 0;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
81 tv.tv_usec = 0;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
82 n = select(tcp_fd + 1, &rfds, NULL, NULL, &tv);
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
83 if (n > 0) {
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
84 if (FD_ISSET(tcp_fd, &rfds)) {
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
85 RTSPMessageHeader reply;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
86
5697
484fceabfad2 Prefix non-static RTSP functions with ff_.
rbultje
parents: 5695
diff changeset
87 if (ff_rtsp_read_reply(s, &reply, NULL, 0) < 0)
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
88 return AVERROR(EPIPE);
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
89 /* XXX: parse message */
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
90 if (rt->state != RTSP_STATE_STREAMING)
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
91 return AVERROR(EPIPE);
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
92 }
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
93 }
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
94
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
95 if (pkt->stream_index < 0 || pkt->stream_index >= rt->nb_rtsp_streams)
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
96 return AVERROR_INVALIDDATA;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
97 rtsp_st = rt->rtsp_streams[pkt->stream_index];
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
98 rtpctx = rtsp_st->transport_priv;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
99
5721
82b0dc4f052a RTSP muxer: Use a local copy of the AVPacket for sending to the chained muxer
mstorsjo
parents: 5697
diff changeset
100 /* Use a local packet for writing to the chained muxer, otherwise
82b0dc4f052a RTSP muxer: Use a local copy of the AVPacket for sending to the chained muxer
mstorsjo
parents: 5697
diff changeset
101 * the internal stream_index = 0 becomes visible to the muxer user. */
82b0dc4f052a RTSP muxer: Use a local copy of the AVPacket for sending to the chained muxer
mstorsjo
parents: 5697
diff changeset
102 local_pkt = *pkt;
82b0dc4f052a RTSP muxer: Use a local copy of the AVPacket for sending to the chained muxer
mstorsjo
parents: 5697
diff changeset
103 local_pkt.stream_index = 0;
82b0dc4f052a RTSP muxer: Use a local copy of the AVPacket for sending to the chained muxer
mstorsjo
parents: 5697
diff changeset
104 return av_write_frame(rtpctx, &local_pkt);
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
105 }
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
106
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
107 static int rtsp_write_close(AVFormatContext *s)
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
108 {
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
109 RTSPState *rt = s->priv_data;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
110 char cmd[1024];
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
111
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
112 snprintf(cmd, sizeof(cmd),
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
113 "TEARDOWN %s RTSP/1.0\r\n",
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
114 s->filename);
5697
484fceabfad2 Prefix non-static RTSP functions with ff_.
rbultje
parents: 5695
diff changeset
115 ff_rtsp_send_cmd_async(s, cmd);
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
116
5697
484fceabfad2 Prefix non-static RTSP functions with ff_.
rbultje
parents: 5695
diff changeset
117 ff_rtsp_close_streams(s);
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
118 url_close(rt->rtsp_hd);
5756
7c7fe75728dd Use ff_url_join for assembling URLs, instead of snprintf
mstorsjo
parents: 5721
diff changeset
119 ff_network_close();
5695
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
120 return 0;
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
121 }
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
122
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
123 AVOutputFormat rtsp_muxer = {
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
124 "rtsp",
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
125 NULL_IF_CONFIG_SMALL("RTSP output format"),
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
126 NULL,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
127 NULL,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
128 sizeof(RTSPState),
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
129 CODEC_ID_PCM_MULAW,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
130 CODEC_ID_NONE,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
131 rtsp_write_header,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
132 rtsp_write_packet,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
133 rtsp_write_close,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
134 .flags = AVFMT_NOFILE | AVFMT_GLOBALHEADER,
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
135 };
25062326d2f9 Add an RTSP muxer
mstorsjo
parents:
diff changeset
136