Exemplo n.º 1
0
void IcyConnector::ProcessHeaders(const QString &hdrs)
{
    QStringList f0;
    QStringList f1;
    QString txt;

    f0=hdrs.split("\r\n");
    if(f0[0]!="OK2") {
        Log(LOG_WARNING,
            QString().sprintf("login to \"%s:%d\" rejected: %s",
                              (const char *)hostHostname().toUtf8(),
                              0xFFFF&hostPort(),
                              (const char *)f0[0].toUtf8()));
        return;
    }
    icy_authenticated=true;
    WriteHeader("icy-name: "+streamName());
    WriteHeader("icy-genre: "+streamGenre());
    WriteHeader("icy-pub: "+QString().sprintf("%d",streamPublic()));
    WriteHeader("icy-br: "+QString().sprintf("%u",audioBitrate()));
    if(icy_protocol_version==1) {
        WriteHeader("icy-url: "+streamUrl());
    }
    WriteHeader("icy-irc: "+streamIrc());
    WriteHeader("icy-icq: "+streamIcq());
    WriteHeader("icy-aim: "+streamAim());
    WriteHeader("Content-Type: "+contentType());
    WriteHeader("");

    setConnected(true);
}
Exemplo n.º 2
0
void HlsConnector::connectToHostConnector(const QString &hostname,uint16_t port)
{
  //
  // Calculate publish point info
  //
  QStringList f0=serverMountpoint().split("/",QString::SkipEmptyParts);
  hls_put_basename=f0[f0.size()-1];
  hls_put_basestamp=QString().sprintf("%ld",time(NULL));
  QStringList f1=hls_put_basename.split(".");
  if((f1[f1.size()-1]!="m3u8")&&(f1[f1.size()-1]!="m3u")) {
    hls_put_basename+=".m3u8";
  }
  hls_put_directory="";
  for(int i=0;i<f0.size()-1;i++) {
    hls_put_directory+="/";
    hls_put_directory+=f0[i];
  }

  //
  // Create playlist file
  //
  hls_playlist_filename=hls_temp_dir->path()+"/"+hls_put_basename;

  if(hls_is_top) {
    WriteTopPlaylistFile();
    hls_conveyor->push(this,hls_playlist_filename,
		       "http://"+hostHostname()+hls_put_directory+"/",
		       ConveyorEvent::PutMethod);
    unlink(hls_playlist_filename.toUtf8());
  }
  else {
    //
    // Create initial media file
    //
    hls_media_filename=GetMediaFilename(hls_sequence_back);
    if((hls_media_handle=
	fopen((hls_temp_dir->path()+"/"+hls_media_filename).toUtf8(),"w"))==
       NULL) {
      Log(LOG_WARNING,
	  QString().sprintf("unable to write media data to \"%s\" [%s]",
	     (const char *)(hls_temp_dir->path()+"/"+
			    hls_media_filename).toUtf8(),strerror(errno)));
    }

    //
    // Write ID3 tag
    //
#ifndef HLS_OMIT_ID3_TIMESTAMPS
    uint8_t id3_header[HLS_ID3_HEADER_SIZE];
    hls_total_media_frames=HLS_SEGMENT_SIZE*audioSamplerate();
    GetStreamTimestamp(id3_header,hls_total_media_frames);
    fwrite(id3_header,1,HLS_ID3_HEADER_SIZE,hls_media_handle);
#endif  // HLS_OMIT_ID3_TIMESTAMPS
  }

  setConnected(true);
  emit unmuteRequested();
}
Exemplo n.º 3
0
void IcyConnector::socketDisconnectedData()
{
    if(!icy_authenticated) {
        Log(LOG_WARNING,
            QString().sprintf("login to \"%s:%d\" rejected: bad password",
                              (const char *)hostHostname().toUtf8(),
                              0xFFFF&hostPort()));
    }
    icy_authenticated=false;
    setConnected(false);
}
Exemplo n.º 4
0
void IcyConnector::socketReadyReadData()
{
    char data[1501];
    int64_t n;

    while((n=icy_socket->read(data,1500))>0) {
        data[n]=0;
        for(int64_t i=0; i<n; i++) {
            switch(0xFF&data[i]) {
            case 10:
                if((icy_recv_buffer.length()>=2)&&
                        (icy_recv_buffer.toUtf8().at(icy_recv_buffer.length()-3)==13)) {
                    icy_recv_buffer=icy_recv_buffer.left(icy_recv_buffer.length()-1);
                    ProcessHeaders(icy_recv_buffer);
                    icy_recv_buffer="";
                }
                else {
                    icy_recv_buffer+=data[i];
                }
                break;

            case 13:
                if(QString(icy_recv_buffer)=="invalid password") {
                    Log(LOG_WARNING,
                        QString().sprintf("login to \"%s:%d\" rejected: invalid password",
                                          (const char *)hostHostname().toUtf8(),
                                          0xFFFF&hostPort()));
                }
                else {
                    icy_recv_buffer+=data[i];
                }
                break;

            default:
                icy_recv_buffer+=data[i];
                break;
            }
        }
    }
}
Exemplo n.º 5
0
void HlsConnector::RotateMediaFile()
{
  //
  // Update working files
  //
  fclose(hls_media_handle);
  hls_media_datetimes[hls_sequence_back]=
    QDateTime(QDate::currentDate(),QTime::currentTime());
  hls_media_durations[hls_sequence_back]=
    (double)hls_media_frames/(double)audioSamplerate();
  if((hls_sequence_back-hls_sequence_head)>=HLS_MINIMUM_SEGMENT_QUAN) {
    // Schedule garbage collection
    hls_media_killtimes[hls_sequence_head++]=hls_total_media_frames+
      (HLS_MINIMUM_SEGMENT_QUAN+1)*HLS_SEGMENT_SIZE*audioSamplerate();
  }
  WritePlaylistFile();

  //
  // HTTP Uploads
  //
  hls_conveyor->push(this,hls_temp_dir->path()+"/"+hls_media_filename,
		     "http://"+hostHostname()+
		     QString().sprintf(":%u",hostPort())+
		     hls_put_directory+"/",ConveyorEvent::PutMethod);
  unlink((hls_temp_dir->path()+"/"+hls_media_filename).toUtf8());
  hls_conveyor->push(this,hls_playlist_filename,
		     "http://"+hostHostname()+hls_put_directory+"/",
		     ConveyorEvent::PutMethod);
  unlink(hls_playlist_filename.toUtf8());

  //
  // Take out the trash
  //
  std::map<int,uint64_t>::iterator ci=hls_media_killtimes.begin();
  while(ci!=hls_media_killtimes.end()) {
    if(ci->second<hls_total_media_frames) {
      std::map<int,double>::iterator cj=hls_media_durations.begin();
      while(cj!=hls_media_durations.end()) {
	if(cj->first==ci->first) {
	  hls_media_durations.erase(cj++);
	}
	else {
	  ++cj;
	}
      }
      std::map<int,QDateTime>::iterator dj=hls_media_datetimes.begin();
      while(dj!=hls_media_datetimes.end()) {
	if(dj->first==ci->first) {
	  hls_media_datetimes.erase(dj++);
	}
	else {
	  ++dj;
	}
      }
      hls_conveyor->push(this,"","http://"+hostHostname()+hls_put_directory+"/"+
			 GetMediaFilename(ci->first),
			 ConveyorEvent::DeleteMethod);
      hls_media_killtimes.erase(ci++);
    }
    else {
      ++ci;
    }
  }

  //
  // Initialize for next segment
  //
  hls_sequence_back++;
  hls_media_frames=0;
  //hls_media_killname=hls_media_filename;
  hls_media_filename=GetMediaFilename(hls_sequence_back);
  if((hls_media_handle=
      fopen((hls_temp_dir->path()+"/"+hls_media_filename).toUtf8(),"w"))==
     NULL) {
    Log(LOG_WARNING,
	QString().sprintf("unable to write media data to \"%s\" [%s]",
	   (const char *)(hls_temp_dir->path()+"/"+hls_media_filename).toUtf8(),
			  strerror(errno)));
  }
#ifndef HLS_OMIT_ID3_TIMESTAMPS
  uint8_t id3_header[HLS_ID3_HEADER_SIZE];
  GetStreamTimestamp(id3_header,hls_total_media_frames);
  fwrite(id3_header,1,HLS_ID3_HEADER_SIZE,hls_media_handle);
#endif  // HLS_OMIT_ID3_TIMESTAMPS
}