Пример #1
0
// MT safe.
func (o *GstObj) GetName() string {
	s := C.gst_object_get_name(o.g())
	if s == nil {
		return ""
	}
	defer C.g_free(C.gpointer(s))
	return C.GoString((*C.char)(s))
}
Пример #2
0
// GetName() is a wrapper around gst_object_get_name().
func (v *Object) GetName() string {
	c := C.gst_object_get_name(v.native())
	defer C.g_free(C.gpointer(c))
	return C.GoString((*C.char)(c))
}
Пример #3
0
func play() {
	// element
	e, err := NewElement("fakesrc", "source")
	if err != nil {
		log.Fatal(err)
	}
	p("%v\n", e)

	name := C.gst_object_get_name(asGstObj(e))
	p("%s\n", fromGStr(name))

	// factory
	factory, err := NewFactory("fakesrc")
	if err != nil {
		log.Fatal(err)
	}
	p("%s\n", fromGStr(C.gst_object_get_name(asGstObj(factory))))
	p("%s\n", fromGStr(C.gst_element_factory_get_metadata(factory, asGStr(C.CString(C.GST_ELEMENT_METADATA_KLASS)))))
	p("%s\n", fromGStr(C.gst_element_factory_get_metadata(factory, asGStr(C.CString(C.GST_ELEMENT_METADATA_DESCRIPTION)))))

	// id pipeline
	pipeline := C.gst_pipeline_new(toGStr("pipeline"))
	source, _ := NewElement("fakesrc", "source")
	filter, _ := NewElement("identity", "filter")
	sink, _ := NewElement("fakesink", "sink")
	BinAdd(pipeline, source, filter, sink)
	ElementLink(source, filter, sink)
	C.gst_element_set_state(pipeline, C.GST_STATE_PLAYING)
	C.gst_element_sync_state_with_parent(filter)

	/*
		// bin
		bin := C.gst_bin_new(toGStr("bin"))
		source, _ = NewElement("fakesrc", "source")
		sink, _ = NewElement("fakesink", "sink")
		BinAdd(bin, source, sink)
		//C.gst_bin_remove(asGstBin(bin), source)
		ElementLink(source, sink)
		BinAdd(pipeline, bin)
		source = C.gst_bin_get_by_name(asGstBin(bin), toGStr("source"))
	*/

	// bus
	messages := PipelineWatchBus(asGstPipeline(pipeline))
	loop := C.g_main_loop_new(nil, 0)
	go func() {
		C.g_main_loop_run(loop)
	}()

	// message
loop:
	for msg := range messages {
		runtime.GC()
		p("=> %s from %s\n", fromGStr(C.gst_message_type_get_name(msg._type)),
			fromGStr(C.gst_object_get_name(asGstObj(msg.src))))
		switch msg._type {

		case C.GST_MESSAGE_ERROR:
			var err *C.GError
			var debug *C.gchar
			C.gst_message_parse_error(msg, &err, &debug)
			p("Error: %s\n%s\n", fromGStr(err.message), fromGStr(debug))
			C.g_error_free(err)
			C.g_free(asGPtr(debug))
			C.g_main_loop_quit(loop)
			break loop
		case C.GST_MESSAGE_WARNING:
		case C.GST_MESSAGE_INFO:

		case C.GST_MESSAGE_EOS:
			C.g_main_loop_quit(loop)
			break loop

		case C.GST_MESSAGE_TAG:
			var tags *C.GstTagList
			C.gst_message_parse_tag(msg, &tags)
			//TagListForeach(tags, ) TODO
			C.gst_tag_list_unref(tags)

		case C.GST_MESSAGE_STATE_CHANGED:
			var newState, oldState C.GstState
			C.gst_message_parse_state_changed(msg, &oldState, &newState, nil)
			p("%s -> %s\n", fromGStr(C.gst_element_state_get_name(oldState)),
				fromGStr(C.gst_element_state_get_name(newState)))

		}
	}
}
Пример #4
0
func play2() {
	pipeline := C.gst_pipeline_new(toGStr("pipeline"))

	source, err := NewElement("filesrc", "source")
	if err != nil {
		log.Fatal(err)
	}
	ObjSet(asGObj(source), "location", os.Args[1])

	demux, err := NewElement("oggdemux", "demuxer")
	if err != nil {
		log.Fatal(err)
	}

	BinAdd(pipeline, source, demux)
	C.gst_element_link_pads(source, toGStr("src"), demux, toGStr("sink"))
	ObjConnect(asGObj(demux), "pad-added", func(demuxer *C.GstElement, pad *C.GstPad) {
		p("pad added %T %v\n", pad, pad)
	})

	// bus
	messages := PipelineWatchBus(asGstPipeline(pipeline))

	C.gst_element_set_state(pipeline, C.GST_STATE_PLAYING)

	loop := C.g_main_loop_new(nil, 0)
	go func() {
	loop:
		for msg := range messages {
			runtime.GC()
			p("=> %s: %s\n", fromGStr(C.gst_object_get_name(asGstObj(msg.src))),
				fromGStr(C.gst_message_type_get_name(msg._type)))
			switch msg._type {

			case C.GST_MESSAGE_ERROR:
				var err *C.GError
				var debug *C.gchar
				C.gst_message_parse_error(msg, &err, &debug)
				p("Error: %s\n%s\n", fromGStr(err.message), fromGStr(debug))
				C.g_error_free(err)
				C.g_free(asGPtr(debug))
				C.g_main_loop_quit(loop)
				break loop
			case C.GST_MESSAGE_WARNING:
			case C.GST_MESSAGE_INFO:

			case C.GST_MESSAGE_EOS:
				C.g_main_loop_quit(loop)
				break loop

			case C.GST_MESSAGE_TAG:
				var tags *C.GstTagList
				C.gst_message_parse_tag(msg, &tags)
				//TagListForeach(tags, ) TODO
				C.gst_tag_list_unref(tags)

			case C.GST_MESSAGE_STATE_CHANGED:
				var newState, oldState C.GstState
				C.gst_message_parse_state_changed(msg, &oldState, &newState, nil)
				p("%s -> %s\n", fromGStr(C.gst_element_state_get_name(oldState)),
					fromGStr(C.gst_element_state_get_name(newState)))

			}

			C.gst_message_unref(msg)
		}
		p("loop break.\n")
	}()

	runtime.LockOSThread()
	C.g_main_loop_run(loop)
	p("quit.\n")
}
Пример #5
0
func MessageDump(msg *C.GstMessage) {
	srcName := fromGStr(C.gst_object_get_name(msg.src))
	switch msg._type {
	case C.GST_MESSAGE_UNKNOWN: // unknown
		pMsg(srcName, "Unknown")
	case C.GST_MESSAGE_EOS: // end of stream
		pMsg(srcName, "Eos")
	case C.GST_MESSAGE_ERROR: // error
		var err *C.GError
		var debug *C.gchar
		C.gst_message_parse_error(msg, &err, &debug)
		pMsg(srcName, "Error", "%s %s", fromGStr(err.message), fromGStr(debug))
		C.g_error_free(err)
		C.g_free(asGPtr(debug))
	//case C.GST_MESSAGE_WARNING: // warning
	//case C.GST_MESSAGE_INFO: // info
	case C.GST_MESSAGE_TAG: // tag
		var tagList *C.GstTagList
		C.gst_message_parse_tag(msg, &tagList)
		pMsg(srcName, "Tag")
		TagForeach(tagList, func(tag *C.gchar) {
			num := C.gst_tag_list_get_tag_size(tagList, tag)
			for i := C.guint(0); i < num; i++ {
				val := C.gst_tag_list_get_value_index(tagList, tag, i)
				pMsg(srcName, "Tag", "%s = %v", fromGStr(tag), fromGValue(val))
			}
		})
		C.gst_tag_list_unref(tagList)
	//case C.GST_MESSAGE_BUFFERING: // buffering
	case C.GST_MESSAGE_STATE_CHANGED: // state changed
		var oldState, newState C.GstState
		C.gst_message_parse_state_changed(msg, &oldState, &newState, nil)
		pMsg(srcName, "State", "%s -> %s",
			fromGStr(C.gst_element_state_get_name(oldState)),
			fromGStr(C.gst_element_state_get_name(newState)))
	//case C.GST_MESSAGE_STATE_DIRTY: // state dirty
	//case C.GST_MESSAGE_STEP_DONE: // step done
	//case C.GST_MESSAGE_CLOCK_PROVIDE: // clock provide
	//case C.GST_MESSAGE_CLOCK_LOST: // clock lost
	case C.GST_MESSAGE_NEW_CLOCK: // new clock
		var clock *C.GstClock
		C.gst_message_parse_new_clock(msg, &clock)
		pMsg(srcName, "New clock")
	//case C.GST_MESSAGE_STRUCTURE_CHANGE: // structure change
	case C.GST_MESSAGE_STREAM_STATUS: // stream status
		var t C.GstStreamStatusType
		var owner *C.GstElement
		C.gst_message_parse_stream_status(msg, &t, &owner)
		pMsg(srcName, "Stream status", "%d", t)
	//case C.GST_MESSAGE_APPLICATION: // application
	case C.GST_MESSAGE_ELEMENT: // element
		pMsg(srcName, "Element", "%v", msg)
	//case C.GST_MESSAGE_SEGMENT_START: // segment start
	//case C.GST_MESSAGE_SEGMENT_DONE: // segment done
	case C.GST_MESSAGE_DURATION_CHANGED: // duration changed
		pMsg(srcName, "Duration changed")
	case C.GST_MESSAGE_LATENCY: // latency
		pMsg(srcName, "Latency")
	//case C.GST_MESSAGE_ASYNC_START: // async start
	case C.GST_MESSAGE_ASYNC_DONE: // async done
		C.gst_message_parse_async_done(msg, nil)
		pMsg(srcName, "Async done")
	//case C.GST_MESSAGE_REQUEST_STATE: // request state
	//case C.GST_MESSAGE_STEP_START: // step start
	//case C.GST_MESSAGE_QOS: // qos
	//case C.GST_MESSAGE_PROGRESS: // progress
	//case C.GST_MESSAGE_TOC: // toc
	case C.GST_MESSAGE_RESET_TIME: // reset time
		C.gst_message_parse_reset_time(msg, nil)
		pMsg(srcName, "Reset time")
	case C.GST_MESSAGE_STREAM_START: // stream start
		pMsg(srcName, "Stream start")
	//case C.GST_MESSAGE_NEED_CONTEXT: // need context
	//case C.GST_MESSAGE_HAVE_CONTEXT: // have context
	//case C.GST_MESSAGE_ANY: // any
	default:
		name := C.gst_message_type_get_name(msg._type)
		p("message type %s\n", fromGStr(name))
		panic("fixme")
	}
	C.gst_message_unref(msg)
}