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"
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
)
44 if (url_seek(s
->priv
, s
->pos
, SEEK_SET
) < 0) {
51 static int control(stream_t
*s
, int cmd
, void *arg
)
56 case STREAM_CTRL_GET_SIZE
:
57 size
= url_filesize(s
->priv
);
63 case STREAM_CTRL_SEEK_TO_TIME
:
65 ts
= pts
* AV_TIME_BASE
;
66 ts
= av_url_read_seek(s
->priv
, -1, ts
, 0);
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
)
85 URLContext
*ctx
= NULL
;
86 int res
= STREAM_ERROR
;
91 if (mode
== STREAM_READ
)
93 else if (mode
== STREAM_WRITE
)
96 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[ffmpeg] Unknown open mode %d\n", mode
);
97 res
= STREAM_UNSUPPORTED
;
102 filename
= stream
->url
;
104 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[ffmpeg] No URL\n");
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)
115 mp_msg(MSGT_OPEN
, MSGL_V
, "[ffmpeg] libavformat URL type: %s\n",
117 if (!strncmp("rtmp", ctx
->prot
->name
, 4)) {
118 *file_format
= DEMUXER_TYPE_LAVF
;
119 stream
->lavf_type
= "flv";
122 size
= dummy
? 0 : url_filesize(ctx
);
124 stream
->end_pos
= size
;
125 stream
->type
= STREAMTYPE_FILE
;
127 if (dummy
|| ctx
->is_streamed
) {
128 stream
->type
= STREAMTYPE_STREAM
;
132 stream
->fill_buffer
= fill_buffer
;
133 stream
->write_buffer
= write_buffer
;
134 stream
->control
= control
;
135 stream
->close
= close_f
;
143 const stream_info_t stream_info_ffmpeg
= {
149 { "ffmpeg", "rtmp", NULL
},
151 1 // Urls are an option string