Ejemplo n.º 1
0
//export busCallback
func busCallback(bus *C.GstBus, msg *C.GstMessage, data C.gpointer) C.gboolean {
	if IsMessage(msg) {
		messageChan := *((*chan *C.GstMessage)(unsafe.Pointer(data)))
		copy := C.gst_message_copy(msg)
		runtime.SetFinalizer(copy, func(m *C.GstMessage) {
			C.gst_message_unref(m)
		})
		messageChan <- copy
	}
	return True()
}
Ejemplo n.º 2
0
Archivo: play.go Proyecto: reusee/oplay
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")
}
Ejemplo n.º 3
0
Archivo: gst.go Proyecto: reusee/oplay
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)
}
Ejemplo n.º 4
0
func (m *Message) Unref() {
	C.gst_message_unref(m.g())
}