/** * ly_gla_uri_get_dir: * @uri: the uri * * Get the directory of a uri string. * * Returns: the dir */ char* ly_gla_uri_get_dir (char *uri) { if(!uri) return NULL; gchar *basename=ly_gla_uri_get_path(uri); gchar *dir=NULL; gint i=strlen(basename); gchar *p=basename+strlen(basename); while(*p!='/' && p!=basename) { p--; i--; } if(i==0 && *p!='/') dir=NULL; else dir=g_strndup(basename, i+1); g_free(basename); return dir; }
/** * ly_gla_fina: * * Create a new allocate LyMdhMetadata type structure based on a uri. It fills * all fields in metadata struct. * * Returns: a newly allocated metadata struct. */ LyMdhMetadata* ly_mdh_new_with_uri_full (char *uri) { /* * test file */ char *prefix=ly_gla_uri_get_prefix(uri); char *path=ly_gla_uri_get_path(uri); if(!g_str_equal(prefix, "file://")) { g_free(prefix); ly_log_put_with_flag(G_LOG_LEVEL_DEBUG, _("Cannot open file: %s. unsupported protocol!"), uri); return NULL; } g_free(prefix); if(!g_file_test(path, G_FILE_TEST_EXISTS)) { g_free(path); ly_log_put_with_flag(G_LOG_LEVEL_DEBUG, _("Cannot open file: %s. file not found!"), uri); return NULL; } g_free(path); ly_mdh_pipeline=NULL; ly_mdh_md_eos=FALSE; /* * create and initial metadata */ LyMdhMetadata *metadata=ly_mdh_new(); g_strlcpy(metadata->uri, uri, sizeof(metadata->uri)); /* * build the pipeline */ GstFormat fmt=GST_FORMAT_TIME; GstElement *urisrc; GstElement *decodebin; GstElement *fakesink; GstBus *bus=NULL; gint changeTimeout = 0; GstStateChangeReturn rt; GstMessage *msg; ly_mdh_pipeline=gst_pipeline_new("pipeline"); urisrc=gst_element_make_from_uri(GST_URI_SRC,metadata->uri,"urisrc"); decodebin=gst_element_factory_make("decodebin","decodebin"); fakesink=gst_element_factory_make("fakesink","fakesink"); gst_bin_add_many(GST_BIN(ly_mdh_pipeline),urisrc,decodebin,fakesink,NULL); gst_element_link(urisrc,decodebin); g_signal_connect_object(G_OBJECT(decodebin),"new-decoded-pad",G_CALLBACK(ly_mdh_new_with_uri_pipe_cb),fakesink,0); bus = gst_pipeline_get_bus(GST_PIPELINE(ly_mdh_pipeline)); gst_element_set_state(ly_mdh_pipeline,GST_STATE_NULL); gst_element_set_state(ly_mdh_pipeline,GST_STATE_READY); rt = gst_element_set_state(ly_mdh_pipeline,GST_STATE_PAUSED); if(!rt) { if(ly_mdh_pipeline!=NULL) gst_object_unref(GST_OBJECT(ly_mdh_pipeline)); ly_mdh_md_eos=FALSE; ly_mdh_pipeline=NULL; return FALSE; } while(rt==GST_STATE_CHANGE_ASYNC && !ly_mdh_md_eos && changeTimeout < 5) { msg = gst_bus_timed_pop(bus, 1 * GST_SECOND); if(msg!=NULL) { ly_mdh_new_with_uri_full_bus_cb(bus, msg, metadata); gst_message_unref(msg); changeTimeout = 0; } else changeTimeout++; rt = gst_element_get_state(ly_mdh_pipeline, NULL, NULL, 0); } gst_object_unref(bus); ly_mdh_new_with_uri_full_loop_cb(metadata, ly_mdh_pipeline, FALSE); if(rt!=GST_STATE_CHANGE_SUCCESS) { gst_element_set_state(ly_mdh_pipeline,GST_STATE_NULL); if(ly_mdh_pipeline!=NULL) gst_object_unref(GST_OBJECT(ly_mdh_pipeline)); return FALSE; } /* * get duration */ gint64 dura=0; gst_element_query_duration(ly_mdh_pipeline,&fmt,&dura); char *duration=ly_mdh_time_int2str(dura); g_strlcpy(metadata->duration,duration,sizeof(metadata->duration)); g_free(duration); rt = gst_element_set_state(ly_mdh_pipeline,GST_STATE_NULL); gst_object_unref(ly_mdh_pipeline); char *str; if(g_str_equal(metadata->title,"")||g_str_equal(metadata->title,"unknown")) { str=ly_gla_uri_get_filename(uri); g_strlcpy(metadata->title,str,sizeof(metadata->title)); g_free(str); } ly_mdh_pipeline=NULL; ly_mdh_md_eos=FALSE; return metadata; }