Commit b6b3c5f5 authored by Ronald S. Bultje's avatar Ronald S. Bultje

This fixes some problems when recording AVI files with gstrec

Original commit message from CVS:
This fixes some problems when recording AVI files with gstrec
parent 3fccf3c2
......@@ -47,7 +47,6 @@ gst_avimux_details =
{
"Avi multiplexer",
"Codec/Muxer",
"LGPL",
"Muxes audio and video into an avi stream",
VERSION,
"Ronald Bultje <rbultje@ronald.bitfreak.net>",
......@@ -260,9 +259,11 @@ gst_avimux_init (GstAviMux *avimux)
for (i=0;i<MAX_NUM_AUDIO_PADS;i++)
avimux->audiosinkpad[i] = NULL;
avimux->num_audio_pads = 0;
avimux->num_audio_pads_connected = 0;
for (i=0;i<MAX_NUM_VIDEO_PADS;i++)
avimux->videosinkpad[i] = NULL;
avimux->num_video_pads = 0;
avimux->num_video_pads_connected = 0;
avimux->num_frames = 0;
......@@ -417,6 +418,56 @@ done:
return GST_PAD_CONNECT_OK;
}
static void
gst_avimux_pad_connect (GstPad *pad,
GstPad *peer,
gpointer data)
{
GstAviMux *avimux = GST_AVIMUX(data);
const gchar *padname = gst_pad_get_name (pad);
if (!strncmp(padname, "audio_", 6))
{
avimux->num_audio_pads_connected++;
}
else if (!strncmp(padname, "video_", 6))
{
avimux->num_video_pads_connected++;
}
else
{
g_warning("Unknown padname '%s'", padname);
return;
}
GST_DEBUG(GST_CAT_PLUGIN_INFO, "pad '%s' connected", padname);
}
static void
gst_avimux_pad_disconnect (GstPad *pad,
GstPad *peer,
gpointer data)
{
GstAviMux *avimux = GST_AVIMUX(data);
const gchar *padname = gst_pad_get_name (pad);
if (!strncmp(padname, "audio_", 6))
{
avimux->num_audio_pads_connected--;
}
else if (!strncmp(padname, "video_", 6))
{
avimux->num_video_pads_connected--;
}
else
{
g_warning("Unknown padname '%s'", padname);
return;
}
GST_DEBUG(GST_CAT_PLUGIN_INFO, "pad '%s' disconnected", padname);
}
static GstPad*
gst_avimux_request_new_pad (GstElement *element,
GstPadTemplate *templ,
......@@ -460,6 +511,10 @@ gst_avimux_request_new_pad (GstElement *element,
return NULL;
}
g_signal_connect(newpad, "connected",
G_CALLBACK(gst_avimux_pad_connect), (gpointer)avimux);
g_signal_connect(newpad, "disconnected",
G_CALLBACK(gst_avimux_pad_disconnect), (gpointer)avimux);
gst_pad_set_chain_function (newpad, gst_avimux_chain);
gst_pad_set_connect_function (newpad, gst_avimux_sinkconnect);
gst_element_add_pad (element, newpad);
......@@ -484,12 +539,12 @@ gst_avimux_riff_get_avi_header (GstAviMux *avimux)
/* first, let's see what actually needs to be in the buffer */
GST_BUFFER_SIZE(buffer) = 0;
GST_BUFFER_SIZE(buffer) += 32 + sizeof(gst_riff_avih); /* avi header */
if (avimux->num_video_pads)
if (avimux->num_video_pads_connected)
{ /* we have video */
GST_BUFFER_SIZE(buffer) += 28 + sizeof(gst_riff_strh) + sizeof(gst_riff_strf_vids); /* vid hdr */
GST_BUFFER_SIZE(buffer) += 24; /* odml header */
}
if (avimux->num_audio_pads)
if (avimux->num_audio_pads_connected)
{ /* we have audio */
GST_BUFFER_SIZE(buffer) += 28 + sizeof(gst_riff_strh) + sizeof(gst_riff_strf_auds); /* aud hdr */
}
......@@ -542,7 +597,7 @@ gst_avimux_riff_get_avi_header (GstAviMux *avimux)
temp32 = LE_FROM_GUINT32(avimux->avi_hdr.length);
memcpy(buffdata, &temp32, 4); buffdata += 4;
if (avimux->num_video_pads)
if (avimux->num_video_pads_connected)
{
/* video header metadata */
memcpy(buffdata, "LIST", 4); buffdata += 4;
......@@ -607,7 +662,7 @@ gst_avimux_riff_get_avi_header (GstAviMux *avimux)
memcpy(buffdata, &temp32, 4); buffdata += 4;
}
if (avimux->num_audio_pads)
if (avimux->num_audio_pads_connected)
{
/* audio header */
memcpy(buffdata, "LIST", 4); buffdata += 4;
......@@ -662,7 +717,7 @@ gst_avimux_riff_get_avi_header (GstAviMux *avimux)
memcpy(buffdata, &temp16, 2); buffdata += 2;
}
if (avimux->num_video_pads)
if (avimux->num_video_pads_connected)
{
/* odml header */
memcpy(buffdata, "LIST", 4); buffdata += 4;
......@@ -743,17 +798,14 @@ gst_avimux_riff_get_audio_header (guint32 audio_sample_size)
/* some other usable functions (thankyou xawtv ;-) ) */
static void
gst_avimux_add_index (GstAviMux *avimux, guint32 fourcc, guint32 flags, guint32 size)
gst_avimux_add_index (GstAviMux *avimux, guchar *code, guint32 flags, guint32 size)
{
guint32 temp32;
if (avimux->idx_index == avimux->idx_count)
{
avimux->idx_count += 256;
avimux->idx = realloc(avimux->idx, avimux->idx_count*sizeof(gst_riff_index_entry));
}
temp32 = LE_FROM_GUINT32(fourcc);
memcpy(&(avimux->idx[avimux->idx_index].id), &temp32, 4);
memcpy(&(avimux->idx[avimux->idx_index].id), code, 4);
avimux->idx[avimux->idx_index].flags = LE_FROM_GUINT32(flags);
avimux->idx[avimux->idx_index].offset = LE_FROM_GUINT32(avimux->idx_offset-avimux->header_size-8);
avimux->idx[avimux->idx_index].size = LE_FROM_GUINT32(size);
......@@ -852,7 +904,7 @@ gst_avimux_start_file (GstAviMux *avimux)
avimux->idx = NULL;
/* header */
avimux->avi_hdr.streams = avimux->num_video_pads + avimux->num_audio_pads;
avimux->avi_hdr.streams = avimux->num_video_pads_connected + avimux->num_audio_pads_connected;
avimux->is_bigfile = FALSE;
header = gst_avimux_riff_get_avi_header(avimux);
......@@ -870,7 +922,7 @@ gst_avimux_stop_file (GstAviMux *avimux)
GstBuffer *header;
/* if bigfile, rewrite header, else write indexes */
if (avimux->num_video_pads)
if (avimux->num_video_pads_connected)
{
if (avimux->is_bigfile)
{
......@@ -885,17 +937,17 @@ gst_avimux_stop_file (GstAviMux *avimux)
/* statistics/total_frames/... */
avimux->avi_hdr.tot_frames = avimux->num_frames;
if (avimux->num_video_pads)
if (avimux->num_video_pads_connected)
avimux->vids_hdr.length = avimux->num_frames;
if (avimux->num_audio_pads)
if (avimux->num_audio_pads_connected)
avimux->auds_hdr.length = avimux->audio_size/avimux->auds_hdr.scale;
/* TODO: fps calculation!! */
avimux->avi_hdr.us_frame = 1000000/avimux->framerate;
avimux->avi_hdr.max_bps = 0;
if (avimux->num_audio_pads)
if (avimux->num_audio_pads_connected)
avimux->avi_hdr.max_bps += avimux->auds.av_bps;
if (avimux->num_video_pads)
if (avimux->num_video_pads_connected)
avimux->avi_hdr.max_bps += avimux->vids.bit_cnt/8 * avimux->framerate;
/* seek and rewrite the header */
......@@ -982,7 +1034,7 @@ gst_avimux_chain (GstPad *pad, GstBuffer *buf)
{
avimux->data_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
avimux->audio_size += GST_BUFFER_SIZE(buf);
gst_avimux_add_index(avimux, avimux->auds.format, 0x0, GST_BUFFER_SIZE(buf));
gst_avimux_add_index(avimux, "01wb", 0x0, GST_BUFFER_SIZE(buf));
}
gst_pad_push(avimux->srcpad, newbuf);
......@@ -1016,7 +1068,7 @@ gst_avimux_chain (GstPad *pad, GstBuffer *buf)
{
avimux->data_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
avimux->num_frames++;
gst_avimux_add_index(avimux, avimux->vids.compression, 0x12, GST_BUFFER_SIZE(buf));
gst_avimux_add_index(avimux, "00db", 0x12, GST_BUFFER_SIZE(buf));
}
gst_pad_push(avimux->srcpad, newbuf);
......
......@@ -55,9 +55,9 @@ struct _GstAviMux {
/* pads */
GstPad *srcpad;
GstPad *audiosinkpad[MAX_NUM_AUDIO_PADS];
gint num_audio_pads;
gint num_audio_pads, num_audio_pads_connected;
GstPad *videosinkpad[MAX_NUM_VIDEO_PADS];
gint num_video_pads;
gint num_video_pads, num_video_pads_connected;
/* timestamps of first and current frame + num_frames for fps calculation */
gdouble framerate;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment