Commit fc65166a authored by Francois Cartegnie's avatar Francois Cartegnie

demux: hevc: use packetizer frame rate

Removes dependency on hevc_nal
and allows more refactoring with h264
parent d789b884
...@@ -166,8 +166,7 @@ demux_LTLIBRARIES += libes_plugin.la ...@@ -166,8 +166,7 @@ demux_LTLIBRARIES += libes_plugin.la
libh264_plugin_la_SOURCES = demux/mpeg/h264.c libh264_plugin_la_SOURCES = demux/mpeg/h264.c
demux_LTLIBRARIES += libh264_plugin.la demux_LTLIBRARIES += libh264_plugin.la
libhevc_plugin_la_SOURCES = demux/mpeg/hevc.c packetizer/hevc_nal.h \ libhevc_plugin_la_SOURCES = demux/mpeg/hevc.c
packetizer/hevc_nal.c packetizer/hxxx_nal.h
demux_LTLIBRARIES += libhevc_plugin.la demux_LTLIBRARIES += libhevc_plugin.la
libmkv_plugin_la_SOURCES = \ libmkv_plugin_la_SOURCES = \
......
...@@ -35,9 +35,6 @@ ...@@ -35,9 +35,6 @@
#include <vlc_codec.h> #include <vlc_codec.h>
#include <vlc_mtime.h> #include <vlc_mtime.h>
#include "../packetizer/hevc_nal.h"
#include "../packetizer/hxxx_nal.h"
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
*****************************************************************************/ *****************************************************************************/
...@@ -65,7 +62,6 @@ vlc_module_end () ...@@ -65,7 +62,6 @@ vlc_module_end ()
static int Demux( demux_t * ); static int Demux( demux_t * );
static int Control( demux_t *, int, va_list ); static int Control( demux_t *, int, va_list );
static int32_t getFPS( demux_t *, uint8_t, block_t * );
struct demux_sys_t struct demux_sys_t
{ {
...@@ -75,9 +71,6 @@ struct demux_sys_t ...@@ -75,9 +71,6 @@ struct demux_sys_t
unsigned frame_rate_num; unsigned frame_rate_num;
unsigned frame_rate_den; unsigned frame_rate_den;
decoder_t *p_packetizer; decoder_t *p_packetizer;
/* Only for probing fps */
hevc_video_parameter_set_t *rgp_vps[HEVC_VPS_MAX];
}; };
#define HEVC_BLOCK_SIZE 2048 #define HEVC_BLOCK_SIZE 2048
...@@ -121,12 +114,10 @@ static int Open( vlc_object_t * p_this ) ...@@ -121,12 +114,10 @@ static int Open( vlc_object_t * p_this )
p_sys->frame_rate_den = 1000; p_sys->frame_rate_den = 1000;
p_sys->frame_rate_num = 1000 * f_force_fps; p_sys->frame_rate_num = 1000 * f_force_fps;
date_Init( &p_sys->dts, p_sys->frame_rate_num, p_sys->frame_rate_den ); date_Init( &p_sys->dts, p_sys->frame_rate_num, p_sys->frame_rate_den );
msg_Dbg( p_demux, "using %.2f fps", (double) f_force_fps );
} }
else else
date_Init( &p_sys->dts, 25000, 1000 ); /* Will be overwritten */ date_Init( &p_sys->dts, 25000, 1000 ); /* Will be overwritten */
date_Set( &p_sys->dts, VLC_TS_0 ); date_Set( &p_sys->dts, VLC_TS_0 );
memset(p_sys->rgp_vps, 0, sizeof(p_sys->rgp_vps[0]) * HEVC_VPS_MAX);
/* Load the hevc packetizer */ /* Load the hevc packetizer */
es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_HEVC ); es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_HEVC );
...@@ -137,13 +128,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -137,13 +128,7 @@ static int Open( vlc_object_t * p_this )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_out); p_sys->p_es = NULL;
if( !p_sys->p_es )
{
demux_PacketizerDestroy( p_sys->p_packetizer );
free( p_sys );
return VLC_ENOMEM;
}
p_demux->pf_demux = Demux; p_demux->pf_demux = Demux;
p_demux->pf_control= Control; p_demux->pf_control= Control;
...@@ -163,12 +148,6 @@ static void Close( vlc_object_t * p_this ) ...@@ -163,12 +148,6 @@ static void Close( vlc_object_t * p_this )
demux_PacketizerDestroy( p_sys->p_packetizer ); demux_PacketizerDestroy( p_sys->p_packetizer );
for( unsigned i=0; i<HEVC_VPS_MAX; i++ )
{
if( p_sys->rgp_vps[i] )
hevc_rbsp_release_vps( p_sys->rgp_vps[i] );
}
free( p_sys ); free( p_sys );
} }
...@@ -187,9 +166,6 @@ static int Demux( demux_t *p_demux) ...@@ -187,9 +166,6 @@ static int Demux( demux_t *p_demux)
return 0; return 0;
} }
p_block_in->i_dts = VLC_TS_INVALID;
p_block_in->i_pts = VLC_TS_INVALID;
while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) ) while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) )
{ {
while( p_block_out ) while( p_block_out )
...@@ -197,38 +173,45 @@ static int Demux( demux_t *p_demux) ...@@ -197,38 +173,45 @@ static int Demux( demux_t *p_demux)
block_t *p_next = p_block_out->p_next; block_t *p_next = p_block_out->p_next;
p_block_out->p_next = NULL; p_block_out->p_next = NULL;
p_block_out->i_dts = date_Get( &p_sys->dts ); /* As we'll receive the pts of the head of the packetizer helper blockstream
p_block_out->i_pts = VLC_TS_INVALID; * the dts/pts will always be late until next frame. */
p_block_in->i_dts = date_Get( &p_sys->dts );
p_block_in->i_pts = VLC_TS_INVALID;
uint8_t nal_type = (p_block_out->p_buffer[4] & 0x7E) >> 1; if( p_sys->p_es == NULL )
uint8_t nal_layer = hevc_getNALLayer(&p_block_out->p_buffer[4]); {
p_sys->p_packetizer->fmt_out.b_packetized = true;
p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_out);
if( !p_sys->p_es )
return VLC_DEMUXER_EOF;
}
/*Get fps from vps if available and not already forced*/ bool frame = p_block_out->i_flags & BLOCK_FLAG_TYPE_MASK;
if( p_sys->frame_rate_den == 0 && es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
(nal_type == HEVC_NAL_VPS || nal_type == HEVC_NAL_SPS) ) if( frame )
{ {
if( getFPS( p_demux, nal_type, p_block_out) ) if( !p_sys->frame_rate_den )
{ {
msg_Err(p_demux,"getFPS failed"); /* Use packetizer's one */
return 0; if( p_sys->p_packetizer->fmt_out.video.i_frame_rate_base )
{
p_sys->frame_rate_num = p_sys->p_packetizer->fmt_out.video.i_frame_rate;
p_sys->frame_rate_den = p_sys->p_packetizer->fmt_out.video.i_frame_rate_base;
} }
else if( p_sys->frame_rate_den ) else
{ {
p_sys->frame_rate_num = 25000;
p_sys->frame_rate_den = 1000;
}
date_Init( &p_sys->dts, p_sys->frame_rate_num, p_sys->frame_rate_den ); date_Init( &p_sys->dts, p_sys->frame_rate_num, p_sys->frame_rate_den );
date_Set( &p_sys->dts, VLC_TS_0 ); date_Set( &p_sys->dts, VLC_TS_0 );
} msg_Dbg( p_demux, "using %.2f fps", (double) p_sys->frame_rate_num / p_sys->frame_rate_den );
} }
/* Update DTS only on VCL NAL*/ es_out_Control( p_demux->out, ES_OUT_SET_PCR, date_Get( &p_sys->dts ) );
if( nal_type < HEVC_NAL_VPS && p_sys->frame_rate_den &&
nal_layer == 0 ) /* Only on base layer */
{
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
date_Increment( &p_sys->dts, 1 ); date_Increment( &p_sys->dts, 1 );
} }
es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
p_block_out = p_next; p_block_out = p_next;
} }
...@@ -246,52 +229,3 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) ...@@ -246,52 +229,3 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
0, 1, i_query, args ); 0, 1, i_query, args );
} }
static int32_t getFPS(demux_t *p_demux, uint8_t i_nal_type, block_t *p_block)
{
demux_sys_t *p_sys = p_demux->p_sys;
hevc_sequence_parameter_set_t *p_sps = NULL;
uint8_t i_id;
if( !hevc_get_xps_id( p_block->p_buffer, p_block->i_buffer, &i_id ) )
return -1;
if( p_sys->rgp_vps[i_id] && i_nal_type == HEVC_NAL_VPS )
return -1;
const uint8_t *p_nald = p_block->p_buffer;
size_t i_nald = p_block->i_buffer;
if( hxxx_strip_AnnexB_startcode( &p_nald, &i_nald ) )
{
if( i_nal_type == HEVC_NAL_VPS )
p_sys->rgp_vps[i_id] = hevc_decode_vps( p_nald, i_nald, true );
else
p_sps = hevc_decode_sps( p_nald, i_nald, true );
}
if( p_sps )
{
if( !hevc_get_frame_rate( p_sps, p_sys->rgp_vps,
&p_sys->frame_rate_num, &p_sys->frame_rate_den ) )
{
p_sys->frame_rate_num = 25;
p_sys->frame_rate_den = 1;
msg_Warn( p_demux, "No timing info in VPS defaulting to 25 fps");
}
else
{
msg_Dbg( p_demux,"Using framerate %2.f fps from VPS",
(float) p_sys->frame_rate_num / (float) p_sys->frame_rate_den );
for( unsigned i=0; i<HEVC_VPS_MAX; i++ )
{
if( p_sys->rgp_vps[i] )
{
hevc_rbsp_release_vps( p_sys->rgp_vps[i] );
p_sys->rgp_vps[i] = NULL;
}
}
}
hevc_rbsp_release_sps( p_sps );
}
return 0;
}
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