Commit f8bf106d authored by Laurent Aimar's avatar Laurent Aimar

Added stream output. (common work with titer).

parent 3f126864
......@@ -135,6 +135,7 @@ case "x${target_os}" in
LDFLAGS_access_mms="${LDFLAGS_access_mms} -lws2_32"
LDFLAGS_access_rtp="${LDFLAGS_access_rtp} -lws2_32"
LDFLAGS_access_udp="${LDFLAGS_access_udp} -lws2_32"
LDFLAGS_access_output_udp="${LDFLAGS_access_output_udp} -lws2_32"
LDFLAGS_rc="${LDFLAGS_rc} -lws2_32"
LDFLAGS_sap="${LDFLAGS_sap} -lws2_32"
fi
......@@ -273,6 +274,7 @@ AC_CHECK_FUNC(send,,[
LDFLAGS_access_rtp="${LDFLAGS_access_rtp} -lsocket"
LDFLAGS_access_udp="${LDFLAGS_access_udp} -lsocket"
LDFLAGS_sap="${LDFLAGS_sap} -lsocket"
LDFLAGS_access_output_udp="${LDFLAGS_access_output_udp} -lsocket"
)])
AC_CHECK_FUNC(gethostbyname,,[
......@@ -865,6 +867,20 @@ AC_ARG_ENABLE(release,
[ --enable-release activate extra optimizations (default disabled)])
AM_CONDITIONAL(RELEASE, test "x${enable_release}" = "xyes")
dnl
dnl Stream output
dnl
AC_ARG_ENABLE(sout,
[ --enable-sout Stream output modules (default enabled)])
if test "x${enable_sout}" != "xno"
then
PLUGINS="${PLUGINS} access_output_dummy access_output_udp access_output_file"
PLUGINS="${PLUGINS} mux_ts mux_ps mux_dummy"
PLUGINS="${PLUGINS} packetizer_mpegaudio packetizer_mpegvideo packetizer_a52"
PLUGINS="${PLUGINS} packetizer_mpeg4video packetizer_copy"
fi
dnl
dnl Input plugins
dnl
......
......@@ -2,15 +2,17 @@
* stream_output.h : stream output module
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: stream_output.h,v 1.1 2002/08/12 22:12:50 massiot Exp $
* $Id: stream_output.h,v 1.2 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* 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
* the Free Software Foundation; either version 2 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
......@@ -24,6 +26,59 @@
/*****************************************************************************
* sout_instance_t: stream output thread descriptor
*****************************************************************************/
struct sout_buffer_t
{
size_t i_allocated_size;
byte_t *p_buffer;
size_t i_size;
// mtime_t i_date;
mtime_t i_length;
mtime_t i_dts;
mtime_t i_pts;
int i_bitrate;
struct sout_buffer_t *p_next;
};
struct sout_packet_format_t
{
int i_cat; // AUDIO_ES, VIDEO_ES, SPU_ES
vlc_fourcc_t i_fourcc;
void *p_format; // WAVEFORMATEX or BITMAPINFOHEADER
};
struct sout_fifo_t
{
vlc_mutex_t lock; /* fifo data lock */
vlc_cond_t wait; /* fifo data conditional variable */
int i_depth;
sout_buffer_t *p_first;
sout_buffer_t **pp_last;
};
struct sout_input_t
{
vlc_mutex_t lock;
sout_instance_t *p_sout;
sout_packet_format_t input_format;
sout_fifo_t *p_fifo;
void *p_mux_data;
};
#define SOUT_METHOD_NONE 0x00
#define SOUT_METHOD_FILE 0x10
#define SOUT_METHOD_NETWORK 0x20
struct sout_instance_t
{
VLC_COMMON_MEMBERS
......@@ -33,10 +88,30 @@ struct sout_instance_t
char * psz_mux;
char * psz_name;
module_t * p_access;
module_t * p_mux;
module_t *p_access;
int i_method;
void *p_access_data;
int (* pf_write )( sout_instance_t *, sout_buffer_t * );
int (* pf_seek )( sout_instance_t *, off_t );
module_t *p_mux;
void *p_mux_data;
int (* pf_mux_addstream )( sout_instance_t *,
sout_input_t * );
int (* pf_mux_delstream )( sout_instance_t *,
sout_input_t * );
int (* pf_mux ) ( sout_instance_t * );
vlc_mutex_t lock;
int i_nb_inputs;
sout_input_t **pp_inputs;
};
/*****************************************************************************
* Prototypes
*****************************************************************************/
......@@ -44,7 +119,21 @@ struct sout_instance_t
VLC_EXPORT( sout_instance_t *, __sout_NewInstance, ( vlc_object_t *, char * ) );
VLC_EXPORT( void, sout_DeleteInstance, ( sout_instance_t * ) );
sout_fifo_t * sout_CreateFifo ( void );
void sout_DestroyFifo ( sout_fifo_t * );
void sout_FreeFifo ( sout_fifo_t * );
VLC_EXPORT( sout_fifo_t *, sout_FifoCreate, ( sout_instance_t * ) );
VLC_EXPORT( void, sout_FifoDestroy, ( sout_instance_t *, sout_fifo_t * ) );
VLC_EXPORT( void, sout_FifoFree, ( sout_instance_t *,sout_fifo_t * ) );
VLC_EXPORT( void, sout_FifoPut, ( sout_fifo_t *, sout_buffer_t* ) );
VLC_EXPORT( sout_buffer_t *, sout_FifoGet, ( sout_fifo_t * ) );
VLC_EXPORT( sout_buffer_t *, sout_FifoShow, ( sout_fifo_t * ) );
#define sout_InputNew( a, b ) __sout_InputNew( VLC_OBJECT(a), b )
VLC_EXPORT( sout_input_t *, __sout_InputNew, ( vlc_object_t *, sout_packet_format_t * ) );
VLC_EXPORT( int, sout_InputDelete, ( sout_input_t * ) );
VLC_EXPORT( int, sout_InputSendBuffer, ( sout_input_t *, sout_buffer_t* ) );
VLC_EXPORT( sout_buffer_t*, sout_BufferNew, ( sout_instance_t *, size_t ) );
VLC_EXPORT( int, sout_BufferRealloc,( sout_instance_t *, sout_buffer_t*, size_t ) );
VLC_EXPORT( int, sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
......@@ -3,7 +3,7 @@
* Collection of useful common types and macros definitions
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: vlc_common.h,v 1.43 2002/12/13 01:56:29 gbazin Exp $
* $Id: vlc_common.h,v 1.44 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr>
......@@ -241,6 +241,9 @@ typedef struct subpicture_sys_t subpicture_sys_t;
/* Stream output */
typedef struct sout_instance_t sout_instance_t;
typedef struct sout_fifo_t sout_fifo_t;
typedef struct sout_input_t sout_input_t;
typedef struct sout_buffer_t sout_buffer_t;
typedef struct sout_packet_format_t sout_packet_format_t;
/* Decoders */
typedef struct decoder_fifo_t decoder_fifo_t;
......
......@@ -8,6 +8,7 @@ EXTRA_DIST = \
access/satellite/Modules.am \
access/v4l/Modules.am \
access/vcd/Modules.am \
access_output/Modules.am \
audio_filter/channel_mixer/Modules.am \
audio_filter/converter/Modules.am \
audio_filter/resampler/Modules.am \
......@@ -53,6 +54,9 @@ EXTRA_DIST = \
misc/memcpy/Modules.am \
misc/network/Modules.am \
misc/testsuite/Modules.am \
mux/Modules.am \
mux/mpeg/Modules.am \
packetizer/Modules.am \
video_chroma/Modules.am \
video_filter/Modules.am \
video_filter/deinterlace/Modules.am \
......
SOURCES_access_output_dummy = modules/access_output/dummy.c
SOURCES_access_output_file = modules/access_output/file.c
SOURCES_access_output_udp = modules/access_output/udp.c
/*****************************************************************************
* dummy.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: dummy.c,v 1.1 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* 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
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <vlc/sout.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
# include <io.h>
#endif
/*****************************************************************************
* Exported prototypes
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int Write( sout_instance_t *, sout_buffer_t * );
static int Seek( sout_instance_t *, off_t );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("Dummy stream ouput") );
set_capability( "sout access", 0 );
add_shortcut( "dummy" );
set_callbacks( Open, Close );
vlc_module_end();
/*****************************************************************************
* Open: open the file
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
p_sout->i_method = SOUT_METHOD_NONE;
p_sout->p_access_data = NULL;
p_sout->pf_write = Write;
p_sout->pf_seek = Seek;
msg_Info( p_sout, "dummy stream output access launched" );
return VLC_SUCCESS;
}
/*****************************************************************************
* Close: close the target
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
msg_Info( p_sout, "Close" );
}
/*****************************************************************************
* Read: standard read on a file descriptor.
*****************************************************************************/
static int Write( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
{
size_t i_write = 0;
do
{
sout_buffer_t *p_next;
i_write += p_buffer->i_size;
p_next = p_buffer->p_next;
sout_BufferDelete( p_sout, p_buffer );
p_buffer = p_next;
} while( p_buffer );
msg_Dbg( p_sout, "Dummy Skipped: len:%d", (uint32_t)i_write );
return( i_write );
}
/*****************************************************************************
* Seek: seek to a specific location in a file
*****************************************************************************/
static int Seek( sout_instance_t *p_sout, off_t i_pos )
{
msg_Dbg( p_sout, "Seek: pos:%lld", (int64_t)i_pos );
return( 0 );
}
/*****************************************************************************
* file.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: file.c,v 1.1 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* 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
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <vlc/sout.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
# include <io.h>
#endif
/*****************************************************************************
* Exported prototypes
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int Write( sout_instance_t *, sout_buffer_t * );
static int Seek( sout_instance_t *, off_t );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("File stream ouput") );
set_capability( "sout access", 50 );
add_shortcut( "file" );
set_callbacks( Open, Close );
vlc_module_end();
typedef struct sout_access_data_s
{
FILE *p_file;
} sout_access_data_t;
/*****************************************************************************
* Open: open the file
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
sout_access_data_t *p_access;
char * psz_name = p_sout->psz_name;
p_access = malloc( sizeof( sout_access_data_t ) );
if( !( p_access->p_file = fopen( psz_name, "wb" ) ) )
{
msg_Err( p_sout, "cannot open `%s'", psz_name );
free( p_access );
return( -1 );
}
p_sout->i_method = SOUT_METHOD_FILE;
p_sout->p_access_data = p_access;
p_sout->pf_write = Write;
p_sout->pf_seek = Seek;
msg_Info( p_sout, "Open: name:`%s'", psz_name );
return VLC_SUCCESS;
}
/*****************************************************************************
* Close: close the target
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
sout_access_data_t *p_access = (sout_access_data_t*)p_sout->p_access_data;
if( p_access->p_file )
{
fclose( p_access->p_file );
}
msg_Info( p_sout, "Close" );
}
/*****************************************************************************
* Read: standard read on a file descriptor.
*****************************************************************************/
static int Write( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
{
sout_access_data_t *p_access = (sout_access_data_t*)p_sout->p_access_data;
size_t i_write = 0;
do
{
sout_buffer_t *p_next;
i_write += fwrite( p_buffer->p_buffer, 1, p_buffer->i_size,
p_access->p_file );
p_next = p_buffer->p_next;
sout_BufferDelete( p_sout, p_buffer );
p_buffer = p_next;
} while( p_buffer );
msg_Dbg( p_sout, "Write: len:%d", (uint32_t)i_write );
return( i_write );
}
/*****************************************************************************
* Seek: seek to a specific location in a file
*****************************************************************************/
static int Seek( sout_instance_t *p_sout, off_t i_pos )
{
sout_access_data_t *p_access = (sout_access_data_t*)p_sout->p_access_data;
msg_Dbg( p_sout, "Seek: pos:%lld", (int64_t)i_pos );
return( fseek( p_access->p_file, i_pos, SEEK_SET ) );
}
This diff is collapsed.
SOURCES_mux_dummy = modules/mux/dummy.c
/*****************************************************************************
* dummy.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: dummy.c,v 1.1 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* 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
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <vlc/sout.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
# include <io.h>
#endif
#include "codecs.h"
/*****************************************************************************
* Exported prototypes
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static int AddStream( sout_instance_t *, sout_input_t * );
static int DelStream( sout_instance_t *, sout_input_t * );
static int Mux ( sout_instance_t * );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("Dummy muxer") );
set_capability( "sout mux", 5 );
add_shortcut( "dummy" );
set_callbacks( Open, Close );
vlc_module_end();
/*****************************************************************************
* Open:
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
msg_Info( p_sout, "Open" );
p_sout->pf_mux_addstream = AddStream;
p_sout->pf_mux_delstream = DelStream;
p_sout->pf_mux = Mux;
return VLC_SUCCESS;
}
/*****************************************************************************
* Close:
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
sout_instance_t *p_sout = (sout_instance_t*)p_this;
msg_Info( p_sout, "Close" );
}
static int AddStream( sout_instance_t *p_sout, sout_input_t *p_input )
{
msg_Dbg( p_sout, "adding input" );
return( 0 );
}
static int DelStream( sout_instance_t *p_sout, sout_input_t *p_input )
{
msg_Dbg( p_sout, "removing input" );
return( 0 );
}
static int Mux ( sout_instance_t *p_sout )
{
int i;
for( i = 0; i < p_sout->i_nb_inputs; i++ )
{
int i_count;
sout_fifo_t *p_fifo;
p_fifo = p_sout->pp_inputs[i]->p_fifo;
i_count = p_fifo->i_depth;
while( i_count > 0 )
{
sout_buffer_t *p_data;
p_data = sout_FifoGet( p_fifo );
p_sout->pf_write( p_sout, p_data );
i_count--;
}
}
return( 0 );
}
SOURCES_mux_ps = modules/mux/mpeg/ps.c \
modules/mux/mpeg/pes.c \
modules/mux/mpeg/pes.h \
modules/mux/mpeg/bits.h \
$(NULL)
SOURCES_mux_ts = modules/mux/mpeg/ts.c \
modules/mux/mpeg/pes.c \
modules/mux/mpeg/pes.h \
modules/mux/mpeg/bits.h \
$(NULL)
/*****************************************************************************
* bits.h
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: bits.h,v 1.1 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* 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
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
typedef struct bits_buffer_s
{
int i_size;
int i_data;
uint8_t i_mask;
uint8_t *p_data;
} bits_buffer_t;
static inline int bits_initwrite( bits_buffer_t *p_buffer,
int i_size, void *p_data )
{
p_buffer->i_size = i_size;
p_buffer->i_data = 0;
p_buffer->i_mask = 0x80;
p_buffer->p_data = p_data;
p_buffer->p_data[0] = 0;
if( !p_buffer->p_data )
{
if( !( p_buffer->p_data = malloc( i_size ) ) )
{
return( -1 );
}
else
{
return( 0 );
}
}
else
{
return( 0 );
}
}
static inline void bits_align( bits_buffer_t *p_buffer )
{
if( p_buffer->i_mask != 0x80 && p_buffer->i_data < p_buffer->i_size )
{
p_buffer->i_mask = 0x80;
p_buffer->i_data++;
p_buffer->p_data[p_buffer->i_data] = 0x00;
}
}
static inline void bits_write( bits_buffer_t *p_buffer,
int i_count, uint64_t i_bits )
{
while( i_count > 0 )
{
if( i_bits & ( 1 << ( i_count - 1 ) ) )
{
p_buffer->p_data[p_buffer->i_data] |= p_buffer->i_mask;
}
p_buffer->i_mask >>= 1;
if( p_buffer->i_mask == 0 )
{
p_buffer->i_data++;
if( p_buffer->i_data < p_buffer->i_size )
{
p_buffer->p_data[p_buffer->i_data] = 0;
p_buffer->i_mask = 0x80;
}
}
i_count--;
}
}
/*****************************************************************************
* pes.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: pes.c,v 1.1 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* 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
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <vlc/sout.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
# include <io.h>
#endif
#include "codecs.h"
#include "pes.h"
#include "bits.h"
int EStoPES( sout_instance_t *p_sout,
sout_buffer_t **pp_pes,
sout_buffer_t *p_es,
int i_stream_id,
int b_mpeg2 )
{
sout_buffer_t *p_pes;
bits_buffer_t bits;
mtime_t i_pts, i_dts;
uint8_t *p_data;
int i_size;
i_pts = p_es->i_pts * 9 / 100; // 90000 units clock
i_dts = p_es->i_dts * 9 / 100; // 90000 units clock
i_size = p_es->i_size;
p_data = p_es->p_buffer;
*pp_pes = p_pes = NULL;
do
{
int i_copy;
i_copy = __MIN( i_size, 65500 );
if( *pp_pes == NULL )
{
*pp_pes = p_pes = sout_BufferNew( p_sout, 100 + i_copy);
p_pes->i_dts = p_es->i_dts;
p_pes->i_pts = p_es->i_pts;
p_pes->i_length = p_es->i_length;
}
else
{
p_pes->p_next = sout_BufferNew( p_sout, 100 + i_copy );
p_pes = p_pes->p_next;
p_pes->i_dts = 0;
p_pes->i_pts = 0;
p_pes->i_length = 0;
}
p_pes->i_size = 0;
bits_initwrite( &bits, 100, p_pes->p_buffer );
/* first 4 bytes common pes header */
/* add start code for pes 0x000001 */
bits_write( &bits, 24, 0x01 );
/* add stream id */
bits_write( &bits, 8, i_stream_id );
switch( i_stream_id )
{
case PES_PROGRAM_STREAM_MAP:
case PES_PADDING:
case PES_PRIVATE_STREAM_2:
case PES_ECM:
case PES_EMM:
case PES_PROGRAM_STREAM_DIRECTORY:
case PES_DSMCC_STREAM:
case PES_ITU_T_H222_1_TYPE_E_STREAM:
/* add pes data size */
bits_write( &bits, 16, i_copy );
bits_align( &bits );
break;
default:
/* arg, a little more difficult */
if( b_mpeg2 )
{
int i_pts_dts;
if( i_dts > 0 )
{
bits_write( &bits, 16, i_copy + 13 );
i_pts_dts = 0x03;
}
else
{
bits_write( &bits, 16, i_copy + 8 );
i_pts_dts = 0x02;
}
bits_write( &bits, 2, 0x02 ); // mpeg2 id
bits_write( &bits, 2, 0x00 ); // pes scrambling control
bits_write( &bits, 1, 0x00 ); // pes priority
bits_write( &bits, 1, 0x00 ); // data alignement indicator
bits_write( &bits, 1, 0x00 ); // copyright
bits_write( &bits, 1, 0x00 ); // original or copy
bits_write( &bits, 2, i_pts_dts ); // pts_dts flags
bits_write( &bits, 1, 0x00 ); // escr flags
bits_write( &bits, 1, 0x00 ); // es rate flag
bits_write( &bits, 1, 0x00 ); // dsm trick mode flag
bits_write( &bits, 1, 0x00 ); // additional copy info flag
bits_write( &bits, 1, 0x00 ); // pes crc flag
bits_write( &bits, 1, 0x00 ); // pes extention flags
if( i_pts_dts & 0x01 )
{
bits_write( &bits, 8, 0x0a ); // header size -> pts and dts
}
else
{
bits_write( &bits, 8, 0x05 ); // header size -> pts
}
/* write pts */
bits_write( &bits, 4, i_pts_dts ); // '0010' or '0011'
bits_write( &bits, 3, i_pts >> 30 );
bits_write( &bits, 1, 0x01 ); // marker
bits_write( &bits, 15, i_pts >> 15 );
bits_write( &bits, 1, 0x01 ); // marker
bits_write( &bits, 15, i_pts );
bits_write( &bits, 1, 0x01 ); // marker
/* write i_dts */
if( i_pts_dts & 0x01 )
{
bits_write( &bits, 4, 0x01 ); // '0001'
bits_write( &bits, 3, i_dts >> 30 );
bits_write( &bits, 1, 0x01 ); // marker
bits_write( &bits, 15, i_dts >> 15 );
bits_write( &bits, 1, 0x01 ); // marker
bits_write( &bits, 15, i_dts );
bits_write( &bits, 1, 0x01 ); // marker
i_dts = 0; // write dts only once
}
}
else
{
msg_Warn( p_sout, "es isn't mpeg2 -->corrupted pes" );
}
/* now should be stuffing */
/* and then pes data */
bits_align( &bits );
break;
}
if( i_copy > 0 )
{
memcpy( p_pes->p_buffer + bits.i_data, p_data, i_copy );
}
i_size -= i_copy;
p_data += i_copy;
p_pes->i_size = bits.i_data + i_copy;
} while( i_size > 0 );
sout_BufferDelete( p_sout, p_es );
return( 0 );
}
/*****************************************************************************
* pes.h
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: pes.h,v 1.1 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* 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
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define PES_PROGRAM_STREAM_MAP 0xbc
#define PES_PADDING 0xbe
#define PES_PRIVATE_STREAM_2 0xbf
#define PES_ECM 0xb0
#define PES_EMM 0xb1
#define PES_PROGRAM_STREAM_DIRECTORY 0xff
#define PES_DSMCC_STREAM 0xf2
#define PES_ITU_T_H222_1_TYPE_E_STREAM 0xf8
int EStoPES( sout_instance_t *p_sout,
sout_buffer_t **pp_pes, sout_buffer_t *p_es,
int i_stream_id, int b_mpeg2 );
This diff is collapsed.
This diff is collapsed.
SOURCES_packetizer_copy = modules/packetizer/copy.c
SOURCES_packetizer_a52 = modules/packetizer/a52.c
SOURCES_packetizer_mpegaudio = modules/packetizer/mpegaudio.c
SOURCES_packetizer_mpegvideo = modules/packetizer/mpegvideo.c
SOURCES_packetizer_mpeg4video = modules/packetizer/mpeg4video.c
This diff is collapsed.
/*****************************************************************************
* copy.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: copy.c,v 1.1 2002/12/14 21:32:41 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* 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
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <vlc/vlc.h>
#include <vlc/aout.h>
#include <vlc/decoder.h>
#include <vlc/input.h>
#include <vlc/sout.h>
#include <stdlib.h> /* malloc(), free() */
#include <string.h> /* strdup() */
/*****************************************************************************
* Local prototypes
*****************************************************************************/
typedef struct packetizer_thread_s
{
/* Input properties */
decoder_fifo_t *p_fifo;
/* Output properties */
sout_input_t *p_sout_input;
sout_packet_format_t output_format;
} packetizer_thread_t;
static int Open ( vlc_object_t * );
static int Run ( decoder_fifo_t * );
static int InitThread ( packetizer_thread_t * );
static void PacketizeThread ( packetizer_thread_t * );
static void EndThread ( packetizer_thread_t * );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("Copy packetizer") );
set_capability( "packetizer", 0 );
set_callbacks( Open, NULL );
vlc_module_end();
/*****************************************************************************
* OpenDecoder: probe the packetizer and return score
*****************************************************************************
* Tries to launch a decoder and return score so that the interface is able
* to choose.
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
p_fifo->pf_run = Run;
return VLC_SUCCESS;
#if 0
if( p_fifo->i_fourcc == VLC_FOURCC( 'm', 'p', 'g', 'a') )
....
#endif
}
/*****************************************************************************
* RunDecoder: this function is called just after the thread is created
*****************************************************************************/
static int Run( decoder_fifo_t *p_fifo )
{
packetizer_thread_t *p_pack;
int b_error;
msg_Info( p_fifo, "Running copy packetizer" );
if( !( p_pack = malloc( sizeof( packetizer_thread_t ) ) ) )
{
msg_Err( p_fifo, "out of memory" );
DecoderError( p_fifo );
return( -1 );
}
memset( p_pack, 0, sizeof( packetizer_thread_t ) );
p_pack->p_fifo = p_fifo;
if( InitThread( p_pack ) != 0 )
{
DecoderError( p_fifo );
return( -1 );
}
while( ( !p_pack->p_fifo->b_die )&&( !p_pack->p_fifo->b_error ) )
{
PacketizeThread( p_pack );
}
if( ( b_error = p_pack->p_fifo->b_error ) )
{
DecoderError( p_pack->p_fifo );
}
EndThread( p_pack );
if( b_error )
{
return( -1 );
}
return( 0 );
}
#define FREE( p ) if( p ) free( p ); p = NULL
/*****************************************************************************
* InitThread: initialize data before entering main loop
*****************************************************************************/
static int InitThread( packetizer_thread_t *p_pack )
{
// p_pack->output_format.i_cat = p_pack->p_fifo->i_cat;
p_pack->output_format.i_fourcc = p_pack->p_fifo->i_fourcc;
p_pack->p_sout_input =
sout_InputNew( p_pack->p_fifo,
&p_pack->output_format );
if( !p_pack->p_sout_input )
{
msg_Err( p_pack->p_fifo,
"cannot add a new stream" );
return( -1 );
}
return( 0 );
}
/*****************************************************************************
* PacketizeThread: packetize an unit (here copy a complete pes)
*****************************************************************************/
static void PacketizeThread( packetizer_thread_t *p_pack )
{
sout_buffer_t *p_sout_buffer;
pes_packet_t *p_pes;
size_t i_size;
/* **** get samples count **** */
input_ExtractPES( p_pack->p_fifo, &p_pes );
if( !p_pes )
{
p_pack->p_fifo->b_error = 1;
return;
}
i_size = p_pes->i_pes_size;
if( i_size > 0 )
{
data_packet_t *p_data;
size_t i_buffer;
p_sout_buffer =
sout_BufferNew( p_pack->p_sout_input->p_sout, i_size );
if( !p_sout_buffer )
{
p_pack->p_fifo->b_error = 1;
return;
}
/* TODO: memcpy of the pes packet */
for( i_buffer = 0, p_data = p_pes->p_first;
p_data != NULL && i_buffer < i_size;
p_data = p_data->p_next)
{
size_t i_copy;
i_copy = __MIN( p_data->p_payload_end - p_data->p_payload_start,
i_size - i_buffer );
if( i_copy > 0 )
{
p_pack->p_fifo->p_vlc->pf_memcpy( p_sout_buffer->p_buffer + i_buffer,
p_data->p_payload_start,
i_copy );
}
i_buffer += i_copy;
}
sout_InputSendBuffer( p_pack->p_sout_input,
p_sout_buffer );
}
input_DeletePES( p_pack->p_fifo->p_packets_mgt, p_pes );
}
/*****************************************************************************
* EndThread : packetizer thread destruction
*****************************************************************************/
static void EndThread ( packetizer_thread_t *p_pack)
{
if( p_pack->p_sout_input )
{
sout_InputDelete( p_pack->p_sout_input );
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@
* input_dec.c: Functions for the management of decoders
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: input_dec.c,v 1.52 2002/12/06 16:34:08 sam Exp $
* $Id: input_dec.c,v 1.53 2002/12/14 21:32:42 fenrir Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -44,6 +44,7 @@ static void DeleteDecoderFifo( decoder_fifo_t * );
decoder_fifo_t * input_RunDecoder( input_thread_t * p_input,
es_descriptor_t * p_es )
{
char *psz_sout;
decoder_fifo_t *p_fifo;
int i_priority;
......@@ -56,8 +57,23 @@ decoder_fifo_t * input_RunDecoder( input_thread_t * p_input,
return NULL;
}
p_fifo->p_module = NULL;
/* If we are in sout mode, search first for packetizer module then
* codec to do transcoding */
psz_sout = config_GetPsz( p_input, "sout" );
if( psz_sout != NULL && *psz_sout != 0 )
{
p_fifo->p_module = module_Need( p_fifo, "packetizer", "$packetizer" );
}
/* default Get a suitable decoder module */
if( p_fifo->p_module == NULL )
{
p_fifo->p_module = module_Need( p_fifo, "decoder", "$codec" );
}
#if 0
/* Get a suitable module */
p_fifo->p_module = module_Need( p_fifo, "decoder", "$codec" );
#endif
if( p_fifo->p_module == NULL )
{
msg_Err( p_fifo, "no suitable decoder module for fourcc `%4.4s'",
......
......@@ -2,7 +2,7 @@
* libvlc.h: main libvlc header
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: libvlc.h,v 1.28 2002/12/09 00:52:42 babal Exp $
* $Id: libvlc.h,v 1.29 2002/12/14 21:32:42 fenrir Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -283,6 +283,17 @@
#define SOUT_TEXT N_("choose a stream output")
#define SOUT_LONGTEXT N_( \
"Empty if no stream output.")
#define PACKETIZER_TEXT N_("choose prefered packetizer list")
#define PACKETIZER_LONGTEXT N_( \
"This allows you to select the order in which vlc will choose its " \
"packetizers." )
#define MUX_TEXT N_("mux module")
#define MUX_LONGTEXT N_( \
"This is a legacy entry to let you configure mux modules")
#define ACCESS_OUTPUT_TEXT N_("access output module")
#define ACCESS_OUTPUT_LONGTEXT N_( \
"This is a legacy entry to let you configure access output modules")
#define MMX_TEXT N_("enable CPU MMX support")
#define MMX_LONGTEXT N_( \
......@@ -475,6 +486,13 @@ vlc_module_begin();
add_category_hint( N_("Decoders"), NULL );
add_module( "codec", "decoder", NULL, NULL, CODEC_TEXT, CODEC_LONGTEXT );
/* Stream output */
add_category_hint( N_("Stream output"), NULL );
add_module( "packetizer", "packetizer", NULL, NULL, PACKETIZER_TEXT, PACKETIZER_LONGTEXT );
add_module( "mux", "mux", NULL, NULL, MUX_TEXT, MUX_LONGTEXT );
add_module( "access_output", "access_output", NULL, NULL, ACCESS_OUTPUT_TEXT, ACCESS_OUTPUT_LONGTEXT );
add_string( "sout", NULL, NULL, SOUT_TEXT, SOUT_LONGTEXT );
/* CPU options */
add_category_hint( N_("CPU"), NULL );
#if defined( __i386__ )
......@@ -504,7 +522,6 @@ vlc_module_begin();
add_module( "memcpy", "memcpy", NULL, NULL, MEMCPY_TEXT, MEMCPY_LONGTEXT );
add_module( "access", "access", NULL, NULL, ACCESS_TEXT, ACCESS_LONGTEXT );
add_module( "demux", "demux", NULL, NULL, DEMUX_TEXT, DEMUX_LONGTEXT );
add_string( "sout", NULL, NULL, SOUT_TEXT, SOUT_LONGTEXT );
#if defined(WIN32)
add_bool( "fast-mutex", 0, NULL, FAST_MUTEX_TEXT, FAST_MUTEX_LONGTEXT );
......
This diff is collapsed.
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