annotate librtmp.c @ 6085:72c7c3d5c4e9 libavformat

matroskaenc: Mux clusters better Start them on keyframes when reasonable, and delay writing audio packets to help ensure that there's audio samples available for the first frame in clusters. Patch by James Zern <jzern at google>
author conrad
date Fri, 04 Jun 2010 22:40:50 +0000
parents 7fdda2416684
children fa244b4fe683
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
1 /*
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
2 * RTMP network protocol
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
3 * Copyright (c) 2010 Howard Chu
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
4 *
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
5 * This file is part of FFmpeg.
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
6 *
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
11 *
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
15 * Lesser General Public License for more details.
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
16 *
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
20 */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
21
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
22 /**
5969
178de7695c6c Remove explicit filename from Doxygen @file commands.
diego
parents: 5963
diff changeset
23 * @file
5951
28103c669f01 whitespace cosmetics
diego
parents: 5904
diff changeset
24 * RTMP protocol based on http://rtmpdump.mplayerhq.hu/ librtmp
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
25 */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
26
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
27 #include "avformat.h"
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
28
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
29 #include <librtmp/rtmp.h>
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
30 #include <librtmp/log.h>
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
31
5952
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
32 static void rtmp_log(int level, const char *fmt, va_list args)
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
33 {
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
34 switch (level) {
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
35 default:
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
36 case RTMP_LOGCRIT: level = AV_LOG_FATAL; break;
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
37 case RTMP_LOGERROR: level = AV_LOG_ERROR; break;
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
38 case RTMP_LOGWARNING: level = AV_LOG_WARNING; break;
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
39 case RTMP_LOGINFO: level = AV_LOG_INFO; break;
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
40 case RTMP_LOGDEBUG: level = AV_LOG_VERBOSE; break;
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
41 case RTMP_LOGDEBUG2: level = AV_LOG_DEBUG; break;
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
42 }
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
43
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
44 av_vlog(NULL, level, fmt, args);
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
45 av_log(NULL, level, "\n");
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
46 }
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
47
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
48 static int rtmp_close(URLContext *s)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
49 {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
50 RTMP *r = s->priv_data;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
51
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
52 RTMP_Close(r);
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
53 av_free(r);
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
54 return 0;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
55 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
56
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
57 /**
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
58 * Opens RTMP connection and verifies that the stream can be played.
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
59 *
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
60 * URL syntax: rtmp://server[:port][/app][/playpath][ keyword=value]...
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
61 * where 'app' is first one or two directories in the path
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
62 * (e.g. /ondemand/, /flash/live/, etc.)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
63 * and 'playpath' is a file name (the rest of the path,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
64 * may be prefixed with "mp4:")
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
65 *
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
66 * Additional RTMP library options may be appended as
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
67 * space-separated key-value pairs.
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
68 */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
69 static int rtmp_open(URLContext *s, const char *uri, int flags)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
70 {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
71 RTMP *r;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
72 int rc;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
73
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
74 r = av_mallocz(sizeof(RTMP));
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
75 if (!r)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
76 return AVERROR(ENOMEM);
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
77
5951
28103c669f01 whitespace cosmetics
diego
parents: 5904
diff changeset
78 switch (av_log_get_level()) {
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
79 default:
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
80 case AV_LOG_FATAL: rc = RTMP_LOGCRIT; break;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
81 case AV_LOG_ERROR: rc = RTMP_LOGERROR; break;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
82 case AV_LOG_WARNING: rc = RTMP_LOGWARNING; break;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
83 case AV_LOG_INFO: rc = RTMP_LOGINFO; break;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
84 case AV_LOG_VERBOSE: rc = RTMP_LOGDEBUG; break;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
85 case AV_LOG_DEBUG: rc = RTMP_LOGDEBUG2; break;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
86 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
87 RTMP_LogSetLevel(rc);
5952
7f9a0da9f56a Plug librtmp logging into av_log.
diego
parents: 5951
diff changeset
88 RTMP_LogSetCallback(rtmp_log);
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
89
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
90 RTMP_Init(r);
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
91 if (!RTMP_SetupURL(r, s->filename)) {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
92 rc = -1;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
93 goto fail;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
94 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
95
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
96 if (flags & URL_WRONLY)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
97 r->Link.protocol |= RTMP_FEATURE_WRITE;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
98
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
99 if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
100 rc = -1;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
101 goto fail;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
102 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
103
5951
28103c669f01 whitespace cosmetics
diego
parents: 5904
diff changeset
104 s->priv_data = r;
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
105 s->is_streamed = 1;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
106 return 0;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
107 fail:
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
108 av_free(r);
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
109 return rc;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
110 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
111
6068
7fdda2416684 Declare the url_write buffer parameter as const
mstorsjo
parents: 5969
diff changeset
112 static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
113 {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
114 RTMP *r = s->priv_data;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
115
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
116 return RTMP_Write(r, buf, size);
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
117 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
118
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
119 static int rtmp_read(URLContext *s, uint8_t *buf, int size)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
120 {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
121 RTMP *r = s->priv_data;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
122
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
123 return RTMP_Read(r, buf, size);
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
124 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
125
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
126 static int rtmp_read_pause(URLContext *s, int pause)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
127 {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
128 RTMP *r = s->priv_data;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
129
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
130 if (pause)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
131 r->m_pauseStamp =
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
132 r->m_channelTimestamp[r->m_mediaChannel];
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
133 if (!RTMP_SendPause(r, pause, r->m_pauseStamp))
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
134 return -1;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
135 return 0;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
136 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
137
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
138 static int64_t rtmp_read_seek(URLContext *s, int stream_index,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
139 int64_t timestamp, int flags)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
140 {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
141 RTMP *r = s->priv_data;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
142
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
143 if (flags & AVSEEK_FLAG_BYTE)
5962
e967aa2c1754 Prefer AVERROR(ENOSYS) over AVERROR_NOTSUPP.
stefano
parents: 5952
diff changeset
144 return AVERROR(ENOSYS);
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
145
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
146 /* seeks are in milliseconds */
5963
12bdd63f5259 Implement librtmp seek support.
stefano
parents: 5962
diff changeset
147 if (stream_index < 0)
12bdd63f5259 Implement librtmp seek support.
stefano
parents: 5962
diff changeset
148 timestamp = av_rescale_rnd(timestamp, 1000, AV_TIME_BASE,
12bdd63f5259 Implement librtmp seek support.
stefano
parents: 5962
diff changeset
149 flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP);
12bdd63f5259 Implement librtmp seek support.
stefano
parents: 5962
diff changeset
150
5904
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
151 if (!RTMP_SendSeek(r, timestamp))
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
152 return -1;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
153 return timestamp;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
154 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
155
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
156 static int rtmp_get_file_handle(URLContext *s)
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
157 {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
158 RTMP *r = s->priv_data;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
159
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
160 return r->m_sb.sb_socket;
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
161 }
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
162
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
163 URLProtocol rtmp_protocol = {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
164 "rtmp",
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
165 rtmp_open,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
166 rtmp_read,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
167 rtmp_write,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
168 NULL, /* seek */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
169 rtmp_close,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
170 NULL, /* next */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
171 rtmp_read_pause,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
172 rtmp_read_seek,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
173 rtmp_get_file_handle
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
174 };
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
175
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
176 URLProtocol rtmpt_protocol = {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
177 "rtmpt",
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
178 rtmp_open,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
179 rtmp_read,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
180 rtmp_write,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
181 NULL, /* seek */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
182 rtmp_close,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
183 NULL, /* next */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
184 rtmp_read_pause,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
185 rtmp_read_seek,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
186 rtmp_get_file_handle
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
187 };
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
188
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
189 URLProtocol rtmpe_protocol = {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
190 "rtmpe",
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
191 rtmp_open,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
192 rtmp_read,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
193 rtmp_write,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
194 NULL, /* seek */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
195 rtmp_close,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
196 NULL, /* next */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
197 rtmp_read_pause,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
198 rtmp_read_seek,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
199 rtmp_get_file_handle
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
200 };
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
201
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
202 URLProtocol rtmpte_protocol = {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
203 "rtmpte",
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
204 rtmp_open,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
205 rtmp_read,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
206 rtmp_write,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
207 NULL, /* seek */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
208 rtmp_close,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
209 NULL, /* next */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
210 rtmp_read_pause,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
211 rtmp_read_seek,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
212 rtmp_get_file_handle
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
213 };
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
214
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
215 URLProtocol rtmps_protocol = {
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
216 "rtmps",
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
217 rtmp_open,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
218 rtmp_read,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
219 rtmp_write,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
220 NULL, /* seek */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
221 rtmp_close,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
222 NULL, /* next */
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
223 rtmp_read_pause,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
224 rtmp_read_seek,
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
225 rtmp_get_file_handle
5564d7f2ed5a Implement support to RTMP, RTMPT, RTMPE, RTMPTE, RTMPS protocols via
stefano
parents:
diff changeset
226 };