[vlc-devel] [PATCH 1/3] blockhelper: create new block_FindMaskedFlags
davidf+nntp at woaf.net
davidf+nntp at woaf.net
Tue Apr 21 20:26:46 CEST 2009
From: David Flynn <davidf at rd.bbc.co.uk>
Searches a bytestream_t, between two points, returning the position of
the first block with flags that are a subset of given mask.
Signed-off-by: David Flynn <davidf at rd.bbc.co.uk>
---
include/vlc_block_helper.h | 61 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/include/vlc_block_helper.h b/include/vlc_block_helper.h
index 654d26b..1938e5a 100644
--- a/include/vlc_block_helper.h
+++ b/include/vlc_block_helper.h
@@ -520,4 +520,65 @@ static inline int block_FindStartcodeFromOffset(
return VLC_EGENERIC;
}
+/**
+ * block_FindMaskedFlags:
+ *
+ * searches @p_bytestream, between @pi_start and @pi_end, for the first
+ * block with flags that are a subset of @pi_flags_mask.
+ *
+ * *pi_end is updated to contain the offset of byte after the last
+ * block searched.
+ *
+ * On Success, *pi_offset is updated to the offset of the matching block.
+ * *pi_flags_mask is updated to the unmasked value of flags found
+ * On Failure, *pi_offset is not modified.
+ */
+static inline int block_FindMaskedFlags(
+ block_bytestream_t *p_bytestream, uint32_t *pi_flags_mask,
+ size_t *pi_start, size_t *pi_end)
+{
+ block_t *p_block = p_bytestream->p_block;
+ size_t i_offset = p_bytestream->i_offset + *pi_start;
+ size_t i_length = *pi_end - *pi_start;
+
+ /* Find the block i_offset indexes */
+ for(; p_block != NULL; p_block = p_block->p_next )
+ {
+ if( i_offset < p_block->i_buffer )
+ break;
+ i_offset -= p_block->i_buffer;
+ }
+
+ /* ensure there is atleast i_start of data */
+ if( !p_block )
+ return VLC_EGENERIC;
+
+ /* special case when i_len == 0 */
+ if( !i_length )
+ return VLC_ENOITEM;
+
+ /* i_offset will be the offset to the start of each block */
+ /* *pi_end will be the offset of the next next block */
+ *pi_end = *pi_start - i_offset;
+ i_offset = *pi_start;
+ i_length += i_offset;
+
+ /* search for a block that has any of the flags set in mask */
+ for(; p_block; p_block = p_block->p_next )
+ {
+ *pi_end += p_block->i_buffer;
+ if( p_block->i_flags & *pi_flags_mask )
+ {
+ *pi_flags_mask = p_block->i_flags;
+ *pi_start = i_offset;
+ return VLC_SUCCESS;
+ }
+ i_offset = *pi_end;
+ if( i_length < p_block->i_buffer )
+ break;
+ i_length -= p_block->i_buffer;
+ }
+
+ return VLC_ENOITEM;
+}
#endif /* VLC_BLOCK_HELPER_H */
--
1.5.6.5
More information about the vlc-devel
mailing list