demux: do not set global sub_utf8
[mplayer.git] / stream / open.c
blob91e9ae295621287483cd7034d45aac898092a3cd
1 /*
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.
19 #include <ctype.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <string.h>
27 #include "config.h"
28 #include "mp_msg.h"
29 #include "talloc.h"
31 #ifdef __FreeBSD__
32 #include <sys/cdrio.h>
33 #endif
35 #include "m_option.h"
36 #include "options.h"
37 #include "stream.h"
38 #include "libmpdemux/demuxer.h"
41 /// We keep these 2 for the gui atm, but they will be removed.
42 int vcd_track=0;
43 char* cdrom_device=NULL;
44 char* dvd_device=NULL;
45 int dvd_title=0;
47 #ifdef CONFIG_LIBQUVI
49 #include <quvi/quvi.h>
51 static const char *resolve_quvi(const char *url, struct MPOpts *opts)
53 char *media_title, *media_url;
54 quvi_media_t m;
55 QUVIcode rc;
56 quvi_t q;
58 rc = quvi_init(&q);
59 if (rc != QUVI_OK)
60 return NULL;
62 // Don't try to use quvi on an URL that's not directly supported, since
63 // quvi will do a network access anyway in order to check for HTTP
64 // redirections etc.
65 // The documentation says this will fail on "shortened" URLs.
66 if (quvi_supported(q, (char *)url) != QUVI_OK) {
67 quvi_close(&q);
68 return NULL;
71 mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n");
73 // Can use quvi_query_formats() to get a list of formats like this:
74 // "fmt05_240p|fmt18_360p|fmt34_360p|fmt35_480p|fmt43_360p|fmt44_480p"
75 // (This example is youtube specific.)
76 // That call requires an extra net access. quvi_next_media_url() doesn't
77 // seem to do anything useful. So we can't really do anything useful
78 // except pass through the user's format setting.
79 quvi_setopt(q, QUVIOPT_FORMAT, opts->quvi_format
80 ? opts->quvi_format : "best");
82 rc = quvi_parse(q, (char *)url, &m);
83 if (rc != QUVI_OK) {
84 mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_strerror(q, rc));
85 quvi_close(&q);
86 return NULL;
89 quvi_getprop(m, QUVIPROP_PAGETITLE, &media_title);
90 quvi_getprop(m, QUVIPROP_MEDIAURL, &media_url);
92 mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Site media title: '%s'\n",
93 media_title);
94 media_url = talloc_strdup(NULL, media_url);
96 quvi_parse_close(&m);
97 quvi_close(&q);
99 return media_url;
101 #endif
103 // Open a new stream (stdin/file/vcd/url)
105 stream_t* open_stream(const char *filename, struct MPOpts *options,
106 int *file_format)
108 if (!file_format)
109 file_format = &(int){DEMUXER_TYPE_UNKNOWN};
110 // Check if playlist or unknown
111 if (*file_format != DEMUXER_TYPE_PLAYLIST){
112 *file_format=DEMUXER_TYPE_UNKNOWN;
115 if(!filename) {
116 mp_msg(MSGT_OPEN,MSGL_ERR,"NULL filename, report this bug\n");
117 return NULL;
120 const char *resolved = NULL;
122 #ifdef CONFIG_LIBQUVI
123 resolved = resolve_quvi(filename, options);
124 #endif
126 if (resolved)
127 filename = resolved;
129 stream_t *res = open_stream_full(filename,STREAM_READ,options,file_format);
130 talloc_free((void *)resolved);
131 return res;