gstreamer 指定有中文的 URI地址,需使用UTF8编码
2011-08-25 17:36
302 查看
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
}
/* 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
}
相关文章推荐
- vim,gvim使用指定编码打开文件,gvim中文乱码
- Qt: 界面中使用中文(三种方法,QApplication::translate可指定编码)
- 使用c++分割utf8编码的中文
- 使用tomcat的时候,网页地址出现中文,出现不认识编码导致查询无法完成解决方案
- 中文乱码 ajax使用encodeURIComponent()或encodeURI()编码 location.herf编码两次
- mysql导入导出数据中文乱码解决方法小结(1、navicat导入问题已解决,创建连接后修改连接属性,选择高级->将使用Mysql字符集复选框去掉,下拉框选择GBK->导入sql文件OK;2、phpmyadmin显示乱码的问题也解决,两步:1.将sql文件以utf8的字符集编码另存,2.将文件中sql语句中的字段字符集编码改成utf8,导入OK)
- [乐意黎原创] Mysql使用UTF8编码时让某字段使用中文排序(UTF8按字段拼音首字母排序)
- 编译utf8编码的tex文件使用中文truetype
- vim,gvim使用指定编码打开文件,gvim中文乱码
- tnsnames.ora的连接名称使用中文名称,报错“无法解析指定的连接标识符”
- 英文版SQL Server 2008使用时,字段中存在中文的要注意编码问题
- 使用java.net.URLEncoder.encode()可以对要传递的中文进行编码
- 使用python提取中文地址描述中的省市区信息
- //对中文键盘输入英文 (去除中文系统自带的UTF8编码)
- 29. 在Linux上使用unzip解压以默认编码解压,中文文件名会出现乱码
- 黄聪:VS2010启动程序提示文件加载 使用 简体中文(GB2312)编码加载文件解决办法
- [转载 php]php截取utf8编码的中文函数
- php使用 MsSql server时遇到的中文编码问题
- Linux下MySQL 5.5的修改字符集编码为UTF8(彻底解决中文乱码问题)
- easy_install 和pip安装软件时使用指定的 源地址