Commit 348244d2 authored by Laurent Aimar's avatar Laurent Aimar

* stream_output.h, transrate.c : do not use SOUT_BUFFER_FLAG_GOP anymore

 (may be readded later).

 * mpgv.c: new demuxer using the packetizer (allow to stream ES).
parent 9cbc047c
dnl Autoconf settings for vlc dnl Autoconf settings for vlc
dnl $Id: configure.ac,v 1.115 2003/11/22 15:53:18 sam Exp $ dnl $Id: configure.ac,v 1.116 2003/11/22 17:03:57 fenrir Exp $
AC_INIT(vlc,0.6.3-cvs) AC_INIT(vlc,0.6.3-cvs)
...@@ -866,7 +866,7 @@ dnl ...@@ -866,7 +866,7 @@ dnl
dnl default modules dnl default modules
dnl dnl
AX_ADD_PLUGINS([dummy rc logger gestures memcpy hotkeys]) AX_ADD_PLUGINS([dummy rc logger gestures memcpy hotkeys])
AX_ADD_PLUGINS([es mpga m4v mpeg_system ps ts avi asf aac mp4 rawdv]) AX_ADD_PLUGINS([mpgv mpga m4v mpeg_system ps ts avi asf aac mp4 rawdv])
AX_ADD_PLUGINS([spudec mpeg_audio lpcm a52 dts cinepak dvbsub]) AX_ADD_PLUGINS([spudec mpeg_audio lpcm a52 dts cinepak dvbsub])
AX_ADD_PLUGINS([deinterlace invert adjust wall transform distort clone crop motionblur]) AX_ADD_PLUGINS([deinterlace invert adjust wall transform distort clone crop motionblur])
AX_ADD_PLUGINS([float32tos16 float32tos8 float32tou16 float32tou8 a52tospdif dtstospdif fixed32tofloat32 fixed32tos16 s16tofixed32 s16tofloat32 s16tofloat32swab s8tofloat32 u8tofixed32 u8tofloat32]) AX_ADD_PLUGINS([float32tos16 float32tos8 float32tou16 float32tou8 a52tospdif dtstospdif fixed32tofloat32 fixed32tos16 s16tofixed32 s16tofloat32 s16tofloat32swab s8tofloat32 u8tofixed32 u8tofloat32])
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* stream_output.h : stream output module * stream_output.h : stream output module
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: stream_output.h,v 1.16 2003/11/21 15:32:08 fenrir Exp $ * $Id: stream_output.h,v 1.17 2003/11/22 17:03:57 fenrir Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
* *
*/ */
#define SOUT_BUFFER_FLAGS_HEADER 0x0001 #define SOUT_BUFFER_FLAGS_HEADER 0x0001
#define SOUT_BUFFER_FLAGS_GOP 0x0002
/* /*
* Flags for muxer/access private usage. * Flags for muxer/access private usage.
......
SOURCES_mpeg_system = \ SOURCES_mpeg_system = system.c system.h
system.c \ SOURCES_m4v = m4v.c
system.h \ SOURCES_ps = ps.c
$(NULL) SOURCES_ts = ts.c
SOURCES_ts_dvbpsi = ts.c
SOURCES_es = \ SOURCES_mpga = mpga.c
es.c \ SOURCES_mpgv = mpgv.c
$(NULL)
SOURCES_m4v = \
m4v.c \
$(NULL)
SOURCES_ps = \
ps.c \
$(NULL)
SOURCES_ts = \
ts.c \
$(NULL)
SOURCES_ts_dvbpsi = \
ts.c \
$(NULL)
SOURCES_mpga = \
mpga.c \
$(NULL)
/***************************************************************************** /*****************************************************************************
* mpeg_es.c : Elementary Stream input module for vlc * mpgv.c : MPEG-I/II Video demuxer
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: es.c,v 1.5 2003/09/10 11:51:00 fenrir Exp $ * $Id: mpgv.c,v 1.1 2003/11/22 17:03:57 fenrir Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -28,105 +28,148 @@ ...@@ -28,105 +28,148 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/input.h> #include <vlc/input.h>
#include "vlc_codec.h"
/***************************************************************************** /*****************************************************************************
* Constants * Module descriptor
*****************************************************************************/ *****************************************************************************/
#define ES_PACKET_SIZE 65536 static int Open ( vlc_object_t * );
#define MAX_PACKETS_IN_FIFO 3 static void Close ( vlc_object_t * );
vlc_module_begin();
set_description( _("MPEG-I/II Video demuxer" ) );
set_capability( "demux", 100 );
set_callbacks( Open, Close );
add_shortcut( "mpgv" );
vlc_module_end();
/* TODO:
* - free bitrate
*/
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
static int Activate ( vlc_object_t * );
static int Demux ( input_thread_t * ); static int Demux ( input_thread_t * );
/***************************************************************************** struct demux_sys_t
* Module descriptor {
*****************************************************************************/ vlc_bool_t b_start;
vlc_module_begin();
set_description( _("ISO 13818-1 MPEG Elementary Stream input") );
set_capability( "demux", 150 );
set_callbacks( Activate, NULL );
add_shortcut( "es" );
vlc_module_end();
/* es_out_id_t *p_es;
* Data reading functions
*/ decoder_t *p_packetizer;
};
#define MPGV_PACKET_SIZE 4096
/***************************************************************************** /*****************************************************************************
* Activate: initializes ES structures * Open: initializes demux structures
*****************************************************************************/ *****************************************************************************/
static int Activate( vlc_object_t * p_this ) static int Open( vlc_object_t * p_this )
{ {
input_thread_t * p_input = (input_thread_t *)p_this; input_thread_t *p_input = (input_thread_t *)p_this;
es_descriptor_t * p_es; demux_sys_t *p_sys;
byte_t * p_peek; vlc_bool_t b_forced = VLC_FALSE;
/* Set the demux function */ uint8_t *p_peek;
p_input->pf_demux = Demux;
p_input->pf_demux_control = demux_vaControlDefault; es_format_t fmt;
/* Initialize access plug-in structures. */ if( stream_Peek( p_input->s, &p_peek, 4 ) < 4 )
if( p_input->i_mtu == 0 )
{ {
/* Improve speed. */ msg_Err( p_input, "cannot peek" );
p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE; return VLC_EGENERIC;
} }
/* Have a peep at the show. */ if( p_input->psz_demux && !strncmp( p_input->psz_demux, "mpgv", 4 ) )
if( input_Peek( p_input, &p_peek, 4 ) < 4 )
{ {
/* Stream shorter than 4 bytes... */ b_forced = VLC_TRUE;
msg_Err( p_input, "cannot peek()" );
return( -1 );
} }
if( *p_peek || *(p_peek + 1) || *(p_peek + 2) != 1 ) if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 )
{ {
if( *p_input->psz_demux && !strncmp( p_input->psz_demux, "es", 3 ) ) if( !b_forced )
{
/* User forced */
msg_Err( p_input, "this doesn't look like an MPEG ES stream, continuing" );
}
else
{ {
msg_Warn( p_input, "ES module discarded (no startcode)" ); msg_Warn( p_input, "ES module discarded (no startcode)" );
return( -1 ); return VLC_EGENERIC;
} }
msg_Err( p_input, "this doesn't look like an MPEG ES stream, continuing" );
} }
else if( *(p_peek + 3) > 0xb9 )
{ if( p_peek[3] > 0xb9 )
if( *p_input->psz_demux && !strncmp( p_input->psz_demux, "es", 3 ) )
{ {
/* User forced */ if( !b_forced )
msg_Err( p_input, "this seems to be a system stream (PS plug-in ?), but continuing" );
}
else
{ {
msg_Warn( p_input, "ES module discarded (system startcode)" ); msg_Warn( p_input, "ES module discarded (system startcode)" );
return( -1 ); return VLC_EGENERIC;
} }
msg_Err( p_input, "this seems to be a system stream (PS plug-in ?), but continuing" );
} }
if( input_InitStream( p_input, 0 ) == -1 ) vlc_mutex_lock( &p_input->stream.stream_lock );
if( input_InitStream( p_input, 0 ) == -1)
{ {
return( -1 ); vlc_mutex_unlock( &p_input->stream.stream_lock );
msg_Err( p_input, "cannot init stream" );
return VLC_EGENERIC;
} }
input_AddProgram( p_input, 0, 0 ); p_input->stream.i_mux_rate = 0 / 50;
p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
vlc_mutex_lock( &p_input->stream.stream_lock );
p_es = input_AddES( p_input, p_input->stream.p_selected_program, 0xE0,
VIDEO_ES, NULL, 0 );
p_es->i_stream_id = 0xE0;
p_es->i_fourcc = VLC_FOURCC('m','p','g','v');
input_SelectES( p_input, p_es );
p_input->stream.p_selected_area->i_tell = 0;
p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
return( 0 ); p_input->pf_demux = Demux;
p_input->pf_rewind = NULL;
p_input->pf_demux_control = demux_vaControlDefault;
p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) );
p_sys->b_start = VLC_TRUE;
p_sys->p_es = NULL;
/*
* Load the mpegvideo packetizer
*/
p_sys->p_packetizer = vlc_object_create( p_input, VLC_OBJECT_PACKETIZER );
p_sys->p_packetizer->pf_decode = NULL;
p_sys->p_packetizer->pf_decode_audio = NULL;
p_sys->p_packetizer->pf_decode_video = NULL;
p_sys->p_packetizer->pf_decode_sub = NULL;
p_sys->p_packetizer->pf_packetize = NULL;
p_sys->p_packetizer->pf_run = NULL;
es_format_Init( &p_sys->p_packetizer->fmt_in, VIDEO_ES, VLC_FOURCC( 'm', 'p', 'g', 'v' ) );
es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
p_sys->p_packetizer->p_module =
module_Need( p_sys->p_packetizer, "packetizer", NULL );
if( p_sys->p_packetizer->p_module == NULL)
{
vlc_object_destroy( p_sys->p_packetizer );
msg_Err( p_input, "cannot find mpgv packetizer" );
free( p_sys );
return VLC_EGENERIC;
}
/*
* create the output
*/
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'm', 'p', 'g', 'v' ) );
p_sys->p_es = es_out_Add( p_input->p_es_out, &fmt );
return VLC_SUCCESS;
}
/*****************************************************************************
* Close: frees unused data
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
input_thread_t *p_input = (input_thread_t*)p_this;
demux_sys_t *p_sys = p_input->p_demux_data;
module_Unneed( p_sys->p_packetizer, p_sys->p_packetizer->p_module );
vlc_object_destroy( p_sys->p_packetizer );
free( p_sys );
} }
/***************************************************************************** /*****************************************************************************
...@@ -136,58 +179,57 @@ static int Activate( vlc_object_t * p_this ) ...@@ -136,58 +179,57 @@ static int Activate( vlc_object_t * p_this )
*****************************************************************************/ *****************************************************************************/
static int Demux( input_thread_t * p_input ) static int Demux( input_thread_t * p_input )
{ {
ssize_t i_read; demux_sys_t *p_sys = p_input->p_demux_data;
decoder_fifo_t * p_fifo = block_t *p_block_in, *p_block_out;
p_input->stream.p_selected_program->pp_es[0]->p_decoder_fifo;
pes_packet_t * p_pes;
data_packet_t * p_data;
if( p_fifo == NULL ) if( ( p_block_in = stream_Block( p_input->s, MPGV_PACKET_SIZE ) ) == NULL )
{ {
return -1; return 0;
} }
i_read = input_SplitBuffer( p_input, &p_data, ES_PACKET_SIZE ); if( p_sys->b_start )
if ( i_read <= 0 )
{ {
return i_read; p_block_in->i_pts =
p_block_in->i_dts = 1;
} }
else
p_pes = input_NewPES( p_input->p_method_data );
if( p_pes == NULL )
{ {
msg_Err( p_input, "out of memory" ); p_block_in->i_pts =
input_DeletePacket( p_input->p_method_data, p_data ); p_block_in->i_dts = 0;
return -1;
} }
p_pes->i_rate = p_input->stream.control.i_rate; while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) )
p_pes->p_first = p_pes->p_last = p_data; {
p_pes->i_nb_data = 1; p_sys->b_start = VLC_FALSE;
vlc_mutex_lock( &p_fifo->data_lock );
if( p_fifo->i_depth >= MAX_PACKETS_IN_FIFO ) while( p_block_out )
{ {
/* Wait for the decoder. */ block_t *p_next = p_block_out->p_next;
vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
}
vlc_mutex_unlock( &p_fifo->data_lock );
if( (p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT) input_ClockManageRef( p_input,
| (input_ClockManageControl( p_input,
p_input->stream.p_selected_program, p_input->stream.p_selected_program,
(mtime_t)0 ) == PAUSE_S) ) p_block_out->i_dts * 9 / 100 );
p_block_out->i_dts =
input_ClockGetTS( p_input, p_input->stream.p_selected_program,
p_block_out->i_dts * 9 / 100 );
if( p_block_out->i_pts > 0 )
{ {
msg_Warn( p_input, "synchro reinit" ); p_block_out->i_pts =
p_pes->i_pts = mdate() + DEFAULT_PTS_DELAY; input_ClockGetTS( p_input, p_input->stream.p_selected_program,
p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_OK; p_block_out->i_pts * 9 / 100 );
}
else
{
p_block_out->i_pts = 0;
} }
input_DecodePES( p_fifo, p_pes ); p_block_out->p_next = NULL;
es_out_Send( p_input->p_es_out, p_sys->p_es, p_block_out );
p_block_out = p_next;
}
}
return 1; return 1;
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (C) 2003 Antoine Missout * Copyright (C) 2003 Antoine Missout
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
* $Id: transrate.c,v 1.3 2003/11/21 15:32:08 fenrir Exp $ * $Id: transrate.c,v 1.4 2003/11/22 17:03:57 fenrir Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
...@@ -1959,10 +1959,35 @@ static int transrate_video_process( sout_stream_t *p_stream, ...@@ -1959,10 +1959,35 @@ static int transrate_video_process( sout_stream_t *p_stream,
{ {
transrate_t *tr = &id->tr; transrate_t *tr = &id->tr;
bs_transrate_t *bs = &tr->bs; bs_transrate_t *bs = &tr->bs;
vlc_bool_t b_gop = VLC_FALSE;
*out = NULL; *out = NULL;
if ( in->i_flags & SOUT_BUFFER_FLAGS_GOP ) if( GetDWBE( in->p_buffer ) != 0x100 )
{
uint8_t *p = in->p_buffer;
uint8_t *p_end = &in->p_buffer[in->i_buffer];
uint32_t code = GetDWBE( p );
/* We may have a GOP */
while( p < p_end - 4 )
{
if( code == 0x1b8 )
{
b_gop = VLC_TRUE;
break;
}
else if( code == 0x100 )
{
break;
}
code = ( code << 8 )|p[4];
p++;
}
}
if( b_gop )
{ {
while ( id->p_current_buffer != NULL ) while ( id->p_current_buffer != NULL )
{ {
......
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