/* mediastreamer2 library - modular sound and video processing and streaming Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include "mediastreamer-config.h" #endif #include #include "mediastreamer2/mediastream.h" #include "mediastreamer2/msequalizer.h" #include "mediastreamer2/msvolume.h" #ifdef VIDEO_ENABLED #include "mediastreamer2/msv4l.h" #endif #include #include #include #ifndef WIN32 #include #else #include #endif #include #include #include #ifdef __APPLE__ #include #endif #if defined(__ios) || defined (ANDROID) #ifdef __ios #import #include #endif extern void ms_set_video_stream(VideoStream* video); #ifdef HAVE_X264 extern void libmsx264_init(); #endif #ifdef HAVE_SILK extern void libmssilk_init(); #endif #endif #ifdef ANDROID #include #include #endif #include #define MEDIASTREAM_MAX_ICE_CANDIDATES 3 static int cond=1; typedef struct _MediastreamIceCandidate { char ip[64]; char type[6]; int port; } MediastreamIceCandidate; typedef struct _MediastreamDatas { int localport,remoteport,payload; char ip[64]; char *fmtp; int jitter; int bitrate; MSVideoSize vs; bool_t ec; bool_t agc; bool_t eq; bool_t is_verbose; int device_rotation; #ifdef VIDEO_ENABLED VideoStream *video; #endif char * capture_card; char * playback_card; char * camera; char *infile,*outfile; float ng_threshold; bool_t use_ng; bool_t two_windows; bool_t el; bool_t use_rc; bool_t enable_srtp; bool_t pad[3]; float el_speed; float el_thres; float el_force; int el_sustain; float el_transmit_thres; float ng_floorgain; char * zrtp_secrets; PayloadType *custom_pt; int video_window_id; int preview_window_id; /* starting values echo canceller */ int ec_len_ms, ec_delay_ms, ec_framesize; char* srtp_local_master_key; char* srtp_remote_master_key; int netsim_bw; int netsim_lossrate; float zoom; float zoom_cx, zoom_cy; AudioStream *audio; PayloadType *pt; RtpSession *session; OrtpEvQueue *q; RtpProfile *profile; IceSession *ice_session; MediastreamIceCandidate ice_local_candidates[MEDIASTREAM_MAX_ICE_CANDIDATES]; MediastreamIceCandidate ice_remote_candidates[MEDIASTREAM_MAX_ICE_CANDIDATES]; int ice_local_candidates_nb; int ice_remote_candidates_nb; } MediastreamDatas; // MAIN METHODS /* init default arguments */ MediastreamDatas* init_default_args(); /* parse args */ bool_t parse_args(int argc, char** argv, MediastreamDatas* out); /* setup streams */ void setup_media_streams(MediastreamDatas* args); /* run loop */ void run_interactive_loop(MediastreamDatas* args); void run_non_interactive_loop(MediastreamDatas* args); /* exit */ void clear_mediastreams(MediastreamDatas* args); // HELPER METHODS static void stop_handler(int signum); static bool_t parse_addr(const char *addr, char *ip, int len, int *port); static bool_t parse_ice_addr(char* addr, char* type, int type_len, char* ip, int ip_len, int* port); static void display_items(void *user_data, uint32_t csrc, rtcp_sdes_type_t t, const char *content, uint8_t content_len); static void parse_rtcp(mblk_t *m); static void parse_events(RtpSession *session, OrtpEvQueue *q); static PayloadType* create_custom_payload_type(const char *type, const char *subtype, const char *rate, int number); static PayloadType* parse_custom_payload(const char *name); static bool_t parse_window_ids(const char *ids, int* video_id, int* preview_id); const char *usage="mediastream --local --remote \n" "--payload \n" "[ --fmtp ]\n" "[ --jitter ]\n" "[ --width ]\n" "[ --height ]\n" "[ --bitrate ]\n" "[ --ec (enable echo canceller) ]\n" "[ --ec-tail ]\n" "[ --ec-delay ]\n" "[ --ec-framesize ]\n" "[ --agc (enable automatic gain control) ]\n" "[ --ng (enable noise gate)] \n" "[ --ng-threshold <(float) [0-1]> (noise gate threshold) ]\n" "[ --ng-floorgain <(float) [0-1]> (gain applied to the signal when its energy is below the threshold.) ]\n" "[ --capture-card ]\n" "[ --playback-card ]\n" "[ --infile specify a wav file to be used for input, instead of soundcard ]\n" "[ --outfile specify a wav file to write audio into, instead of soundcard ]\n" "[ --camera ]\n" "[ --el (enable echo limiter) ]\n" "[ --el-speed <(float) [0-1]> (gain changes are smoothed with a coefficent) ]\n" "[ --el-thres <(float) [0-1]> (Threshold above which the system becomes active) ]\n" "[ --el-force <(float) [0-1]> (The proportional coefficient controlling the mic attenuation) ]\n" "[ --el-sustain <(int)> (Time in milliseconds for which the attenuation is kept unchanged after) ]\n" "[ --el-transmit-thres <(float) [0-1]> (TO BE DOCUMENTED) ]\n" "[ --rc (enable adaptive rate control) ]\n" "[ --zrtp (enable zrtp) ]\n" "[ --verbose (most verbose messages) ]\n" "[ --video-windows-id