📄 shout.c
字号:
/***************************************************************************** * shout.c: This module forwards vorbis streams to an icecast server ***************************************************************************** * Copyright (C) 2005 the VideoLAN team * $Id: c51704a6eaecc14b1f382a30f8fa54ecc77157b0 $ * * Authors: Daniel Fischer <dan at subsignal dot org> * Derk-Jan Hartman <hartman at videolan dot org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Some Comments: * * - this only works for ogg and/or mp3, and we don't check this yet. * - MP3 metadata is not passed along, since metadata is only available after * this module is opened. * * Typical usage: * * vlc v4l:/dev/video:input=2:norm=pal:size=192x144 \ * --sout '#transcode{vcodec=theora,vb=300,acodec=vorb,ab=96}\ * :std{access=shout,mux=ogg,dst=localhost:8005}' * *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_sout.h>#include <vlc_block.h>#include <shout/shout.h>/***************************************************************************** * Module descriptor *****************************************************************************/static int Open ( vlc_object_t * );static void Close( vlc_object_t * );#define SOUT_CFG_PREFIX "sout-shout-"#define NAME_TEXT N_("Stream name")#define NAME_LONGTEXT N_("Name to give to this stream/channel on the " \ "shoutcast/icecast server." )#define DESCRIPTION_TEXT N_("Stream description")#define DESCRIPTION_LONGTEXT N_("Description of the stream content or " \ "information about your channel." )#define MP3_TEXT N_("Stream MP3")#define MP3_LONGTEXT N_("You normally have to feed the shoutcast module " \ "with Ogg streams. It is also possible to stream " \ "MP3 instead, so you can forward MP3 streams to " \ "the shoutcast/icecast server." )/* To be listed properly as a public stream on the Yellow Pages of shoutcast/icecast the genres should match those used on the corresponding sites. Several examples are Alternative, Classical, Comedy, Country etc. */#define GENRE_TEXT N_("Genre description")#define GENRE_LONGTEXT N_("Genre of the content. " )#define URL_TEXT N_("URL description")#define URL_LONGTEXT N_("URL with information about the stream or your channel. " )/* The shout module only "transmits" data. It does not have direct access to "codec level" information. Stream information such as bitrate, samplerate, channel numbers and quality (in case of Ogg streaming) need to be set manually */#define BITRATE_TEXT N_("Bitrate")#define BITRATE_LONGTEXT N_("Bitrate information of the transcoded stream. " )#define SAMPLERATE_TEXT N_("Samplerate")#define SAMPLERATE_LONGTEXT N_("Samplerate information of the transcoded stream. " )#define CHANNELS_TEXT N_("Number of channels")#define CHANNELS_LONGTEXT N_("Number of channels information of the transcoded stream. " )#define QUALITY_TEXT N_("Ogg Vorbis Quality")#define QUALITY_LONGTEXT N_("Ogg Vorbis Quality information of the transcoded stream. " )#define PUBLIC_TEXT N_("Stream public")#define PUBLIC_LONGTEXT N_("Make the server publicly available on the 'Yellow Pages' " \ "(directory listing of streams) on the icecast/shoutcast " \ "website. Requires the bitrate information specified for " \ "shoutcast. Requires Ogg streaming for icecast." )vlc_module_begin(); set_description( N_("IceCAST output") ); set_shortname( "Shoutcast" ); set_capability( "sout access", 50 ); set_category( CAT_SOUT ); set_subcategory( SUBCAT_SOUT_ACO ); add_shortcut( "shout" ); add_string( SOUT_CFG_PREFIX "name", "VLC media player - Live stream", NULL, NAME_TEXT, NAME_LONGTEXT, false ); add_string( SOUT_CFG_PREFIX "description", "Live stream from VLC media player", NULL, DESCRIPTION_TEXT, DESCRIPTION_LONGTEXT, false ); add_bool( SOUT_CFG_PREFIX "mp3", false, NULL, MP3_TEXT, MP3_LONGTEXT, true ); add_string( SOUT_CFG_PREFIX "genre", "Alternative", NULL, GENRE_TEXT, GENRE_LONGTEXT, false ); add_string( SOUT_CFG_PREFIX "url", "http://www.videolan.org/vlc", NULL, URL_TEXT, URL_LONGTEXT, false ); add_string( SOUT_CFG_PREFIX "bitrate", "", NULL, BITRATE_TEXT, BITRATE_LONGTEXT, false ); add_string( SOUT_CFG_PREFIX "samplerate", "", NULL, SAMPLERATE_TEXT, SAMPLERATE_LONGTEXT, false ); add_string( SOUT_CFG_PREFIX "channels", "", NULL, CHANNELS_TEXT, CHANNELS_LONGTEXT, false ); add_string( SOUT_CFG_PREFIX "quality", "", NULL, QUALITY_TEXT, QUALITY_LONGTEXT, false ); add_bool( SOUT_CFG_PREFIX "public", false, NULL, PUBLIC_TEXT, PUBLIC_LONGTEXT, true ); set_callbacks( Open, Close );vlc_module_end();/***************************************************************************** * Exported prototypes *****************************************************************************/static const char *const ppsz_sout_options[] = { "name", "description", "mp3", "genre", "url", "bitrate", "samplerate", "channels", "quality", "public", NULL};/***************************************************************************** * Exported prototypes *****************************************************************************/static ssize_t Write( sout_access_out_t *, block_t * );static int Seek ( sout_access_out_t *, off_t );struct sout_access_out_sys_t{ shout_t *p_shout;};/***************************************************************************** * 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; unsigned int i_port; vlc_value_t val; char *psz_accessname = NULL; char *psz_parser = NULL; char *psz_user = NULL; char *psz_pass = NULL; char *psz_host = NULL; char *psz_mount = NULL; char *psz_name = NULL; char *psz_description = NULL; char *tmp_port = NULL; char *psz_genre = NULL; char *psz_url = NULL; 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; } psz_accessname = psz_parser = strdup( p_access->psz_path ); if( !psz_parser ) return VLC_ENOMEM; /* Parse connection data user:pwd@host:port/mountpoint */ psz_user = psz_parser; while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++; if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; } psz_pass = psz_parser; while( psz_parser[0] && psz_parser[0] != '@' ) psz_parser++; if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; } psz_host = psz_parser; while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++; if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; } tmp_port = psz_parser; while( psz_parser[0] && psz_parser[0] != '/' ) psz_parser++; if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; } psz_mount = psz_parser; i_port = atoi( tmp_port ); p_sys = p_access->p_sys = malloc( sizeof( sout_access_out_sys_t ) ); if( !p_sys ) { free( psz_accessname ); return VLC_ENOMEM; } var_Get( p_access, SOUT_CFG_PREFIX "name", &val ); if( *val.psz_string ) psz_name = val.psz_string; else free( val.psz_string ); var_Get( p_access, SOUT_CFG_PREFIX "description", &val ); if( *val.psz_string ) psz_description = val.psz_string; else free( val.psz_string ); var_Get( p_access, SOUT_CFG_PREFIX "genre", &val ); if( *val.psz_string ) psz_genre = val.psz_string; else free( val.psz_string ); var_Get( p_access, SOUT_CFG_PREFIX "url", &val ); if( *val.psz_string ) psz_url = val.psz_string; else free( val.psz_string ); p_shout = p_sys->p_shout = shout_new(); if( !p_shout || shout_set_host( p_shout, psz_host ) != SHOUTERR_SUCCESS || shout_set_protocol( p_shout, SHOUT_PROTOCOL_ICY ) != SHOUTERR_SUCCESS || shout_set_port( p_shout, i_port ) != SHOUTERR_SUCCESS || shout_set_password( p_shout, psz_pass ) != SHOUTERR_SUCCESS || shout_set_mount( p_shout, psz_mount ) != SHOUTERR_SUCCESS || shout_set_user( p_shout, psz_user ) != 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", psz_host, i_port, psz_mount ); free( p_access->p_sys ); free( psz_accessname ); free( psz_name ); free( psz_description ); free( psz_genre ); free( psz_url ); return VLC_EGENERIC; } free( psz_name ); free( psz_description ); free( psz_genre ); free( psz_url ); var_Get( p_access, SOUT_CFG_PREFIX "mp3", &val ); if( val.b_bool == true ) i_ret = shout_set_format( p_shout, SHOUT_FORMAT_MP3 ); else i_ret = shout_set_format( p_shout, SHOUT_FORMAT_OGG );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -