diff --git a/util/demux.c b/util/demux.c
index e4fc150c41fa6067852d57ea51a8f23dff7639fe..a77bbb8746ceed6e9fe571928bd4f56ba5c4bd1d 100644 (file)
--- a/util/demux.c
+++ b/util/demux.c
#include "util.h"
char mpeg4head[45] = {0,0,0,0};
-int esds_length;
-unsigned char *esds_data;
-extern int first_in_buff;
-int get_esds_offset(const char *filename);
-
-
+int get_esds_offset(const char *filename, struct demux *demux);
static AVFormatContext *
open_file(const char *filename)
{
- AVFormatContext *afc;
- int err = av_open_input_file(&afc, filename, NULL, 0, NULL);
+ static AVFormatContext *afc = NULL;
+ int err = avformat_open_input(&afc, filename, NULL, NULL);
if (!err)
- err = av_find_stream_info(afc);
+ err = avformat_find_stream_info(afc, NULL);
if (err < 0) {
ERROR("%s: lavf error %d", filename, err);
exit(1);
}
- dump_format(afc, 0, filename, 0);
+ av_dump_format(afc, 0, filename, 0);
return afc;
}
AVBitStreamFilterContext *bsf = NULL;
struct demux *demux;
- if ((cc->codec_id != CODEC_ID_H264) && (cc->codec_id != CODEC_ID_MPEG2VIDEO) && ( cc->codec_id != CODEC_ID_MPEG4)){
+ if ((cc->codec_id != AV_CODEC_ID_H264) && (cc->codec_id != AV_CODEC_ID_MPEG2VIDEO) && ( cc->codec_id != AV_CODEC_ID_MPEG4)){
ERROR("could not open '%s': unsupported codec %d", filename, cc->codec_id);
return NULL;
}
@@ -112,20 +107,27 @@ static struct demux * open_stream(const char * filename, int *width, int *height
demux->cc = cc;
demux->st = st;
demux->bsf = bsf;
+ demux->first_in_buff = 0;
return demux;
}
struct demux * demux_init(const char * filename, int *width, int *height)
{
+ struct demux *demux;
+
av_register_all();
avcodec_register_all();
- if(get_esds_offset(filename))
- return NULL;
- return open_stream(filename, width, height);
+ demux = open_stream(filename, width, height);
+ if ((demux != NULL) && (demux->cc->codec_id == AV_CODEC_ID_MPEG4)) {
+ if(get_esds_offset(filename, demux))
+ return NULL;
+ }
+
+ return demux;
}
-int get_esds_offset(const char *filename) {
+int get_esds_offset(const char *filename, struct demux *demux) {
FILE *inputStream;
int i=0;
unsigned char *buffer = NULL;
break;
}
}
- esds_length= buffer[esds_index];
- esds_data=malloc(esds_length);
- for(i=1; i<=esds_length; i++) {
+ demux->esds.length= buffer[esds_index];
+ demux->esds.data=malloc(demux->esds.length);
+ for(i=1; i<=demux->esds.length; i++) {
//printf(" index= %x \n",buffer[esds_index+i]);
- esds_data[i-1]=buffer[esds_index+i];
- printf(" index= %x \n",esds_data[i-1]);
+ demux->esds.data[i-1]=buffer[esds_index+i];
+ printf(" index= %x \n",demux->esds.data[i-1]);
}
free(buffer);
return 0;
if (bufsize > size)
bufsize = size;
- if(first_in_buff == 1) {
- memcpy(input,esds_data,esds_length);
- memcpy(input+esds_length, buf, bufsize);
- first_in_buff =0;
- bufsize = bufsize+esds_length;
+ if(demux->first_in_buff == 1) {
+ memcpy(input, demux->esds.data, demux->esds.length);
+ memcpy(input + demux->esds.length, buf, bufsize);
+ demux->first_in_buff =0;
+ bufsize = bufsize + demux->esds.length;
}
else {
memcpy(input, buf, bufsize);
void demux_deinit(struct demux *demux)
{
- av_close_input_file(demux->afc);
+ avformat_close_input(demux->afc);
if (demux->bsf)
av_bitstream_filter_close(demux->bsf);
+ free(demux->esds.data);
free(demux);
}