• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* MPEG-PS muxer plugin for GStreamer
2  * Copyright 2008 Lin YANG <oxcsnicho@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 /*
20  * Unless otherwise indicated, Source Code is licensed under MIT license.
21  * See further explanation attached in License Statement (distributed in the file
22  * LICENSE).
23  *
24  * Permission is hereby granted, free of charge, to any person obtaining a copy of
25  * this software and associated documentation files (the "Software"), to deal in
26  * the Software without restriction, including without limitation the rights to
27  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28  * of the Software, and to permit persons to whom the Software is furnished to do
29  * so, subject to the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be included in all
32  * copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40  * SOFTWARE.
41  */
42 
43 
44 
45 #ifndef __PSMUX_H__
46 #define __PSMUX_H__
47 
48 #include <glib.h>
49 
50 #include "psmuxcommon.h"
51 #include "psmuxstream.h"
52 
53 G_BEGIN_DECLS
54 
55 #define PSMUX_MAX_ES_INFO_LENGTH ((1 << 12) - 1)
56 
57 typedef gboolean (*PsMuxWriteFunc) (guint8 *data, guint len, void *user_data);
58 
59 struct PsMux {
60   GList *streams;    /* PsMuxStream* array of all streams */
61   guint nb_streams;
62   guint nb_private_streams;
63   PsMuxStreamIdInfo id_info; /* carrying the info which ids are used */
64 
65   /* timestamps: pts */
66   GstClockTime pts;
67 
68   guint32 pes_cnt; /* # of pes that has been created */
69   guint16 pes_max_payload; /* maximum payload size in pes packets */
70 
71   guint64 bit_size;  /* accumulated bit size of processed data */
72   guint bit_rate;  /* bit rate */
73   GstClockTime bit_pts; /* last time the bit_rate is updated */
74 
75   guint pack_hdr_freq; /* PS pack header frequency */
76   GstClockTime pack_hdr_pts; /* last time a pack header is written */
77 
78   guint sys_hdr_freq; /* system header frequency */
79   GstClockTime sys_hdr_pts; /* last time a system header is written */
80 
81   guint psm_freq; /* program stream map frequency */
82   GstClockTime psm_pts; /* last time a psm is written */
83 
84   guint8 packet_buf[PSMUX_MAX_PACKET_LEN];
85   guint packet_bytes_written; /* # of bytes written in the buf */
86   PsMuxWriteFunc write_func;
87   void *write_func_data;
88 
89   /* Scratch space for writing ES_info descriptors */
90   guint8 es_info_buf[PSMUX_MAX_ES_INFO_LENGTH];
91 
92   /* bounds in system header */
93   guint8 audio_bound;
94   guint8 video_bound;
95   guint32 rate_bound;
96 
97   /* stream headers */
98   GstBuffer *sys_header;
99   GstBuffer *psm;
100 };
101 
102 /* create/free new muxer session */
103 PsMux *		psmux_new 			(void);
104 void 		psmux_free 			(PsMux *mux);
105 
106 /* Setting muxing session properties */
107 void 		psmux_set_write_func 		(PsMux *mux, PsMuxWriteFunc func, void *user_data);
108 
109 /* stream management */
110 PsMuxStream *	psmux_create_stream 		(PsMux *mux, PsMuxStreamType stream_type);
111 
112 /* writing stuff */
113 gboolean 	psmux_write_stream_packet 	(PsMux *mux, PsMuxStream *stream);
114 gboolean	psmux_write_end_code		(PsMux *mux);
115 
116 GList *		psmux_get_stream_headers	(PsMux *mux);
117 
118 G_END_DECLS
119 
120 #endif
121