/** * ly_aud_get_position_abs: * * Get the current position by GStreamer inner clock which is in a format of gint64. * * Returns: The abusolute position time. */ gint64 ly_aud_get_position_abs() { GstState state; state=ly_aud_get_state(); if((state!=GST_STATE_PLAYING)&&(state!=GST_STATE_PAUSED)) return 0; LyMdhMetadata *md=ly_pqm_get_current_md(); if(!md) return 0; GstElement *play=ly_ppl_get_playbin(); if(!play) return 0; GstFormat fmt=GST_FORMAT_TIME; gint64 start=0; gint64 dura=0; gint64 pos=0; start=ly_mdh_time_str2int(md->start); dura=ly_mdh_time_str2int(md->duration); if(dura<=0) { gst_element_query_duration(play, &fmt, &dura); dura-=start; gchar *str=ly_mdh_time_int2str(dura); gchar sql[128]=""; g_snprintf(sql, sizeof(sql), "UPDATE metadatas SET duration='%s' WHERE id=%d", str, md->id); g_free(str); ly_dbm_exec(sql, NULL, NULL); ly_pqm_set_current_md(md->id); } if(!gst_element_query_position(play, &fmt, &pos)) { ly_log_put_with_flag(G_LOG_LEVEL_DEBUG, _("Position wrong!")); return 0; } if(pos-start<-60000000000) { ly_log_put_with_flag(G_LOG_LEVEL_DEBUG, _("Position wrong!")); return 0; } pos=pos-start; if(pos<0) pos=0; else if(pos>dura) pos=dura; return pos; }
/** * 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; }