mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 03:01:03 +00:00
MPEG2 decoder fixes, unified MPEG System stream parser. an mpeg encoder.
Original commit message from CVS: MPEG2 decoder fixes, unified MPEG System stream parser. an mpeg encoder.
This commit is contained in:
parent
c81358367e
commit
58dede8409
7 changed files with 237 additions and 8 deletions
|
@ -317,6 +317,7 @@ plugins/mpeg2/parse/Makefile
|
|||
plugins/mpeg2/ac3parse/Makefile
|
||||
plugins/mpeg2/ac3dec/Makefile
|
||||
plugins/mpeg2/video/Makefile
|
||||
plugins/mpeg2/mpeg2enc/Makefile
|
||||
plugins/mpeg1/Makefile
|
||||
plugins/mpeg1/mpeg_play/Makefile
|
||||
plugins/mpeg1/parse/Makefile
|
||||
|
|
|
@ -22,6 +22,8 @@ typedef struct _gst_getbits_t gst_getbits_t;
|
|||
struct _gst_getbits_t {
|
||||
unsigned char *ptr;
|
||||
unsigned long *longptr;
|
||||
unsigned char *endptr;
|
||||
unsigned long length;
|
||||
long bits;
|
||||
unsigned long dword;
|
||||
unsigned long temp;
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include <glib.h>
|
||||
|
||||
//#define GETBITS_DEBUG_ENABLED
|
||||
//#define GETBITS_OVERRUN_ENABLED
|
||||
|
||||
#ifdef GETBITS_DEBUG_ENABLED
|
||||
#define debug2(format,args...) g_print(format,##args)
|
||||
|
@ -64,6 +65,14 @@
|
|||
#define debug2(format,args...)
|
||||
#endif
|
||||
|
||||
#ifdef GETBITS_OVERRUN_ENABLED
|
||||
#define checklength2(src, dst) (((unsigned char*)src)<(dst)?0:printf("overrun !! %p>=%p %ld %s %d\n", (src), (dst), (gb)->bits, __PRETTY_FUNCTION__, __LINE__))
|
||||
#define checklength(src, dst) (((unsigned char*)src)<(dst)?0:printf("overrun !! %p>=%p %ld %s %d\n", (src), (dst), (gb)->bits, __PRETTY_FUNCTION__, __LINE__)),
|
||||
#else
|
||||
#define checklength(src, dst)
|
||||
#define checklength2(src, dst)
|
||||
#endif
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# define swab32(x) (x)
|
||||
#else
|
||||
|
@ -86,9 +95,11 @@ extern unsigned long gst_getbits_nBitMask[];
|
|||
|
||||
#define gst_getbits_init(gb)
|
||||
|
||||
#define gst_getbits_newbuf(gb, buffer) \
|
||||
#define gst_getbits_newbuf(gb, buffer, len) \
|
||||
{ \
|
||||
(gb)->longptr = (unsigned long *)(buffer); \
|
||||
(gb)->endptr = (unsigned char *)buffer+len; \
|
||||
(gb)->length = len; \
|
||||
(gb)->bits = 0; \
|
||||
(gb)->dword = swab32(*(gb)->longptr); \
|
||||
}
|
||||
|
@ -101,6 +112,10 @@ extern unsigned long gst_getbits_nBitMask[];
|
|||
|
||||
#define gst_getbits_bufferpos(gb) ((gb)->longptr)
|
||||
|
||||
#define gst_getbits_bytesleft(gb) ((gb)->endptr - (unsigned char*)(gb)->longptr)
|
||||
|
||||
#define gst_getbits_bitsleft(gb) (((gb)->endptr - (unsigned char*)(gb)->longptr)*8 - (gb)->bits)
|
||||
|
||||
#define gst_getbits1(gb) \
|
||||
( \
|
||||
((gb)->temp = (((gb)->dword & 0x80000000) != 0)), \
|
||||
|
@ -110,6 +125,7 @@ extern unsigned long gst_getbits_nBitMask[];
|
|||
((gb)->bits & 0x20 ? ( \
|
||||
(gb)->bits = 0, \
|
||||
(gb)->longptr++, \
|
||||
checklength((gb)->longptr, (gb)->endptr) \
|
||||
((gb)->dword = swab32(*(gb)->longptr)) \
|
||||
) \
|
||||
:0), \
|
||||
|
@ -124,6 +140,7 @@ extern unsigned long gst_getbits_nBitMask[];
|
|||
((gb)->bits & 0x20 ? ( \
|
||||
(gb)->bits -= 32, \
|
||||
(gb)->longptr++, \
|
||||
checklength((gb)->longptr, (gb)->endptr) \
|
||||
((gb)->bits ? ( \
|
||||
((gb)->dword |= \
|
||||
(swab32(*(gb)->longptr) >> (2 - (gb)->bits))) \
|
||||
|
@ -149,6 +166,7 @@ extern unsigned long gst_getbits_nBitMask[];
|
|||
((gb)->bits & 0x20 ? ( \
|
||||
(gb)->bits -= 32, \
|
||||
(gb)->longptr++, \
|
||||
checklength((gb)->longptr, (gb)->endptr) \
|
||||
((gb)->bits ? ( \
|
||||
((gb)->dword |= (swab32(*(gb)->longptr) >> \
|
||||
((num) - (gb)->bits))) \
|
||||
|
@ -254,6 +272,7 @@ extern unsigned long gst_getbits_nBitMask[];
|
|||
#define gst_flushbits32(gb) \
|
||||
{ \
|
||||
(gb)->longptr++; \
|
||||
checklength2((gb)->longptr, (gb)->endptr); \
|
||||
(gb)->dword = swab32(*(gb)->longptr) << (gb)->bits; \
|
||||
}
|
||||
|
||||
|
@ -265,6 +284,7 @@ extern unsigned long gst_getbits_nBitMask[];
|
|||
if ((gb)->bits & 0x20) { \
|
||||
(gb)->bits -= 32; \
|
||||
(gb)->longptr++; \
|
||||
checklength2((gb)->longptr, (gb)->endptr); \
|
||||
(gb)->dword = swab32(*(gb)->longptr) << (gb)->bits; \
|
||||
} \
|
||||
else { \
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#noinst_PROGRAMS = basic m types a r plugin w s args mpg123 mcut push qtest
|
||||
noinst_PROGRAMS = qtest spectrum record wave mp3 teardown buffer mp3parse \
|
||||
mpeg2parse mp1parse mp3play ac3parse ac3play dvdcat fake cobin videotest \
|
||||
aviparse vidcapture
|
||||
aviparse vidcapture avi2mpg
|
||||
|
||||
SUBDIRS = xml cothreads bindings
|
||||
|
||||
|
|
164
test/avi2mpg.c
Normal file
164
test/avi2mpg.c
Normal file
|
@ -0,0 +1,164 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <glib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
|
||||
extern gboolean _gst_plugin_spew;
|
||||
gboolean idle_func(gpointer data);
|
||||
int fd;
|
||||
char *outfile;
|
||||
|
||||
void eof(GstSrc *src) {
|
||||
g_print("have eos, quitting\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void new_pad_created(GstElement *parse,GstPad *pad,GstElement *pipeline) {
|
||||
GstElement *parse_audio, *parse_video, *decode, *decode_video, *play, *encode;
|
||||
GstElement *audio_queue, *video_queue;
|
||||
GstElement *audio_thread, *video_thread;
|
||||
GstElement *fdsink;
|
||||
GstElementFactory *fdsinkfactory;
|
||||
|
||||
GtkWidget *appwindow;
|
||||
|
||||
g_print("***** a new pad %s was created\n", gst_pad_get_name(pad));
|
||||
|
||||
// connect to audio pad
|
||||
//if (0) {
|
||||
if (strncmp(gst_pad_get_name(pad), "audio_", 6) == 0) {
|
||||
// construct internal pipeline elements
|
||||
play = gst_elementfactory_make("audiosink","play_audio");
|
||||
g_return_if_fail(play != NULL);
|
||||
|
||||
// create the thread and pack stuff into it
|
||||
audio_thread = gst_thread_new("audio_thread");
|
||||
g_return_if_fail(audio_thread != NULL);
|
||||
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(play));
|
||||
|
||||
// set up pad connections
|
||||
gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
|
||||
gst_element_get_pad(play,"sink"));
|
||||
|
||||
// construct queue and connect everything in the main pipelie
|
||||
audio_queue = gst_elementfactory_make("queue","audio_queue");
|
||||
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(audio_queue));
|
||||
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(audio_thread));
|
||||
gst_pad_connect(pad,
|
||||
gst_element_get_pad(audio_queue,"sink"));
|
||||
gst_pad_connect(gst_element_get_pad(audio_queue,"src"),
|
||||
gst_element_get_pad(audio_thread,"sink"));
|
||||
|
||||
// set up thread state and kick things off
|
||||
gtk_object_set(GTK_OBJECT(audio_thread),"create_thread",TRUE,NULL);
|
||||
g_print("setting to RUNNING state\n");
|
||||
gst_element_set_state(GST_ELEMENT(audio_thread),GST_STATE_RUNNING);
|
||||
g_print("setting to PLAYING state\n");
|
||||
gst_element_set_state(GST_ELEMENT(audio_thread),GST_STATE_PLAYING);
|
||||
} else if (strncmp(gst_pad_get_name(pad), "video_", 6) == 0) {
|
||||
//} else if (0) {
|
||||
|
||||
gst_plugin_load("mpeg2enc");
|
||||
// construct internal pipeline elements
|
||||
encode = gst_elementfactory_make("mpeg2enc","encode");
|
||||
g_return_if_fail(encode != NULL);
|
||||
//gtk_object_set(GTK_OBJECT(show),"width",640, "height", 480,NULL);
|
||||
fd = open(outfile,O_CREAT|O_RDWR|O_TRUNC);
|
||||
|
||||
fdsinkfactory = gst_elementfactory_find("fdsink");
|
||||
g_return_if_fail(fdsinkfactory != NULL);
|
||||
fdsink = gst_elementfactory_create(fdsinkfactory,"fdsink");
|
||||
g_return_if_fail(fdsink != NULL);
|
||||
gtk_object_set(GTK_OBJECT(fdsink),"fd",fd,NULL);
|
||||
|
||||
// create the thread and pack stuff into it
|
||||
video_thread = gst_thread_new("video_thread");
|
||||
g_return_if_fail(video_thread != NULL);
|
||||
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(encode));
|
||||
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(fdsink));
|
||||
gst_pad_connect(gst_element_get_pad(encode,"src"),
|
||||
gst_element_get_pad(fdsink,"sink"));
|
||||
|
||||
// set up pad connections
|
||||
gst_element_add_ghost_pad(GST_ELEMENT(video_thread),
|
||||
gst_element_get_pad(encode,"sink"));
|
||||
|
||||
// construct queue and connect everything in the main pipeline
|
||||
video_queue = gst_elementfactory_make("queue","video_queue");
|
||||
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(video_queue));
|
||||
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(video_thread));
|
||||
gst_pad_connect(pad,
|
||||
gst_element_get_pad(video_queue,"sink"));
|
||||
gst_pad_connect(gst_element_get_pad(video_queue,"src"),
|
||||
gst_element_get_pad(video_thread,"sink"));
|
||||
|
||||
// set up thread state and kick things off
|
||||
gtk_object_set(GTK_OBJECT(video_thread),"create_thread",TRUE,NULL);
|
||||
g_print("setting to RUNNING state\n");
|
||||
gst_element_set_state(GST_ELEMENT(video_thread),GST_STATE_RUNNING);
|
||||
g_print("setting to PLAYING state\n");
|
||||
gst_element_set_state(GST_ELEMENT(video_thread),GST_STATE_PLAYING);
|
||||
}
|
||||
g_print("\n");
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[]) {
|
||||
GstPipeline *pipeline;
|
||||
GstElement *src, *parse;
|
||||
|
||||
g_print("have %d args\n",argc);
|
||||
|
||||
//_gst_plugin_spew = TRUE;
|
||||
gst_init(&argc,&argv);
|
||||
gst_plugin_load("parseavi");
|
||||
|
||||
pipeline = gst_pipeline_new("pipeline");
|
||||
g_return_if_fail(pipeline != NULL);
|
||||
|
||||
src = gst_elementfactory_make("disksrc","src");
|
||||
g_return_if_fail(src != NULL);
|
||||
gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
|
||||
g_print("should be using file '%s'\n",argv[1]);
|
||||
|
||||
g_print("should be using output file '%s'\n",argv[2]);
|
||||
outfile = argv[2];
|
||||
|
||||
parse = gst_elementfactory_make("parseavi","parse");
|
||||
g_return_if_fail(parse != NULL);
|
||||
|
||||
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(src));
|
||||
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(parse));
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(parse),"new_pad",
|
||||
GTK_SIGNAL_FUNC(new_pad_created),pipeline);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(src),"eos",
|
||||
GTK_SIGNAL_FUNC(eof),NULL);
|
||||
|
||||
gst_pad_connect(gst_element_get_pad(src,"src"),
|
||||
gst_element_get_pad(parse,"sink"));
|
||||
|
||||
g_print("setting to RUNNING state\n");
|
||||
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_RUNNING);
|
||||
|
||||
xmlSaveFile("aviparse.xml",gst_xml_write(GST_ELEMENT(pipeline)));
|
||||
|
||||
g_print("about to enter loop\n");
|
||||
|
||||
while (1) {
|
||||
gst_src_push(GST_SRC(src));
|
||||
}
|
||||
// this does not work due to multithreading
|
||||
/*
|
||||
g_idle_add(idle_func,src);
|
||||
|
||||
gtk_main();
|
||||
*/
|
||||
}
|
||||
|
||||
gboolean idle_func(gpointer data) {
|
||||
gst_src_push(GST_SRC(data));
|
||||
return TRUE;
|
||||
}
|
|
@ -67,14 +67,14 @@ void new_pad_created(GstElement *parse,GstPad *pad,GstElement *pipeline) {
|
|||
//} else if (0) {
|
||||
|
||||
gst_plugin_load("mp1videoparse");
|
||||
gst_plugin_load("mpeg_play");
|
||||
//gst_plugin_load("mpeg2play");
|
||||
//gst_plugin_load("mpeg_play");
|
||||
gst_plugin_load("mpeg2play");
|
||||
gst_plugin_load("videosink");
|
||||
// construct internal pipeline elements
|
||||
parse_video = gst_elementfactory_make("mp1videoparse","parse_video");
|
||||
g_return_if_fail(parse_video != NULL);
|
||||
decode_video = gst_elementfactory_make("mpeg_play","decode_video");
|
||||
//decode_video = gst_elementfactory_make("mpeg2play","decode_video");
|
||||
//decode_video = gst_elementfactory_make("mpeg_play","decode_video");
|
||||
decode_video = gst_elementfactory_make("mpeg2play","decode_video");
|
||||
g_return_if_fail(decode_video != NULL);
|
||||
show = gst_elementfactory_make("videosink","show");
|
||||
g_return_if_fail(show != NULL);
|
||||
|
|
|
@ -17,8 +17,8 @@ void mpeg2parse_newpad(GstElement *parser,GstPad *pad, GstElement *pipeline) {
|
|||
g_print("***** a new pad %s was created\n", gst_pad_get_name(pad));
|
||||
|
||||
// connect to audio pad
|
||||
if (0) {
|
||||
//if (strncmp(gst_pad_get_name(pad), "private_stream_1.0", 18) == 0) {
|
||||
//if (0) {
|
||||
if (strncmp(gst_pad_get_name(pad), "private_stream_1.0", 18) == 0) {
|
||||
gst_plugin_load("ac3parse");
|
||||
gst_plugin_load("ac3dec");
|
||||
// construct internal pipeline elements
|
||||
|
@ -36,6 +36,48 @@ void mpeg2parse_newpad(GstElement *parser,GstPad *pad, GstElement *pipeline) {
|
|||
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(decode));
|
||||
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(play));
|
||||
|
||||
// set up pad connections
|
||||
gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
|
||||
gst_element_get_pad(parse_audio,"sink"));
|
||||
gst_pad_connect(gst_element_get_pad(parse_audio,"src"),
|
||||
gst_element_get_pad(decode,"sink"));
|
||||
gst_pad_connect(gst_element_get_pad(decode,"src"),
|
||||
gst_element_get_pad(play,"sink"));
|
||||
|
||||
// construct queue and connect everything in the main pipelie
|
||||
audio_queue = gst_elementfactory_make("queue","audio_queue");
|
||||
gtk_object_set(GTK_OBJECT(audio_queue),"max_level",30,NULL);
|
||||
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(audio_queue));
|
||||
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(audio_thread));
|
||||
gst_pad_connect(pad,
|
||||
gst_element_get_pad(audio_queue,"sink"));
|
||||
gst_pad_connect(gst_element_get_pad(audio_queue,"src"),
|
||||
gst_element_get_pad(audio_thread,"sink"));
|
||||
|
||||
// set up thread state and kick things off
|
||||
gtk_object_set(GTK_OBJECT(audio_thread),"create_thread",TRUE,NULL);
|
||||
g_print("setting to RUNNING state\n");
|
||||
gst_element_set_state(GST_ELEMENT(audio_thread),GST_STATE_RUNNING);
|
||||
g_print("setting to PLAYING state\n");
|
||||
gst_element_set_state(GST_ELEMENT(audio_thread),GST_STATE_PLAYING);
|
||||
} else if (strncmp(gst_pad_get_name(pad), "audio_", 6) == 0) {
|
||||
gst_plugin_load("mp3parse");
|
||||
gst_plugin_load("mpg123");
|
||||
// construct internal pipeline elements
|
||||
parse_audio = gst_elementfactory_make("mp3parse","parse_audio");
|
||||
g_return_if_fail(parse_audio != NULL);
|
||||
decode = gst_elementfactory_make("mpg123","decode_audio");
|
||||
g_return_if_fail(decode != NULL);
|
||||
play = gst_elementfactory_make("audiosink","play_audio");
|
||||
g_return_if_fail(play != NULL);
|
||||
|
||||
// create the thread and pack stuff into it
|
||||
audio_thread = gst_thread_new("audio_thread");
|
||||
g_return_if_fail(audio_thread != NULL);
|
||||
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(parse_audio));
|
||||
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(decode));
|
||||
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(play));
|
||||
|
||||
// set up pad connections
|
||||
gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
|
||||
gst_element_get_pad(parse_audio,"sink"));
|
||||
|
|
Loading…
Reference in a new issue