From 8821277dc6fe163bc8d07c69ea23b965a2f25ea2 Mon Sep 17 00:00:00 2001 From: tinyzimmer <38474291+tinyzimmer@users.noreply.github.com> Date: Thu, 1 Oct 2020 09:31:52 +0300 Subject: [PATCH] build out gsttoc and tocentry more --- gst/gst_toc.go | 133 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/gst/gst_toc.go b/gst/gst_toc.go index 19658c4..7552701 100644 --- a/gst/gst_toc.go +++ b/gst/gst_toc.go @@ -73,12 +73,143 @@ func (t *TOC) GetTags() *TagList { return wrapTagList(tagList) } -// MergeTags +// MergeTags merges the given tags into this TOC's TagList. +func (t *TOC) MergeTags(tagList *TagList, mergeMode TagMergeMode) { + C.gst_toc_merge_tags(t.Instance(), tagList.Instance(), C.GstTagMergeMode(mergeMode)) +} + +// SetTags sets tags for the entire TOC. +func (t *TOC) SetTags(tagList *TagList) { + C.gst_toc_set_tags(t.Instance(), tagList.Instance()) +} // TOCEntry is a go representation of a GstTocEntry, type TOCEntry struct { ptr *C.GstTocEntry } +// NewTOCEntry creates a new TOCEntry with the given UID and type. +func NewTOCEntry(entryType TOCEntryType, uid string) *TOCEntry { + cuid := C.CString(uid) + defer C.free(unsafe.Pointer(cuid)) + entry := C.gst_toc_entry_new( + C.GstTocEntryType(entryType), + (*C.gchar)(unsafe.Pointer(cuid)), + ) + if entry == nil { + return nil + } + return wrapTOCEntry(entry) +} + // Instance returns the underlying GstTocEntry instance. func (t *TOCEntry) Instance() *C.GstTocEntry { return t.ptr } + +// AppendSubEntry appends the given entry as a subentry to this one. +func (t *TOCEntry) AppendSubEntry(subEntry *TOCEntry) { + C.gst_toc_entry_append_sub_entry(t.Instance(), subEntry.Instance()) +} + +// GetEntryType returns the type of this TOCEntry +func (t *TOCEntry) GetEntryType() TOCEntryType { + return TOCEntryType(C.gst_toc_entry_get_entry_type(t.Instance())) +} + +// GetEntryTypeString returns a string representation of the entry type. +func (t *TOCEntry) GetEntryTypeString() string { + return C.GoString(C.gst_toc_entry_type_get_nick(C.GstTocEntryType(t.GetEntryType()))) +} + +// GetLoop gets the loop type and repeat count for the TOC entry. +func (t *TOCEntry) GetLoop() (bool, TOCLoopType, int) { + var loopType C.GstTocLoopType + var repeatCount C.gint + ok := C.gst_toc_entry_get_loop(t.Instance(), &loopType, &repeatCount) + return gobool(ok), TOCLoopType(loopType), int(repeatCount) +} + +// GetParent gets the parent of this TOCEntry. +func (t *TOCEntry) GetParent() *TOCEntry { + parent := C.gst_toc_entry_get_parent(t.Instance()) + if parent == nil { + return nil + } + return wrapTOCEntry(parent) +} + +// GetStartStopTimes gets the start and stop times for the TOCEntry if available. +func (t *TOCEntry) GetStartStopTimes() (ok bool, startTime, stopTime int64) { + var start, stop C.gint64 + gok := C.gst_toc_entry_get_start_stop_times(t.Instance(), &start, &stop) + return gobool(gok), int64(start), int64(stop) +} + +// GetSubEntries gets all the subentries for this TOCEntry. +func (t *TOCEntry) GetSubEntries() []*TOCEntry { + gList := C.gst_toc_entry_get_sub_entries(t.Instance()) + + defer C.g_list_free(gList) + out := make([]*TOCEntry, 0) + + for { + entry := C.glistNext(gList) + if entry == nil { + break + } + out = append(out, wrapTOCEntry((*C.GstTocEntry)(unsafe.Pointer(entry)))) + } + return out +} + +// GetTags gets the tags for this entry. +func (t *TOCEntry) GetTags() *TagList { + tagList := C.gst_toc_entry_get_tags(t.Instance()) + if tagList == nil { + return nil + } + return wrapTagList(tagList) +} + +// GetTOC returns the parent TOC of this entry. +func (t *TOCEntry) GetTOC() *TOC { + toc := C.gst_toc_entry_get_toc(t.Instance()) + if toc == nil { + return nil + } + return wrapTOC(toc) +} + +// GetUID returns the uid of this entry. +func (t *TOCEntry) GetUID() string { + return C.GoString(C.gst_toc_entry_get_uid(t.Instance())) +} + +// IsAlternative returns true if this is an alternative entry. +func (t *TOCEntry) IsAlternative() bool { + return gobool(C.gst_toc_entry_is_alternative(t.Instance())) +} + +// IsSequence returns true if this is a sequence entry. +func (t *TOCEntry) IsSequence() bool { + return gobool(C.gst_toc_entry_is_sequence(t.Instance())) +} + +// MergeTags merges the given tags with the given mode. +func (t *TOCEntry) MergeTags(tagList *TagList, mergeMode TagMergeMode) { + C.gst_toc_entry_merge_tags(t.Instance(), tagList.Instance(), C.GstTagMergeMode(mergeMode)) +} + +// SetLoop sets the loop type and repeat counts for the entry. +func (t *TOCEntry) SetLoop(loopType TOCLoopType, repeatCount int) { + C.gst_toc_entry_set_loop(t.Instance(), C.GstTocLoopType(loopType), C.gint(repeatCount)) +} + +// SetStartStopTimes sets the start and stop times for the TOC entry. +func (t *TOCEntry) SetStartStopTimes(startTime, stopTime int64) { + C.gst_toc_entry_set_start_stop_times(t.Instance(), C.gint64(startTime), C.gint64(stopTime)) +} + +// SetTags sets the tags on the TOC entry. +func (t *TOCEntry) SetTags(tagList *TagList) { + C.gst_toc_entry_set_tags(t.Instance(), tagList.Instance()) +}