2
* Copyright 2006 BBC and Fluendo S.A.
4
* This library is licensed under 4 different licenses and you
5
* can choose to use it under the terms of any one of them. The
6
* four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
11
* The contents of this file are subject to the Mozilla Public License
12
* Version 1.1 (the "License"); you may not use this file except in
13
* compliance with the License. You may obtain a copy of the License at
14
* http://www.mozilla.org/MPL/.
16
* Software distributed under the License is distributed on an "AS IS"
17
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18
* License for the specific language governing rights and limitations
23
* This library is free software; you can redistribute it and/or
24
* modify it under the terms of the GNU Library General Public
25
* License as published by the Free Software Foundation; either
26
* version 2 of the License, or (at your option) any later version.
28
* This library is distributed in the hope that it will be useful,
29
* but WITHOUT ANY WARRANTY; without even the implied warranty of
30
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31
* Library General Public License for more details.
33
* You should have received a copy of the GNU Library General Public
34
* License along with this library; if not, write to the
35
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
36
* Boston, MA 02111-1307, USA.
40
* This program is free software; you can redistribute it and/or modify
41
* it under the terms of the GNU General Public License as published by
42
* the Free Software Foundation; either version 2 of the License, or
43
* (at your option) any later version.
45
* This program is distributed in the hope that it will be useful,
46
* but WITHOUT ANY WARRANTY; without even the implied warranty of
47
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48
* GNU General Public License for more details.
50
* You should have received a copy of the GNU General Public License
51
* along with this program; if not, write to the Free Software
52
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
56
* Unless otherwise indicated, Source Code is licensed under MIT license.
57
* See further explanation attached in License Statement (distributed in the file
60
* Permission is hereby granted, free of charge, to any person obtaining a copy of
61
* this software and associated documentation files (the "Software"), to deal in
62
* the Software without restriction, including without limitation the rights to
63
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
64
* of the Software, and to permit persons to whom the Software is furnished to do
65
* so, subject to the following conditions:
67
* The above copyright notice and this permission notice shall be included in all
68
* copies or substantial portions of the Software.
70
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
71
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
72
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
73
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
74
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
75
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
80
#ifndef __TSMUXSTREAM_H__
81
#define __TSMUXSTREAM_H__
85
#include "tsmuxcommon.h"
89
typedef enum TsMuxStreamType TsMuxStreamType;
90
typedef enum TsMuxStreamState TsMuxStreamState;
91
typedef struct TsMuxStreamBuffer TsMuxStreamBuffer;
93
typedef void (*TsMuxStreamBufferReleaseFunc) (guint8 *data, void *user_data);
95
/* Stream type assignments
97
* 0x00 ITU-T | ISO/IEC Reserved
98
* 0x01 ISO/IEC 11172 Video
99
* 0x02 ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or
100
* ISO/IEC 11172-2 constrained parameter video
102
* 0x03 ISO/IEC 11172 Audio
103
* 0x04 ISO/IEC 13818-3 Audio
104
* 0x05 ITU-T Rec. H.222.0 | ISO/IEC 13818-1
106
* 0x06 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES
107
* packets containing private data
108
* 0x07 ISO/IEC 13522 MHEG
109
* 0x08 ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A
111
* 0x09 ITU-T Rec. H.222.1
112
* 0x0A ISO/IEC 13818-6 type A
113
* 0x0B ISO/IEC 13818-6 type B
114
* 0x0C ISO/IEC 13818-6 type C
115
* 0x0D ISO/IEC 13818-6 type D
116
* 0x0E ISO/IEC 13818-1 auxiliary
117
* 0x0F-0x7F ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
118
* 0x80-0xFF User Private
120
enum TsMuxStreamType {
121
TSMUX_ST_RESERVED = 0x00,
122
TSMUX_ST_VIDEO_MPEG1 = 0x01,
123
TSMUX_ST_VIDEO_MPEG2 = 0x02,
124
TSMUX_ST_AUDIO_MPEG1 = 0x03,
125
TSMUX_ST_AUDIO_MPEG2 = 0x04,
126
TSMUX_ST_PRIVATE_SECTIONS = 0x05,
127
TSMUX_ST_PRIVATE_DATA = 0x06,
128
TSMUX_ST_MHEG = 0x07,
129
TSMUX_ST_DSMCC = 0x08,
130
TSMUX_ST_H222_1 = 0x09,
132
/* later extensions */
133
TSMUX_ST_AUDIO_AAC = 0x0f,
134
TSMUX_ST_VIDEO_MPEG4 = 0x10,
135
TSMUX_ST_VIDEO_H264 = 0x1b,
137
/* private stream types */
138
TSMUX_ST_PS_AUDIO_AC3 = 0x81,
139
TSMUX_ST_PS_AUDIO_DTS = 0x8a,
140
TSMUX_ST_PS_AUDIO_LPCM = 0x8b,
141
TSMUX_ST_PS_DVD_SUBPICTURE = 0xff,
143
/* Non-standard definitions */
144
TSMUX_ST_VIDEO_DIRAC = 0xD1
147
enum TsMuxStreamState {
148
TSMUX_STREAM_STATE_HEADER,
149
TSMUX_STREAM_STATE_PACKET
152
/* TsMuxStream receives elementary streams for parsing.
153
* Via the write_bytes() method, it can output a PES stream piecemeal */
155
TsMuxStreamState state;
157
TsMuxStreamType stream_type;
158
guint8 id; /* stream id */
159
guint8 id_extended; /* extended stream id (13818-1 Amdt 2) */
161
gboolean is_video_stream;
163
/* List of data buffers available for writing out */
167
/* Current data buffer being consumed */
168
TsMuxStreamBuffer *cur_buffer;
169
guint32 cur_buffer_consumed;
171
TsMuxStreamBufferReleaseFunc buffer_release;
173
guint16 pes_payload_size;
174
guint16 cur_pes_payload_size;
175
guint16 pes_bytes_written;
177
/* PTS/DTS to write if the flags in the packet info are set */
192
/* stream management */
193
TsMuxStream * tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type);
194
void tsmux_stream_free (TsMuxStream *stream);
196
guint16 tsmux_stream_get_pid (TsMuxStream *stream);
198
void tsmux_stream_set_buffer_release_func (TsMuxStream *stream,
199
TsMuxStreamBufferReleaseFunc func);
201
/* Add a new buffer to the pool of available bytes. If pts or dts are not -1, they
202
* indicate the PTS or DTS of the first access unit within this packet */
203
void tsmux_stream_add_data (TsMuxStream *stream, guint8 *data, guint len,
204
void *user_data, gint64 pts, gint64 dts);
206
void tsmux_stream_pcr_ref (TsMuxStream *stream);
207
void tsmux_stream_pcr_unref (TsMuxStream *stream);
208
gboolean tsmux_stream_is_pcr (TsMuxStream *stream);
210
gboolean tsmux_stream_at_pes_start (TsMuxStream *stream);
211
void tsmux_stream_get_es_descrs (TsMuxStream *stream, guint8 *buf, guint16 *len);
213
gint tsmux_stream_bytes_in_buffer (TsMuxStream *stream);
214
gint tsmux_stream_bytes_avail (TsMuxStream *stream);
215
gboolean tsmux_stream_get_data (TsMuxStream *stream, guint8 *buf, guint len);
217
guint64 tsmux_stream_get_pts (TsMuxStream *stream);