vo_gl: reject MS Windows native OpenGL as software rasterizer
[mplayer.git] / stream / stream_ffmpeg.c
blobaf716757132b06f7c54a6680d639502796631808
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 AVIOContext *avio = s->priv;
32 int r = avio_read(avio, buffer, max_len);
33 return (r <= 0) ? -1 : r;
36 static int write_buffer(stream_t *s, char *buffer, int len)
38 AVIOContext *avio = s->priv;
39 avio_write(avio, buffer, len);
40 avio_flush(avio);
41 if (avio->error)
42 return -1;
43 return len;
46 static int seek(stream_t *s, off_t newpos)
48 AVIOContext *avio = s->priv;
49 s->pos = newpos;
50 if (avio_seek(avio, s->pos, SEEK_SET) < 0) {
51 s->eof = 1;
52 return 0;
54 return 1;
57 static int control(stream_t *s, int cmd, void *arg)
59 AVIOContext *avio = s->priv;
60 int64_t size, ts;
61 double pts;
62 switch(cmd) {
63 case STREAM_CTRL_GET_SIZE:
64 size = avio_size(avio);
65 if(size >= 0) {
66 *(off_t *)arg = size;
67 return 1;
69 break;
70 case STREAM_CTRL_SEEK_TO_TIME:
71 pts = *(double *)arg;
72 ts = pts * AV_TIME_BASE;
73 ts = avio_seek_time(avio, -1, ts, 0);
74 if (ts >= 0)
75 return 1;
76 break;
78 return STREAM_UNSUPPORTED;
81 static void close_f(stream_t *stream)
83 AVIOContext *avio = stream->priv;
84 /* NOTE: As of 2011 write streams must be manually flushed before close.
85 * Currently write_buffer() always flushes them after writing.
86 * avio_close() could return an error, but we have no way to return that
87 * with the current stream API.
89 avio_close(avio);
92 static const char prefix[] = "ffmpeg://";
94 static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
96 int flags = 0;
97 const char *filename;
98 AVIOContext *avio = NULL;
99 int res = STREAM_ERROR;
100 int64_t size;
101 int dummy;
103 if (mode == STREAM_READ)
104 flags = AVIO_FLAG_READ;
105 else if (mode == STREAM_WRITE)
106 flags = AVIO_FLAG_WRITE;
107 else {
108 mp_msg(MSGT_OPEN, MSGL_ERR, "[ffmpeg] Unknown open mode %d\n", mode);
109 res = STREAM_UNSUPPORTED;
110 goto out;
113 if (stream->url)
114 filename = stream->url;
115 else {
116 mp_msg(MSGT_OPEN, MSGL_ERR, "[ffmpeg] No URL\n");
117 goto out;
119 if (!strncmp(filename, prefix, strlen(prefix)))
120 filename += strlen(prefix);
121 dummy = !strncmp(filename, "rtsp:", 5);
122 mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] Opening %s\n", filename);
124 if (!dummy && avio_open(&avio, filename, flags) < 0)
125 goto out;
127 char *rtmp[] = {"rtmp:", "rtmpt:", "rtmpe:", "rtmpte:", "rtmps:"};
128 for (int i = 0; i < FF_ARRAY_ELEMS(rtmp); i++)
129 if (!strncmp(filename, rtmp[i], strlen(rtmp[i]))) {
130 *file_format = DEMUXER_TYPE_LAVF;
131 stream->lavf_type = "flv";
133 stream->priv = avio;
134 size = dummy ? 0 : avio_size(avio);
135 if (size >= 0)
136 stream->end_pos = size;
137 stream->type = STREAMTYPE_FILE;
138 stream->seek = seek;
139 if (dummy || !avio->seekable) {
140 stream->type = STREAMTYPE_STREAM;
141 stream->seek = NULL;
143 if (!dummy) {
144 stream->fill_buffer = fill_buffer;
145 stream->write_buffer = write_buffer;
146 stream->control = control;
147 stream->close = close_f;
149 res = STREAM_OK;
151 out:
152 return res;
155 const stream_info_t stream_info_ffmpeg = {
156 "FFmpeg",
157 "ffmpeg",
160 open_f,
161 { "ffmpeg", "rtmp", NULL },
162 NULL,
163 1 // Urls are an option string