Browse code

avdevice: migrate to AVFormatContext->url

Signed-off-by: Marton Balint <cus@passwd.hu>

Marton Balint authored on 2017/12/30 07:29:52
Showing 31 changed files
... ...
@@ -177,8 +177,8 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
177 177
     snd_pcm_uframes_t buffer_size, period_size;
178 178
     uint64_t layout = ctx->streams[0]->codecpar->channel_layout;
179 179
 
180
-    if (ctx->filename[0] == 0) audio_device = "default";
181
-    else                       audio_device = ctx->filename;
180
+    if (ctx->url[0] == 0) audio_device = "default";
181
+    else                  audio_device = ctx->url;
182 182
 
183 183
     if (*codec_id == AV_CODEC_ID_NONE)
184 184
         *codec_id = DEFAULT_CODEC_ID;
... ...
@@ -259,7 +259,7 @@ static void destroy_context(AVFContext* ctx)
259 259
 static void parse_device_name(AVFormatContext *s)
260 260
 {
261 261
     AVFContext *ctx = (AVFContext*)s->priv_data;
262
-    char *tmp = av_strdup(s->filename);
262
+    char *tmp = av_strdup(s->url);
263 263
     char *save;
264 264
 
265 265
     if (tmp[0] != ':') {
... ...
@@ -294,7 +294,7 @@ static int grab_read_header(AVFormatContext *s1)
294 294
     st->codecpar->height = s->height;
295 295
     st->avg_frame_rate = framerate;
296 296
 
297
-    if (bktr_init(s1->filename, s->width, s->height, s->standard,
297
+    if (bktr_init(s1->url, s->width, s->height, s->standard,
298 298
                   &s->video_fd, &s->tuner_fd, -1, 0.0) < 0) {
299 299
         ret = AVERROR(EIO);
300 300
         goto out;
... ...
@@ -178,7 +178,7 @@ static int caca_write_header(AVFormatContext *s)
178 178
     }
179 179
 
180 180
     if (!c->window_title)
181
-        c->window_title = av_strdup(s->filename);
181
+        c->window_title = av_strdup(s->url);
182 182
     caca_set_display_title(c->display, c->window_title);
183 183
     caca_set_display_time(c->display, av_rescale_q(1, st->codec->time_base, AV_TIME_BASE_Q));
184 184
 
... ...
@@ -404,7 +404,7 @@ int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direct
404 404
     }
405 405
 
406 406
     av_log(avctx, AV_LOG_INFO, "Supported formats for '%s':\n\tformat_code\tdescription",
407
-               avctx->filename);
407
+               avctx->url);
408 408
     while (itermode->Next(&mode) == S_OK) {
409 409
         BMDTimeValue tb_num, tb_den;
410 410
         mode->GetFrameRate(&tb_num, &tb_den);
... ...
@@ -951,7 +951,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
951 951
         cctx->raw_format = MKBETAG('v','2','1','0');
952 952
     }
953 953
 
954
-    strcpy (fname, avctx->filename);
954
+    av_strlcpy(fname, avctx->url, sizeof(fname));
955 955
     tmp=strchr (fname, '@');
956 956
     if (tmp != NULL) {
957 957
         av_log(avctx, AV_LOG_WARNING, "The @mode syntax is deprecated and will be removed. Please use the -format_code option.\n");
... ...
@@ -966,7 +966,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
966 966
     /* Get input device. */
967 967
     if (ctx->dl->QueryInterface(IID_IDeckLinkInput, (void **) &ctx->dli) != S_OK) {
968 968
         av_log(avctx, AV_LOG_ERROR, "Could not open input device from '%s'\n",
969
-               avctx->filename);
969
+               avctx->url);
970 970
         ret = AVERROR(EIO);
971 971
         goto error;
972 972
     }
... ...
@@ -400,14 +400,14 @@ av_cold int ff_decklink_write_header(AVFormatContext *avctx)
400 400
         return AVERROR_EXIT;
401 401
     }
402 402
 
403
-    ret = ff_decklink_init_device(avctx, avctx->filename);
403
+    ret = ff_decklink_init_device(avctx, avctx->url);
404 404
     if (ret < 0)
405 405
         return ret;
406 406
 
407 407
     /* Get output device. */
408 408
     if (ctx->dl->QueryInterface(IID_IDeckLinkOutput, (void **) &ctx->dlo) != S_OK) {
409 409
         av_log(avctx, AV_LOG_ERROR, "Could not open output device from '%s'\n",
410
-               avctx->filename);
410
+               avctx->url);
411 411
         ret = AVERROR(EIO);
412 412
         goto error;
413 413
     }
... ...
@@ -1033,7 +1033,7 @@ static int parse_device_name(AVFormatContext *avctx)
1033 1033
 {
1034 1034
     struct dshow_ctx *ctx = avctx->priv_data;
1035 1035
     char **device_name = ctx->device_name;
1036
-    char *name = av_strdup(avctx->filename);
1036
+    char *name = av_strdup(avctx->url);
1037 1037
     char *tmp = name;
1038 1038
     int ret = 1;
1039 1039
     char *type;
... ...
@@ -78,8 +78,8 @@ static av_cold int fbdev_read_header(AVFormatContext *avctx)
78 78
     if (avctx->flags & AVFMT_FLAG_NONBLOCK)
79 79
         flags |= O_NONBLOCK;
80 80
 
81
-    if (avctx->filename[0])
82
-        device = avctx->filename;
81
+    if (avctx->url[0])
82
+        device = avctx->url;
83 83
     else
84 84
         device = ff_fbdev_default_device();
85 85
 
... ...
@@ -53,8 +53,8 @@ static av_cold int fbdev_write_header(AVFormatContext *h)
53 53
         return AVERROR(EINVAL);
54 54
     }
55 55
 
56
-    if (h->filename[0])
57
-        device = h->filename;
56
+    if (h->url[0])
57
+        device = h->url;
58 58
     else
59 59
         device = ff_fbdev_default_device();
60 60
 
... ...
@@ -230,7 +230,7 @@ gdigrab_read_header(AVFormatContext *s1)
230 230
     HBITMAP hbmp   = NULL;
231 231
     void *buffer   = NULL;
232 232
 
233
-    const char *filename = s1->filename;
233
+    const char *filename = s1->url;
234 234
     const char *name     = NULL;
235 235
     AVStream   *st       = NULL;
236 236
 
... ...
@@ -259,14 +259,14 @@ static int iec61883_read_header(AVFormatContext *context)
259 259
         goto fail;
260 260
     }
261 261
 
262
-    inport = strtol(context->filename, &endptr, 10);
263
-    if (endptr != context->filename && *endptr == '\0') {
262
+    inport = strtol(context->url, &endptr, 10);
263
+    if (endptr != context->url && *endptr == '\0') {
264 264
         av_log(context, AV_LOG_INFO, "Selecting IEEE1394 port: %d\n", inport);
265 265
         j = inport;
266 266
         nb_ports = inport + 1;
267
-    } else if (strcmp(context->filename, "auto")) {
267
+    } else if (strcmp(context->url, "auto")) {
268 268
         av_log(context, AV_LOG_ERROR, "Invalid input \"%s\", you should specify "
269
-               "\"auto\" for auto-detection, or the port number.\n", context->filename);
269
+               "\"auto\" for auto-detection, or the port number.\n", context->url);
270 270
         goto fail;
271 271
     }
272 272
 
... ...
@@ -150,8 +150,8 @@ static int start_jack(AVFormatContext *context)
150 150
     jack_status_t status;
151 151
     int i, test;
152 152
 
153
-    /* Register as a JACK client, using the context filename as client name. */
154
-    self->client = jack_client_open(context->filename, JackNullOption, &status);
153
+    /* Register as a JACK client, using the context url as client name. */
154
+    self->client = jack_client_open(context->url, JackNullOption, &status);
155 155
     if (!self->client) {
156 156
         av_log(context, AV_LOG_ERROR, "Unable to register as a JACK client\n");
157 157
         return AVERROR(EIO);
... ...
@@ -174,7 +174,7 @@ static int start_jack(AVFormatContext *context)
174 174
                                             JackPortIsInput, 0);
175 175
         if (!self->ports[i]) {
176 176
             av_log(context, AV_LOG_ERROR, "Unable to register port %s:%s\n",
177
-                   context->filename, str);
177
+                   context->url, str);
178 178
             jack_client_close(self->client);
179 179
             return AVERROR(EIO);
180 180
         }
... ...
@@ -166,7 +166,7 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
166 166
     }
167 167
 
168 168
     if (!lavfi->graph_str)
169
-        lavfi->graph_str = av_strdup(avctx->filename);
169
+        lavfi->graph_str = av_strdup(avctx->url);
170 170
 
171 171
     /* parse the graph, create a stream for each open output */
172 172
     if (!(lavfi->graph = avfilter_graph_alloc()))
... ...
@@ -60,9 +60,9 @@ static av_cold int read_header(AVFormatContext *ctx)
60 60
 
61 61
     if (!(st = avformat_new_stream(ctx, NULL)))
62 62
         return AVERROR(ENOMEM);
63
-    s->drive = cdio_cddap_identify(ctx->filename, CDDA_MESSAGE_LOGIT, &err);
63
+    s->drive = cdio_cddap_identify(ctx->url, CDDA_MESSAGE_LOGIT, &err);
64 64
     if (!s->drive) {
65
-        av_log(ctx, AV_LOG_ERROR, "Could not open drive %s.\n", ctx->filename);
65
+        av_log(ctx, AV_LOG_ERROR, "Could not open drive %s.\n", ctx->url);
66 66
         return AVERROR(EINVAL);
67 67
     }
68 68
     if (err) {
... ...
@@ -70,7 +70,7 @@ static av_cold int read_header(AVFormatContext *ctx)
70 70
         free(err);
71 71
     }
72 72
     if ((ret = cdio_cddap_open(s->drive)) < 0 || !s->drive->opened) {
73
-        av_log(ctx, AV_LOG_ERROR, "Could not open disk in drive %s.\n", ctx->filename);
73
+        av_log(ctx, AV_LOG_ERROR, "Could not open disk in drive %s.\n", ctx->url);
74 74
         return AVERROR(EINVAL);
75 75
     }
76 76
 
... ...
@@ -149,7 +149,7 @@ static int ndi_read_header(AVFormatContext *avctx)
149 149
     }
150 150
 
151 151
     /* Find available sources. */
152
-    ret = ndi_find_sources(avctx, avctx->filename, &recv_create_desc.source_to_connect_to);
152
+    ret = ndi_find_sources(avctx, avctx->url, &recv_create_desc.source_to_connect_to);
153 153
     if (ctx->find_sources) {
154 154
         return AVERROR_EXIT;
155 155
     }
... ...
@@ -233,7 +233,7 @@ static int ndi_write_header(AVFormatContext *avctx)
233 233
     int ret = 0;
234 234
     unsigned int n;
235 235
     struct NDIContext *ctx = avctx->priv_data;
236
-    const NDIlib_send_create_t ndi_send_desc = { .p_ndi_name = avctx->filename,
236
+    const NDIlib_send_create_t ndi_send_desc = { .p_ndi_name = avctx->url,
237 237
         .p_groups = NULL, .clock_video = ctx->clock_video, .clock_audio = ctx->clock_audio };
238 238
 
239 239
     if (!NDIlib_initialize()) {
... ...
@@ -260,7 +260,7 @@ static int ndi_write_header(AVFormatContext *avctx)
260 260
 
261 261
     ctx->ndi_send = NDIlib_send_create(&ndi_send_desc);
262 262
     if (!ctx->ndi_send) {
263
-        av_log(avctx, AV_LOG_ERROR, "Failed to create NDI output %s\n", avctx->filename);
263
+        av_log(avctx, AV_LOG_ERROR, "Failed to create NDI output %s\n", avctx->url);
264 264
         ret = AVERROR_EXTERNAL;
265 265
     }
266 266
 
... ...
@@ -139,7 +139,7 @@ static int read_header(AVFormatContext *ctx)
139 139
 
140 140
     /* Open device for capture */
141 141
     ad->device =
142
-        alcCaptureOpenDevice(ctx->filename[0] ? ctx->filename : NULL,
142
+        alcCaptureOpenDevice(ctx->url[0] ? ctx->url : NULL,
143 143
                              ad->sample_rate,
144 144
                              ad->sample_format,
145 145
                              ad->sample_rate); /* Maximum 1 second of sample data to be read at once */
... ...
@@ -1070,7 +1070,7 @@ static av_cold int opengl_write_header(AVFormatContext *h)
1070 1070
         opengl->window_height = opengl->height;
1071 1071
 
1072 1072
     if (!opengl->window_title && !opengl->no_window)
1073
-        opengl->window_title = av_strdup(h->filename);
1073
+        opengl->window_title = av_strdup(h->url);
1074 1074
 
1075 1075
     if ((ret = opengl_create_window(h)))
1076 1076
         goto fail;
... ...
@@ -52,7 +52,7 @@ static int audio_read_header(AVFormatContext *s1)
52 52
         return AVERROR(ENOMEM);
53 53
     }
54 54
 
55
-    ret = ff_oss_audio_open(s1, 0, s1->filename);
55
+    ret = ff_oss_audio_open(s1, 0, s1->url);
56 56
     if (ret < 0) {
57 57
         return AVERROR(EIO);
58 58
     }
... ...
@@ -46,7 +46,7 @@ static int audio_write_header(AVFormatContext *s1)
46 46
     st = s1->streams[0];
47 47
     s->sample_rate = st->codecpar->sample_rate;
48 48
     s->channels = st->codecpar->channels;
49
-    ret = ff_oss_audio_open(s1, 1, s1->filename);
49
+    ret = ff_oss_audio_open(s1, 1, s1->url);
50 50
     if (ret < 0) {
51 51
         return AVERROR(EIO);
52 52
     } else {
... ...
@@ -158,8 +158,8 @@ static av_cold int pulse_read_header(AVFormatContext *s)
158 158
 
159 159
     attr.fragsize = pd->fragment_size;
160 160
 
161
-    if (s->filename[0] != '\0' && strcmp(s->filename, "default"))
162
-        device = s->filename;
161
+    if (s->url[0] != '\0' && strcmp(s->url, "default"))
162
+        device = s->url;
163 163
 
164 164
     if (!(pd->mainloop = pa_threaded_mainloop_new())) {
165 165
         pulse_close(s);
... ...
@@ -459,8 +459,8 @@ static av_cold int pulse_write_header(AVFormatContext *h)
459 459
     st = h->streams[0];
460 460
 
461 461
     if (!stream_name) {
462
-        if (h->filename[0])
463
-            stream_name = h->filename;
462
+        if (h->url[0])
463
+            stream_name = h->url;
464 464
         else
465 465
             stream_name = "Playback";
466 466
     }
... ...
@@ -165,7 +165,7 @@ static int sdl2_write_header(AVFormatContext *s)
165 165
     int flags  = 0;
166 166
 
167 167
     if (!sdl->window_title)
168
-        sdl->window_title = av_strdup(s->filename);
168
+        sdl->window_title = av_strdup(s->url);
169 169
 
170 170
     if (SDL_WasInit(SDL_INIT_VIDEO)) {
171 171
         av_log(s, AV_LOG_WARNING,
... ...
@@ -41,7 +41,7 @@ static av_cold int audio_read_header(AVFormatContext *s1)
41 41
     if (!st)
42 42
         return AVERROR(ENOMEM);
43 43
 
44
-    ret = ff_sndio_open(s1, 0, s1->filename);
44
+    ret = ff_sndio_open(s1, 0, s1->url);
45 45
     if (ret < 0)
46 46
         return ret;
47 47
 
... ...
@@ -38,7 +38,7 @@ static av_cold int audio_write_header(AVFormatContext *s1)
38 38
     s->sample_rate = st->codecpar->sample_rate;
39 39
     s->channels    = st->codecpar->channels;
40 40
 
41
-    ret = ff_sndio_open(s1, 1, s1->filename);
41
+    ret = ff_sndio_open(s1, 1, s1->url);
42 42
 
43 43
     return ret;
44 44
 }
... ...
@@ -106,7 +106,7 @@ struct buff_data {
106 106
     int index;
107 107
 };
108 108
 
109
-static int device_open(AVFormatContext *ctx)
109
+static int device_open(AVFormatContext *ctx, const char* device_path)
110 110
 {
111 111
     struct video_data *s = ctx->priv_data;
112 112
     struct v4l2_capability cap;
... ...
@@ -147,11 +147,11 @@ static int device_open(AVFormatContext *ctx)
147 147
         flags |= O_NONBLOCK;
148 148
     }
149 149
 
150
-    fd = v4l2_open(ctx->filename, flags, 0);
150
+    fd = v4l2_open(device_path, flags, 0);
151 151
     if (fd < 0) {
152 152
         err = AVERROR(errno);
153 153
         av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s: %s\n",
154
-               ctx->filename, av_err2str(err));
154
+               device_path, av_err2str(err));
155 155
         return err;
156 156
     }
157 157
 
... ...
@@ -840,7 +840,7 @@ static int v4l2_read_header(AVFormatContext *ctx)
840 840
         v4l2_log_file = fopen("/dev/null", "w");
841 841
 #endif
842 842
 
843
-    s->fd = device_open(ctx);
843
+    s->fd = device_open(ctx, ctx->url);
844 844
     if (s->fd < 0)
845 845
         return s->fd;
846 846
 
... ...
@@ -1042,11 +1042,13 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
1042 1042
         return ret;
1043 1043
     }
1044 1044
     while ((entry = readdir(dir))) {
1045
+        char device_name[256];
1046
+
1045 1047
         if (!v4l2_is_v4l_dev(entry->d_name))
1046 1048
             continue;
1047 1049
 
1048
-        snprintf(ctx->filename, sizeof(ctx->filename), "/dev/%s", entry->d_name);
1049
-        if ((s->fd = device_open(ctx)) < 0)
1050
+        snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name);
1051
+        if ((s->fd = device_open(ctx, device_name)) < 0)
1050 1052
             continue;
1051 1053
 
1052 1054
         if (v4l2_ioctl(s->fd, VIDIOC_QUERYCAP, &cap) < 0) {
... ...
@@ -1060,7 +1062,7 @@ static int v4l2_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_l
1060 1060
             ret = AVERROR(ENOMEM);
1061 1061
             goto fail;
1062 1062
         }
1063
-        device->device_name = av_strdup(ctx->filename);
1063
+        device->device_name = av_strdup(device_name);
1064 1064
         device->device_description = av_strdup(cap.card);
1065 1065
         if (!device->device_name || !device->device_description) {
1066 1066
             ret = AVERROR(ENOMEM);
... ...
@@ -39,10 +39,10 @@ static av_cold int write_header(AVFormatContext *s1)
39 39
     if (s1->flags & AVFMT_FLAG_NONBLOCK)
40 40
         flags |= O_NONBLOCK;
41 41
 
42
-    s->fd = open(s1->filename, flags);
42
+    s->fd = open(s1->url, flags);
43 43
     if (s->fd < 0) {
44 44
         res = AVERROR(errno);
45
-        av_log(s1, AV_LOG_ERROR, "Unable to open V4L2 device '%s'\n", s1->filename);
45
+        av_log(s1, AV_LOG_ERROR, "Unable to open V4L2 device '%s'\n", s1->url);
46 46
         return res;
47 47
     }
48 48
 
... ...
@@ -256,7 +256,7 @@ static int vfw_read_header(AVFormatContext *s)
256 256
     int ret;
257 257
     AVRational framerate_q;
258 258
 
259
-    if (!strcmp(s->filename, "list")) {
259
+    if (!strcmp(s->url, "list")) {
260 260
         for (devnum = 0; devnum <= 9; devnum++) {
261 261
             char driver_name[256];
262 262
             char driver_ver[256];
... ...
@@ -279,7 +279,7 @@ static int vfw_read_header(AVFormatContext *s)
279 279
     }
280 280
 
281 281
     /* If atoi fails, devnum==0 and the default device is used */
282
-    devnum = atoi(s->filename);
282
+    devnum = atoi(s->url);
283 283
 
284 284
     ret = SendMessage(ctx->hwnd, WM_CAP_DRIVER_CONNECT, devnum, 0);
285 285
     if(!ret) {
... ...
@@ -629,14 +629,14 @@ static av_cold int xcbgrab_read_header(AVFormatContext *s)
629 629
     XCBGrabContext *c = s->priv_data;
630 630
     int screen_num, ret;
631 631
     const xcb_setup_t *setup;
632
-    char *display_name = av_strdup(s->filename);
632
+    char *display_name = av_strdup(s->url);
633 633
 
634 634
     if (!display_name)
635 635
         return AVERROR(ENOMEM);
636 636
 
637
-    if (!sscanf(s->filename, "%[^+]+%d,%d", display_name, &c->x, &c->y)) {
637
+    if (!sscanf(s->url, "%[^+]+%d,%d", display_name, &c->x, &c->y)) {
638 638
         *display_name = 0;
639
-        sscanf(s->filename, "+%d,%d", &c->x, &c->y);
639
+        sscanf(s->url, "+%d,%d", &c->x, &c->y);
640 640
     }
641 641
 
642 642
     c->conn = xcb_connect(display_name[0] ? display_name : NULL, &screen_num);
... ...
@@ -644,7 +644,7 @@ static av_cold int xcbgrab_read_header(AVFormatContext *s)
644 644
 
645 645
     if ((ret = xcb_connection_has_error(c->conn))) {
646 646
         av_log(s, AV_LOG_ERROR, "Cannot open display %s, error %d.\n",
647
-               s->filename[0] ? s->filename : "default", ret);
647
+               s->url[0] ? s->url : "default", ret);
648 648
         return AVERROR(EIO);
649 649
     }
650 650
 
... ...
@@ -151,7 +151,7 @@ static int xv_write_header(AVFormatContext *s)
151 151
                                          xv->window_width, xv->window_height,
152 152
                                          0, 0, 0);
153 153
         if (!xv->window_title) {
154
-            if (!(xv->window_title = av_strdup(s->filename))) {
154
+            if (!(xv->window_title = av_strdup(s->url))) {
155 155
                 ret = AVERROR(ENOMEM);
156 156
                 goto fail;
157 157
             }