Commit adb4130e authored by Lin Yang's avatar Lin Yang Committed by Sebastian Dröge

mpegpsmux: Add MPEG PS muxer

parent de1f0577
......@@ -274,6 +274,7 @@ AG_GST_CHECK_PLUGIN(librfb)
AG_GST_CHECK_PLUGIN(liveadder)
AG_GST_CHECK_PLUGIN(mpegdemux)
AG_GST_CHECK_PLUGIN(mpegtsmux)
AG_GST_CHECK_PLUGIN(mpegpsmux)
AG_GST_CHECK_PLUGIN(mpeg4videoparse)
AG_GST_CHECK_PLUGIN(mpegvideoparse)
AG_GST_CHECK_PLUGIN(mve)
......@@ -1724,6 +1725,7 @@ gst/liveadder/Makefile
gst/mpegdemux/Makefile
gst/mpegtsmux/Makefile
gst/mpegtsmux/tsmux/Makefile
gst/mpegpsmux/Makefile
gst/mpeg4videoparse/Makefile
gst/mpegvideoparse/Makefile
gst/mve/Makefile
......
plugin_LTLIBRARIES = libgstmpegpsmux.la
libgstmpegpsmux_la_SOURCES = \
mpegpsmux.c \
psmux.c \
psmuxstream.c \
mpegpsmux_aac.c \
mpegpsmux_h264.c
libgstmpegpsmux_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CLFAGS)
libgstmpegpsmux_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS)
libgstmpegpsmux_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstmpegpsmux_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = \
mpegpsmux.h \
psmux.h \
psmuxstream.h \
psmuxcommon.h \
mpegpsmux_aac.h \
mpegpsmux_h264.h \
bits.h \
crc.h
/*****************************************************************************
* bits.h
*****************************************************************************
* Copyright (C) 2001, 2002 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
*
* Copyright (C) 2008 Lin YANG <oxcsnicho@gmail.com>
*
* 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef __BITS_H__
#define __BITS_H__
#include <glib.h>
G_BEGIN_DECLS
typedef struct bits_buffer_s
{
gint i_size;
gint i_data;
guint8 i_mask;
guint8* p_data;
} bits_buffer_t;
static inline gint bits_initwrite( bits_buffer_t *p_buffer,
gint 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;
if( !p_buffer->p_data )
{
if( !( p_buffer->p_data = g_slice_alloc0( i_size ) ) )
return -1;
}
p_buffer->p_data[0] = 0;
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,
gint i_count, guint64 i_bits )
{
while( i_count > 0 )
{
i_count--;
if( ( i_bits >> i_count )&0x01 )
{
p_buffer->p_data[p_buffer->i_data] |= p_buffer->i_mask;
}
else
{
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++;
p_buffer->i_mask = 0x80;
}
}
}
G_END_DECLS
#endif
/* MPEG-PS muxer plugin for GStreamer
* Copyright 2008 Lin YANG <oxcsnicho@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* See further explanation attached in License Statement (distributed in the file
* LICENSE).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
static guint32 crc_tab[256] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
static guint32
calc_crc32 (guint8 *data, guint datalen)
{
guint i;
guint32 crc = 0xffffffff;
for (i=0; i<datalen; i++) {
crc = (crc << 8) ^ crc_tab[((crc >> 24) ^ *data++) & 0xff];
}
return crc;
}
This diff is collapsed.
/* MPEG-PS muxer plugin for GStreamer
* Copyright 2008 Lin YANG <oxcsnicho@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* See further explanation attached in License Statement (distributed in the file
* LICENSE).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __MPEGPSMUX_H__
#define __MPEGPSMUX_H__
#include <gst/gst.h>
#include <gst/base/gstcollectpads.h>
#include <gst/base/gstadapter.h>
G_BEGIN_DECLS
#include "psmux.h"
#define GST_TYPE_MPEG_PSMUX (mpegpsmux_get_type())
#define GST_MPEG_PSMUX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MPEG_PSMUX, MpegPsMux))
typedef struct MpegPsMux MpegPsMux;
typedef struct MpegPsMuxClass MpegPsMuxClass;
typedef struct MpegPsPadData MpegPsPadData;
typedef GstBuffer * (*MpegPsPadDataPrepareFunction) (GstBuffer * buf,
MpegPsPadData * data, MpegPsMux * mux);
struct MpegPsMux {
GstElement parent;
GstPad *srcpad;
GstCollectPads *collect; // pads collector
PsMux *psmux;
gboolean first;
GstFlowReturn last_flow_ret;
GstClockTime last_ts;
};
struct MpegPsMuxClass {
GstElementClass parent_class;
};
struct MpegPsPadData {
GstCollectData collect; /* Parent */
guint8 stream_id;
guint8 stream_id_ext;
PsMuxStream *stream;
GstBuffer *queued_buf; /* Currently pulled buffer */
GstClockTime cur_ts; /* Adjusted TS for the pulled buffer */
GstClockTime last_ts; /* Most recent valid TS for this stream */
GstBuffer * codec_data; /* Optional codec data available in the caps */
MpegPsPadDataPrepareFunction prepare_func; /* Handler to prepare input data */
gboolean eos;
};
GType mpegpsmux_get_type (void);
#define CLOCK_BASE 9LL
#define CLOCK_FREQ (CLOCK_BASE * 10000)
#define MPEGTIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \
GST_MSECOND/10, CLOCK_BASE))
#define GSTTIME_TO_MPEGTIME(time) (gst_util_uint64_scale ((time), \
CLOCK_BASE, GST_MSECOND/10))
#define NORMAL_TS_PACKET_LENGTH 188
#define M2TS_PACKET_LENGTH 192
#define STANDARD_TIME_CLOCK 27000000
/*33 bits as 1 ie 0x1ffffffff*/
#define TWO_POW_33_MINUS1 ((0xffffffff * 2) - 1)
G_END_DECLS
#endif
This diff is collapsed.
/* MPEG-PS muxer plugin for GStreamer
* Copyright 2008 Lin YANG <oxcsnicho@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* See further explanation attached in License Statement (distributed in the file
* LICENSE).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __PSMUX_H__
#define __PSMUX_H__
#include <glib.h>
#include "psmuxcommon.h"
#include "psmuxstream.h"
G_BEGIN_DECLS
#define PSMUX_MAX_ES_INFO_LENGTH ((1 << 12) - 1)
typedef gboolean (*PsMuxWriteFunc) (guint8 *data, guint len, void *user_data);
struct PsMux {
GList *streams; /* PsMuxStream* array of all streams */
guint nb_streams;
guint nb_private_streams;
PsMuxStreamIdInfo id_info; /* carrying the info which ids are used */
/* timestamps: pts */
GstClockTime pts;
guint32 pes_cnt; /* # of pes that has been created */
guint16 pes_max_payload; /* maximum payload size in pes packets */
guint64 bit_size; /* accumulated bit size of processed data */
guint bit_rate; /* bit rate */
GstClockTime bit_pts; /* last time the bit_rate is updated */
guint pack_hdr_freq; /* PS pack header frequency */
GstClockTime pack_hdr_pts; /* last time a pack header is written */
guint sys_hdr_freq; /* system header frequency */
GstClockTime sys_hdr_pts; /* last time a system header is written */
guint psm_freq; /* program stream map frequency */
GstClockTime psm_pts; /* last time a psm is written */
guint8 packet_buf[PSMUX_MAX_PACKET_LEN];
guint packet_bytes_written; /* # of bytes written in the buf */
PsMuxWriteFunc write_func;
void *write_func_data;
/* Scratch space for writing ES_info descriptors */
guint8 es_info_buf[PSMUX_MAX_ES_INFO_LENGTH];
/* bounds in system header */
guint8 audio_bound;
guint8 video_bound;
guint32 rate_bound;
};
/* create/free new muxer session */
PsMux * psmux_new (void);
void psmux_free (PsMux *mux);
/* Setting muxing session properties */
void psmux_set_write_func (PsMux *mux, PsMuxWriteFunc func, void *user_data);
/* stream management */
PsMuxStream * psmux_create_stream (PsMux *mux, PsMuxStreamType stream_type);
/* writing stuff */
gboolean psmux_write_stream_packet (PsMux *mux, PsMuxStream *stream);
gboolean psmux_write_end_code (PsMux *mux);
G_END_DECLS
#endif
/* MPEG-PS muxer plugin for GStreamer
* Copyright 2008 Lin YANG <oxcsnicho@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* See further explanation attached in License Statement (distributed in the file
* LICENSE).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __PSMUX_COMMON_H__
#define __PSMUX_COMMON_H__
#include <glib.h>
#include <gst/gst.h>
#include "bits.h" /* from VLC */
#undef PS_DEBUG_ON
G_BEGIN_DECLS
#define PSMUX_PACK_HDR_FREQ 30
#define PSMUX_SYS_HDR_FREQ 300
#define PSMUX_PSM_FREQ 300
#define PSMUX_PES_MAX_PAYLOAD 65500 /* from VLC */
#define PSMUX_PES_MAX_HDR_LEN 30
#define PSMUX_MAX_PACKET_LEN (PSMUX_PES_MAX_PAYLOAD + PSMUX_PES_MAX_HDR_LEN)
#define CLOCKBASE 90000
#define PSMUX_PACK_HDR_INTERVAL ( 0.7 * CLOCKBASE) /* interval to update pack header. 0.7 sec */
#define PSMUX_BITRATE_CALC_INTERVAL CLOCKBASE /* interval to update bitrate in pack header. 1 sec */
#define PSMUX_PES_BITRATE_DEFAULT 1000 /* Default bit_rate to write in the first pack header */
#define PSMUX_START_CODE_PREFIX 0x01
/* stream_id */
#define PSMUX_PACK_HEADER 0xba
#define PSMUX_SYSTEM_HEADER 0xbb
#define PSMUX_PROGRAM_STREAM_MAP 0xbc
#define PSMUX_PRIVATE_STREAM_1 0xbd
#define PSMUX_PADDING_STREAM 0xbe
#define PSMUX_PRIVATE_STREAM_2 0xbf
#define PSMUX_ECM 0xb0
#define PSMUX_EMM 0xb1
#define PSMUX_PROGRAM_STREAM_DIRECTORY 0xff
#define PSMUX_DSMCC_STREAM 0xf2
#define PSMUX_ITU_T_H222_1_TYPE_E 0xf8
#define PSMUX_EXTENDED_STREAM 0xfd
#define PSMUX_PROGRAM_END 0xb9
#define PSMUX_MIN_ES_DESC_LEN 8
/* Frequency for PCR representation */
#define PSMUX_SYS_CLOCK_FREQ (27000000L)
/* Frequency for PTS values */
#define PSMUX_CLOCK_FREQ (PSMUX_SYS_CLOCK_FREQ / 300)
/* TODO: flags? looks that we don't need these */
#define PSMUX_PACKET_FLAG_NONE (0)
#define PSMUX_PACKET_FLAG_ADAPTATION (1 << 0)
#define PSMUX_PACKET_FLAG_DISCONT (1 << 1)
#define PSMUX_PACKET_FLAG_RANDOM_ACCESS (1 << 2)
#define PSMUX_PACKET_FLAG_PRIORITY (1 << 3)
#define PSMUX_PACKET_FLAG_WRITE_PCR (1 << 4)
#define PSMUX_PACKET_FLAG_WRITE_OPCR (1 << 5)
#define PSMUX_PACKET_FLAG_WRITE_SPLICE (1 << 6)
#define PSMUX_PACKET_FLAG_WRITE_ADAPT_EXT (1 << 7)
/* PES stream specific flags */
#define PSMUX_PACKET_FLAG_PES_FULL_HEADER (1 << 8)
#define PSMUX_PACKET_FLAG_PES_WRITE_PTS (1 << 9)
#define PSMUX_PACKET_FLAG_PES_WRITE_PTS_DTS (1 << 10)
#define PSMUX_PACKET_FLAG_PES_WRITE_ESCR (1 << 11)
#define PSMUX_PACKET_FLAG_PES_EXT_STREAMID (1 << 12)
#define PSMUX_PACKET_FLAG_PES_DATA_ALIGN (1 << 13)
typedef struct PsMuxPacketInfo PsMuxPacketInfo;
typedef struct PsMuxProgram PsMuxProgram;
typedef struct PsMuxStream PsMuxStream;
typedef struct PsMuxStreamIdInfo PsMuxStreamIdInfo;
typedef struct PsMux PsMux;
typedef enum PsMuxStreamType PsMuxStreamType;
typedef struct PsMuxStreamBuffer PsMuxStreamBuffer;
/* clearup and see if we need this anymore */
struct PsMuxPacketInfo {
guint32 flags;
};
/* bitstream writers */
static inline void
psmux_put16 (guint8 **pos, guint16 val)
{
*(*pos)++ = (val >> 8) & 0xff;
*(*pos)++ = val & 0xff;
}
static inline void
psmux_put32 (guint8 **pos, guint32 val)
{
*(*pos)++ = (val >> 24) & 0xff;
*(*pos)++ = (val >> 16) & 0xff;
*(*pos)++ = (val >> 8) & 0xff;
*(*pos)++ = val & 0xff;
}
static inline void
psmux_put_ts (guint8 **pos, guint8 id, gint64 ts)
{
/* 1: 4 bit id value | TS [32..30] | marker_bit */
*(*pos)++ = ((id << 4) | ((ts >> 29) & 0x0E) | 0x01) & 0xff;
/* 2, 3: TS[29..15] | marker_bit */
psmux_put16 (pos, ((ts >> 14) & 0xfffe) | 0x01);
/* 4, 5: TS[14..0] | marker_bit */
psmux_put16 (pos, ((ts << 1) & 0xfffe) | 0x01);
}
#ifdef PS_DEBUG_ON
#define PS_DEBUG(...) g_print(__VA_ARGS__); g_print ("\n")
#else
#define PS_DEBUG(...)
#endif
G_END_DECLS
#endif
This diff is collapsed.
/* MPEG-PS muxer plugin for GStreamer
* Copyright 2008 Lin YANG <oxcsnicho@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Unless otherwise indicated, Source Code is licensed under MIT license.
* See further explanation attached in License Statement (distributed in the file
* LICENSE).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __PSMUXSTREAM_H__
#define __PSMUXSTREAM_H__
#include <glib.h>
#include "psmuxcommon.h"
G_BEGIN_DECLS
typedef void (*PsMuxStreamBufferReleaseFunc) (guint8 *data, void *user_data);
enum PsMuxStreamType { /* Table 2-29 in spec */
PSMUX_ST_RESERVED = 0x00,
PSMUX_ST_VIDEO_MPEG1 = 0x01,
PSMUX_ST_VIDEO_MPEG2 = 0x02,
PSMUX_ST_AUDIO_MPEG1 = 0x03,
PSMUX_ST_AUDIO_MPEG2 = 0x04,
PSMUX_ST_PRIVATE_SECTIONS = 0x05,
PSMUX_ST_PRIVATE_DATA = 0x06,
PSMUX_ST_MHEG = 0x07,
PSMUX_ST_DSMCC = 0x08,
PSMUX_ST_H222_1 = 0x09,
/* later extensions */
PSMUX_ST_AUDIO_AAC = 0x0f,
PSMUX_ST_VIDEO_MPEG4 = 0x10,
PSMUX_ST_VIDEO_H264 = 0x1b,
/* private stream types */
PSMUX_ST_PS_AUDIO_AC3 = 0x81,
PSMUX_ST_PS_AUDIO_DTS = 0x8a,
PSMUX_ST_PS_AUDIO_LPCM = 0x8b,
PSMUX_ST_PS_DVD_SUBPICTURE = 0xff,
/* Non-standard definitions */
PSMUX_ST_VIDEO_DIRAC = 0xD1
};
struct PsMuxStreamBuffer
{
guint8 *data;
guint32 size;
/* PTS & DTS associated with the contents of this buffer */
GstClockTime pts;
GstClockTime dts;
void *user_data;
};
/* PsMuxStream receives elementary streams for parsing.
* Via the write_bytes() method, it can output a PES stream piecemeal */
struct PsMuxStream{
PsMuxPacketInfo pi;
PsMuxStreamType stream_type;
guint8 stream_id;
guint8 stream_id_ext; /* extended stream id (13818-1 Amdt 2) */
/* List of data buffers available for writing out */
GList *buffers;
guint32 bytes_avail;
/* Current data buffer being consumed */
PsMuxStreamBuffer *cur_buffer;