static void reinit_stream() { int err; int nbTries; if (shout_get_connected(shout) == SHOUTERR_CONNECTED) { printf ("Disconnecting the stream\n"); shout_close(shout); } nbTries = 0; do { err = shout_open(shout); if ( err != SHOUTERR_SUCCESS) { printf ("Failed to connect to server [%s]\n", shout_get_error(shout)); nbTries++; /* if (nbTries < 10) { */ printf ("Retrying ... [%d]\n", nbTries); sleep(2); /* } else { */ /* printf("Too many retries. Exiting ...\n"); */ /* exit(1); */ /* } */ } } while (err != SHOUTERR_SUCCESS); _setSong(); printf("Connected to server\n"); }
bool EngineShoutcast::isConnected() { if (m_pShout) { m_iShoutStatus = shout_get_connected(m_pShout); if (m_iShoutStatus == SHOUTERR_CONNECTED) return true; } return false; }
bool Shouter::start() { int res; char srv[64]; switch(login()) { case SHOUT_PROTOCOL_HTTP: sprintf(srv,"icecast2"); break; case SHOUT_PROTOCOL_ICY: sprintf(srv,"shoutcast"); break; default: sprintf(srv,"icecast 1"); break; } if(shout_get_connected(ice)) { // if allready connected, reconnect func("icecast still connected: disconnecting"); shout_sync(ice); shout_close(ice); } notice("Contacting %s server %s on port %u",srv,host(),port()); shout_sync(ice); res = shout_open(ice); func("Shouter::start() shout_open returns %i",res); if(res==SHOUTERR_SUCCESS) { notice("started streaming on %s",streamurl); running = true; } else { error("shout_open: %s",shout_get_error(ice)); shout_sync(ice); shout_close(ice); running = false; } return(running); }
/***************************************************************************** * Open: open the shout connection *****************************************************************************/ static int Open( vlc_object_t *p_this ) { sout_access_out_t *p_access = (sout_access_out_t*)p_this; sout_access_out_sys_t *p_sys; shout_t *p_shout; long i_ret; char *psz_val; char *psz_name; char *psz_description; char *psz_genre; char *psz_url; vlc_url_t url; config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg ); if( !p_access->psz_path ) { msg_Err( p_access, "please specify url=user:password@host:port/mountpoint" ); return VLC_EGENERIC; } vlc_UrlParse( &url , p_access->psz_path, 0 ); if( url.i_port <= 0 ) url.i_port = 8000; p_sys = p_access->p_sys = malloc( sizeof( sout_access_out_sys_t ) ); if( !p_sys ) { vlc_UrlClean( &url ); return VLC_ENOMEM; } psz_name = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "name" ); psz_description = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "description" ); psz_genre = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "genre" ); psz_url = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "url" ); p_shout = p_sys->p_shout = shout_new(); if( !p_shout || shout_set_host( p_shout, url.psz_host ) != SHOUTERR_SUCCESS || shout_set_protocol( p_shout, SHOUT_PROTOCOL_ICY ) != SHOUTERR_SUCCESS || shout_set_port( p_shout, url.i_port ) != SHOUTERR_SUCCESS || shout_set_password( p_shout, url.psz_password ) != SHOUTERR_SUCCESS || shout_set_mount( p_shout, url.psz_path ) != SHOUTERR_SUCCESS || shout_set_user( p_shout, url.psz_username ) != SHOUTERR_SUCCESS || shout_set_agent( p_shout, "VLC media player " VERSION ) != SHOUTERR_SUCCESS || shout_set_name( p_shout, psz_name ) != SHOUTERR_SUCCESS || shout_set_description( p_shout, psz_description ) != SHOUTERR_SUCCESS || shout_set_genre( p_shout, psz_genre ) != SHOUTERR_SUCCESS || shout_set_url( p_shout, psz_url ) != SHOUTERR_SUCCESS /* || shout_set_nonblocking( p_shout, 1 ) != SHOUTERR_SUCCESS */ ) { msg_Err( p_access, "failed to initialize shout streaming to %s:%i/%s", url.psz_host, url.i_port, url.psz_path ); free( psz_name ); free( psz_description ); free( psz_genre ); free( psz_url ); goto error; } free( psz_name ); free( psz_description ); free( psz_genre ); free( psz_url ); i_ret = shout_set_format( p_shout, var_GetBool( p_access, SOUT_CFG_PREFIX "mp3" ) ? SHOUT_FORMAT_MP3 : SHOUT_FORMAT_OGG ); if( i_ret != SHOUTERR_SUCCESS ) { msg_Err( p_access, "failed to set the shoutcast streaming format" ); goto error; } /* Don't force bitrate to 0 but only use when specified. This will otherwise show an empty field on icecast directory listing instead of NA */ psz_val = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "bitrate" ); if( psz_val ) { i_ret = shout_set_audio_info( p_shout, SHOUT_AI_BITRATE, psz_val ); free( psz_val ); if( i_ret != SHOUTERR_SUCCESS ) { msg_Err( p_access, "failed to set the information about the bitrate" ); goto error; } } else { /* Bitrate information is used for icecast/shoutcast servers directory listings (sorting, stream info etc.) */ msg_Warn( p_access, "no bitrate information specified (required for listing " \ "the server as public on the shoutcast website)" ); } /* Information about samplerate, channels and quality will not be propagated through the YP protocol for icecast to the public directory listing when the icecast server is operating in shoutcast compatibility mode */ psz_val = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "samplerate" ); if( psz_val ) { i_ret = shout_set_audio_info( p_shout, SHOUT_AI_SAMPLERATE, psz_val ); free( psz_val ); if( i_ret != SHOUTERR_SUCCESS ) { msg_Err( p_access, "failed to set the information about the samplerate" ); goto error; } } psz_val = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "channels" ); if( psz_val ) { i_ret = shout_set_audio_info( p_shout, SHOUT_AI_CHANNELS, psz_val ); free( psz_val ); if( i_ret != SHOUTERR_SUCCESS ) { msg_Err( p_access, "failed to set the information about the number of channels" ); goto error; } } psz_val = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "quality" ); if( psz_val ) { i_ret = shout_set_audio_info( p_shout, SHOUT_AI_QUALITY, psz_val ); free( psz_val ); if( i_ret != SHOUTERR_SUCCESS ) { msg_Err( p_access, "failed to set the information about Ogg Vorbis quality" ); goto error; } } if( var_GetBool( p_access, SOUT_CFG_PREFIX "public" ) ) { i_ret = shout_set_public( p_shout, 1 ); if( i_ret != SHOUTERR_SUCCESS ) { msg_Err( p_access, "failed to set the server status setting to public" ); goto error; } } /* Connect at startup. Cycle through the possible protocols. */ i_ret = shout_get_connected( p_shout ); while ( i_ret != SHOUTERR_CONNECTED ) { /* Shout parameters cannot be changed on an open connection */ i_ret = shout_close( p_shout ); if( i_ret == SHOUTERR_SUCCESS ) { i_ret = SHOUTERR_UNCONNECTED; } /* Re-initialize for Shoutcast using ICY protocol. Not needed for initial connection but it is when we are reconnecting after other protocol was tried. */ i_ret = shout_set_protocol( p_shout, SHOUT_PROTOCOL_ICY ); if( i_ret != SHOUTERR_SUCCESS ) { msg_Err( p_access, "failed to set the protocol to 'icy'" ); goto error; } i_ret = shout_open( p_shout ); if( i_ret == SHOUTERR_SUCCESS ) { i_ret = SHOUTERR_CONNECTED; msg_Dbg( p_access, "connected using 'icy' (shoutcast) protocol" ); } else { msg_Warn( p_access, "failed to connect using 'icy' (shoutcast) protocol" ); /* Shout parameters cannot be changed on an open connection */ i_ret = shout_close( p_shout ); if( i_ret == SHOUTERR_SUCCESS ) { i_ret = SHOUTERR_UNCONNECTED; } /* IceCAST using HTTP protocol */ i_ret = shout_set_protocol( p_shout, SHOUT_PROTOCOL_HTTP ); if( i_ret != SHOUTERR_SUCCESS ) { msg_Err( p_access, "failed to set the protocol to 'http'" ); goto error; } i_ret = shout_open( p_shout ); if( i_ret == SHOUTERR_SUCCESS ) { i_ret = SHOUTERR_CONNECTED; msg_Dbg( p_access, "connected using 'http' (icecast 2.x) protocol" ); } else msg_Warn( p_access, "failed to connect using 'http' (icecast 2.x) protocol " ); } /* for non-blocking, use: while( i_ret == SHOUTERR_BUSY ) { sleep( 1 ); i_ret = shout_get_connected( p_shout ); } */ if ( i_ret != SHOUTERR_CONNECTED ) { msg_Warn( p_access, "unable to establish connection, retrying..." ); msleep( 30000000 ); } } if( i_ret != SHOUTERR_CONNECTED ) { msg_Err( p_access, "failed to open shout stream to %s:%i/%s: %s", url.psz_host, url.i_port, url.psz_path, shout_get_error(p_shout) ); goto error; } p_access->pf_write = Write; p_access->pf_seek = Seek; p_access->pf_control = Control; msg_Dbg( p_access, "shout access output opened (%s@%s:%i/%s)", url.psz_username, url.psz_host, url.i_port, url.psz_path ); vlc_UrlClean( &url ); return VLC_SUCCESS; error: if( p_sys->p_shout ) shout_free( p_sys->p_shout ); vlc_UrlClean( &url ); free( p_sys ); return VLC_EGENERIC; }
int sendStream(shout_t *shout, FILE *filepstream, const char *fileName, int isStdin, const char *songLenStr, struct timeval *tv) { unsigned char buff[4096]; size_t bytes_read, total, oldTotal; int ret; double kbps = -1.0; struct timeval timeStamp, *startTime = tv; struct timeval callTime, currentTime; if (startTime == NULL) { printf("%s: sendStream(): Internal error: startTime is NULL\n", __progname); abort(); } ez_gettimeofday((void *)&callTime); timeStamp.tv_sec = startTime->tv_sec; timeStamp.tv_usec = startTime->tv_usec; total = oldTotal = 0; ret = STREAM_DONE; while ((bytes_read = fread(buff, 1UL, sizeof(buff), filepstream)) > 0) { if (shout_get_connected(shout) != SHOUTERR_CONNECTED && reconnectServer(shout, 0) == 0) { ret = STREAM_SERVERR; break; } shout_sync(shout); if (shout_send(shout, buff, bytes_read) != SHOUTERR_SUCCESS) { printf("%s: shout_send(): %s\n", __progname, shout_get_error(shout)); if (reconnectServer(shout, 1)) break; else { ret = STREAM_SERVERR; break; } } if (quit) break; if (rereadPlaylist_notify) { rereadPlaylist_notify = 0; if (!pezConfig->fileNameIsProgram) printf("%s: SIGHUP signal received, will reread playlist after this file\n", __progname); } if (skipTrack) { skipTrack = 0; ret = STREAM_SKIP; break; } ez_gettimeofday((void *)¤tTime); if (queryMetadata || (pezConfig->metadataRefreshInterval != -1 && (currentTime.tv_sec - callTime.tv_sec >= pezConfig->metadataRefreshInterval) ) ) { queryMetadata = 0; if (metadataFromProgram) { ret = STREAM_UPDMDATA; break; } } total += bytes_read; if (qFlag && vFlag) { double oldTime, newTime; if (!isStdin && playlistMode) { if (pezConfig->fileNameIsProgram) { char *tmp = xstrdup(pezConfig->fileName); printf(" [%s]", local_basename(tmp)); xfree(tmp); } else printf(" [%4lu/%-4lu]", playlist_get_position(playlist), playlist_get_num_items(playlist)); } oldTime = (double)timeStamp.tv_sec + (double)timeStamp.tv_usec / 1000000.0; newTime = (double)currentTime.tv_sec + (double)currentTime.tv_usec / 1000000.0; if (songLenStr == NULL) printf(" [ %s]", getTimeString(currentTime.tv_sec - startTime->tv_sec)); else printf(" [ %s/%s]", getTimeString(currentTime.tv_sec - startTime->tv_sec), songLenStr); if (newTime - oldTime >= 1.0) { kbps = (((double)(total - oldTotal) / (newTime - oldTime)) * 8.0) / 1000.0; timeStamp.tv_sec = currentTime.tv_sec; timeStamp.tv_usec = currentTime.tv_usec; oldTotal = total; } if (kbps < 0) printf(" "); else printf(" [%8.2f kbps]", kbps); printf(" \r"); fflush(stdout); } } if (ferror(filepstream)) { if (errno == EINTR) { clearerr(filepstream); ret = STREAM_CONT; } else if (errno == EBADF && isStdin) printf("%s: No (more) data available on standard input\n", __progname); else printf("%s: sendStream(): Error while reading '%s': %s\n", __progname, fileName, strerror(errno)); } return (ret); }
bool EngineShoutcast::serverConnect() { // set to busy in case another thread calls one of the other // EngineShoutcast calls m_iShoutStatus = SHOUTERR_BUSY; m_pShoutcastStatus->set(SHOUTCAST_CONNECTING); // reset the number of failures to zero m_iShoutFailures = 0; // set to a high number to automatically update the metadata // on the first change m_iMetaDataLife = 31337; // clear metadata, to make sure the first track is not skipped // because it was sent via an previous connection (see metaDataHasChanged) if(m_pMetaData) { m_pMetaData.clear(); } //If static metadata is available, we only need to send metadata one time m_firstCall = false; /*Check if m_encoder is initalized * Encoder is initalized in updateFromPreferences which is called always before serverConnect() * If m_encoder is NULL, then we propably want to use MP3 streaming, however, lame could not be found * It does not make sense to connect */ if(m_encoder == NULL){ m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY,"enabled"),ConfigValue("0")); m_pShoutcastStatus->set(SHOUTCAST_DISCONNECTED); return false; } const int iMaxTries = 3; while (!m_bQuit && m_iShoutFailures < iMaxTries) { if (m_pShout) shout_close(m_pShout); m_iShoutStatus = shout_open(m_pShout); if (m_iShoutStatus == SHOUTERR_SUCCESS) m_iShoutStatus = SHOUTERR_CONNECTED; if ((m_iShoutStatus == SHOUTERR_BUSY) || (m_iShoutStatus == SHOUTERR_CONNECTED) || (m_iShoutStatus == SHOUTERR_SUCCESS)) break; m_iShoutFailures++; qDebug() << "Shoutcast failed connect. Failures:" << m_iShoutFailures; sleep(1); } if (m_iShoutFailures == iMaxTries) { if (m_pShout) shout_close(m_pShout); m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY,"enabled"),ConfigValue("0")); m_pShoutcastStatus->set(SHOUTCAST_DISCONNECTED); return false; } if (m_bQuit) { if (m_pShout) shout_close(m_pShout); m_pShoutcastStatus->set(SHOUTCAST_DISCONNECTED); return false; } m_iShoutFailures = 0; int timeout = 0; while (m_iShoutStatus == SHOUTERR_BUSY && timeout < TIMEOUT) { qDebug() << "Connection pending. Sleeping..."; sleep(1); m_iShoutStatus = shout_get_connected(m_pShout); ++ timeout; } if (m_iShoutStatus == SHOUTERR_CONNECTED) { qDebug() << "***********Connected to Shoutcast server..."; m_pShoutcastStatus->set(SHOUTCAST_CONNECTED); return true; } //otherwise disable shoutcast in preferences m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY,"enabled"),ConfigValue("0")); if(m_pShout){ shout_close(m_pShout); //errorDialog(tr("Mixxx could not connect to the server"), tr("Please check your connection to the Internet and verify that your username and password are correct.")); } m_pShoutcastStatus->set(SHOUTCAST_DISCONNECTED); return false; }
static PyObject* pshoutobj_get_connected(ShoutObject* self) { return Py_BuildValue("i", shout_get_connected(self->conn)); }
int main() { shout_t *shout; char buff[4096]; long read, ret, total; shout_init(); if (!(shout = shout_new())) { printf("Could not allocate shout_t\n"); return 1; } if (shout_set_host(shout, "127.0.0.1") != SHOUTERR_SUCCESS) { printf("Error setting hostname: %s\n", shout_get_error(shout)); return 1; } if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) { printf("Error setting protocol: %s\n", shout_get_error(shout)); return 1; } if (shout_set_port(shout, 8000) != SHOUTERR_SUCCESS) { printf("Error setting port: %s\n", shout_get_error(shout)); return 1; } if (shout_set_password(shout, "hackme") != SHOUTERR_SUCCESS) { printf("Error setting password: %s\n", shout_get_error(shout)); return 1; } if (shout_set_mount(shout, "/example.ogg") != SHOUTERR_SUCCESS) { printf("Error setting mount: %s\n", shout_get_error(shout)); return 1; } if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) { printf("Error setting user: %s\n", shout_get_error(shout)); return 1; } if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) { printf("Error setting user: %s\n", shout_get_error(shout)); return 1; } if (shout_set_nonblocking(shout, 1) != SHOUTERR_SUCCESS) { printf("Error setting non-blocking mode: %s\n", shout_get_error(shout)); return 1; } ret = shout_open(shout); if (ret == SHOUTERR_SUCCESS) ret = SHOUTERR_CONNECTED; if (ret == SHOUTERR_BUSY) printf("Connection pending...\n"); while (ret == SHOUTERR_BUSY) { usleep(10000); ret = shout_get_connected(shout); } if (ret == SHOUTERR_CONNECTED) { printf("Connected to server...\n"); total = 0; while (1) { read = fread(buff, 1, sizeof(buff), stdin); total = total + read; if (read > 0) { ret = shout_send(shout, buff, read); if (ret != SHOUTERR_SUCCESS) { printf("DEBUG: Send error: %s\n", shout_get_error(shout)); break; } } else { break; } if (shout_queuelen(shout) > 0) printf("DEBUG: queue length: %d\n", (int)shout_queuelen(shout)); shout_sync(shout); } } else { printf("Error connecting: %s\n", shout_get_error(shout)); } shout_close(shout); shout_shutdown(); return 0; }