[gst-devel] chained bytestream
David I. Lehn
dlehn at vt.edu
Fri Sep 21 15:06:02 CEST 2001
So now the bytestream code is in cvs and rumor is it works too.
The current version is designed for loop elements. A similar idea could
be used for chain elements. Maybe this isn't in the spirit of gstreamer
and use of cothreads. Maybe this is useful for optimized chain pipelines
that really fly. Dunno benifits of loop vs chain after this.
Idea here is to have a similar buffer resize object.
..init..
gst_pad_set_chain_function(pad, main_chain);
self->bs = gst_bytestream_init(pad);
gst_bytestream_set_chain_function(self->bs, read_header);
gst_bytestream_set_peek_size(self->bs, header_size);
void main_chain(GstPad *pad, GsBuffer *buf) {
gst_bytestream_push(self->bs, buf);
}
void read_header(GstByteStream *bs, GstPad *pad, GstBuffer *buf) {
// buf will be the size you requested last
// maybe need to check for partial reads or something...
// or error handlers.. dunno
if (header_check(...)) {
gst_bytestream_set_chain_function(bs, process_frame);
gst_bytestream_set_read_size(bs, frame_size);
} else {
// advance 1 byte to try and sync to proper data
// will try again with same size and func
// this isn't doing immediate flush.. maybe rename
gst_bytestream_flush(bs, 1);
}
}
void process_frame(GstByteStream *bs, GstPad *pad, GstBuffer *buf) {
do_something(...); // process & push data to output
gst_bytestream_set_chain_function(bs, read_header);
gst_bytestream_set_peek_size(bs, header_size);
}
Internally the bytestream code will do something like:
void gst_bytestream_push(GstByteStream *bs, GstBuffer *buf) {
append_to_stream(bs, buf);
while (stream_size(bs) > next_size(bs)) {
switch (next_mode(bs)) {
case FLUSH: bs_flush(bs, next_size); break;
case PEEK: next_func(bs)(bs, bs_pad(bs), bs_peek(bs, next_size)); break;
case READ: next_func(bs)(bs, bs_pad(bs), bs_read(bs, next_size)); break;
default : puke();
}
} // when too empty do nothing and wait for next chain buf
}
neat eh? process all data in current buf and queue the rest. implement
with basically what current cvs bytestream code does.
there are probably other ways to implement the state machine part.
could have table lookups or the bs chain funcs could return the next
func, mode (read/peek/etc), and size.
Thoughts?
-dave
--
David I. Lehn <dlehn at vt.edu> | http://www.lehn.org/~dlehn/
Computer Engineering Graduate @ Virginia Tech in sunny Blacksburg, VA
More information about the gstreamer-devel
mailing list