原始文件路径保留字符时崩溃

时间:2013-07-28 06:38:03

标签: c gstreamer

我写了一个应用程序来录制电视台与Gstreamer:

管道创建filesink with:

    #include <gio/gio.h>


    Encoder* recording_start (const char* filename)
    {

    ------------------------------------------------------------
        GstElement *filesink;
        gchar *path;

        filesink = gst_element_factory_make ("filesink", NULL);
        g_return_val_if_fail (filesink != NULL, NULL);

        path = g_strdup_printf("%s.mov", filename);

        g_object_set(G_OBJECT(filesink), "location", path, NULL);

        gst_bin_add_many (GST_BIN (pipeline), source, encodebin, filesink, NULL);

        if (!gst_element_link_many (source, encodebin, filesink, NULL)) {
            gst_object_unref (pipeline);
            g_return_val_if_reached (NULL);
        }

        gst_element_set_state (pipeline, GST_STATE_PLAYING);

        Encoder *encoder = g_malloc0(sizeof(Encoder));

        Encoder->filename = path;

        return encoder;
    }

录制台的文件名由:

生成
    /*  args for this format are:
     *  path
     *  station title
     *  time
     */

    char *filename = g_strdup_printf (_("%s/%s_%s.mov"), destination, station, time);

我使用GFile查询有关录制文件的信息(指向重新编辑文件的指针):

    file = g_file_new_for_path (encoder->filename);

用户可以从组合框中选择要记录的电台,例如:

            --------------
            | STATION 1  |
            --------------
            | STATION 2  |
            --------------
            | STATION 3  |
            --------------

当电台名称包含以下字符组合时:“&lt; /”例如:

            -----------------------
            | Canal Algérie </ 10  |
            -----------------------

应用程序获取错误:

    ERROR: from element /GstFileSink:filesink3: Could not open file "/home/ubuntu/</_20130728-044308.mov" for writing.
    Additional debug info:
    gstfilesink.c(420): gst_file_sink_open_file (): /GstPipeline:pipeline/GstFileSink:filesink3:
    system error: No such file or directory

然后崩溃

为什么当原始文件路径有保留字符或不存在时应用程序崩溃(GIO返回有效路径)?

如果我删除“&lt;”从车站名称:“运河阿尔及利/ 10”,一切都很好,应用程序不会崩溃。

由于

1 个答案:

答案 0 :(得分:0)

您的程序没有崩溃,它正确退出,并显示明确的错误消息,说明确切的问题。

您正在将电台名称复制到将用作文件名的字符串中。如您所见,工作站名称可能包含对文件名无效的字符。从文件名中删除这些字符,或用有效字符替换它们,以解决问题。

我不确定为什么GIO都没能找到坏道路。有几种可能性:它可能是库中的一个诚实错误,或者它可能只检查路径是否有效 - 即,它的所有组件都是 - 没有深入检查是否路径及其子路径实际上存在。 (虽然字符<本身肯定会引发错误。)