After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 619292 - [API] add chunk writer
[API] add chunk writer
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks: 619293
 
 
Reported: 2010-05-21 13:35 UTC by Mark Nauwelaerts
Modified: 2018-11-03 12:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add mark stacking API (4.91 KB, patch)
2010-05-21 13:36 UTC, Mark Nauwelaerts
needs-work Details | Review
Add GstChunkWriter (9.23 KB, patch)
2010-05-25 08:50 UTC, Mark Nauwelaerts
reviewed Details | Review

Description Mark Nauwelaerts 2010-05-21 13:35:38 UTC
Bytewriting typically involves nested structures with sizes recorded in the bytestream (e.g. avi chunks, qt atoms, ebml elements, jpeg markers, etc).  Additional proposed API aids in tracking nested structures positions and sizes,
which could be used in any of the above cases, rather than coming up with yet another home made on in each case separately.

Evidently, some variations on the proposed are possible, e.g. using a separate (inherited) type for this (GstByteWriterStack or so).
Comment 1 Mark Nauwelaerts 2010-05-21 13:36:26 UTC
Created attachment 161643 [details] [review]
Add mark stacking API
Comment 2 Tim-Philipp Müller 2010-05-21 14:24:47 UTC
Review of attachment 161643 [details] [review]:

::: libs/gst/base/gstbytewriter.h
@@ +47,3 @@
+
+  /*< private >*/
+  GArray *marks;

Sadly I don't think we can do this, because we allow allocation of byte writers on the stack and "forgot" to add padding to these structs. Guess we need a GstChunkWriter class or so (which could just keep track of the chunks and return/init a byte writer to write into as chunk? Another thing we could have done if we had padding - allow for a 'parent' byte writer..)
Comment 3 Benjamin Otte (Company) 2010-05-22 09:07:50 UTC
It took me a bit of thinking about the API to get an idea of what it's supposed to do. I'm still not quite sure though.

Could you explain what you want the API to be used for and give a small pseudo-code example with your proposed API?

Because I have some other ideas on how to do something like that, but I'm not sure they fit your use case.
Comment 4 Benjamin Otte (Company) 2010-05-22 09:54:15 UTC
I found bug 619293 and its attached use case. I think I have a solution that works fine (I think it works even better) without new API.

I should probably elaborate on why I don't like APIs like this:
My problem is that it's not a byte writer's job to care about nesting. A byte writer's job is to care about writing bytes to a data buffer and that should be it. There's nothing against sophisticated APIs for doing this kind of job, but keeping the API focussed on this one job is an important thing IMO.
Comment 5 Mark Nauwelaerts 2010-05-22 19:53:53 UTC
I was wondering from the start whether this belonged to a "pure" bytewriter, as so indicated by an alternative as a separate type in the original report.

Given that, and the padding problem, a more appropriate one would be a separate (e.g.) GstChunkWriter that would be associated to a GstByteWriter (rather than inherited or intertwined API).
Comment 6 Tim-Philipp Müller 2010-05-22 20:10:50 UTC
I've always been wanting API like this myself, but was never quite sure how it should look like (and too lazy). Would be useful for avimux, matroskamux, qtmux, asfmux, wavenc, etc. An associated byte writer instead of inheritance sounds like a good plan to me, that way we get the 'backed by a single memory region' thing automatically.
Comment 7 Benjamin Otte (Company) 2010-05-22 20:53:06 UTC
If I were to do something like this, I'd have an API that hands you a new bytewriter object that writes a subpart of the parent bytewriter. But this is not really what you want for the chunked files use case - all you want here is write the size of a chunk later.
And I think rewind(), put_uint32(), back_to_end() - style API is very suitable for that. And you can support that very well with offsets, which are basically the same thing as marks.

A different API would probably make sense if you wanted to reserve a fixed-size section of more than 4 bytes and write them later or maybe even interchangably with the rest of the byte writer (dunno, maybe an index?), where it'd be nice to be able to create a fixed size byte writer ala
  subsection_writer = gst_byte_writer_new_for_section (parent_writer, num_bytes);
but that is hard to do with the current bytewriter API (due to resizes invalidating the pointer) and I don't think we have any use cases for it.
Comment 8 Mark Nauwelaerts 2010-05-25 08:50:55 UTC
Created attachment 161919 [details] [review]
Add GstChunkWriter

So here is another stab at some stack marking API, this time in a separate GstChunkWriter helper associated with a GstByteWriter.  In any case, it is not exactly humongous API.
Comment 9 Sebastian Dröge (slomo) 2013-07-24 08:21:56 UTC
Comment on attachment 161919 [details] [review]
Add GstChunkWriter

Looks good to me, but could use a unit test, maybe an initialization macro to init it on the stack, and a use in a plugin somewhere.

After that I'm fine with having this pushed.
Comment 10 Tim-Philipp Müller 2013-07-24 10:59:14 UTC
I always thought this would be handy, but I don't think it should be pushed before there's a user for it too.
Comment 11 GStreamer system administrator 2018-11-03 12:13:58 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/14.