gstreamer中当指定中文位置(URI地址)时,需指定UTF8编码,以filesrc为例,在src_set_location中有说明
/* we store the filename as received by the application. On Windoes this
* should be UTF8 */
src->filename = g_strdup (location);
src->uri = gst_uri_construct ("file", src->filename);
在用gst_open打开文件时,有如下代码:
static int
gst_open (const gchar * filename, int flags, int mode)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); //如为WINDOWS平台,从UTF8转为UTF16,因为windows平台内部编码为utf16,Linux平台默认编码为UTF8,不用转换。
int retval;
int save_errno;
if (wfilename == NULL) {
errno = EINVAL;
return -1;
}
static gboolean
gst_file_src_set_location (GstFileSrc * src, const gchar * location)
{
GstState state;
/* the element must be stopped in order to do this */
GST_OBJECT_LOCK (src);
state = GST_STATE (src);
if (state != GST_STATE_READY && state != GST_STATE_NULL)
goto wrong_state;
GST_OBJECT_UNLOCK (src);
g_free (src->filename);
g_free (src->uri);
/* clear the filename if we get a NULL (is that possible?) */
if (location == NULL) {
src->filename = NULL;
src->uri = NULL;
} else {
/* we store the filename as received by the application. On Windoes this
* should be UTF8 */
src->filename = g_strdup (location);
src->uri = gst_uri_construct ("file", src->filename);
}
g_object_notify (G_OBJECT (src), "location");
gst_uri_handler_new_uri (GST_URI_HANDLER (src), src->uri);
return TRUE;
/* ERROR */
wrong_state:
{
g_warning ("Changing the `location' property on filesrc when a file is "
"open is not supported.");
GST_OBJECT_UNLOCK (src);
return FALSE;
}
}
static int
gst_open (const gchar * filename, int flags, int mode)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL) {
errno = EINVAL;
return -1;
}
retval = _wopen (wfilename, flags, mode);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return open (filename, flags, mode);
#endif
}