vlc | branch: master | Kazuki Yamaguchi <[email protected]> | Tue Feb 16 00:33:29 2016 +0900| [b74735e49b5daf32052d8641476d06b63cdf7185] | committer: Yuudai Yamashigi
aribcam: refactor Read() * First try of p_sys->p_b25->get() always does nothing, so read from stream first. * Merge DecoderRead() into Read() Signed-off-by: Yuudai Yamashigi <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b74735e49b5daf32052d8641476d06b63cdf7185 --- modules/stream_filter/aribcam.c | 77 +++++++++++++++------------------------ 1 file changed, 30 insertions(+), 47 deletions(-) diff --git a/modules/stream_filter/aribcam.c b/modules/stream_filter/aribcam.c index bb519d6..d7fe885 100644 --- a/modules/stream_filter/aribcam.c +++ b/modules/stream_filter/aribcam.c @@ -163,14 +163,14 @@ static void RemainFlush( stream_sys_t *p_sys ) #define ALL_READY (UNIT_SIZE_READY|ECM_READY|PMT_READY) -static int DecoderRead( stream_t *p_stream, uint8_t *p_dst, int i_toread ) +static ssize_t Read( stream_t *p_stream, void *p_buf, size_t i_toread ) { stream_sys_t *p_sys = p_stream->p_sys; - ARIB_STD_B25_BUFFER getbuf = { NULL, 0 }; + uint8_t *p_dst = p_buf; int i_total_read = 0; int i_ret; - if ( !p_dst || ! i_toread ) + if ( !p_dst || !i_toread ) return -1; /* Use data from previous reads */ @@ -179,71 +179,54 @@ static int DecoderRead( stream_t *p_stream, uint8_t *p_dst, int i_toread ) p_dst += i_fromremain; i_toread -= i_fromremain; - while( i_toread ) + while ( i_toread ) { - - do + /* make use of the existing buffer, overwritten by decoder data later */ + int i_srcread = stream_Read( p_stream->p_source, p_dst, i_toread ); + if ( i_srcread > 0 ) { - getbuf.size = 0; - - i_ret = p_sys->p_b25->get( p_sys->p_b25, &getbuf ); + ARIB_STD_B25_BUFFER putbuf = { p_dst, i_srcread }; + i_ret = p_sys->p_b25->put( p_sys->p_b25, &putbuf ); if ( i_ret < 0 ) - msg_Err( p_stream, "decoder get failed: %s", - GetErrorMessage( i_ret, b25_errors ) ); - - /* If the decoders needs buffering or data is not ready, push some */ - if ( i_ret == 0 && getbuf.size == 0 ) { - /* make use of the existing buffer, - overwritten by decoder data later */ - int i_srcread = stream_Read( p_stream->p_source, p_dst, i_toread ); - if ( i_srcread > 0 ) - { - ARIB_STD_B25_BUFFER putbuf = { p_dst, i_srcread }; - i_ret = p_sys->p_b25->put( p_sys->p_b25, &putbuf ); - if ( i_ret < 0 ) - msg_Err( p_stream, "decoder put failed: %s", - GetErrorMessage( i_ret, b25_errors ) ); - } - else - { - if ( i_srcread < 0 ) - msg_Err( p_stream, "Can't read %d bytes from source stream: %d", i_toread, i_srcread ); - i_ret = -1; - } + msg_Err( p_stream, "decoder put failed: %s", + GetErrorMessage( i_ret, b25_errors ) ); + return -1; } } - while ( i_ret == 0 && getbuf.size == 0 ); + else + { + if ( i_srcread < 0 ) + msg_Err( p_stream, "Can't read %lu bytes from source stream: %d", i_toread, i_srcread ); + return -1; + } + ARIB_STD_B25_BUFFER getbuf; + i_ret = p_sys->p_b25->get( p_sys->p_b25, &getbuf ); if ( i_ret < 0 ) + { + msg_Err( p_stream, "decoder get failed: %s", + GetErrorMessage( i_ret, b25_errors ) ); return -1; + } - memcpy( p_dst, getbuf.data, __MIN(getbuf.size, i_toread) ); - - if ( getbuf.size > i_toread ) + if ( (size_t)getbuf.size > i_toread ) { /* Hold remaining data for next call */ RemainAdd( p_stream, getbuf.data + i_toread, getbuf.size - i_toread ); } - i_total_read += __MIN(getbuf.size, i_toread); - p_dst += __MIN(getbuf.size, i_toread); - i_toread -= __MIN(getbuf.size, i_toread); + int consume = __MIN( (size_t)getbuf.size, i_toread ); + memcpy( p_dst, getbuf.data, consume ); + i_total_read += consume; + p_dst += consume; + i_toread -= consume; } return i_total_read; } -static ssize_t Read( stream_t *p_stream, void *p_buf, size_t i_toread ) -{ - stream_sys_t *p_sys = p_stream->p_sys; - int i_read = DecoderRead( p_stream, p_buf, i_toread ); - if ( i_read < 0 ) - return -1; - return i_read; -} - /** * */ _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
