mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-23 07:49:37 +08:00
more log improvements
This commit is contained in:
@@ -109,6 +109,7 @@ func (f *fileSrc) setLocation(path string) error {
|
||||
// gst.GoElement implementation. Here we simply create a new fileSrc with zeroed settings
|
||||
// and state objects.
|
||||
func (f *fileSrc) New() gst.GoElement {
|
||||
CAT.Log(gst.LevelDebug, "Initializing new fileSrc object")
|
||||
return &fileSrc{
|
||||
settings: &settings{},
|
||||
state: &state{},
|
||||
@@ -118,12 +119,14 @@ func (f *fileSrc) New() gst.GoElement {
|
||||
// The TypeInit method should register any additional interfaces provided by the element.
|
||||
// In this example we signal to the type system that we also implement the GstURIHandler interface.
|
||||
func (f *fileSrc) TypeInit(instance *gst.TypeInstance) {
|
||||
CAT.Log(gst.LevelDebug, "Adding URIHandler interface to type")
|
||||
instance.AddInterface(gst.InterfaceURIHandler)
|
||||
}
|
||||
|
||||
// The ClassInit method should specify the metadata for this element and add any pad templates
|
||||
// and properties.
|
||||
func (f *fileSrc) ClassInit(klass *gst.ElementClass) {
|
||||
CAT.Log(gst.LevelDebug, "Initializing gofilesrc class")
|
||||
klass.SetMetadata(
|
||||
"File Source",
|
||||
"Source/File",
|
||||
@@ -137,6 +140,7 @@ func (f *fileSrc) ClassInit(klass *gst.ElementClass) {
|
||||
gst.PadPresenceAlways,
|
||||
caps,
|
||||
)
|
||||
CAT.Log(gst.LevelDebug, "Adding src pad template and properties to class")
|
||||
klass.AddPadTemplate(srcPadTemplate)
|
||||
klass.InstallProperties(properties)
|
||||
}
|
||||
@@ -164,7 +168,7 @@ func (f *fileSrc) SetProperty(self *gst.Object, id uint, value *glib.Value) {
|
||||
err.Error(),
|
||||
)
|
||||
}
|
||||
self.Log(CAT, gst.LevelInfo, fmt.Sprintf("Set location to %s", f.settings.location))
|
||||
self.Log(CAT, gst.LevelInfo, fmt.Sprintf("Set `location` to %s", f.settings.location))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +185,7 @@ func (f *fileSrc) GetProperty(self *gst.Object, id uint) *glib.Value {
|
||||
if err == nil {
|
||||
return val
|
||||
}
|
||||
gst.ToElement(self).ErrorMessage(gst.DomainLibrary, gst.LibraryErrorSettings,
|
||||
gst.ToElement(self).ErrorMessage(gst.DomainLibrary, gst.LibraryErrorFailed,
|
||||
fmt.Sprintf("Could not convert %s to GValue", f.settings.location),
|
||||
err.Error(),
|
||||
)
|
||||
@@ -193,6 +197,7 @@ func (f *fileSrc) GetProperty(self *gst.Object, id uint) *glib.Value {
|
||||
// during the initialization process can be performed here. In this example, we set the format on our
|
||||
// underlying GstBaseSrc to bytes.
|
||||
func (f *fileSrc) Constructed(self *gst.Object) {
|
||||
self.Log(CAT, gst.LevelDebug, "Setting format of GstBaseSrc to bytes")
|
||||
base.ToGstBaseSrc(self).SetFormat(gst.FormatBytes)
|
||||
}
|
||||
|
||||
@@ -216,6 +221,7 @@ func (f *fileSrc) GetSize(self *base.GstBaseSrc) (bool, int64) {
|
||||
)
|
||||
return false, 0
|
||||
}
|
||||
self.Log(CAT, gst.LevelDebug, fmt.Sprintf("file stat - name: %s size: %d mode: %v modtime: %v", stat.Name(), stat.Size(), stat.Mode(), stat.ModTime()))
|
||||
return true, stat.Size()
|
||||
}
|
||||
|
||||
@@ -233,6 +239,7 @@ func (f *fileSrc) Start(self *base.GstBaseSrc) bool {
|
||||
}
|
||||
|
||||
var err error
|
||||
self.Log(CAT, gst.LevelDebug, fmt.Sprintf("Opening file %s for reading", f.settings.location))
|
||||
f.state.file, err = os.OpenFile(f.settings.location, syscall.O_RDONLY, 0444)
|
||||
if err != nil {
|
||||
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorOpenRead,
|
||||
@@ -245,7 +252,7 @@ func (f *fileSrc) Start(self *base.GstBaseSrc) bool {
|
||||
|
||||
self.StartComplete(gst.FlowOK)
|
||||
|
||||
self.Log(CAT, gst.LevelInfo, "Started")
|
||||
self.Log(CAT, gst.LevelInfo, "GoFileSrc has started")
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -265,7 +272,7 @@ func (f *fileSrc) Stop(self *base.GstBaseSrc) bool {
|
||||
f.state.position = 0
|
||||
f.state.started = false
|
||||
|
||||
self.Log(CAT, gst.LevelInfo, "Stopped")
|
||||
self.Log(CAT, gst.LevelInfo, "GoFileSrc has stopped")
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -278,7 +285,10 @@ func (f *fileSrc) Fill(self *base.GstBaseSrc, offset uint64, size uint, buffer *
|
||||
return gst.FlowError
|
||||
}
|
||||
|
||||
self.Log(CAT, gst.LevelDebug, fmt.Sprintf("Request to fill buffer from offset %v with size %v", offset, size))
|
||||
|
||||
if f.state.position != offset {
|
||||
self.Log(CAT, gst.LevelDebug, fmt.Sprintf("Seeking to new position at offset %v from previous position at offset %v", offset, f.state.position))
|
||||
if _, err := f.state.file.Seek(int64(offset), 0); err != nil {
|
||||
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorSeek,
|
||||
fmt.Sprintf("Failed to seek to %d in file", offset), err.Error())
|
||||
@@ -287,6 +297,7 @@ func (f *fileSrc) Fill(self *base.GstBaseSrc, offset uint64, size uint, buffer *
|
||||
f.state.position = offset
|
||||
}
|
||||
|
||||
self.Log(CAT, gst.LevelDebug, fmt.Sprintf("Reading %v bytes from file at offset %v", size, f.state.position))
|
||||
out := make([]byte, int(size))
|
||||
if _, err := f.state.file.Read(out); err != nil && err != io.EOF {
|
||||
self.ErrorMessage(gst.DomainResource, gst.ResourceErrorRead,
|
||||
@@ -295,7 +306,9 @@ func (f *fileSrc) Fill(self *base.GstBaseSrc, offset uint64, size uint, buffer *
|
||||
}
|
||||
|
||||
f.state.position = f.state.position + uint64(size)
|
||||
self.Log(CAT, gst.LevelDebug, fmt.Sprintf("Incremented current position to %v", f.state.position))
|
||||
|
||||
self.Log(CAT, gst.LevelDebug, fmt.Sprintf("Writing data from file to buffer"))
|
||||
bufmap := buffer.Map(gst.MapWrite)
|
||||
if bufmap == nil {
|
||||
self.ErrorMessage(gst.DomainLibrary, gst.LibraryErrorFailed, "Failed to map buffer", "")
|
||||
@@ -329,5 +342,6 @@ func (f *fileSrc) SetURI(uri string) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
CAT.Log(gst.LevelInfo, fmt.Sprintf("Set `location` to %s via URIHandler", f.settings.location))
|
||||
return true, nil
|
||||
}
|
||||
|
@@ -303,7 +303,7 @@ func goURIHdlrSetURI(hdlr *C.GstURIHandler, uri *C.gchar, gerr **C.GError) C.gbo
|
||||
iface := FromObjectUnsafePrivate(unsafe.Pointer(hdlr))
|
||||
ok, err := iface.(URIHandler).SetURI(C.GoString(uri))
|
||||
if err != nil {
|
||||
C.g_set_error_literal(gerr, newQuarkFromString(string(DomainLibrary)), C.gint(LibraryErrorSettings), C.CString(err.Error()))
|
||||
C.g_set_error_literal(gerr, DomainLibrary.toQuark(), C.gint(LibraryErrorSettings), C.CString(err.Error()))
|
||||
}
|
||||
return gboolean(ok)
|
||||
}
|
||||
|
@@ -96,6 +96,19 @@ func NewDebugCategory(name string, color DebugColorFlags, description string) *D
|
||||
return &DebugCategory{ptr: cat}
|
||||
}
|
||||
|
||||
func (d *DebugCategory) logDepth(level DebugLevel, message string, depth int, obj *C.GObject) {
|
||||
function, file, line, _ := runtime.Caller(depth)
|
||||
C.cgoDebugLog(
|
||||
d.ptr,
|
||||
C.GstDebugLevel(level),
|
||||
C.CString(path.Base(file)),
|
||||
(C.CString(runtime.FuncForPC(function).Name())),
|
||||
C.gint(line),
|
||||
obj,
|
||||
C.CString(message),
|
||||
)
|
||||
}
|
||||
|
||||
// Log logs the given message using the currently registered debugging handlers. You can optionally
|
||||
// provide a single object to log the message for. GStreamer will automatically add a newline to the
|
||||
// end of the message.
|
||||
@@ -104,14 +117,5 @@ func (d *DebugCategory) Log(level DebugLevel, message string, obj ...*Object) {
|
||||
if len(obj) > 0 {
|
||||
o = (*C.GObject)(obj[0].Unsafe())
|
||||
}
|
||||
function, file, line, _ := runtime.Caller(1)
|
||||
C.cgoDebugLog(
|
||||
d.ptr,
|
||||
C.GstDebugLevel(level),
|
||||
C.CString(path.Base(file)),
|
||||
(C.CString(runtime.FuncForPC(function).Name())),
|
||||
C.gint(line),
|
||||
o,
|
||||
C.CString(message),
|
||||
)
|
||||
d.logDepth(level, message, 2, o)
|
||||
}
|
||||
|
@@ -181,7 +181,7 @@ func (e *Element) MessageFull(msgType MessageType, domain Domain, code ErrorCode
|
||||
C.gst_element_message_full(
|
||||
e.Instance(),
|
||||
C.GstMessageType(msgType),
|
||||
newQuarkFromString(string(domain)),
|
||||
domain.toQuark(),
|
||||
C.gint(code),
|
||||
(*C.gchar)(cTxt),
|
||||
(*C.gchar)(cDbg),
|
||||
|
@@ -16,6 +16,21 @@ const (
|
||||
DomainStream Domain = "STREAM"
|
||||
)
|
||||
|
||||
func (d Domain) toQuark() C.GQuark {
|
||||
switch d {
|
||||
case DomainCore:
|
||||
return C.gst_core_error_quark()
|
||||
case DomainLibrary:
|
||||
return C.gst_library_error_quark()
|
||||
case DomainResource:
|
||||
return C.gst_resource_error_quark()
|
||||
case DomainStream:
|
||||
return C.gst_stream_error_quark()
|
||||
default:
|
||||
return C.gst_library_error_quark()
|
||||
}
|
||||
}
|
||||
|
||||
// ErrorCode represents GstGError codes.
|
||||
type ErrorCode int
|
||||
|
||||
|
@@ -80,5 +80,5 @@ func (o *Object) ListProperties() []*ParameterSpec {
|
||||
// Log logs a message to the given category from this object using the currently registered
|
||||
// debugging handlers.
|
||||
func (o *Object) Log(cat *DebugCategory, level DebugLevel, message string) {
|
||||
cat.Log(level, message, o)
|
||||
cat.logDepth(level, message, 2, (*C.GObject)(o.Unsafe()))
|
||||
}
|
||||
|
Reference in New Issue
Block a user