summaryrefslogtreecommitdiffstats
path: root/gst/mpegtsmux
diff options
context:
space:
mode:
authorvanista <vanista@gmail.com>2009-01-05 11:28:49 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2009-01-05 11:28:49 +0000
commit751555b5c3839b19274565ef65c6189c494a6924 (patch)
tree05653635b4e46e7eef4c9b89658df007a57c7c54 /gst/mpegtsmux
parentcaa83490672d4acfd8569d876b4f134c5f72afaa (diff)
downloadgst-plugins-bad-751555b5c3839b19274565ef65c6189c494a6924.tar.gz
gst-plugins-bad-751555b5c3839b19274565ef65c6189c494a6924.tar.bz2
gst-plugins-bad-751555b5c3839b19274565ef65c6189c494a6924.zip
gst/mpegtsmux/: Improve muxing of AC3/h264 streams a bit. Fixes bug #550613.
Original commit message from CVS: Patch by: vanista <vanista at gmail dot com> * gst/mpegtsmux/mpegtsmux.c: (mpegtsmux_create_stream): * gst/mpegtsmux/tsmux/tsmux.c: (tsmux_write_pmt): * gst/mpegtsmux/tsmux/tsmuxstream.c: (tsmux_stream_new), (tsmux_stream_write_pes_header), (tsmux_stream_get_es_descrs): * gst/mpegtsmux/tsmux/tsmuxstream.h: Improve muxing of AC3/h264 streams a bit. Fixes bug #550613.
Diffstat (limited to 'gst/mpegtsmux')
-rw-r--r--gst/mpegtsmux/mpegtsmux.c4
-rw-r--r--gst/mpegtsmux/tsmux/tsmux.c11
-rw-r--r--gst/mpegtsmux/tsmux/tsmuxstream.c164
-rw-r--r--gst/mpegtsmux/tsmux/tsmuxstream.h4
4 files changed, 177 insertions, 6 deletions
diff --git a/gst/mpegtsmux/mpegtsmux.c b/gst/mpegtsmux/mpegtsmux.c
index 53306c3d..f24c4a3e 100644
--- a/gst/mpegtsmux/mpegtsmux.c
+++ b/gst/mpegtsmux/mpegtsmux.c
@@ -399,6 +399,10 @@ mpegtsmux_create_stream (MpegTsMux * mux, MpegTsPadData * ts_data, GstPad * pad)
}
if (ts_data->stream != NULL) {
+ gst_structure_get_int (s, "rate", &ts_data->stream->audio_sampling);
+ gst_structure_get_int (s, "channels", &ts_data->stream->audio_channels);
+ gst_structure_get_int (s, "bitrate", &ts_data->stream->audio_bitrate);
+
tsmux_stream_set_buffer_release_func (ts_data->stream, release_buffer_cb);
tsmux_program_add_stream (mux->program, ts_data->stream);
diff --git a/gst/mpegtsmux/tsmux/tsmux.c b/gst/mpegtsmux/tsmux/tsmux.c
index 1283f9a8..70ad3dcd 100644
--- a/gst/mpegtsmux/tsmux/tsmux.c
+++ b/gst/mpegtsmux/tsmux/tsmux.c
@@ -1000,9 +1000,14 @@ tsmux_write_pmt (TsMux * mux, TsMuxProgram * program)
else
tsmux_put16 (&pos, 0xE000 | tsmux_stream_get_pid (program->pcr_stream));
- /* FIXME: Write program descriptors if needed, for now write a
- * length of 0 */
- tsmux_put16 (&pos, 0xF000);
+ /* 4 bits reserved, 12 bits program_info_length, descriptor : HDMV */
+ tsmux_put16 (&pos, 0xF00C);
+ tsmux_put16 (&pos, 0x0504);
+ tsmux_put16 (&pos, 0x4844);
+ tsmux_put16 (&pos, 0x4D56);
+ tsmux_put16 (&pos, 0x8804);
+ tsmux_put16 (&pos, 0x0FFF);
+ tsmux_put16 (&pos, 0xFCFC);
/* Write out the entries */
for (i = 0; i < program->nb_streams; i++) {
diff --git a/gst/mpegtsmux/tsmux/tsmuxstream.c b/gst/mpegtsmux/tsmux/tsmuxstream.c
index 0c212710..3d848b49 100644
--- a/gst/mpegtsmux/tsmux/tsmuxstream.c
+++ b/gst/mpegtsmux/tsmux/tsmuxstream.c
@@ -157,7 +157,7 @@ tsmux_stream_new (guint16 pid, TsMuxStreamType stream_type)
stream->id_extended = 0x80;
break;
case TSMUX_ST_PS_AUDIO_AC3:
- stream->id_extended = 0x81;
+ stream->id_extended = 0x71;
break;
case TSMUX_ST_PS_AUDIO_DTS:
stream->id_extended = 0x82;
@@ -559,7 +559,7 @@ tsmux_stream_write_pes_header (TsMuxStream * stream, guint8 * data)
ext_len = 1; /* Only writing 1 byte into the extended fields */
*data++ = 0x80 | ext_len;
/* Write the extended streamID */
- *data++ = 0x80 | stream->id_extended;
+ *data++ = stream->id_extended;
}
}
}
@@ -631,9 +631,28 @@ tsmux_stream_get_es_descrs (TsMuxStream * stream, guint8 * buf, guint16 * len)
* PMT ES_info field */
pos = buf;
+ /* tag (registration_descriptor), length, format_identifier */
switch (stream->stream_type) {
+ case TSMUX_ST_AUDIO_AAC:
+ /* FIXME */
+ break;
+ case TSMUX_ST_VIDEO_MPEG4:
+ /* FIXME */
+ break;
+ case TSMUX_ST_VIDEO_H264:
+ *pos++ = 0x05;
+ *pos++ = 8;
+ *pos++ = 0x48; /* 'H' */
+ *pos++ = 0x44; /* 'D' */
+ *pos++ = 0x4D; /* 'M' */
+ *pos++ = 0x56; /* 'V' */
+ /* FIXME : Not sure about this additional_identification_info */
+ *pos++ = 0xFF;
+ *pos++ = 0x1B;
+ *pos++ = 0x44;
+ *pos++ = 0x3F;
+ break;
case TSMUX_ST_VIDEO_DIRAC:
- /* tag (registration_descriptor), length, format_identifier */
*pos++ = 0x05;
*pos++ = 4;
*pos++ = 0x64; /* 'd' */
@@ -641,6 +660,145 @@ tsmux_stream_get_es_descrs (TsMuxStream * stream, guint8 * buf, guint16 * len)
*pos++ = 0x61; /* 'a' */
*pos++ = 0x63; /* 'c' */
break;
+ case TSMUX_ST_PS_AUDIO_AC3:
+ {
+ *pos++ = 0x05;
+ *pos++ = 4;
+ *pos++ = 0x41; /* 'A' */
+ *pos++ = 0x43; /* 'C' */
+ *pos++ = 0x2D; /* '-' */
+ *pos++ = 0x33; /* '3' */
+
+ /* audio_stream_descriptor () | ATSC A/52-2001 Annex A
+ *
+ * descriptor_tag 8 uimsbf
+ * descriptor_length 8 uimsbf
+ * sample_rate_code 3 bslbf
+ * bsid 5 bslbf
+ * bit_rate_code 6 bslbf
+ * surround_mode 2 bslbf
+ * bsmod 3 bslbf
+ * num_channels 4 bslbf
+ * full_svc 1 bslbf
+ * langcod 8 bslbf
+ * [...]
+ */
+ *pos++ = 0x81;
+ *pos++ = 0x04;
+
+ /* 3 bits sample_rate_code, 5 bits hardcoded bsid (default ver 8) */
+ switch (stream->audio_sampling) {
+ case 48000:
+ *pos++ = 0x08;
+ break;
+ case 44100:
+ *pos++ = 0x28;
+ break;
+ case 32000:
+ *pos++ = 0x48;
+ break;
+ default:
+ *pos++ = 0xE8;
+ break; /* 48, 44.1 or 32 Khz */
+ }
+
+ /* 1 bit bit_rate_limit, 5 bits bit_rate_code, 2 bits suround_mode */
+ switch (stream->audio_bitrate) {
+ case 32:
+ *pos++ = 0x00 << 2;
+ break;
+ case 40:
+ *pos++ = 0x01 << 2;
+ break;
+ case 48:
+ *pos++ = 0x02 << 2;
+ break;
+ case 56:
+ *pos++ = 0x03 << 2;
+ break;
+ case 64:
+ *pos++ = 0x04 << 2;
+ break;
+ case 80:
+ *pos++ = 0x05 << 2;
+ break;
+ case 96:
+ *pos++ = 0x06 << 2;
+ break;
+ case 112:
+ *pos++ = 0x07 << 2;
+ break;
+ case 128:
+ *pos++ = 0x08 << 2;
+ break;
+ case 160:
+ *pos++ = 0x09 << 2;
+ break;
+ case 192:
+ *pos++ = 0x0A << 2;
+ break;
+ case 224:
+ *pos++ = 0x0B << 2;
+ break;
+ case 256:
+ *pos++ = 0x0C << 2;
+ break;
+ case 320:
+ *pos++ = 0x0D << 2;
+ break;
+ case 384:
+ *pos++ = 0x0E << 2;
+ break;
+ case 448:
+ *pos++ = 0x0F << 2;
+ break;
+ case 512:
+ *pos++ = 0x10 << 2;
+ break;
+ case 576:
+ *pos++ = 0x11 << 2;
+ break;
+ case 640:
+ *pos++ = 0x12 << 2;
+ break;
+ default:
+ *pos++ = 0x32 << 2;
+ break; /* 640 Kb/s upper limit */
+ }
+
+ /* 3 bits bsmod, 4 bits num_channels, 1 bit full_svc */
+ switch (stream->audio_channels) {
+ case 1:
+ *pos++ = 0x01 << 1;
+ break; /* 1/0 */
+ case 2:
+ *pos++ = 0x02 << 1;
+ break; /* 2/0 */
+ case 3:
+ *pos++ = 0x0A << 1;
+ break; /* <= 3 */
+ case 4:
+ *pos++ = 0x0B << 1;
+ break; /* <= 4 */
+ case 5:
+ *pos++ = 0x0C << 1;
+ break; /* <= 5 */
+ case 6:
+ default:
+ *pos++ = 0x0D << 1;
+ break; /* <= 6 */
+ }
+
+ *pos++ = 0x00;
+
+ break;
+ }
+ case TSMUX_ST_PS_AUDIO_DTS:
+ /* FIXME */
+ break;
+ case TSMUX_ST_PS_AUDIO_LPCM:
+ /* FIXME */
+ break;
default:
break;
}
diff --git a/gst/mpegtsmux/tsmux/tsmuxstream.h b/gst/mpegtsmux/tsmux/tsmuxstream.h
index bf1e23b9..4ee6ae18 100644
--- a/gst/mpegtsmux/tsmux/tsmuxstream.h
+++ b/gst/mpegtsmux/tsmux/tsmuxstream.h
@@ -183,6 +183,10 @@ struct TsMuxStream {
gint pcr_ref;
gint64 last_pcr;
+
+ gint audio_sampling;
+ gint audio_channels;
+ gint audio_bitrate;
};
/* stream management */