2002-03-20 21:45:04 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:26:33 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-11-07 12:47:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2001-12-23 12:18:18 +00:00
|
|
|
#include <gst/getbits/getbits.h>
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
|
|
|
#define SEQUENCE_HEADER 0x000001b3
|
|
|
|
#define SEQUENCE_END 0x000001b7
|
|
|
|
#define PICTURE_START 0x00000100
|
|
|
|
#define GROUP_START 0x000001b8
|
|
|
|
#define SYNCWORD_START 0x000001
|
|
|
|
|
|
|
|
#define AUDIO_SYNCWORD 0xfff
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
#define CLOCKS 90000.0
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-05-21 18:16:30 +00:00
|
|
|
#ifdef G_HAVE_ISO_VARARGS
|
|
|
|
|
|
|
|
#define DEBUG(...) g_print (__VA_ARGS__)
|
|
|
|
|
|
|
|
#elif defined(G_HAVE_GNUC_VARARGS)
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
#define DEBUG(a, b...) g_print (##b)
|
|
|
|
|
2003-05-21 18:16:30 +00:00
|
|
|
#endif
|
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
/* This must match decoder and encoder tables */
|
2004-03-14 22:34:33 +00:00
|
|
|
static double picture_rates[16] = {
|
|
|
|
0.0,
|
|
|
|
24000.0 / 1001.,
|
|
|
|
24.0,
|
|
|
|
25.0,
|
|
|
|
30000.0 / 1001.,
|
|
|
|
30.0,
|
|
|
|
50.0,
|
|
|
|
60000.0 / 1001.,
|
|
|
|
60.0,
|
|
|
|
|
|
|
|
1,
|
|
|
|
5,
|
|
|
|
10,
|
|
|
|
12,
|
|
|
|
15,
|
|
|
|
0,
|
|
|
|
0
|
2001-12-22 23:26:33 +00:00
|
|
|
};
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-08-05 16:20:11 +00:00
|
|
|
/* defined but not used
|
2001-12-22 23:26:33 +00:00
|
|
|
static double ratio [16] = { 0., 1., 0.6735, 0.7031, 0.7615, 0.8055,
|
2005-12-06 19:55:58 +00:00
|
|
|
0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575,
|
|
|
|
1.2015, 0.};
|
2002-04-06 03:40:15 +00:00
|
|
|
*/
|
2002-08-05 16:20:11 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2004-03-14 22:34:33 +00:00
|
|
|
static char picture_types[4][3] = { "I", "P", "B", "D" };
|
2002-08-05 16:20:11 +00:00
|
|
|
#endif
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
static int bitrate_index[2][3][16] =
|
2004-03-14 22:34:33 +00:00
|
|
|
{ {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
|
|
|
|
{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
|
|
|
|
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
|
|
|
|
{{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
|
|
|
|
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
|
|
|
|
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}},
|
2001-12-22 23:26:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static long frequency[9] =
|
2004-03-14 22:34:33 +00:00
|
|
|
{ 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000 };
|
|
|
|
|
|
|
|
static double dfrequency[9] = { 44.1, 48, 32, 22.05, 24, 16, 11.025, 12, 8 };
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static unsigned int samples[4] = { 192, 384, 1152, 1152 };
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2002-04-06 03:40:15 +00:00
|
|
|
/* deined but not used
|
2001-12-22 23:26:33 +00:00
|
|
|
static char mode [4][15] =
|
|
|
|
{ "stereo", "joint stereo", "dual channel", "single channel" };
|
|
|
|
static char copyright [2][20] =
|
|
|
|
{ "no copyright","copyright protected" };
|
|
|
|
static char original [2][10] =
|
|
|
|
{ "copy","original" };
|
|
|
|
static char emphasis [4][20] =
|
|
|
|
{ "none", "50/15 microseconds", "reserved", "CCITT J.17" };
|
2002-04-06 03:40:15 +00:00
|
|
|
*/
|
2004-03-14 22:34:33 +00:00
|
|
|
static void mpeg1mux_buffer_update_video_info (Mpeg1MuxBuffer * mb);
|
|
|
|
static void mpeg1mux_buffer_update_audio_info (Mpeg1MuxBuffer * mb);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
Mpeg1MuxBuffer *
|
|
|
|
mpeg1mux_buffer_new (guchar type, guchar id)
|
|
|
|
{
|
|
|
|
Mpeg1MuxBuffer *new = g_malloc (sizeof (Mpeg1MuxBuffer));
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
new->buffer = NULL;
|
|
|
|
new->length = 0;
|
|
|
|
new->base = 0;
|
|
|
|
new->buffer_type = type;
|
|
|
|
new->stream_id = id;
|
|
|
|
new->scan_pos = 0;
|
|
|
|
new->new_frame = TRUE;
|
|
|
|
new->current_start = 0;
|
|
|
|
new->timecode_list = NULL;
|
|
|
|
new->queued_list = NULL;
|
|
|
|
new->next_frame_time = 0;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
void
|
|
|
|
mpeg1mux_buffer_queue (Mpeg1MuxBuffer * mb, GstBuffer * buf)
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
if (mb->buffer == NULL) {
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->buffer = g_malloc (GST_BUFFER_SIZE (buf));
|
|
|
|
mb->length = GST_BUFFER_SIZE (buf);
|
|
|
|
memcpy (mb->buffer, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
|
|
|
} else {
|
|
|
|
mb->buffer = g_realloc (mb->buffer, mb->length + GST_BUFFER_SIZE (buf));
|
|
|
|
memcpy (mb->buffer + mb->length, GST_BUFFER_DATA (buf),
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_SIZE (buf));
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->length += GST_BUFFER_SIZE (buf);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("queuing buffer %lu", mb->length);
|
2001-12-22 23:26:33 +00:00
|
|
|
if (mb->buffer_type == BUFFER_TYPE_VIDEO) {
|
2004-03-14 22:34:33 +00:00
|
|
|
mpeg1mux_buffer_update_video_info (mb);
|
|
|
|
} else {
|
|
|
|
mpeg1mux_buffer_update_audio_info (mb);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gulong
|
|
|
|
mpeg1mux_buffer_update_queued (Mpeg1MuxBuffer * mb, guint64 scr)
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
GList *queued_list;
|
|
|
|
Mpeg1MuxTimecode *tc;
|
|
|
|
gulong total_queued = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("queued in buffer on SCR=%" G_GUINT64_FORMAT, scr);
|
2004-03-14 22:34:33 +00:00
|
|
|
queued_list = g_list_first (mb->queued_list);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
while (queued_list) {
|
|
|
|
tc = (Mpeg1MuxTimecode *) queued_list->data;
|
|
|
|
if (tc->DTS < scr) {
|
|
|
|
/* this buffer should be sent out */
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->queued_list = g_list_remove (mb->queued_list, tc);
|
|
|
|
queued_list = g_list_first (mb->queued_list);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("queued in buffer %ld, %" G_GUINT64_FORMAT,
|
2004-03-15 19:32:27 +00:00
|
|
|
tc->original_length, tc->DTS);
|
2001-12-22 23:26:33 +00:00
|
|
|
total_queued += tc->original_length;
|
2004-03-14 22:34:33 +00:00
|
|
|
queued_list = g_list_next (queued_list);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
}
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("queued in buffer %lu", total_queued);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
return total_queued;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
void
|
|
|
|
mpeg1mux_buffer_shrink (Mpeg1MuxBuffer * mb, gulong size)
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
GList *timecode_list;
|
|
|
|
Mpeg1MuxTimecode *tc;
|
|
|
|
gulong consumed = 0;
|
|
|
|
gulong count;
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("shrinking buffer %lu", size);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_assert (mb->length >= size);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
memcpy (mb->buffer, mb->buffer + size, mb->length - size);
|
|
|
|
mb->buffer = g_realloc (mb->buffer, mb->length - size);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
mb->length -= size;
|
|
|
|
mb->scan_pos -= size;
|
|
|
|
mb->current_start -= size;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
timecode_list = g_list_first (mb->timecode_list);
|
2001-12-22 23:26:33 +00:00
|
|
|
tc = (Mpeg1MuxTimecode *) timecode_list->data;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
if (tc->length > size) {
|
|
|
|
tc->length -= size;
|
|
|
|
mb->new_frame = FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2001-12-22 23:26:33 +00:00
|
|
|
consumed += tc->length;
|
|
|
|
while (size >= consumed) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("removing timecode: %" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT
|
2004-03-15 19:32:27 +00:00
|
|
|
" %lu %lu", tc->DTS, tc->PTS, tc->length, consumed);
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->timecode_list = g_list_remove_link (mb->timecode_list, timecode_list);
|
|
|
|
mb->queued_list = g_list_append (mb->queued_list, tc);
|
|
|
|
timecode_list = g_list_first (mb->timecode_list);
|
2001-12-22 23:26:33 +00:00
|
|
|
tc = (Mpeg1MuxTimecode *) timecode_list->data;
|
|
|
|
consumed += tc->length;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("next timecode: %" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT
|
2004-03-15 19:32:27 +00:00
|
|
|
" %lu %lu", tc->DTS, tc->PTS, tc->length, consumed);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
mb->new_frame = TRUE;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("leftover frame size from %lu to %lu ", tc->length,
|
2004-03-15 19:32:27 +00:00
|
|
|
consumed - size);
|
2001-12-22 23:26:33 +00:00
|
|
|
tc->length = consumed - size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mb->buffer_type == BUFFER_TYPE_VIDEO) {
|
|
|
|
mb->info.video.DTS = tc->DTS;
|
|
|
|
mb->info.video.PTS = tc->PTS;
|
|
|
|
mb->next_frame_time = tc->DTS;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2001-12-22 23:26:33 +00:00
|
|
|
mb->info.audio.PTS = tc->PTS;
|
|
|
|
mb->next_frame_time = tc->PTS;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("next frame time timecode: %" G_GUINT64_FORMAT " %lu",
|
|
|
|
mb->next_frame_time, tc->length);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
/* check buffer consistency */
|
2004-03-14 22:34:33 +00:00
|
|
|
timecode_list = g_list_first (mb->timecode_list);
|
2001-12-22 23:26:33 +00:00
|
|
|
count = 0;
|
|
|
|
|
|
|
|
while (timecode_list) {
|
|
|
|
tc = (Mpeg1MuxTimecode *) timecode_list->data;
|
|
|
|
count += tc->length;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
timecode_list = g_list_next (timecode_list);
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (count != mb->current_start)
|
|
|
|
g_print ("********** error %lu != %lu\n", count, mb->current_start);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
mb->base += size;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
mpeg1mux_buffer_update_video_info (Mpeg1MuxBuffer * mb)
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
gboolean have_sync = FALSE;
|
|
|
|
guchar *data = mb->buffer;
|
|
|
|
gulong offset = mb->scan_pos;
|
|
|
|
guint sync_zeros = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
gulong id = 0;
|
2001-12-22 23:26:33 +00:00
|
|
|
guint temporal_reference, temp;
|
|
|
|
gst_getbits_t gb;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_video_info %lu %lu", mb->base, mb->scan_pos);
|
2001-12-22 23:26:33 +00:00
|
|
|
if (mb->base == 0 && mb->scan_pos == 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
if ((SYNCWORD_START << 8) + *(mb->buffer + 3) == SEQUENCE_HEADER) {
|
|
|
|
|
|
|
|
gst_getbits_init (&gb, NULL, NULL);
|
|
|
|
gst_getbits_newbuf (&gb, data + 4, mb->length);
|
|
|
|
mb->info.video.horizontal_size = gst_getbits12 (&gb);
|
|
|
|
mb->info.video.vertical_size = gst_getbits12 (&gb);
|
|
|
|
mb->info.video.aspect_ratio = gst_getbits4 (&gb);
|
|
|
|
mb->info.video.picture_rate = gst_getbits4 (&gb);
|
|
|
|
mb->info.video.bit_rate = gst_getbits18 (&gb);
|
|
|
|
if (gst_getbits1 (&gb) != 1) {
|
2004-03-15 19:32:27 +00:00
|
|
|
g_print ("mpeg1mux::update_video_info: marker bit error\n");
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.video.vbv_buffer_size = gst_getbits10 (&gb);
|
|
|
|
mb->info.video.CSPF = gst_getbits1 (&gb);
|
|
|
|
|
|
|
|
mb->info.video.secs_per_frame =
|
2004-03-15 19:32:27 +00:00
|
|
|
1. / picture_rates[mb->info.video.picture_rate];
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.video.decoding_order = 0;
|
|
|
|
mb->info.video.group_order = 0;
|
|
|
|
GST_DEBUG ("mpeg1mux::update_video_info: secs per frame %g",
|
2004-03-15 19:32:27 +00:00
|
|
|
mb->info.video.secs_per_frame);
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
|
|
|
g_print ("mpeg1mux::update_video_info: Invalid MPEG Video header\n");
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
while (offset < mb->length - 6) {
|
2001-12-22 23:26:33 +00:00
|
|
|
if (!have_sync) {
|
2004-03-14 22:34:33 +00:00
|
|
|
guchar byte = *(data + offset);
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
/*GST_DEBUG ("mpeg1mux::update_video_info: found #%d at %lu",byte,offset); */
|
2001-12-22 23:26:33 +00:00
|
|
|
offset++;
|
|
|
|
/* if it's zero, increment the zero count */
|
|
|
|
if (byte == 0) {
|
2004-03-15 19:32:27 +00:00
|
|
|
sync_zeros++;
|
|
|
|
/*GST_DEBUG ("mpeg1mux::update_video_info: found zero #%d at %lu",sync_zeros,offset-1); */
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
/* if it's a one and we have two previous zeros, we have sync */
|
|
|
|
else if ((byte == 1) && (sync_zeros >= 2)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_video_info: synced at %lu", offset - 1);
|
|
|
|
have_sync = TRUE;
|
|
|
|
sync_zeros = 0;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
/* if it's anything else, we've lost it completely */
|
2004-03-14 22:34:33 +00:00
|
|
|
else
|
2004-03-15 19:32:27 +00:00
|
|
|
sync_zeros = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
/* then snag the chunk ID */
|
2001-12-22 23:26:33 +00:00
|
|
|
} else if (id == 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
id = *(data + offset);
|
|
|
|
GST_DEBUG ("mpeg1mux::update_video_info: got id 0x%02lX", id);
|
|
|
|
id = (SYNCWORD_START << 8) + id;
|
2001-12-22 23:26:33 +00:00
|
|
|
switch (id) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case SEQUENCE_HEADER:
|
|
|
|
GST_DEBUG ("mpeg1mux::update_video_info: sequence header");
|
|
|
|
break;
|
|
|
|
case GROUP_START:
|
|
|
|
GST_DEBUG ("mpeg1mux::update_video_info: group start");
|
|
|
|
mb->info.video.group_order = 0;
|
|
|
|
break;
|
|
|
|
case PICTURE_START:
|
|
|
|
/* skip the first access unit */
|
|
|
|
if (mb->info.video.decoding_order != 0) {
|
|
|
|
Mpeg1MuxTimecode *tc;
|
|
|
|
|
|
|
|
GST_DEBUG ("mpeg1mux::update_video_info: PTS %" G_GUINT64_FORMAT
|
|
|
|
", DTS %" G_GUINT64_FORMAT ", length %lu",
|
|
|
|
mb->info.video.current_PTS, mb->info.video.current_DTS,
|
|
|
|
offset - mb->current_start - 3);
|
|
|
|
|
|
|
|
tc = (Mpeg1MuxTimecode *) g_malloc (sizeof (Mpeg1MuxTimecode));
|
|
|
|
tc->length = offset - mb->current_start - 3;
|
|
|
|
tc->original_length = tc->length;
|
|
|
|
tc->frame_type = mb->info.video.current_type;
|
|
|
|
tc->DTS = mb->info.video.current_DTS;
|
|
|
|
tc->PTS = mb->info.video.current_PTS;
|
|
|
|
|
|
|
|
mb->timecode_list = g_list_append (mb->timecode_list, tc);
|
|
|
|
|
|
|
|
if (mb->info.video.decoding_order == 0) {
|
|
|
|
mb->next_frame_time = tc->DTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
mb->current_start = offset - 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = (*(data + offset + 1) << 8) + *(data + offset + 2);
|
|
|
|
temporal_reference = (temp & 0xffc0) >> 6;
|
|
|
|
mb->info.video.current_type = (temp & 0x0038) >> 3;
|
|
|
|
GST_DEBUG
|
|
|
|
("mpeg1mux::update_video_info: picture start temporal_ref:%d type:%s Frame",
|
|
|
|
temporal_reference,
|
|
|
|
picture_types[mb->info.video.current_type - 1]);
|
|
|
|
|
|
|
|
mb->info.video.current_DTS =
|
|
|
|
mb->info.video.decoding_order * mb->info.video.secs_per_frame *
|
|
|
|
CLOCKS;
|
|
|
|
mb->info.video.current_PTS =
|
|
|
|
(temporal_reference - mb->info.video.group_order + 1 +
|
|
|
|
mb->info.video.decoding_order) * mb->info.video.secs_per_frame *
|
|
|
|
CLOCKS;
|
|
|
|
|
|
|
|
mb->info.video.decoding_order++;
|
|
|
|
mb->info.video.group_order++;
|
|
|
|
|
|
|
|
|
|
|
|
offset++;
|
|
|
|
break;
|
|
|
|
case SEQUENCE_END:
|
|
|
|
GST_DEBUG ("mpeg1mux::update_video_info: sequence end");
|
|
|
|
break;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
/* prepare for next sync */
|
|
|
|
offset++;
|
|
|
|
have_sync = FALSE;
|
|
|
|
id = 0;
|
|
|
|
sync_zeros = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mb->scan_pos = offset;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
mpeg1mux_buffer_update_audio_info (Mpeg1MuxBuffer * mb)
|
|
|
|
{
|
2001-12-22 23:26:33 +00:00
|
|
|
guchar *data = mb->buffer;
|
|
|
|
gulong offset = mb->scan_pos;
|
2004-03-14 22:34:33 +00:00
|
|
|
guint32 id = 0;
|
2001-12-22 23:26:33 +00:00
|
|
|
guint padding_bit;
|
|
|
|
gst_getbits_t gb;
|
|
|
|
guint startup_delay = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
int layer_index, lsf, samplerate_index, padding;
|
2001-12-22 23:26:33 +00:00
|
|
|
long bpf;
|
|
|
|
Mpeg1MuxTimecode *tc;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_audio_info %lu %lu", mb->base, mb->scan_pos);
|
2001-12-22 23:26:33 +00:00
|
|
|
if (mb->base == 0 && mb->scan_pos == 0) {
|
configure.ac: bump required gstreamer version to 0.8.1.1 because of following changes [--ds]
Original commit message from CVS:
reviewed by David Schleef
* configure.ac: bump required gstreamer version to 0.8.1.1
because of following changes [--ds]
* gst-libs/gst/riff/riff-read.c: Include gst/gstutils.h.
(gst_riff_peek_head, gst_riff_peek_list, gst_riff_read_list)
(gst_riff_read_header): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/typefind/gsttypefindfunctions.c: Include gst/gstutils.h.
(mp3_type_find): Use GST_READ_UINT*
macros to access possibly unaligned memory.
(mp3_type_find, mpeg1_parse_header, qt_type_find)
(speex_type_find): Likewise
* gst/tags/gstvorbistag.c: (ADVANCE): Likewise
* gst/qtdemux/qtdemux.c: Include stdlib.h (needed by realloc).
(QTDEMUX_GUINT32_GET, QTDEMUX_GUINT16_GET, QTDEMUX_FP32_GET)
(QTDEMUX_FP16_GET, QTDEMUX_FOURCC_GET)
(gst_qtdemux_loop_header, gst_qtdemux_loop_header)
(qtdemux_node_dump_foreach, qtdemux_tree_get_child_by_type)
(qtdemux_tree_get_sibling_by_type): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/mpegstream/gstmpegpacketize.c: (parse_generic, parse_chunk):
Likewise.
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_parse_syshead)
(gst_mpeg_demux_parse_packet, gst_mpeg_demux_parse_pes): Likewise.
* gst/mpegaudioparse/gstmpegaudioparse.c: (gst_mp3parse_chain):
Likewise.
* gst/mpeg2sub/gstmpeg2subt.c: (GST_BUFFER_DATA)
(gst_mpeg2subt_chain_subtitle): Likewise.
* gst/mpeg1videoparse/gstmp1videoparse.c: (mp1videoparse_parse_seq)
(gst_mp1videoparse_time_code, gst_mp1videoparse_real_chain):
Likewise.
* gst/mpeg1sys/buffer.c: (mpeg1mux_buffer_update_audio_info):
Likewise.
* gst/cdxaparse/gstcdxaparse.c: (gst_bytestream_peek_bytes):
Likewise.
* gst/asfdemux/gstasfdemux.c: (_read_var_length, _read_uint):
Likewise.
2004-04-20 21:04:22 +00:00
|
|
|
id = GST_READ_UINT32_BE (data);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
printf ("MPEG audio id = %08x\n", (unsigned int) id);
|
|
|
|
if ((id & 0xfff00000) == AUDIO_SYNCWORD << 20) {
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2002-03-19 04:10:06 +00:00
|
|
|
/* mpegver = (header >> 19) & 0x3; don't need this for bpf */
|
2001-12-22 23:26:33 +00:00
|
|
|
layer_index = (id >> 17) & 0x3;
|
|
|
|
mb->info.audio.layer = 4 - layer_index;
|
|
|
|
lsf = (id & (1 << 20)) ? ((id & (1 << 19)) ? 0 : 1) : 1;
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.audio.bit_rate =
|
2004-03-15 19:32:27 +00:00
|
|
|
bitrate_index[lsf][mb->info.audio.layer - 1][((id >> 12) & 0xf)];
|
2001-12-22 23:26:33 +00:00
|
|
|
samplerate_index = (id >> 10) & 0x3;
|
|
|
|
padding = (id >> 9) & 0x1;
|
|
|
|
|
|
|
|
if (mb->info.audio.layer == 1) {
|
2004-03-15 19:32:27 +00:00
|
|
|
bpf = mb->info.audio.bit_rate * 12000;
|
|
|
|
bpf /= frequency[samplerate_index];
|
|
|
|
bpf = ((bpf + padding) << 2);
|
2001-12-22 23:26:33 +00:00
|
|
|
} else {
|
2004-03-15 19:32:27 +00:00
|
|
|
bpf = mb->info.audio.bit_rate * 144000;
|
|
|
|
bpf /= frequency[samplerate_index];
|
|
|
|
bpf += padding;
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
mb->info.audio.framesize = bpf;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_audio_info: samples per second %d",
|
2004-03-15 19:32:27 +00:00
|
|
|
samplerate_index);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_getbits_init (&gb, NULL, NULL);
|
|
|
|
gst_getbits_newbuf (&gb, data, mb->length);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flushbitsn (&gb, 12);
|
|
|
|
if (gst_getbits1 (&gb) != 1) {
|
2004-03-15 19:32:27 +00:00
|
|
|
g_print ("mpeg1mux::update_audio_info: marker bit error\n");
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flushbitsn (&gb, 2);
|
|
|
|
mb->info.audio.protection = gst_getbits1 (&gb);
|
|
|
|
gst_flushbitsn (&gb, 4);
|
|
|
|
mb->info.audio.frequency = gst_getbits2 (&gb);
|
|
|
|
padding_bit = gst_getbits1 (&gb);
|
|
|
|
gst_flushbitsn (&gb, 1);
|
|
|
|
mb->info.audio.mode = gst_getbits2 (&gb);
|
|
|
|
mb->info.audio.mode_extension = gst_getbits2 (&gb);
|
|
|
|
mb->info.audio.copyright = gst_getbits1 (&gb);
|
|
|
|
mb->info.audio.original_copy = gst_getbits1 (&gb);
|
|
|
|
mb->info.audio.emphasis = gst_getbits2 (&gb);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_audio_info: layer %d", mb->info.audio.layer);
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_audio_info: bit_rate %d",
|
2004-03-15 19:32:27 +00:00
|
|
|
mb->info.audio.bit_rate);
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_audio_info: frequency %d",
|
2004-03-15 19:32:27 +00:00
|
|
|
mb->info.audio.frequency);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.audio.samples_per_second =
|
2004-03-15 19:32:27 +00:00
|
|
|
(double) dfrequency[mb->info.audio.frequency];
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_audio_info: samples per second %g",
|
2004-03-15 19:32:27 +00:00
|
|
|
mb->info.audio.samples_per_second);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.audio.decoding_order = 0;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
tc = (Mpeg1MuxTimecode *) g_malloc (sizeof (Mpeg1MuxTimecode));
|
2001-12-22 23:26:33 +00:00
|
|
|
tc->length = mb->info.audio.framesize;
|
|
|
|
tc->original_length = tc->length;
|
|
|
|
tc->frame_type = FRAME_TYPE_AUDIO;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.audio.current_PTS =
|
2004-03-15 19:32:27 +00:00
|
|
|
mb->info.audio.decoding_order * samples[mb->info.audio.layer] /
|
|
|
|
mb->info.audio.samples_per_second * 90. + startup_delay;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_audio_info: PTS %" G_GUINT64_FORMAT
|
2004-03-15 19:32:27 +00:00
|
|
|
", length %u", mb->info.audio.current_PTS, mb->info.audio.framesize);
|
2001-12-22 23:26:33 +00:00
|
|
|
tc->PTS = mb->info.audio.current_PTS;
|
|
|
|
tc->DTS = mb->info.audio.current_PTS;
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->timecode_list = g_list_append (mb->timecode_list, tc);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
mb->next_frame_time = tc->PTS;
|
|
|
|
|
|
|
|
mb->info.audio.decoding_order++;
|
|
|
|
offset += tc->length;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
|
|
|
g_print ("mpeg1mux::update_audio_info: Invalid MPEG Video header\n");
|
2001-12-22 23:26:33 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
while (offset < mb->length - 4) {
|
configure.ac: bump required gstreamer version to 0.8.1.1 because of following changes [--ds]
Original commit message from CVS:
reviewed by David Schleef
* configure.ac: bump required gstreamer version to 0.8.1.1
because of following changes [--ds]
* gst-libs/gst/riff/riff-read.c: Include gst/gstutils.h.
(gst_riff_peek_head, gst_riff_peek_list, gst_riff_read_list)
(gst_riff_read_header): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/typefind/gsttypefindfunctions.c: Include gst/gstutils.h.
(mp3_type_find): Use GST_READ_UINT*
macros to access possibly unaligned memory.
(mp3_type_find, mpeg1_parse_header, qt_type_find)
(speex_type_find): Likewise
* gst/tags/gstvorbistag.c: (ADVANCE): Likewise
* gst/qtdemux/qtdemux.c: Include stdlib.h (needed by realloc).
(QTDEMUX_GUINT32_GET, QTDEMUX_GUINT16_GET, QTDEMUX_FP32_GET)
(QTDEMUX_FP16_GET, QTDEMUX_FOURCC_GET)
(gst_qtdemux_loop_header, gst_qtdemux_loop_header)
(qtdemux_node_dump_foreach, qtdemux_tree_get_child_by_type)
(qtdemux_tree_get_sibling_by_type): Use GST_READ_UINT*
macros to access possibly unaligned memory.
* gst/mpegstream/gstmpegpacketize.c: (parse_generic, parse_chunk):
Likewise.
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_parse_syshead)
(gst_mpeg_demux_parse_packet, gst_mpeg_demux_parse_pes): Likewise.
* gst/mpegaudioparse/gstmpegaudioparse.c: (gst_mp3parse_chain):
Likewise.
* gst/mpeg2sub/gstmpeg2subt.c: (GST_BUFFER_DATA)
(gst_mpeg2subt_chain_subtitle): Likewise.
* gst/mpeg1videoparse/gstmp1videoparse.c: (mp1videoparse_parse_seq)
(gst_mp1videoparse_time_code, gst_mp1videoparse_real_chain):
Likewise.
* gst/mpeg1sys/buffer.c: (mpeg1mux_buffer_update_audio_info):
Likewise.
* gst/cdxaparse/gstcdxaparse.c: (gst_bytestream_peek_bytes):
Likewise.
* gst/asfdemux/gstasfdemux.c: (_read_var_length, _read_uint):
Likewise.
2004-04-20 21:04:22 +00:00
|
|
|
id = GST_READ_UINT32_BE (data + offset);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2002-03-19 04:10:06 +00:00
|
|
|
/* mpegver = (header >> 19) & 0x3; don't need this for bpf */
|
2001-12-22 23:26:33 +00:00
|
|
|
layer_index = (id >> 17) & 0x3;
|
|
|
|
mb->info.audio.layer = 4 - layer_index;
|
|
|
|
lsf = (id & (1 << 20)) ? ((id & (1 << 19)) ? 0 : 1) : 1;
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.audio.bit_rate =
|
2004-03-15 19:32:27 +00:00
|
|
|
bitrate_index[lsf][mb->info.audio.layer - 1][((id >> 12) & 0xf)];
|
2001-12-22 23:26:33 +00:00
|
|
|
samplerate_index = (id >> 10) & 0x3;
|
|
|
|
padding = (id >> 9) & 0x1;
|
|
|
|
|
|
|
|
if (mb->info.audio.layer == 1) {
|
|
|
|
bpf = mb->info.audio.bit_rate * 12000;
|
|
|
|
bpf /= frequency[samplerate_index];
|
|
|
|
bpf = ((bpf + padding) << 2);
|
|
|
|
} else {
|
|
|
|
bpf = mb->info.audio.bit_rate * 144000;
|
|
|
|
bpf /= frequency[samplerate_index];
|
|
|
|
bpf += padding;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
tc = (Mpeg1MuxTimecode *) g_malloc (sizeof (Mpeg1MuxTimecode));
|
2001-12-22 23:26:33 +00:00
|
|
|
tc->length = bpf;
|
|
|
|
tc->original_length = tc->length;
|
|
|
|
tc->frame_type = FRAME_TYPE_AUDIO;
|
|
|
|
|
|
|
|
mb->current_start = offset + bpf;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.audio.samples_per_second =
|
2004-03-15 19:32:27 +00:00
|
|
|
(double) dfrequency[mb->info.audio.frequency];
|
2001-12-22 23:26:33 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->info.audio.current_PTS =
|
2004-03-15 19:32:27 +00:00
|
|
|
(mb->info.audio.decoding_order * samples[mb->info.audio.layer]) /
|
|
|
|
mb->info.audio.samples_per_second * 90.;
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
tc->DTS = tc->PTS = mb->info.audio.current_PTS;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("mpeg1mux::update_audio_info: PTS %" G_GUINT64_FORMAT ", %"
|
2004-03-15 19:32:27 +00:00
|
|
|
G_GUINT64_FORMAT " length %lu", mb->info.audio.current_PTS, tc->PTS,
|
|
|
|
tc->length);
|
2004-03-14 22:34:33 +00:00
|
|
|
mb->timecode_list = g_list_append (mb->timecode_list, tc);
|
2001-12-22 23:26:33 +00:00
|
|
|
|
|
|
|
mb->info.audio.decoding_order++;
|
|
|
|
offset += tc->length;
|
|
|
|
}
|
|
|
|
mb->scan_pos = offset;
|
|
|
|
}
|