[mad-dev] repetative decoding of last frame why

prafulla chandra prafulla.list at gmail.com
Sat Dec 24 07:27:57 PST 2005


Hi all,
finally i am almost succeded in the mp3 decoding with buffering concept
except in the decoding of last buffer .for last buffer i am dynamically
creating memory and appending MAD_BUFFER_GAURD. what i am getting 2-12 more
no. of frames extra compared to the memory mapping approch in the
minimad.cwhy is this so ?? can any one tell where the problem is ??
below i am providing our modified input callback function.
thanks in advance.
prafulla chandra.

FILE *fptr;
FILE *pfOutput;

int function(int length);



void moving_fb_decodeengine(int move_length,int destination);
static char memory[4096];
static char buffer_frame[4096];
static int instant_memory_size = 4096;
static unsigned long framesdecoded;
static int remainmemory_length;
static unsigned long  offset ;
static int flag ;
static int count;

static
enum mad_flow input(void *data, struct mad_stream *stream)
{
 struct buffer *buffer = data ;
 int ltb_shifted,i;
 unsigned char temp;
 unsigned char *finalbuffer;
 int end;
 int destination;
  if(!buffer->length)
 {
  printf("total number of frames decoded %ld are ",framesdecoded);
  return MAD_FLOW_STOP;
 }

    if(flag==0)
 {
  end=function(instant_memory_size);
  if(!end)
  {
   destination=1;
  }
  else
   destination=0;
   moving_fb_decodeengine(instant_memory_size,destination);
 }
 else
 {
  ltb_shifted =stream->next_frame-buffer->start;
  remainmemory_length=instant_memory_size-ltb_shifted;
  for(i=0;i<instant_memory_size;i++)
  {
    if(i==remainmemory_length)
   {
    end = function(ltb_shifted);
    if(!end)
    {
     destination=1;
    }
    else
     destination=0;
    moving_fb_decodeengine(ltb_shifted,destination);
    break ;
   }
   temp=memory[i+ltb_shifted];
   memory[i]=temp;
  }
 }

 if(!end)
 {
  finalbuffer=malloc(count+MAD_BUFFER_GUARD);
  if(finalbuffer==0)
  {
   return MAD_FLOW_BREAK;
  }
  memcpy(finalbuffer,memory,count);
  memset(finalbuffer+count,0,MAD_BUFFER_GUARD);
  buffer->start=finalbuffer;
  buffer->length=count+MAD_BUFFER_GUARD;
  mad_stream_buffer(stream, buffer->start, buffer->length);

 }
 else
 {
  buffer->length=instant_memory_size;
  mad_stream_buffer(stream, buffer->start, buffer->length);
 }
 if(!end)
 {
  buffer->length=0;
   }
 flag =1;
return MAD_FLOW_CONTINUE;
}

void moving_fb_decodeengine( int move_length,int destination)
{
  unsigned char temp;
  int j,l;
  if(flag!=0)
  {
   for(j =0;j<4096;j++)
   {
    temp=buffer_frame[j];
    memory[remainmemory_length+j]=temp;
    if(destination)
    {
     if(j==count)
      count=remainmemory_length+j;
    }
   }
  }
  else
  {
   for(l=0;l<instant_memory_size;l++)
   {
    temp=buffer_frame[l];
    memory[l]=temp;
    if(destination)
    {
     if(l==count)
      count=l;
    }
   }
  }
}


int function(int movement_length)
{
  unsigned int  controlvar_length_funct=0,i;
  int cVar1_funct,count1=0;
  fptr =
fopen("BawreNain_1950-Rajkumari-MereRutheHuyeChanda-KidarSharma_Roshan.mp3","rb");
  fseek(fptr,offset,SEEK_SET);
  for(i=0;i<movement_length;i++)
  {
   cVar1_funct=fgetc(fptr);
   if(cVar1_funct==EOF)
   {
    count=count1;
    fclose(fptr);
    return(0);
   }
   else
   {
    count1++;
    buffer_frame[i]=cVar1_funct;
    offset++;
   }
  }
  fclose(fptr);
  return(1);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman/public/mad-dev/attachments/20051224/91230899/attachment.htm


More information about the mad-dev mailing list