Skip to content
This repository
Browse code

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.
  • Loading branch information...
commit 30afc64532ff61577f6fa9d427f6803a00f2ad37 1 parent 1bd5871
authored December 25, 2011

Showing 1 changed file with 31 additions and 19 deletions. Show diff stats Hide diff stats

  1. 50  stream/stream_ffmpeg.c
50  stream/stream_ffmpeg.c
@@ -28,21 +28,26 @@
28 28
 
29 29
 static int fill_buffer(stream_t *s, char *buffer, int max_len)
30 30
 {
31  
-    int r = url_read_complete(s->priv, buffer, max_len);
  31
+    AVIOContext *avio = s->priv;
  32
+    int r = avio_read(avio, buffer, max_len);
32 33
     return (r <= 0) ? -1 : r;
33 34
 }
34 35
 
35 36
 static int write_buffer(stream_t *s, char *buffer, int len)
36 37
 {
37  
-    /* url_write retries internally on short writes and EAGAIN */
38  
-    int r = url_write(s->priv, buffer, len);
39  
-    return (r <= 0) ? -1 : r;
  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;
40 44
 }
41 45
 
42 46
 static int seek(stream_t *s, off_t newpos)
43 47
 {
  48
+    AVIOContext *avio = s->priv;
44 49
     s->pos = newpos;
45  
-    if (url_seek(s->priv, s->pos, SEEK_SET) < 0) {
  50
+    if (avio_seek(avio, s->pos, SEEK_SET) < 0) {
46 51
         s->eof = 1;
47 52
         return 0;
48 53
     }
@@ -51,11 +56,12 @@ static int seek(stream_t *s, off_t newpos)
51 56
 
52 57
 static int control(stream_t *s, int cmd, void *arg)
53 58
 {
  59
+    AVIOContext *avio = avio;
54 60
     int64_t size, ts;
55 61
     double pts;
56 62
     switch(cmd) {
57 63
     case STREAM_CTRL_GET_SIZE:
58  
-        size = url_filesize(s->priv);
  64
+        size = avio_size(avio);
59 65
         if(size >= 0) {
60 66
             *(off_t *)arg = size;
61 67
             return 1;
@@ -64,7 +70,7 @@ static int control(stream_t *s, int cmd, void *arg)
64 70
     case STREAM_CTRL_SEEK_TO_TIME:
65 71
         pts = *(double *)arg;
66 72
         ts = pts * AV_TIME_BASE;
67  
-        ts = av_url_read_seek(s->priv, -1, ts, 0);
  73
+        ts = avio_seek_time(avio, -1, ts, 0);
68 74
         if (ts >= 0)
69 75
             return 1;
70 76
         break;
@@ -74,7 +80,13 @@ static int control(stream_t *s, int cmd, void *arg)
74 80
 
75 81
 static void close_f(stream_t *stream)
76 82
 {
77  
-    url_close(stream->priv);
  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.
  88
+     */
  89
+    avio_close(avio);
78 90
 }
79 91
 
80 92
 static const char prefix[] = "ffmpeg://";
@@ -83,7 +95,7 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
83 95
 {
84 96
     int flags = 0;
85 97
     const char *filename;
86  
-    URLContext *ctx = NULL;
  98
+    AVIOContext *avio = NULL;
87 99
     int res = STREAM_ERROR;
88 100
     int64_t size;
89 101
     int dummy;
@@ -109,22 +121,22 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
109 121
     dummy = !strncmp(filename, "rtsp:", 5);
110 122
     mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] Opening %s\n", filename);
111 123
 
112  
-    if (!dummy && url_open(&ctx, filename, flags) < 0)
  124
+    if (!dummy && avio_open(&avio, filename, flags) < 0)
113 125
         goto out;
114 126
 
115  
-    mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] libavformat URL type: %s\n",
116  
-           ctx->prot->name);
117  
-    if (!strncmp("rtmp", ctx->prot->name, 4)) {
118  
-        *file_format = DEMUXER_TYPE_LAVF;
119  
-        stream->lavf_type = "flv";
120  
-    }
121  
-    stream->priv = ctx;
122  
-    size = dummy ? 0 : url_filesize(ctx);
  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";
  132
+        }
  133
+    stream->priv = avio;
  134
+    size = dummy ? 0 : avio_size(avio);
123 135
     if (size >= 0)
124 136
         stream->end_pos = size;
125 137
     stream->type = STREAMTYPE_FILE;
126 138
     stream->seek = seek;
127  
-    if (dummy || ctx->is_streamed) {
  139
+    if (dummy || !avio->seekable) {
128 140
         stream->type = STREAMTYPE_STREAM;
129 141
         stream->seek = NULL;
130 142
     }

0 notes on commit 30afc64

Please sign in to comment.
Something went wrong with that request. Please try again.