Commit 0b609071 authored by Francois Cartegnie's avatar Francois Cartegnie

packetizer: h264: split some code

parent 51f64595
...@@ -6,7 +6,8 @@ libpacketizer_mpeg4video_plugin_la_SOURCES = packetizer/mpeg4video.c ...@@ -6,7 +6,8 @@ libpacketizer_mpeg4video_plugin_la_SOURCES = packetizer/mpeg4video.c
libpacketizer_mpeg4audio_plugin_la_SOURCES = packetizer/mpeg4audio.c libpacketizer_mpeg4audio_plugin_la_SOURCES = packetizer/mpeg4audio.c
libpacketizer_h264_plugin_la_SOURCES = \ libpacketizer_h264_plugin_la_SOURCES = \
packetizer/h264_nal.c packetizer/h264_nal.h \ packetizer/h264_nal.c packetizer/h264_nal.h \
packetizer/h264.c packetizer/hxxx_nal.h packetizer/h264.c packetizer/hxxx_nal.h \
packetizer/hxxx_common.c packetizer/hxxx_common.h
libpacketizer_vc1_plugin_la_SOURCES = packetizer/vc1.c libpacketizer_vc1_plugin_la_SOURCES = packetizer/vc1.c
libpacketizer_mlp_plugin_la_SOURCES = packetizer/mlp.c libpacketizer_mlp_plugin_la_SOURCES = packetizer/mlp.c
libpacketizer_dirac_plugin_la_SOURCES = packetizer/dirac.c libpacketizer_dirac_plugin_la_SOURCES = packetizer/dirac.c
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "../codec/cc.h" #include "../codec/cc.h"
#include "h264_nal.h" #include "h264_nal.h"
#include "hxxx_nal.h" #include "hxxx_nal.h"
#include "hxxx_common.h"
#include "packetizer_helper.h" #include "packetizer_helper.h"
/***************************************************************************** /*****************************************************************************
...@@ -157,7 +158,6 @@ static block_t *PacketizeParse( void *p_private, bool *pb_ts_used, block_t * ); ...@@ -157,7 +158,6 @@ static block_t *PacketizeParse( void *p_private, bool *pb_ts_used, block_t * );
static int PacketizeValidate( void *p_private, block_t * ); static int PacketizeValidate( void *p_private, block_t * );
static block_t *ParseNALBlock( decoder_t *, bool *pb_ts_used, block_t * ); static block_t *ParseNALBlock( decoder_t *, bool *pb_ts_used, block_t * );
static block_t *CreateAnnexbNAL( decoder_t *, const uint8_t *p, int );
static block_t *OutputPicture( decoder_t *p_dec ); static block_t *OutputPicture( decoder_t *p_dec );
static void PutSPS( decoder_t *p_dec, block_t *p_frag ); static void PutSPS( decoder_t *p_dec, block_t *p_frag );
...@@ -262,7 +262,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -262,7 +262,7 @@ static int Open( vlc_object_t *p_this )
{ {
return VLC_EGENERIC; return VLC_EGENERIC;
} }
block_t *p_sps = CreateAnnexbNAL( p_dec, p, i_length ); block_t *p_sps = CreateAnnexbNAL( p, i_length );
if( !p_sps ) if( !p_sps )
return VLC_EGENERIC; return VLC_EGENERIC;
ParseNALBlock( p_dec, &b_dummy, p_sps ); ParseNALBlock( p_dec, &b_dummy, p_sps );
...@@ -278,7 +278,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -278,7 +278,7 @@ static int Open( vlc_object_t *p_this )
{ {
return VLC_EGENERIC; return VLC_EGENERIC;
} }
block_t *p_pps = CreateAnnexbNAL( p_dec, p, i_length ); block_t *p_pps = CreateAnnexbNAL( p, i_length );
if( !p_pps ) if( !p_pps )
return VLC_EGENERIC; return VLC_EGENERIC;
ParseNALBlock( p_dec, &b_dummy, p_pps ); ParseNALBlock( p_dec, &b_dummy, p_pps );
...@@ -423,57 +423,9 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block ) ...@@ -423,57 +423,9 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
static block_t *PacketizeAVC1( decoder_t *p_dec, block_t **pp_block ) static block_t *PacketizeAVC1( decoder_t *p_dec, block_t **pp_block )
{ {
decoder_sys_t *p_sys = p_dec->p_sys; decoder_sys_t *p_sys = p_dec->p_sys;
block_t *p_block;
block_t *p_ret = NULL;
uint8_t *p;
if( !pp_block || !*pp_block ) return PacketizeXXC1( p_dec, p_sys->i_avcC_length_size,
return NULL; pp_block, ParseNALBlock );
if( (*pp_block)->i_flags&(BLOCK_FLAG_CORRUPTED) )
{
block_Release( *pp_block );
return NULL;
}
p_block = *pp_block;
*pp_block = NULL;
for( p = p_block->p_buffer; p < &p_block->p_buffer[p_block->i_buffer]; )
{
block_t *p_pic;
bool b_dummy;
int i_size = 0;
int i;
for( i = 0; i < p_sys->i_avcC_length_size; i++ )
{
i_size = (i_size << 8) | (*p++);
}
if( i_size <= 0 ||
i_size > ( p_block->p_buffer + p_block->i_buffer - p ) )
{
msg_Err( p_dec, "Broken frame : size %d is too big", i_size );
break;
}
block_t *p_part = CreateAnnexbNAL( p_dec, p, i_size );
if( !p_part )
break;
p_part->i_dts = p_block->i_dts;
p_part->i_pts = p_block->i_pts;
/* Parse the NAL */
if( ( p_pic = ParseNALBlock( p_dec, &b_dummy, p_part ) ) )
{
block_ChainAppend( &p_ret, p_pic );
}
p += i_size;
}
block_Release( p_block );
return p_ret;
} }
/***************************************************************************** /*****************************************************************************
...@@ -543,26 +495,6 @@ static int PacketizeValidate( void *p_private, block_t *p_au ) ...@@ -543,26 +495,6 @@ static int PacketizeValidate( void *p_private, block_t *p_au )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static block_t *CreateAnnexbNAL( decoder_t *p_dec, const uint8_t *p, int i_size )
{
block_t *p_nal;
p_nal = block_Alloc( 4 + i_size );
if( !p_nal ) return NULL;
/* Add start code */
p_nal->p_buffer[0] = 0x00;
p_nal->p_buffer[1] = 0x00;
p_nal->p_buffer[2] = 0x00;
p_nal->p_buffer[3] = 0x01;
/* Copy nalu */
memcpy( &p_nal->p_buffer[4], p, i_size );
VLC_UNUSED(p_dec);
return p_nal;
}
/***************************************************************************** /*****************************************************************************
* ParseNALBlock: parses annexB type NALs * ParseNALBlock: parses annexB type NALs
* All p_frag blocks are required to start with 0 0 0 1 4-byte startcode * All p_frag blocks are required to start with 0 0 0 1 4-byte startcode
......
/*****************************************************************************
* hxxx_common.c: AVC/HEVC packetizers shared code
*****************************************************************************
* Copyright (C) 2001-2015 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "hxxx_common.h"
#include <vlc_block.h>
#include <vlc_codec.h>
block_t *CreateAnnexbNAL( const uint8_t *p, size_t i_size )
{
block_t *p_nal;
p_nal = block_Alloc( 4 + i_size );
if( !p_nal ) return NULL;
/* Add start code */
p_nal->p_buffer[0] = 0x00;
p_nal->p_buffer[1] = 0x00;
p_nal->p_buffer[2] = 0x00;
p_nal->p_buffer[3] = 0x01;
/* Copy nalu */
memcpy( &p_nal->p_buffer[4], p, i_size );
return p_nal;
}
/****************************************************************************
* PacketizeXXC1: Takes VCL blocks of data and creates annexe B type NAL stream
* Will always use 4 byte 0 0 0 1 startcodes
* Will prepend a SPS and PPS before each keyframe
****************************************************************************/
block_t *PacketizeXXC1( decoder_t *p_dec, uint8_t i_nal_length_size,
block_t **pp_block, pf_annexb_nal_packetizer pf_nal_parser )
{
block_t *p_block;
block_t *p_ret = NULL;
uint8_t *p;
if( !pp_block || !*pp_block )
return NULL;
if( (*pp_block)->i_flags&(BLOCK_FLAG_CORRUPTED) )
{
block_Release( *pp_block );
return NULL;
}
p_block = *pp_block;
*pp_block = NULL;
for( p = p_block->p_buffer; p < &p_block->p_buffer[p_block->i_buffer]; )
{
block_t *p_pic;
bool b_dummy;
int i_size = 0;
int i;
for( i = 0; i < i_nal_length_size; i++ )
{
i_size = (i_size << 8) | (*p++);
}
if( i_size <= 0 ||
i_size > ( p_block->p_buffer + p_block->i_buffer - p ) )
{
msg_Err( p_dec, "Broken frame : size %d is too big", i_size );
break;
}
block_t *p_part = CreateAnnexbNAL( p, i_size );
if( !p_part )
break;
p_part->i_dts = p_block->i_dts;
p_part->i_pts = p_block->i_pts;
/* Parse the NAL */
if( ( p_pic = pf_nal_parser( p_dec, &b_dummy, p_part ) ) )
{
block_ChainAppend( &p_ret, p_pic );
}
p += i_size;
}
block_Release( p_block );
return p_ret;
}
/*****************************************************************************
* hxxx_common.h: AVC/HEVC packetizers shared code
*****************************************************************************
* Copyright (C) 2001-2015 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef HXXX_COMMON_H
#define HXXX_COMMON_H
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
block_t *CreateAnnexbNAL( const uint8_t *p, size_t );
typedef block_t * (*pf_annexb_nal_packetizer)(decoder_t *, bool *, block_t *);
block_t *PacketizeXXC1( decoder_t *, uint8_t, block_t **, pf_annexb_nal_packetizer );
#endif // HXXX_COMMON_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment