BOOL CMyPhoneEndPoint::OpenVideoChannel(H323Connection & connection, BOOL isEncoding, H323VideoCodec & codec) { PVideoChannel * channel = new PVideoChannel; PVideoDevice * displayDevice = NULL; if (isEncoding) { // Transmitter part if(!autoStartTransmitVideo) return FALSE; codec.SetTxQualityLevel(config.GetInteger(VideoQualityConfigKey,15)); codec.SetBackgroundFill(2); int videoOutMaxBitRate = config.GetInteger(VideoOutMaxbandWidthKey, 320); videoOutMaxBitRate = 1024 * PMAX(16, PMIN(10240, videoOutMaxBitRate)); H323Channel * lchannel = codec.GetLogicalChannel(); const H323Capability & capability = lchannel->GetCapability(); PString cname = capability.GetFormatName(); PINDEX suffixPos = cname.Find("H.263"); if(suffixPos == P_MAX_INDEX) suffixPos = cname.Find("H.261"); int videoSize = config.GetInteger(VideoOutSizeConfigKey, 2); int width=352, height=288; suffixPos = P_MAX_INDEX; switch(videoSize) { case 0: //QCIF width = 176; height = 144; break; case 1: //QVGA if(suffixPos == P_MAX_INDEX) { width = 320; height = 240; break; } case 2: //CIF width = 352; height = 288; break; case 3: //VGA if(suffixPos == P_MAX_INDEX) { width = 640; height = 480; break; } case 5: //SVGA if(suffixPos == P_MAX_INDEX) { width = 800; height = 600; break; } case 6: //XVGA if(suffixPos == P_MAX_INDEX) { width = 1024; height = 768; break; } case 4: //4CIF width = 704; height = 576; break; case 7: //HD 720 if(suffixPos == P_MAX_INDEX) { width = 1280; height = 720; break; } case 8: //SXGA if(suffixPos == P_MAX_INDEX) { width = 1280; height = 1024; break; } case 9: //16CIF width = 1408; height = 1152; break; case 10: //UXGA if(suffixPos == P_MAX_INDEX) { width = 1600; height = 1200; break; } case 11: //HD 1080 if(suffixPos == P_MAX_INDEX) { width = 1920; height = 1080; break; } default: break; } PTRACE(1, "Video device videoSize=" << videoSize << " width=" << width << " height=" << height); codec.SetVideoSize(width, height); width = codec.GetWidth(); height = codec.GetHeight(); PTRACE(1, "Accepted video device width=" << width << " height=" << height); int curMBR = codec.GetMaxBitRate(); if(curMBR > videoOutMaxBitRate) codec.SetMaxBitRate(videoOutMaxBitRate); int videoFramesPS = config.GetInteger(VideoFPSKey, 10); codec.SetGeneralCodecOption("Frame Rate",videoFramesPS); //Create grabber. bool NoDevice = false; PString deviceName = config.GetString(VideoDeviceConfigKey, deviceName); if (deviceName.IsEmpty()) { PStringArray devices = PVideoInputDevice::GetDriversDeviceNames(VideoInputDriver); if (!devices.IsEmpty()) deviceName = devices[0]; else NoDevice = true; } PVideoInputDevice * grabber = NULL; if (deviceName.Find("fake") == 0) NoDevice = true; // else if (deviceName.Find("screen") == 0) grabber = PVideoInputDevice::CreateDevice("ScreenVideo"); else grabber = PVideoInputDevice::CreateDeviceByName(deviceName,VideoInputDriver); if (NoDevice || !grabber->Open(deviceName, FALSE) || !grabber->SetFrameSize(width, height) || !grabber->SetColourFormatConverter("YUV420P") || !grabber->SetVFlipState(localFlip)) { if(!NoDevice) { char sSrc[64]; m_dialog->OutputStatusStr((LPCTSTR)LoadStringLang(IDS_ERRVDEVSTR), S_SYSTEM, (const char *) deviceName, itoa(config.GetInteger(VideoSourceConfigKey,0), sSrc, 10)); PTRACE(1, "Failed to open or configure the video device \"" << deviceName << '"'); } if(grabber) delete grabber; grabber = PVideoInputDevice::CreateDevice("FakeVideo"); grabber->SetColourFormat("YUV420P"); grabber->SetVideoFormat(PVideoDevice::PAL); grabber->SetFrameSize(width, height); grabber->SetVFlipState(localFlip); grabber->SetChannel(4); } if(videoFramesPS >0 && videoFramesPS<30) grabber->SetFrameRate(videoFramesPS); grabber->Start(); channel->AttachVideoReader(grabber); /* if (localVideo) { BOOL curVFlip = config.GetBoolean(VideoOutVFlipConfigKey, FALSE); BOOL curHFlip = config.GetBoolean(VideoOutHFlipConfigKey, FALSE); displayDevice = new CVideoOutputDevice(m_dialog, connection.GetLocalPartyName(), curVFlip, curHFlip, TRUE, FALSE); } else */ displayDevice = PVideoOutputDevice::CreateDevice("NULLOutput"); } else { // Receiver part if(!autoStartReceiveVideo) return FALSE; BOOL curVFlip = config.GetBoolean(VideoInVFlipConfigKey, FALSE); BOOL curHFlip = config.GetBoolean(VideoInHFlipConfigKey, FALSE); displayDevice = new CVideoOutputDevice( m_vdlg, (LPCTSTR)m_dialog->FindContactName(connection), curVFlip, curHFlip, FALSE, localVideo); } if(displayDevice) { int width = codec.GetWidth(); int height = codec.GetHeight(); // if( m_dialog->autohideVideoPan && !m_dialog->showVideoPan) // m_dialog->ShowVideoPanels(TRUE); // show Video panel if it's hiden displayDevice->SetColourFormat("RGB32"); displayDevice->SetColourFormatConverter("YUV420P"); displayDevice->SetFrameSize(width, height); //Give the video window refreshing class to the channel. channel->AttachVideoPlayer((PVideoOutputDevice *)displayDevice); } return codec.AttachChannel(channel,TRUE); }
/* The main () */ int main (int argc, char ** argv, char ** /*envp*/) { GOptionContext *context = NULL; Ekiga::ServiceCorePtr service_core(new Ekiga::ServiceCore); gchar *path = NULL; gchar *url = NULL; int debug_level = 0; /* Globals */ #ifndef WIN32 if (!XInitThreads ()) exit (1); #endif #if !GLIB_CHECK_VERSION(2,36,0) g_type_init (); #endif #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init(); #endif /* GTK+ initialization */ gtk_init (&argc, &argv); #ifndef WIN32 signal (SIGPIPE, SIG_IGN); #endif /* Gettext initialization */ path = g_build_filename (DATA_DIR, "locale", NULL); textdomain (GETTEXT_PACKAGE); bindtextdomain (GETTEXT_PACKAGE, path); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); g_free (path); /* Application name */ g_set_application_name (_("Ekiga Softphone")); #ifndef WIN32 setenv ("PULSE_PROP_application.name", _("Ekiga Softphone"), true); #endif /* initialize platform-specific code */ gm_platform_init (); #ifdef WIN32 // plugins (i.e. the audio/video ptlib/opal codecs) are searched in ./plugins chdir (win32_datadir ()); #endif /* Configuration backend initialization */ gm_conf_init (); /* Arguments initialization */ GOptionEntry arguments [] = { { "debug", 'd', 0, G_OPTION_ARG_INT, &debug_level, N_("Prints debug messages in the console (level between 1 and 8)"), NULL }, { "call", 'c', 0, G_OPTION_ARG_STRING, &url, N_("Makes Ekiga call the given URI"), NULL }, { NULL, 0, 0, (GOptionArg)0, NULL, NULL, NULL } }; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, arguments, PACKAGE_NAME); g_option_context_set_help_enabled (context, TRUE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); #ifndef WIN32 char* text_label = g_strdup_printf ("%d", debug_level); setenv ("PTLIB_TRACE_CODECS", text_label, TRUE); g_free (text_label); #else char* text_label = g_strdup_printf ("PTLIB_TRACE_CODECS=%d", debug_level); _putenv (text_label); g_free (text_label); if (debug_level != 0) { std::string desk_path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); if (!desk_path.empty ()) std::freopen((desk_path + "\\ekiga-stderr.txt").c_str (), "w", stderr); } #endif #if PTRACING if (debug_level != 0) PTrace::Initialise (PMAX (PMIN (8, debug_level), 0), NULL, PTrace::Timestamp | PTrace::Thread | PTrace::Blocks | PTrace::DateAndTime); #endif #ifdef HAVE_DBUS if (!ekiga_dbus_claim_ownership ()) { ekiga_dbus_client_show (); if (url != NULL) ekiga_dbus_client_connect (url); exit (0); } #endif /* Ekiga initialisation */ // should come *after* ptrace initialisation, to track codec loading for ex. GnomeMeeting instance; Ekiga::Runtime::init (); engine_init (service_core, argc, argv); PTRACE (1, "Ekiga version " << MAJOR_VERSION << "." << MINOR_VERSION << "." << BUILD_NUMBER); #ifdef EKIGA_REVISION PTRACE (1, "Ekiga git revision: " << EKIGA_REVISION); #endif PTRACE (1, "PTLIB version " << PTLIB_VERSION); PTRACE (1, "OPAL version " << OPAL_VERSION); #if defined HAVE_XV || defined HAVE_DX PTRACE (1, "Accelerated rendering support enabled"); #else PTRACE (1, "Accelerated rendering support disabled"); #endif #ifdef HAVE_DBUS PTRACE (1, "DBUS support enabled"); #else PTRACE (1, "DBUS support disabled"); #endif #ifdef HAVE_GCONF PTRACE (1, "GConf support enabled"); #else PTRACE (1, "GConf support disabled"); #endif boost::shared_ptr<GtkFrontend> gtk_frontend = service_core->get<GtkFrontend>("gtk-frontend"); GtkWidget *main_window = GTK_WIDGET (gtk_frontend->get_main_window ()); const int schema_version = MAJOR_VERSION * 1000 + MINOR_VERSION * 10 + BUILD_NUMBER; int crt_version = gm_conf_get_int (GENERAL_KEY "version"); if (crt_version < schema_version) { gmconf_upgrade_version (); // show the assistant if there is no config file if (crt_version == 0) gtk_widget_show_all (GTK_WIDGET (gtk_frontend->get_assistant_window ())); /* Update the version number */ gm_conf_set_int (GENERAL_KEY "version", schema_version); } /* Show the main window */ gtk_widget_show (main_window); /* Call the given host if needed */ if (url) { boost::shared_ptr<Ekiga::CallCore> call_core = service_core->get<Ekiga::CallCore> ("call-core"); call_core->dial (url); } #ifdef HAVE_DBUS EkigaDBusComponent *dbus_component = ekiga_dbus_component_new (*service_core); #endif // from now on, things should have taken their final place service_core->close (); /* The GTK loop */ gtk_main (); #ifdef HAVE_DBUS g_object_unref (dbus_component); #endif /* Exit Ekiga */ GnomeMeeting::Process ()->Exit (); service_core.reset (); Ekiga::Runtime::quit (); /* Save and shutdown the configuration */ gm_conf_save (); gm_conf_shutdown (); /* deinitialize platform-specific code */ gm_platform_shutdown (); return 0; }
void CMyPhoneEndPoint::LoadCapabilities() { BOOL sizeChange = FALSE; capabilities.RemoveAll(); // Add the codecs we know about AddAllCapabilities(0, 0, "*"); // Удаляю не поддерживаемые видео кодеки из реестра PINDEX videoNum = 0; for (;;) { PString key = psprintf("%u", ++videoNum); PString name = config.GetString(VideoCodecsConfigSection, key, ""); if (name.IsEmpty()) break; PINDEX suffixPos = name.Find(OnCodecSuffix); if (suffixPos != P_MAX_INDEX) name.Delete(suffixPos, P_MAX_INDEX); else { suffixPos = name.Find(OffCodecSuffix); name.Delete(suffixPos, P_MAX_INDEX); } int res = 0; for (PINDEX i = 0; i < capabilities.GetSize(); i++) { if (capabilities[i].GetMainType() == H323Capability::e_Video) { if(capabilities[i].GetFormatName() == name) { res = 1; break; } } } if(res == 0) { PINDEX j = videoNum; videoNum--; for (;;) { PString key1 = psprintf("%u", ++j); PString name1 = config.GetString(VideoCodecsConfigSection, key1, ""); if (name1.IsEmpty()) break; config.SetString(VideoCodecsConfigSection, psprintf("%u", j-2), name1); } config.DeleteKey(VideoCodecsConfigSection, psprintf("%u", j-1)); } } // добавляю новые видео кодеки если их нет в конфигурации for (PINDEX i = 0; i < capabilities.GetSize(); i++) { if (capabilities[i].GetMainType() == H323Capability::e_Video) { PINDEX codecNum=0; int res = 0; int suffix = 0; for (;;) { PString key = psprintf("%u", ++codecNum); PString name = config.GetString(VideoCodecsConfigSection, key, ""); if (name.IsEmpty()) break; suffix = 0; PINDEX suffixPos = name.Find(OnCodecSuffix); if (suffixPos != P_MAX_INDEX) name.Delete(suffixPos, P_MAX_INDEX); else { suffix = 1; suffixPos = name.Find(OffCodecSuffix); name.Delete(suffixPos, P_MAX_INDEX); } if(capabilities[i].GetFormatName() == name) { res = 1; break; } } if(res == 0) { config.SetString(VideoCodecsConfigSection, psprintf("%u", codecNum), capabilities[i].GetFormatName() + ((suffix==0)?OnCodecSuffix:OffCodecSuffix)); } } } PINDEX audioNum = 0; for (;;) { PString key = psprintf("%u", ++audioNum); PString name = config.GetString(CodecsConfigSection, key, ""); if (name.IsEmpty()) break; PINDEX suffixPos = name.Find(OnCodecSuffix); if (suffixPos != P_MAX_INDEX) name.Delete(suffixPos, P_MAX_INDEX); else { suffixPos = name.Find(OffCodecSuffix); name.Delete(suffixPos, P_MAX_INDEX); } int res = 0; for (PINDEX i = 0; i < capabilities.GetSize(); i++) { if (capabilities[i].GetMainType() == H323Capability::e_Audio) { if(capabilities[i].GetFormatName() == name) { res = 1; break; } } } if(res == 0) { PINDEX j = audioNum; audioNum--; for (;;) { PString key1 = psprintf("%u", ++j); PString name1 = config.GetString(CodecsConfigSection, key1, ""); if (name1.IsEmpty()) break; config.SetString(CodecsConfigSection, psprintf("%u", j-2), name1); } config.DeleteKey(CodecsConfigSection, psprintf("%u", j-1)); } } for (PINDEX i = 0; i < capabilities.GetSize(); i++) { if (capabilities[i].GetMainType() == H323Capability::e_Audio) { PINDEX codecNum=0; int res = 0; int suffix = 0; for (;;) { PString key = psprintf("%u", ++codecNum); PString name = config.GetString(CodecsConfigSection, key, ""); if (name.IsEmpty()) break; suffix = 0; PINDEX suffixPos = name.Find(OnCodecSuffix); if (suffixPos != P_MAX_INDEX) name.Delete(suffixPos, P_MAX_INDEX); else { suffix = 1; suffixPos = name.Find(OffCodecSuffix); name.Delete(suffixPos, P_MAX_INDEX); } if(capabilities[i].GetFormatName() == name) { res = 1; break; } } if(res == 0) { config.SetString(CodecsConfigSection, psprintf("%u", codecNum), capabilities[i].GetFormatName() + ((suffix==0)?OnCodecSuffix:OffCodecSuffix)); } } } // Add all the UserInput capabilities AddAllUserInputCapabilities(0, 1); int videoSizeRx = config.GetInteger(VideoInSizeConfigKey, 2); int videoSizeTx = config.GetInteger(VideoOutSizeConfigKey, 2); RemoveCapability(H323Capability::e_ExtendVideo); autoStartTransmitVideo = config.GetBoolean(AutoTransmitVideoConfigKey, TRUE); autoStartReceiveVideo = config.GetBoolean(AutoReceiveVideoConfigKey, TRUE); localVideo = config.GetBoolean(VideoLocalConfigKey, FALSE); localFlip = config.GetBoolean(VideoFlipLocalConfigKey, FALSE); int videoInMaxBitRate = config.GetInteger(VideoInMaxbandWidthKey, 320); videoInMaxBitRate = 1024 * PMAX(16, PMIN(10240, videoInMaxBitRate)); // changing audio codecs PStringArray enabledCodecs; PINDEX codecNum = 0; for (;;) { PString key = psprintf("%u", ++codecNum); PString name = config.GetString(CodecsConfigSection, key, ""); if (name.IsEmpty()) break; PINDEX suffixPos = name.Find(OffCodecSuffix); if (suffixPos != P_MAX_INDEX) { capabilities.Remove(name(0, suffixPos-1)); continue; } suffixPos = name.Find(OnCodecSuffix); if (suffixPos != P_MAX_INDEX) name.Delete(suffixPos, P_MAX_INDEX); enabledCodecs.AppendString(name); } codecNum = 0; for (;;) { PString key = psprintf("%u", ++codecNum); PString name = config.GetString(VideoCodecsConfigSection, key, ""); if (name.IsEmpty()) break; } int tvNum = 0; // if(tvCaps==NULL) this generates error in free tvCaps = (char **)calloc(codecNum+1,sizeof(char *)); // while(tvCaps[tvNum]!=NULL) { free(tvCaps[tvNum]); tvCaps[tvNum]=NULL; tvNum++; } tvNum = 0; codecNum = 0; for (;;) { PString key = psprintf("%u", ++codecNum); PString name = config.GetString(VideoCodecsConfigSection, key, ""); if (name.IsEmpty()) break; // удаление отключенных кодеков PINDEX suffixPos = name.Find(OffCodecSuffix); if (suffixPos != P_MAX_INDEX) { capabilities.Remove(name(0, suffixPos-1)); continue; } // удаление суффикса on из имени кодека suffixPos = name.Find(OnCodecSuffix); if (suffixPos != P_MAX_INDEX) name.Delete(suffixPos, P_MAX_INDEX); // проверка кодека на соответствие размеру принимаемой картинки // (меньше можно, больше нельзя) и удаление из списка локальных кодеков suffixPos = P_MAX_INDEX; switch(videoSizeRx) { case 0: //QCIF suffixPos = name.Find("-CIF"); if(suffixPos != P_MAX_INDEX) break; case 1: //QVGA case 2: //CIF suffixPos = name.Find("-4CIF"); if(suffixPos != P_MAX_INDEX) break; suffixPos = name.Find("-480P"); if(suffixPos != P_MAX_INDEX) break; case 3: //VGA case 4: //4CIF suffixPos = name.Find("-SD"); if(suffixPos != P_MAX_INDEX) break; case 5: //SVGA suffixPos = name.Find("-720P"); if(suffixPos != P_MAX_INDEX) break; case 6: //XVGA suffixPos = name.Find("-HD"); if(suffixPos != P_MAX_INDEX) break; suffixPos = name.Find("-16CIF"); if(suffixPos != P_MAX_INDEX) break; case 7: //SXGA suffixPos = name.Find("-FHD"); if(suffixPos != P_MAX_INDEX) break; suffixPos = name.Find("-16CIF"); if(suffixPos != P_MAX_INDEX) break; suffixPos = name.Find("-1080P"); if(suffixPos != P_MAX_INDEX) break; case 8: //16CIF default: break; } if(suffixPos == P_MAX_INDEX) enabledCodecs.AppendString(name); else capabilities.Remove(name); // проверка кодека на соответствие размеру отправляемой картинки // (меньше можно, больше нельзя) и создание списка допустимых кодеков suffixPos = P_MAX_INDEX; switch(videoSizeTx) { case 0: //QCIF suffixPos = name.Find("-CIF"); if(suffixPos != P_MAX_INDEX) break; case 1: //QVGA case 2: //CIF suffixPos = name.Find("-4CIF"); if(suffixPos != P_MAX_INDEX) break; suffixPos = name.Find("-480P"); if(suffixPos != P_MAX_INDEX) break; case 3: //VGA case 4: //4CIF suffixPos = name.Find("-SD"); if(suffixPos != P_MAX_INDEX) break; case 5: //SVGA case 6: //XVGA suffixPos = name.Find("-HD"); if(suffixPos != P_MAX_INDEX) break; case 7: //HD 720 suffixPos = name.Find("-720P"); if(suffixPos != P_MAX_INDEX) break; case 8: //SXGA suffixPos = name.Find("-16CIF"); if(suffixPos != P_MAX_INDEX) break; suffixPos = name.Find("-FHD"); if(suffixPos != P_MAX_INDEX) break; suffixPos = name.Find("-1080P"); if(suffixPos != P_MAX_INDEX) break; case 9: //16CIF default: break; } if(suffixPos == P_MAX_INDEX) // добавляю в список допустимых { const char *p2pstr=name; tvCaps[tvNum]=strdup(p2pstr); tvNum++; } } // Reorder the codecs we have capabilities.Reorder(enabledCodecs); for (PINDEX i = 0; i < capabilities.GetSize(); i++) { if (capabilities[i].GetMainType() == H323Capability::e_Video) { capabilities[i].SetMediaFormatOptionInteger(OpalVideoFormat::MaxBitRateOption, videoInMaxBitRate); if((capabilities[i].GetFormatName().Find("H.264")!=P_MAX_INDEX) || (capabilities[i].GetFormatName().Find("VP8-")==0)) { H323GenericVideoCapability *h264cap = (H323GenericVideoCapability *) &capabilities[i]; h264cap->SetMaxBitRate(videoInMaxBitRate/100); } } } /* PINDEX audioNum = 1; PINDEX videoNum = 1; for (PINDEX i = 0; i < capabilities.GetSize(); i++) { if (capabilities[i].GetMainType() == H323Capability::e_Audio) { config.SetString(CodecsConfigSection, psprintf("%u", audioNum++), capabilities[i].GetFormatName() + OnCodecSuffix); } else if (capabilities[i].GetMainType() == H323Capability::e_Video) { config.SetString(VideoCodecsConfigSection, psprintf("%u", videoNum++), capabilities[i].GetFormatName() + OnCodecSuffix); } } */ PTRACE(1, "MyPhone\tCapability Table:\n" << setprecision(4) << capabilities); }