Ejemplo n.º 1
0
void
Sound_as::update()
{
    probeAudio();

    if (active()) {
        owner().set_member(NSV::PROP_DURATION, getDuration());
        owner().set_member(NSV::PROP_POSITION, getPosition());
    }
}
Ejemplo n.º 2
0
uint8_t
dmxAudioStream::open (char *name)
{
  FILE *file;
  uint32_t dummy;		//,audio=0;
  char string[MAX_LINE];	//,str[1024];;
  uint32_t w = 720, h = 576, fps = 0;
  uint8_t type, progressif;
  char realname[1024];
  uint32_t aPid, vPid, aPes,mainAudio;
  uint32_t nbGop, nbFrame,nbAudioStream;
  int multi;
  char payload[MAX_LINE];
  uint32_t oldIndex=0;
  
  
 file=fopen(name,"rt");
 if(!file) return 0;

  printf ("\n  opening dmx file for audio track : %s\n", name);
  fgets (string, MAX_LINE, file);	// File header
  if (strncmp (string, "ADMY", 4))
    {
       if (strncmp (string, "ADMX", 4))
       {
          fclose (file);
          printf ("This is not a mpeg index G2\n");
          ADM_assert (0);
       }
       oldIndex=1;
    }
    


  fgets (string, MAX_LINE, file);
  sscanf (string, "Type     : %c\n", &type);	// ES for now

char *start;
  fgets (string, MAX_LINE, file);
  //sscanf (string, "File     : %s\n", realname);
  start=strstr(string,":");
  ADM_assert(start);
  strcpy(realname,start+2);

  int l=strlen(realname)-1;
  while(l&&(realname[l]==0x0a || realname[l]==0x0d))
  {
           realname[l]=0;
           l--;
  }


  fgets (string, MAX_LINE, file);
  sscanf(string,"Append   : %d\n",&multi);

  fgets (string, MAX_LINE, file);
  sscanf (string, "Image    : %c\n", &progressif);	// Progressive

  fgets (string, MAX_LINE, file);
  sscanf (string, "Picture  : %u x %u %u fps\n", &w, &h, &fps);	// width...
  if(!oldIndex)
  {
   fgets (string, MAX_LINE, file);
   payload[0]=0;
   sscanf (string, "Payload  : %s\n",payload);	// FIXME ! overflow possible
  }
  fgets (string, MAX_LINE, file);
  sscanf (string, "Nb Gop   : %u \n", &nbGop);	// width...

  fgets (string, MAX_LINE, file);
  sscanf (string, "Nb Images: %u \n", &nbFrame);	// width...

  fgets (string, MAX_LINE, file);
  sscanf(string,"Nb Audio : %u\n",&nbAudioStream); 

  fgets(string,MAX_LINE,file);
  sscanf(string,"Main aud : %u\n",&mainAudio); 

  if(!nbAudioStream)
  {
_abrt:
         fclose (file);
        return 0;
  }
  _tracks=new dmxAudioTrack[nbAudioStream];
  memset(_tracks,0,sizeof(dmxAudioTrack)*nbAudioStream);
  nbTrack=nbAudioStream;
  _index=new dmxAudioIndex[nbGop+1];
  fgets (string, MAX_LINE, file);

  char *needle,*hay;
  uint32_t i=0;
/*
    Extrcat the PES/PID for each audio track from the line
        A(PES):(PID) A(PES):(PID) ....
*/
  hay=string;
  while(1)
  {
        needle=strstr(hay," A");
        if(!needle) goto _nnx;
        sscanf(needle," A%x:%x",&aPid,&aPes);
        ADM_assert(i<nbAudioStream);
        _tracks[i].myPid=aPid;
        _tracks[i].myPes=aPes;
        needle[0]='.';
        needle[1]='.';
        hay=needle;
        i++;
  }
_nnx:
  ADM_assert(i==nbAudioStream);
  currentTrack=mainAudio;
  // Now build the demuxers
  // We build only one demuxer, then we will use changePid
  // To go from one track to another
MPEG_TRACK track;
                track.pes=_tracks[mainAudio].myPes;
                track.pid=_tracks[mainAudio].myPid;
  switch (type)
    {
    case 'M':
                demuxer = new dmx_demuxerMSDVR (1,&track,0);
                break;
    case 'P':
                demuxer = new dmx_demuxerPS (1,&track,multi);
                break;
    case 'T':
                demuxer = new dmx_demuxerTS (1,&track,0,DMX_MPG_TS);
                break;
    case 'S':
                demuxer = new dmx_demuxerTS (1,&track,0,DMX_MPG_TS2);
                break;

    default:
      ADM_assert (0);
    }
  if(!demuxer->open(realname))
        {
                printf("DMX audio : cannot open %s\n");
                
                fclose(file);                
                return 0;
        }
  // Now build the index
  nbIndex = nbGop;
 
  printf ("Building index with %u sync points\n", nbGop);

  uint32_t read = 0, img, count;
  uint64_t abs;

  
  while (read < nbGop)
    {
      if (!fgets (string, MAX_LINE, file))
	break;
      if (string[0] != 'A')
	continue;

      sscanf (string, "A %u %"LLX, &img, &abs); //FIXME read all audio tracks and pick the one we want
        hay=strstr(string,":");
        ADM_assert(hay)
        i=0;
       while(1)
        {
                needle=strstr(hay,":");
                if(!needle) goto _nxt;;
                sscanf(needle,":%lx",&count);
                needle[0]='.';                
                hay=needle;
                _index[read].count[i] = count;
                i++;
        }
_nxt:


      _index[read].img = img;
      _index[read].start = abs;
      
      read++;
    }
    // now read offset
    {
    int trackNo,offset,pts;
    while(1)
    {
        if (!fgets (string, MAX_LINE, file))
            break;
        if(strncmp(string,"# track ",8)) continue;
        if(3!=sscanf(string,"# track %d PTS : %d  delta=%d ms",&trackNo,&pts,&offset))
        {
            printf("Error reading time offset for line [%s]\n",string);
            break;
        }
        ADM_assert(trackNo);
        ADM_assert(trackNo<nbTrack+1);
        trackNo--;
        _tracks[trackNo].avSync=offset;
        
    }
    } // /read offset
  fclose (file);
  nbIndex = read;
  if (!read)
    {
      printf ("No audio at all!\n");              
      return 0;
    }
printf("Filling audio header\n");
  // now fill in the header
  _length = _index[nbIndex - 1].count[mainAudio];
  for(int i=0;i<nbTrack;i++)
  {
    WAVHeader *hdr;
    hdr=&(_tracks[i].wavHeader);
    memset (hdr, 0, sizeof (WAVHeader));

    // put some default value
    hdr->bitspersample = 16;
    hdr->blockalign = 4;
  
    _destroyable = 1;
    strcpy (_name, "dmx audio");
    //demuxer->setPos (0, 0);
  }
  printf("Audio index loaded, probing...\n");
  if(!probeAudio()) return 0;
        
  demuxer->changePid(_tracks[currentTrack].myPid,_tracks[currentTrack].myPes);
  demuxer->setPos (0, 0);
  _pos = 0;
  printf ("\n DMX audio initialized (%lu bytes)\n", _length);
  printf ("With %lu sync point\n", nbIndex);
  changeAudioTrack(mainAudio);
  return 1;
}