bitstream_new size
Allocate a new BitStream of size bytes, and return a pointer to the BitStream. If size=0, only the header, not the buffer, is allocated. This form is useful in conjunction with BitStreamShare() (see below).
bitstream_mmap_read_new fileName
Allocate and return a new BitStream whose contents are a memory map of the file fileName. Returns
bitstream_mmap_read_new: failed to create mmapped bitstream
if the memory map fails.
bitstream_mmap_read_free bs
Free the memory associated with bs and clear the memory map of the file. Bs must have been allocated with bitstream_mmap_read_new.
bitstream_free bs
Deallocate the BitStream pointed to by bs. Use bitstream_mmap_read_free to free memory mapped bitsreams
bitstream_shift bs offset
Moves data in bs, from offset to the end of data in the BitStream, to the beginning of buffer.
For example, if we have 80 bytes of data in a BitStream, calling BitStreamShift(bs, 59) will move bytes 59..79 to positions 0..19.)
bitstream_resize bs size
Reallocate the BitStream to size number of bytes. If the BitStream size is increased, the contents of the buffer are unchanged. If it is decreased, the data will be truncated.
bitstream_share_buffer src dest
Share the buffer of src in dest. That is, dest's buffer will be set to src's buffer. Warning: dest's buffer is not free'd, so memory leaks can occur if not used carefully.
A common way to use this function is in conjunction with BitStreamNew(0).
bitstream_bytes_left bs off
Return the number of bytes of data in bs from postion off to the end.
For example, if bs has 80 bytes, BitStreamBytesLeft(bs, 60) will return 20.
bitstream_dump inbs inOff outbs outOff len
Copy len bytes from inbs+inOff to outbs+outOff. Returns the total number of bytes copied.
bitstream_dump_segments inbs inOff outbs outOff len skip count
This function is useful for copying regularly spaced segments from one BitStream to another. It works as follows. Starting with inbs's at offset inOff, repeat the following steps count times:
Returns the total number of bytes copied.
- Copy len bytes to outbs, starting with offset outoff.
- Skip over skip bytes in inbs.
For example, the following fragment copies bytes 100-119 and 130-149 of bs1 to bytes 10-49 of bs2:
bitstream_dump_segments bs1 100 bs2 10 20 10 2
bitparser_new
Allocate and return a pointer to a new BitParser.
bitparser_free bp
Free the memory allocated for bp.
bitparser_wrap bp bs
Attach bp to bs. The cursor of bp will be set to the first byte in bs. All future reads from and writes to bs will modify the data in bp. All future writes using bp will modify data in bs.
bitparser_tell bp
Return the position of the cursor of bp. This is the offset, in bytes, from the beginning of the BitStream to which bp is attached.
bitparser_seek bp off
Move the cursor of bp to byte offset off.
bitparser_get_bitstream bp
Return a handle to the BitStream the BitParser bp is attached to. Result is undefined in bp is not attached to any BitStream.
bitstream_filter_new size
Create a new BitStreamFilter with size entries.
bitstream_filter_resize filter size
Change the size of BitStreamFilter filter to size entries, existing entries in the filter will remain unchanged.
bitstream_filter_free filter
Deallocate the BitStreamFilter filter and all entries in it.
bitstream_filter_add filter offset length
Add a new entry (offset, length) to the BitStreamFilter filter.
bitstream_filter_read file filter
bitstream_filter_write file filter
Allocate and return a new BitStreamFilter whose contents are a memory map of the file fileName. Returns
bitstream_mmap_read_new: failed to create mmapped bitstream
if the memory map fails.
bitstream_filter_start_scan filter
Reset filter so that the next time it's used it will retrieve data from the beginning of the source.
bitstream_dump_using_filter src srcOffset dest destOffset length filter
Copy a subset of data from the BitStream src (starting at srcOffset) to the BitStream dest (starting at destOffset). The subset is specified by the scatter/gather data in the BitStreamFilter filter. At most length bytes are copied. Filter maintains sufficient state so that the next call to BitStreamDumpUsingFilter() will read the data correctly (provided src is not modified between calls) . You can use the function BitStreamFilterStartScan to reset this state (e.g., if you rewind to the beginning of the file).
The number of bytes copied is returned. For example, the following function uses bitstream_dump_using_filter to make sure that outbs has at least minsize bytes in it. If less than minsize bytes are available in outbs, data from inbs is copied into outbs using the BitStreamFilter filter. The number of bytes added to outbs is returned.
proc FillBS {inbs outbs outbp index minsize} { set pos [bitparser_tell $outbp] set remain [bitstream_bytes_left $outbs $pos] if {$remain < $minsize} { bitstream_shift $outbs $pos bitparser_seek $outbp 0 return [bitstream_dump_using_filter $inbs 0 $outbs $remain 65536 $index] } else { return 0 } }
bitstream_filter_channel_read filter chan
bitstream_filter_channel_write filter chan
These functions are used to save/restore filter to the file (or any other Tcl channel) specified by chan. Chan should be a Tcl channel, filter should be a BitStreamFilter. These functions are needed when using filters that index massive files, since such filters can be expensive to construct (requiring one pass over the file).
bitstream_channel_read bs channel offset
Fill up the BitStream bs with data from Tcl_Channel channel, starting at byte offset position offset. Return the number of bytes read into the buffer.
bitstream_channel_read_segment bs channel offset length
Fill the BitStream bs with length bytes of data from Tcl_Channel channel, starting at byte offset position offset. Return the number of bytes read into the buffer.
bitstream_channel_read_segments bs channel offset length skip times
Starting with bitstream bs's offset off, do the following for times number of loops :
Return the total number of bytes read into the buffer.
- reads length bytes into the bitstream from Tcl_Channel channel
- skip skip number of bytes in channel,
For example, the following fragment reads bytes 100-119 and 130-149 of channel1 into bs1
bitstream_channel_read_segments bs1 channel1 100 20 10 2
bitstream_channel_write bs channel offset
Write data from BitStream bs to Tcl_Channel channel, starting at byte offset position offset, until the most recent byte written into the bitstream. Return the number of bytes written into channel.
bitstream_channel_write_segment bs channel offset length
Writes length byte of data from the BitStream bs into Tcl_Channel channel, starting at byte offset position offset. Return the number of bytes written into the buffer.
bitstream_channel_write_segments bs channel offset length skip times
Starting with BitStream bs's offset offset do the following for times number of times :
Return the total number of bytes written into the channel.
- write length bytes into channel from bs
- skip skip number of bytes in the BitStream
For example, the following fragment writes bytes 100-119 and 130-149 of bs1 into channel1
bitstream_channel_write_segments bs1 channel1 100 20 10 2
bitstream_channel_filter_in bs channel offset filter
Starting with offset position offset in BitStream bs, fill up the BitStream bs with data from Tcl channel channel, using the BitStreamFilter filter : For each pair (offset, length) in the filter, or until the buffer is full, do the following:
The BitStreamFilter maintains the state of the file and will be changed after this function is called, so that the next call to this primitive will read the data correctly.
- seek to offset in the channel
- read length bytes (or less if the BitStream is full) from the channel into the BitStream bs
Last updated : Saturday, November 14, 1998, 07:50 PM