mirror of
https://github.com/mpv-player/mpv
synced 2025-04-10 19:51:43 +00:00
stream_ffmpeg: switch to libavformat avio API
stream_ffmpeg was using the libavformat URLContext API. This API has been deprecated (for public use at least) in libavformat. Switch to the AVIOContext API.
This commit is contained in:
parent
1bd5871762
commit
30afc64532
@ -28,21 +28,26 @@
|
|||||||
|
|
||||||
static int fill_buffer(stream_t *s, char *buffer, int max_len)
|
static int fill_buffer(stream_t *s, char *buffer, int max_len)
|
||||||
{
|
{
|
||||||
int r = url_read_complete(s->priv, buffer, max_len);
|
AVIOContext *avio = s->priv;
|
||||||
|
int r = avio_read(avio, buffer, max_len);
|
||||||
return (r <= 0) ? -1 : r;
|
return (r <= 0) ? -1 : r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_buffer(stream_t *s, char *buffer, int len)
|
static int write_buffer(stream_t *s, char *buffer, int len)
|
||||||
{
|
{
|
||||||
/* url_write retries internally on short writes and EAGAIN */
|
AVIOContext *avio = s->priv;
|
||||||
int r = url_write(s->priv, buffer, len);
|
avio_write(avio, buffer, len);
|
||||||
return (r <= 0) ? -1 : r;
|
avio_flush(avio);
|
||||||
|
if (avio->error)
|
||||||
|
return -1;
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int seek(stream_t *s, off_t newpos)
|
static int seek(stream_t *s, off_t newpos)
|
||||||
{
|
{
|
||||||
|
AVIOContext *avio = s->priv;
|
||||||
s->pos = newpos;
|
s->pos = newpos;
|
||||||
if (url_seek(s->priv, s->pos, SEEK_SET) < 0) {
|
if (avio_seek(avio, s->pos, SEEK_SET) < 0) {
|
||||||
s->eof = 1;
|
s->eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -51,11 +56,12 @@ static int seek(stream_t *s, off_t newpos)
|
|||||||
|
|
||||||
static int control(stream_t *s, int cmd, void *arg)
|
static int control(stream_t *s, int cmd, void *arg)
|
||||||
{
|
{
|
||||||
|
AVIOContext *avio = avio;
|
||||||
int64_t size, ts;
|
int64_t size, ts;
|
||||||
double pts;
|
double pts;
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
case STREAM_CTRL_GET_SIZE:
|
case STREAM_CTRL_GET_SIZE:
|
||||||
size = url_filesize(s->priv);
|
size = avio_size(avio);
|
||||||
if(size >= 0) {
|
if(size >= 0) {
|
||||||
*(off_t *)arg = size;
|
*(off_t *)arg = size;
|
||||||
return 1;
|
return 1;
|
||||||
@ -64,7 +70,7 @@ static int control(stream_t *s, int cmd, void *arg)
|
|||||||
case STREAM_CTRL_SEEK_TO_TIME:
|
case STREAM_CTRL_SEEK_TO_TIME:
|
||||||
pts = *(double *)arg;
|
pts = *(double *)arg;
|
||||||
ts = pts * AV_TIME_BASE;
|
ts = pts * AV_TIME_BASE;
|
||||||
ts = av_url_read_seek(s->priv, -1, ts, 0);
|
ts = avio_seek_time(avio, -1, ts, 0);
|
||||||
if (ts >= 0)
|
if (ts >= 0)
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
@ -74,7 +80,13 @@ static int control(stream_t *s, int cmd, void *arg)
|
|||||||
|
|
||||||
static void close_f(stream_t *stream)
|
static void close_f(stream_t *stream)
|
||||||
{
|
{
|
||||||
url_close(stream->priv);
|
AVIOContext *avio = stream->priv;
|
||||||
|
/* NOTE: As of 2011 write streams must be manually flushed before close.
|
||||||
|
* Currently write_buffer() always flushes them after writing.
|
||||||
|
* avio_close() could return an error, but we have no way to return that
|
||||||
|
* with the current stream API.
|
||||||
|
*/
|
||||||
|
avio_close(avio);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char prefix[] = "ffmpeg://";
|
static const char prefix[] = "ffmpeg://";
|
||||||
@ -83,7 +95,7 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
|
|||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
URLContext *ctx = NULL;
|
AVIOContext *avio = NULL;
|
||||||
int res = STREAM_ERROR;
|
int res = STREAM_ERROR;
|
||||||
int64_t size;
|
int64_t size;
|
||||||
int dummy;
|
int dummy;
|
||||||
@ -109,22 +121,22 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
|
|||||||
dummy = !strncmp(filename, "rtsp:", 5);
|
dummy = !strncmp(filename, "rtsp:", 5);
|
||||||
mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] Opening %s\n", filename);
|
mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] Opening %s\n", filename);
|
||||||
|
|
||||||
if (!dummy && url_open(&ctx, filename, flags) < 0)
|
if (!dummy && avio_open(&avio, filename, flags) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] libavformat URL type: %s\n",
|
char *rtmp[] = {"rtmp:", "rtmpt:", "rtmpe:", "rtmpte:", "rtmps:"};
|
||||||
ctx->prot->name);
|
for (int i = 0; i < FF_ARRAY_ELEMS(rtmp); i++)
|
||||||
if (!strncmp("rtmp", ctx->prot->name, 4)) {
|
if (!strncmp(filename, rtmp[i], strlen(rtmp[i]))) {
|
||||||
*file_format = DEMUXER_TYPE_LAVF;
|
*file_format = DEMUXER_TYPE_LAVF;
|
||||||
stream->lavf_type = "flv";
|
stream->lavf_type = "flv";
|
||||||
}
|
}
|
||||||
stream->priv = ctx;
|
stream->priv = avio;
|
||||||
size = dummy ? 0 : url_filesize(ctx);
|
size = dummy ? 0 : avio_size(avio);
|
||||||
if (size >= 0)
|
if (size >= 0)
|
||||||
stream->end_pos = size;
|
stream->end_pos = size;
|
||||||
stream->type = STREAMTYPE_FILE;
|
stream->type = STREAMTYPE_FILE;
|
||||||
stream->seek = seek;
|
stream->seek = seek;
|
||||||
if (dummy || ctx->is_streamed) {
|
if (dummy || !avio->seekable) {
|
||||||
stream->type = STREAMTYPE_STREAM;
|
stream->type = STREAMTYPE_STREAM;
|
||||||
stream->seek = NULL;
|
stream->seek = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user