[vlc-commits] omxil: Move code for in-buffer conversion of H264 to annex b to h264_nal.h
Martin Storsjö
git at videolan.org
Mon Oct 8 11:38:41 CEST 2012
vlc | branch: master | Martin Storsjö <martin at martin.st> | Mon Oct 8 01:27:43 2012 +0300| [f021e86cf9fb587061f29750476649cf1bc4e62e] | committer: Jean-Baptiste Kempf
omxil: Move code for in-buffer conversion of H264 to annex b to h264_nal.h
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f021e86cf9fb587061f29750476649cf1bc4e62e
---
modules/codec/h264_nal.h | 22 ++++++++++++++++++++++
modules/codec/omxil/omxil.c | 25 +++++--------------------
2 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/modules/codec/h264_nal.h b/modules/codec/h264_nal.h
index 1f90b05..f116f0b 100644
--- a/modules/codec/h264_nal.h
+++ b/modules/codec/h264_nal.h
@@ -96,3 +96,25 @@ static int convert_sps_pps( decoder_t *p_dec, const uint8_t *p_buf,
return VLC_SUCCESS;
}
+/* Convert H.264 NAL format to annex b in-place */
+static void convert_h264_to_annexb( uint8_t *p_buf, uint32_t i_len,
+ int i_nal_size )
+{
+ if( i_nal_size < 3 || i_nal_size > 4 )
+ return;
+
+ /* This only works for NAL sizes 3-4 */
+ while( i_len >= i_nal_size )
+ {
+ uint32_t nal_len = 0;
+ for( int i = 0; i < i_nal_size; i++ ) {
+ nal_len = (nal_len << 8) | p_buf[i];
+ p_buf[i] = 0;
+ }
+ p_buf[i_nal_size - 1] = 1;
+ if( nal_len > INT_MAX || nal_len > (unsigned int) i_len )
+ break;
+ p_buf += nal_len + i_nal_size;
+ i_len -= nal_len + i_nal_size;
+ }
+}
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index e33ab36..0733648 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -1363,26 +1363,11 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
block_Release(p_block);
}
- /* Convert H.264 NAL format to annex b */
- if( p_sys->i_nal_size_length >= 3 && p_sys->i_nal_size_length <= 4 )
- {
- /* This only works for NAL sizes 3-4 */
- int i_len = p_header->nFilledLen, i;
- uint8_t* ptr = p_header->pBuffer;
- while( i_len >= p_sys->i_nal_size_length )
- {
- uint32_t nal_len = 0;
- for( i = 0; i < p_sys->i_nal_size_length; i++ ) {
- nal_len = (nal_len << 8) | ptr[i];
- ptr[i] = 0;
- }
- ptr[p_sys->i_nal_size_length - 1] = 1;
- if( nal_len > INT_MAX || nal_len > (unsigned int) i_len )
- break;
- ptr += nal_len + p_sys->i_nal_size_length;
- i_len -= nal_len + p_sys->i_nal_size_length;
- }
- }
+ /* Convert H.264 NAL format to annex b. Doesn't do anything if
+ * i_nal_size_length == 0, which is the case for codecs other
+ * than H.264 */
+ convert_h264_to_annexb( p_header->pBuffer, p_header->nFilledLen,
+ p_sys->i_nal_size_length );
#ifdef OMXIL_EXTRA_DEBUG
msg_Dbg( p_dec, "EmptyThisBuffer %p, %p, %i", p_header, p_header->pBuffer,
(int)p_header->nFilledLen );
More information about the vlc-commits
mailing list