summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bf974ae)
raw | patch | inline | side by side (parent: bf974ae)
author | Chandramohan C <chandramohan.c@ti.com> | |
Fri, 6 Sep 2013 09:15:23 +0000 (09:15 +0000) | ||
committer | Chandramohan <a0131763@ti.com> | |
Fri, 6 Sep 2013 09:16:50 +0000 (14:46 +0530) |
Function implemented to read the mp4 file into a buffer and parses
for esds data required for ivahd_mpeg4dec decoder and it is copied on
top of the first input buffer.
Only 720p/1080p video is tested
Signed-off-by: Chandramohan C <chandramohan.c@ti.com>
for esds data required for ivahd_mpeg4dec decoder and it is copied on
top of the first input buffer.
Only 720p/1080p video is tested
Signed-off-by: Chandramohan C <chandramohan.c@ti.com>
util/demux.c | patch | blob | history | |
viddec3test.c | patch | blob | history |
diff --git a/util/demux.c b/util/demux.c
index c043848e8ed60e43324bb60e736aec915b14a27a..e4fc150c41fa6067852d57ea51a8f23dff7639fe 100644 (file)
--- a/util/demux.c
+++ b/util/demux.c
#include "demux.h"
#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);
+
+
+
static AVFormatContext *
open_file(const char *filename)
{
AVBitStreamFilterContext *bsf = NULL;
struct demux *demux;
- if ((cc->codec_id != CODEC_ID_H264) && (cc->codec_id != CODEC_ID_MPEG2VIDEO)){
+ if ((cc->codec_id != CODEC_ID_H264) && (cc->codec_id != CODEC_ID_MPEG2VIDEO) && ( cc->codec_id != CODEC_ID_MPEG4)){
ERROR("could not open '%s': unsupported codec %d", filename, cc->codec_id);
return NULL;
}
{
av_register_all();
avcodec_register_all();
+ if(get_esds_offset(filename))
+ return NULL;
return open_stream(filename, width, height);
}
+int get_esds_offset(const char *filename) {
+ FILE *inputStream;
+ int i=0;
+ unsigned char *buffer = NULL;
+ unsigned long fileLen;
+ int esds_index=0;
+ inputStream = fopen(filename,"rb");
+ if (!inputStream) {
+ printf("Unable to open %s\n",filename);
+ return -1;
+ }
+ // Get the length
+ fseek(inputStream, 0, SEEK_END);
+ fileLen=ftell(inputStream);
+ fseek(inputStream, 0, SEEK_SET);
+ buffer=malloc(fileLen);
+ if (!buffer) {
+ printf("Memory error!\n");
+ fclose(inputStream);
+ return -1;
+ }
+ // File to buffer
+ fread(buffer, fileLen, 1, inputStream);
+ fclose(inputStream);
+ printf("Buffer starts: %p\n", &buffer[0]);
+ printf("Buffer ends: %p\n", &buffer[fileLen]);
+ //Determines offset of known_string
+ for(i=0; i<fileLen; i++) {
+ if((buffer[i] == 0x65) && (buffer[++i] == 0x73))
+ if((buffer[++i] == 0x64) && (buffer[i+1] == 0x73)) {
+ printf("data in buffer = %x %x %x %d \n",buffer[i],buffer[i+1],buffer[i+2],buffer[i+27]);
+ esds_index = i+27;
+ break;
+ }
+ }
+ esds_length= buffer[esds_index];
+ esds_data=malloc(esds_length);
+ for(i=1; i<=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]);
+ }
+ free(buffer);
+ return 0;
+}
+
+
+
int demux_read(struct demux *demux, char *input, int size)
{
AVPacket pk = {};
if (bufsize > size)
bufsize = size;
- memcpy(input, buf, bufsize);
+ 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;
+ }
+ else {
+ memcpy(input, buf, bufsize);
+ }
if (demux->bsf)
av_free(buf);
diff --git a/viddec3test.c b/viddec3test.c
index 53004f1d7d54c45bf07293dce2f055066b1b1ecd..ed93d0b21c741dc1d56f90ab745b587b1f2af236 100644 (file)
--- a/viddec3test.c
+++ b/viddec3test.c
#include "util.h"
#include "demux.h"
+/* Used for mpeg4 esds data copy */
+int first_in_buff = 0;
/* Padding for width as per Codec Requirement (for h264) */
#define PADX 32
decoder->codec = VIDDEC3_create(decoder->engine,
"ivahd_h264dec", decoder->params);
}
+ else if (decoder->demux->cc->codec_id == CODEC_ID_MPEG4) {
+ first_in_buff = 1;
+ decoder->codec = VIDDEC3_create(decoder->engine,
+ "ivahd_mpeg4dec", decoder->params);
+ }
if (!decoder->codec) {
ERROR("%p: could not create codec", decoder);