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.
21 #include "libavformat/avformat.h"
22 #include "libavformat/avio.h"
28 static int fill_buffer(stream_t
*s
, char *buffer
, int max_len
)
30 int r
= url_read(s
->priv
, buffer
, max_len
);
31 return (r
<= 0) ? -1 : r
;
34 static int write_buffer(stream_t
*s
, char *buffer
, int len
)
36 int r
= url_write(s
->priv
, buffer
, len
);
37 return (r
<= 0) ? -1 : r
;
40 static int seek(stream_t
*s
, off_t newpos
)
43 if (url_seek(s
->priv
, s
->pos
, SEEK_SET
) < 0) {
50 static int control(stream_t
*s
, int cmd
, void *arg
)
54 case STREAM_CTRL_GET_SIZE
:
55 size
= url_filesize(s
->priv
);
61 return STREAM_UNSUPPORTED
;
64 static void close_f(stream_t
*stream
)
66 url_close(stream
->priv
);
69 static const char prefix
[] = "ffmpeg://";
71 static int open_f(stream_t
*stream
, int mode
, void *opts
, int *file_format
)
75 URLContext
*ctx
= NULL
;
76 int res
= STREAM_ERROR
;
81 if (mode
== STREAM_READ
)
83 else if (mode
== STREAM_WRITE
)
86 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[ffmpeg] Unknown open mode %d\n", mode
);
87 res
= STREAM_UNSUPPORTED
;
92 filename
= stream
->url
;
94 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[ffmpeg] No URL\n");
97 if (!strncmp(filename
, prefix
, strlen(prefix
)))
98 filename
+= strlen(prefix
);
99 dummy
= !strncmp(filename
, "rtsp:", 5);
100 mp_msg(MSGT_OPEN
, MSGL_V
, "[ffmpeg] Opening %s\n", filename
);
102 if (!dummy
&& url_open(&ctx
, filename
, flags
) < 0)
106 size
= dummy
? 0 : url_filesize(ctx
);
108 stream
->end_pos
= size
;
109 stream
->type
= STREAMTYPE_FILE
;
111 if (dummy
|| ctx
->is_streamed
) {
112 stream
->type
= STREAMTYPE_STREAM
;
116 stream
->fill_buffer
= fill_buffer
;
117 stream
->write_buffer
= write_buffer
;
118 stream
->control
= control
;
119 stream
->close
= close_f
;
127 const stream_info_t stream_info_ffmpeg
= {
133 { "ffmpeg", "rtmp", NULL
},
135 1 // Urls are an option string