gst/avi/: Port AVI muxer to GStreamer-0.10 (#332031).

Original commit message from CVS:
Patch by: Mark Nauwelaerts  <manauw at skynet dot be>
* gst/avi/Makefile.am:
* gst/avi/gstavi.c: (plugin_init):
* gst/avi/gstavimux.c: (gst_avi_mux_get_type),
(gst_avi_mux_base_init), (gst_avi_mux_finalize),
(gst_avi_mux_class_init), (gst_avi_mux_init),
(gst_avi_mux_vidsink_set_caps), (gst_avi_mux_audsink_set_caps),
(gst_avi_mux_pad_link), (gst_avi_mux_pad_unlink),
(gst_avi_mux_request_new_pad), (gst_avi_mux_release_pad),
(gst_avi_mux_write_tag), (gst_avi_mux_riff_get_avi_header),
(gst_avi_mux_riff_get_avix_header),
(gst_avi_mux_riff_get_video_header),
(gst_avi_mux_riff_get_audio_header), (gst_avi_mux_add_index),
(gst_avi_mux_write_index), (gst_avi_mux_bigfile),
(gst_avi_mux_start_file), (gst_avi_mux_stop_file),
(gst_avi_mux_restart_file), (gst_avi_mux_handle_event),
(gst_avi_mux_fill_queue), (gst_avi_mux_send_pad_data),
(gst_avi_mux_strip_buffer), (gst_avi_mux_do_audio_buffer),
(gst_avi_mux_do_video_buffer), (gst_avi_mux_do_one_buffer),
(gst_avi_mux_loop), (gst_avi_mux_collect_pads),
(gst_avi_mux_get_property), (gst_avi_mux_set_property),
(gst_avi_mux_change_state):
* gst/avi/gstavimux.h:
Port AVI muxer to GStreamer-0.10 (#332031).
* tests/check/Makefile.am:
* tests/check/elements/avimux.c:
* tests/check/elements/.cvsignore:
Add unit test for AVI muxer.
This commit is contained in:
Mark Nauwelaerts 2006-04-27 14:51:06 +00:00 committed by Tim-Philipp Müller
parent 422c6fcc0c
commit d1cdfa6d3c
8 changed files with 892 additions and 329 deletions

View file

@ -1,3 +1,36 @@
2006-04-27 Tim-Philipp Müller <tim at centricular dot net>
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* gst/avi/Makefile.am:
* gst/avi/gstavi.c: (plugin_init):
* gst/avi/gstavimux.c: (gst_avi_mux_get_type),
(gst_avi_mux_base_init), (gst_avi_mux_finalize),
(gst_avi_mux_class_init), (gst_avi_mux_init),
(gst_avi_mux_vidsink_set_caps), (gst_avi_mux_audsink_set_caps),
(gst_avi_mux_pad_link), (gst_avi_mux_pad_unlink),
(gst_avi_mux_request_new_pad), (gst_avi_mux_release_pad),
(gst_avi_mux_write_tag), (gst_avi_mux_riff_get_avi_header),
(gst_avi_mux_riff_get_avix_header),
(gst_avi_mux_riff_get_video_header),
(gst_avi_mux_riff_get_audio_header), (gst_avi_mux_add_index),
(gst_avi_mux_write_index), (gst_avi_mux_bigfile),
(gst_avi_mux_start_file), (gst_avi_mux_stop_file),
(gst_avi_mux_restart_file), (gst_avi_mux_handle_event),
(gst_avi_mux_fill_queue), (gst_avi_mux_send_pad_data),
(gst_avi_mux_strip_buffer), (gst_avi_mux_do_audio_buffer),
(gst_avi_mux_do_video_buffer), (gst_avi_mux_do_one_buffer),
(gst_avi_mux_loop), (gst_avi_mux_collect_pads),
(gst_avi_mux_get_property), (gst_avi_mux_set_property),
(gst_avi_mux_change_state):
* gst/avi/gstavimux.h:
Port AVI muxer to GStreamer-0.10 (#332031).
* tests/check/Makefile.am:
* tests/check/elements/avimux.c:
* tests/check/elements/.cvsignore:
Add unit test for AVI muxer.
2006-04-27 Stefan Kost <ensonic@users.sf.net>
* gst/wavparse/gstwavparse.c: (gst_wavparse_base_init),

View file

@ -2,6 +2,7 @@ plugin_LTLIBRARIES = libgstavi.la
libgstavi_la_SOURCES = \
gstavi.c \
gstavimux.c \
gstavidemux.c
noinst_HEADERS = \
@ -13,8 +14,9 @@ libgstavi_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) \
-I$(top_srcdir)/gst-libs
libgstavi_la_LIBADD = \
$(GST_PLUGINS_BASE_LIBS) \
$(GST_BASE_LIBS) \
$(GST_LIBS) \
-lgstriff-@GST_MAJORMINOR@
libgstavi_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
EXTRA_DIST = README gstavimux.c
EXTRA_DIST = README

View file

@ -26,7 +26,7 @@
#include "gst/gst-i18n-plugin.h"
#include "gstavidemux.h"
/*#include "gstavimux.h"*/
#include "gstavimux.h"
static gboolean
plugin_init (GstPlugin * plugin)
@ -38,9 +38,14 @@ plugin_init (GstPlugin * plugin)
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
#endif /* ENABLE_NLS */
return (gst_element_register (plugin, "avidemux", GST_RANK_PRIMARY, GST_TYPE_AVI_DEMUX) /*&&
gst_element_register (plugin, "avimux", GST_RANK_NONE, GST_TYPE_AVIMUX) */
);
if (!gst_element_register (plugin, "avidemux", GST_RANK_PRIMARY,
GST_TYPE_AVI_DEMUX) ||
!gst_element_register (plugin, "avimux", GST_RANK_NONE,
GST_TYPE_AVI_MUX)) {
return FALSE;
}
return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,

File diff suppressed because it is too large Load diff

View file

@ -18,30 +18,27 @@
*/
#ifndef __GST_AVIMUX_H__
#define __GST_AVIMUX_H__
#ifndef __GST_AVI_MUX_H__
#define __GST_AVI_MUX_H__
#include <gst/gst.h>
#include <gst/base/gstcollectpads.h>
#include <gst/riff/riff-ids.h>
#include "avi-ids.h"
G_BEGIN_DECLS
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GST_TYPE_AVIMUX \
(gst_avimux_get_type())
#define GST_AVIMUX(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AVIMUX,GstAviMux))
#define GST_AVIMUX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AVIMUX,GstAviMux))
#define GST_IS_AVIMUX(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AVIMUX))
#define GST_IS_AVIMUX_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AVIMUX))
#define GST_TYPE_AVI_MUX \
(gst_avi_mux_get_type())
#define GST_AVI_MUX(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AVI_MUX,GstAviMux))
#define GST_AVI_MUX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AVI_MUX,GstAviMuxClass))
#define GST_IS_AVI_MUX(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AVI_MUX))
#define GST_IS_AVI_MUX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AVI_MUX))
typedef struct _GstAviMux GstAviMux;
@ -51,11 +48,13 @@ struct _GstAviMux {
GstElement element;
/* pads */
GstPad *srcpad;
GstPad *audiosinkpad;
gboolean audio_pad_connected, audio_pad_eos;
GstPad *videosinkpad;
gboolean video_pad_connected, video_pad_eos;
GstPad *srcpad;
GstCollectData *audiocollectdata;
gboolean audio_pad_connected;
GstCollectData *videocollectdata;
gboolean video_pad_connected;
GstCollectPads *collect;
GstPadEventFunction collect_event;
/* the AVI header */
gst_riff_avih avi_hdr;
@ -79,6 +78,8 @@ struct _GstAviMux {
/* tags */
GstTagList *tags;
GstTagList *tags_snap;
guint32 tag_size;
/* information about the AVI index ('idx') */
gst_riff_index_entry *idx;
@ -91,21 +92,15 @@ struct _GstAviMux {
/* whether to use "large AVI files" or just stick to small indexed files */
gboolean enable_large_avi;
/* in order to be usable as a loopbased element, we need an internal
* 'buffered' buffer for each pad, so one for audio, one for video */
GstBuffer *audio_buffer_queue, *video_buffer_queue;
};
struct _GstAviMuxClass {
GstElementClass parent_class;
};
GType gst_avimux_get_type(void);
GType gst_avi_mux_get_type(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_AVIMUX_H__ */
#endif /* __GST_AVI_MUX_H__ */

View file

@ -18,6 +18,7 @@ clean-local: clean-local-check
TESTS = $(check_PROGRAMS)
check_PROGRAMS = \
elements/avimux \
elements/level \
elements/matroskamux \
elements/cmmldec \

View file

@ -3,3 +3,5 @@ level
matroskamux
cmmldec
cmmlenc
icydemux
avimux

View file

@ -0,0 +1,268 @@
/* GStreamer
*
* unit test for avimux
*
* Copyright (C) <2006> Mark Nauwelaerts <manauw@skynet.be>
*
* 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.
*/
#include <unistd.h>
#include <gst/check/gstcheck.h>
/* For ease of programming we use globals to keep refs for our floating
* src and sink pads we create; otherwise we always have to do get_pad,
* get_peer, and then remove references in every test function */
static GstPad *mysrcpad, *mysinkpad;
#define AUDIO_CAPS_STRING "audio/x-ac3, " \
"channels = (int) 1, " \
"rate = (int) 8000"
#define VIDEO_CAPS_STRING "video/x-xvid, " \
"width = (int) 384, " \
"height = (int) 288, " \
"framerate = (fraction) 25/1"
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-msvideo"));
static GstStaticPadTemplate srcvideotemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (VIDEO_CAPS_STRING));
static GstStaticPadTemplate srcaudiotemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (AUDIO_CAPS_STRING));
/* setup and teardown needs some special handling for muxer */
GstPad *
setup_src_pad (GstElement * element,
GstStaticPadTemplate * template, GstCaps * caps, gchar * sinkname)
{
GstPad *srcpad, *sinkpad;
GST_DEBUG_OBJECT (element, "setting up sending pad");
/* sending pad */
srcpad = gst_pad_new_from_static_template (template, "src");
fail_if (srcpad == NULL, "Could not create a srcpad");
ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
sinkpad = gst_element_get_pad (element, sinkname);
fail_if (sinkpad == NULL, "Could not get sink pad from %s",
GST_ELEMENT_NAME (element));
/* references are owned by: 1) us, 2) avimux, 3) collect pads */
ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
if (caps)
fail_unless (gst_pad_set_caps (srcpad, caps));
fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
"Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
gst_object_unref (sinkpad); /* because we got it higher up */
/* references are owned by: 1) avimux, 2) collect pads */
ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
return srcpad;
}
void
teardown_src_pad (GstElement * element, gchar * sinkname)
{
GstPad *srcpad, *sinkpad;
gchar *padname;
/* clean up floating src pad */
/* hm, avimux uses _00 as suffixes for padnames */
padname = g_strdup (sinkname);
memcpy (strchr (padname, '%'), "00", 2);
sinkpad = gst_element_get_pad (element, padname);
g_free (padname);
/* pad refs held by 1) avimux 2) collectpads and 3) us (through _get) */
ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
srcpad = gst_pad_get_peer (sinkpad);
gst_pad_unlink (srcpad, sinkpad);
/* after unlinking, pad refs held by 1) avimux and 2) us (through _get) */
ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
gst_object_unref (sinkpad);
/* one more ref is held by element itself */
/* pad refs held by both creator and this function (through _get_peer) */
ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 2);
gst_object_unref (srcpad);
gst_object_unref (srcpad);
}
GstElement *
setup_avimux (GstStaticPadTemplate * srctemplate, gchar * sinkname)
{
GstElement *avimux;
GST_DEBUG ("setup_avimux");
avimux = gst_check_setup_element ("avimux");
mysrcpad = setup_src_pad (avimux, srctemplate, NULL, sinkname);
mysinkpad = gst_check_setup_sink_pad (avimux, &sinktemplate, NULL);
return avimux;
}
void
cleanup_avimux (GstElement * avimux, gchar * sinkname)
{
GST_DEBUG ("cleanup_avimux");
gst_element_set_state (avimux, GST_STATE_NULL);
teardown_src_pad (avimux, sinkname);
gst_check_teardown_sink_pad (avimux);
gst_check_teardown_element (avimux);
}
void
check_avimux_pad (GstStaticPadTemplate * srctemplate, gchar * src_caps_string,
gchar * chunk_id, gchar * sinkname)
{
GstElement *avimux;
GstBuffer *inbuffer, *outbuffer;
GstCaps *caps;
int num_buffers;
int i;
guint8 data0[4] = "RIFF";
guint8 data1[8] = "AVI LIST";
guint8 data2[8] = "hdrlavih";
guint8 data3[4] = "LIST";
guint8 data4[8] = "strlstrh";
guint8 data5[4] = "strf";
guint8 data6[4] = "LIST";
guint8 data7[4] = "movi";
avimux = setup_avimux (srctemplate, sinkname);
fail_unless (gst_element_set_state (avimux,
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
"could not set to playing");
inbuffer = gst_buffer_new_and_alloc (1);
caps = gst_caps_from_string (src_caps_string);
gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
num_buffers = g_list_length (buffers);
/* at least expect avi header, chunk header, chunk and padding */
fail_unless (num_buffers >= 4);
for (i = 0; i < num_buffers; ++i) {
outbuffer = GST_BUFFER (buffers->data);
fail_if (outbuffer == NULL);
buffers = g_list_remove (buffers, outbuffer);
switch (i) {
case 0:{ /* check riff header */
/* avi header */
guint8 *data = GST_BUFFER_DATA (outbuffer);
fail_unless (memcmp (data, data0, sizeof (data0)) == 0);
fail_unless (memcmp (data + 8, data1, sizeof (data1)) == 0);
fail_unless (memcmp (data + 20, data2, sizeof (data2)) == 0);
/* video or audio header */
data += 32 + 56;
fail_unless (memcmp (data, data3, sizeof (data3)) == 0);
fail_unless (memcmp (data + 8, data4, sizeof (data4)) == 0);
fail_unless (memcmp (data + 68, data5, sizeof (data5)) == 0);
/* avi data header */
data = GST_BUFFER_DATA (outbuffer);
data += GST_BUFFER_SIZE (outbuffer) - 12;
fail_unless (memcmp (data, data6, sizeof (data6)) == 0);
data += 8;
fail_unless (memcmp (data, data7, sizeof (data7)) == 0);
break;
}
case 1: /* chunk header */
fail_unless (GST_BUFFER_SIZE (outbuffer) == 8);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), chunk_id, 4) == 0);
break;
case 2:
fail_unless (GST_BUFFER_SIZE (outbuffer) == 1);
break;
case 3: /* buffer we put in, must be padded to even size */
fail_unless (GST_BUFFER_SIZE (outbuffer) == 1);
break;
default:
break;
}
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
gst_buffer_unref (outbuffer);
outbuffer = NULL;
}
cleanup_avimux (avimux, sinkname);
g_list_free (buffers);
buffers = NULL;
}
GST_START_TEST (test_video_pad)
{
check_avimux_pad (&srcvideotemplate, VIDEO_CAPS_STRING, "00db", "video_%d");
}
GST_END_TEST;
GST_START_TEST (test_audio_pad)
{
check_avimux_pad (&srcaudiotemplate, AUDIO_CAPS_STRING, "01wb", "audio_%d");
}
GST_END_TEST;
Suite *
avimux_suite (void)
{
Suite *s = suite_create ("avimux");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_video_pad);
tcase_add_test (tc_chain, test_audio_pad);
return s;
}
int
main (int argc, char **argv)
{
int nf;
Suite *s = avimux_suite ();
SRunner *sr = srunner_create (s);
gst_check_init (&argc, &argv);
srunner_run_all (sr, CK_NORMAL);
nf = srunner_ntests_failed (sr);
srunner_free (sr);
return nf;
}