3 #include "libavformat/avformat.h"
4 #include "libavformat/avio.h"
10 static int fill_buffer(stream_t
*s
, char *buffer
, int max_len
)
12 int r
= url_read(s
->priv
, buffer
, max_len
);
13 return (r
<= 0) ? -1 : r
;
16 static int write_buffer(stream_t
*s
, char *buffer
, int len
)
18 int r
= url_write(s
->priv
, buffer
, len
);
19 return (r
<= 0) ? -1 : r
;
22 static int seek(stream_t
*s
, off_t newpos
)
25 if (url_seek(s
->priv
, s
->pos
, SEEK_SET
) < 0) {
32 static int control(stream_t
*s
, int cmd
, void *arg
)
36 case STREAM_CTRL_GET_SIZE
:
37 size
= url_filesize(s
->priv
);
43 return STREAM_UNSUPPORTED
;
46 static void close_f(stream_t
*stream
)
48 url_close(stream
->priv
);
51 static const char prefix
[] = "ffmpeg://";
53 static int open_f(stream_t
*stream
, int mode
, void *opts
, int *file_format
)
57 URLContext
*ctx
= NULL
;
58 int res
= STREAM_ERROR
;
62 if (mode
== STREAM_READ
)
64 else if (mode
== STREAM_WRITE
)
67 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[ffmpeg] Unknown open mode %d\n", mode
);
68 res
= STREAM_UNSUPPORTED
;
73 filename
= stream
->url
;
75 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[ffmpeg] No URL\n");
78 if (!strncmp(filename
, prefix
, strlen(prefix
)))
79 filename
+= strlen(prefix
);
80 mp_msg(MSGT_OPEN
, MSGL_V
, "[ffmpeg] Opening %s\n", filename
);
82 if (url_open(&ctx
, filename
, flags
) < 0)
86 size
= url_filesize(ctx
);
88 stream
->end_pos
= size
;
89 stream
->type
= STREAMTYPE_FILE
;
91 if (ctx
->is_streamed
) {
92 stream
->type
= STREAMTYPE_STREAM
;
95 stream
->fill_buffer
= fill_buffer
;
96 stream
->write_buffer
= write_buffer
;
97 stream
->control
= control
;
98 stream
->close
= close_f
;
105 const stream_info_t stream_info_ffmpeg
= {
111 { "ffmpeg", "rtmp", NULL
},
113 1 // Urls are an option string