options: remove CONF_OLD option flag
[mplayer/greg.git] / stream / stream_ffmpeg.c
blobe6705883fcf100723c74cf68d7f70e636a602597
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "config.h"
21 #include "libavformat/avformat.h"
22 #include "libavformat/avio.h"
23 #include "mp_msg.h"
24 #include "stream.h"
25 #include "m_option.h"
26 #include "m_struct.h"
27 #include "libmpdemux/demuxer.h"
29 static int fill_buffer(stream_t *s, char *buffer, int max_len)
31 int r = url_read_complete(s->priv, buffer, max_len);
32 return (r <= 0) ? -1 : r;
35 static int write_buffer(stream_t *s, char *buffer, int len)
37 int r = url_write(s->priv, buffer, len);
38 return (r <= 0) ? -1 : r;
41 static int seek(stream_t *s, off_t newpos)
43 s->pos = newpos;
44 if (url_seek(s->priv, s->pos, SEEK_SET) < 0) {
45 s->eof = 1;
46 return 0;
48 return 1;
51 static int control(stream_t *s, int cmd, void *arg)
53 int64_t size, ts;
54 double pts;
55 switch(cmd) {
56 case STREAM_CTRL_GET_SIZE:
57 size = url_filesize(s->priv);
58 if(size >= 0) {
59 *(off_t *)arg = size;
60 return 1;
62 break;
63 case STREAM_CTRL_SEEK_TO_TIME:
64 pts = *(double *)arg;
65 ts = pts * AV_TIME_BASE;
66 ts = av_url_read_seek(s->priv, -1, ts, 0);
67 if (ts >= 0)
68 return 1;
69 break;
71 return STREAM_UNSUPPORTED;
74 static void close_f(stream_t *stream)
76 url_close(stream->priv);
79 static const char prefix[] = "ffmpeg://";
81 static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
83 int flags = 0;
84 const char *filename;
85 URLContext *ctx = NULL;
86 int res = STREAM_ERROR;
87 int64_t size;
88 int dummy;
90 av_register_all();
91 if (mode == STREAM_READ)
92 flags = URL_RDONLY;
93 else if (mode == STREAM_WRITE)
94 flags = URL_WRONLY;
95 else {
96 mp_msg(MSGT_OPEN, MSGL_ERR, "[ffmpeg] Unknown open mode %d\n", mode);
97 res = STREAM_UNSUPPORTED;
98 goto out;
101 if (stream->url)
102 filename = stream->url;
103 else {
104 mp_msg(MSGT_OPEN, MSGL_ERR, "[ffmpeg] No URL\n");
105 goto out;
107 if (!strncmp(filename, prefix, strlen(prefix)))
108 filename += strlen(prefix);
109 dummy = !strncmp(filename, "rtsp:", 5);
110 mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] Opening %s\n", filename);
112 if (!dummy && url_open(&ctx, filename, flags) < 0)
113 goto out;
115 mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] libavformat URL type: %s\n",
116 ctx->prot->name);
117 if (!strncmp("rtmp", ctx->prot->name, 4)) {
118 *file_format = DEMUXER_TYPE_LAVF;
119 stream->lavf_type = "flv";
121 stream->priv = ctx;
122 size = dummy ? 0 : url_filesize(ctx);
123 if (size >= 0)
124 stream->end_pos = size;
125 stream->type = STREAMTYPE_FILE;
126 stream->seek = seek;
127 if (dummy || ctx->is_streamed) {
128 stream->type = STREAMTYPE_STREAM;
129 stream->seek = NULL;
131 if (!dummy) {
132 stream->fill_buffer = fill_buffer;
133 stream->write_buffer = write_buffer;
134 stream->control = control;
135 stream->close = close_f;
137 res = STREAM_OK;
139 out:
140 return res;
143 const stream_info_t stream_info_ffmpeg = {
144 "FFmpeg",
145 "ffmpeg",
148 open_f,
149 { "ffmpeg", "rtmp", NULL },
150 NULL,
151 1 // Urls are an option string