/* * Class: com_mti_primitives_devices_VideoInputDevice * Method: PlatformGetDevices * Signature: ([Lcom/mti/primitives/devices/VideoInputDevice;)I */ JNIEXPORT jint JNICALL Java_com_mti_primitives_devices_VideoInputDevice_PlatformGetDevices (JNIEnv * Env, jobject sender, jobjectArray deviceList){ Device_Errors retval = Device_Errors::SUCCEEDED; VideoInputDevice* vd = new VideoInputDevice(); vector<Device*> devList; retval = vd->GetDevices(devList); if(retval == Device_Errors::SUCCEEDED) { int size = Env->GetArrayLength(deviceList); for(int x = 0; x < size; x++) { if(x < devList.size()){ jobject dev = New_jVideoInputDevice(Env, (VideoInputDevice*) devList[x]); delete(devList[x]); Env->SetObjectArrayElement(deviceList, x, dev); } else{ Env->SetObjectArrayElement(deviceList, x, NULL); } } devList.clear(); } return retval; }
void VideoInputCore::setup (std::string setting) { GSettings* settings = device_settings->get_g_settings (); GSettings* codecs_settings = video_codecs_settings->get_g_settings (); VideoInputDevice device; /* Get device settings */ if (setting == "any" || setting == "input-device" || setting == "format" || setting == "channel") { gchar *device_string = g_settings_get_string (settings, "input-device"); unsigned video_format = g_settings_get_enum (settings, "format"); unsigned channel = g_settings_get_int (settings, "channel"); device.SetFromString (device_string); set_device (device, channel, (VideoInputFormat) video_format); g_free (device_string); } /* Size and framerate */ if (setting == "any" || setting == "size" || setting == "max-frame-rate") { unsigned size = g_settings_get_enum (settings, "size"); unsigned max_frame_rate = g_settings_get_int (codecs_settings, "max-frame-rate"); if (size >= NB_VIDEO_SIZES) { PTRACE(1, "VidInputCore\t" << "size out of range, ajusting to 0"); size = 0; } set_preview_config (VideoSizes[size].width, VideoSizes[size].height, max_frame_rate); } }
JNIEXPORT jint JNICALL Java_com_mti_primitives_devices_VideoInputDevice_PlatformOpen (JNIEnv * Env, jobject sender, jobject listener, jint width, jint height, jint pixelFormat, jint fps){ jint retval = 0; try{ if(Env->GetJavaVM(&CallbackJVM) != 0) { retval = (jint)Device_Errors::NOT_SUPPORTED; } else if(listener == NULL){ retval = (jint)Device_Errors::INVALID_DATA; } else{ MyListener = Env->NewGlobalRef(listener); jvideoInputDevice = Env->NewGlobalRef(sender); VideoInputDevice* tempDevice = new VideoInputDevice(); Java_To_VideoInputDevice(Env, sender, tempDevice); vector<Device*> deviceList; if(tempDevice->GetDevices(deviceList) == Device_Errors::SUCCEEDED){ videoInputDevice = (VideoInputDevice*)deviceList[tempDevice->DeviceIndex]; for(int x = 0; x < deviceList.size(); x++) { if(x != videoInputDevice->DeviceIndex) delete deviceList[x]; } deviceList.clear(); VideoInputDeviceListener* clistener = new VideoInputDeviceListener(); videoInputDevice->Listener = clistener; VideoMediaFormat* format = new VideoMediaFormat(); format->Width = width; format->Height = height; format->FPS = fps; format->PixelFormat = (VideoPixelFormat) pixelFormat; char buffer[1000]; sprintf(dbg_buffer,"Opening device index %d, device name %s, format width %d, height %d, fps %d, Pixel format %d\n", videoInputDevice->DeviceIndex, videoInputDevice->DeviceName.c_str(), format->Width, format->Height, format->FPS, format->PixelFormat); DbgOut(dbg_buffer); retval = (jint)videoInputDevice->Open(format); sprintf(dbg_buffer, "Open returned %d\n", retval); DbgOut(dbg_buffer); } else{ retval = (jint)Device_Errors::NO_DEVICES; } } } catch(...){ retval = (jint)Device_Errors::UNEXPECTED; } return retval; }
void VideoInputCore::remove_device (const std::string & source, const std::string & device_name, unsigned capabilities, HalManager* /*manager*/) { PTRACE(4, "VidInputCore\tRemoving Device " << device_name); PWaitAndSignal m(core_mutex); VideoInputDevice device; for (std::set<VideoInputManager *>::iterator iter = managers.begin (); iter != managers.end (); iter++) { if ((*iter)->has_device (source, device_name, capabilities, device)) { if ( (current_device == device) && (preview_config.active || stream_config.active) ) { VideoInputDevice new_device; new_device.type = VIDEO_INPUT_FALLBACK_DEVICE_TYPE; new_device.source = VIDEO_INPUT_FALLBACK_DEVICE_SOURCE; new_device.name = VIDEO_INPUT_FALLBACK_DEVICE_NAME; internal_set_device(new_device, current_channel, current_format); } device_removed(device, current_device == device); boost::shared_ptr<Ekiga::Notification> notif (new Ekiga::Notification (Ekiga::Notification::Info, _("Device removed"), device.GetString ())); notification_core->push_notification (notif); } } }
void VideoInputCore::add_device (const std::string & source, const std::string & device_name, unsigned capabilities, HalManager* /*manager*/) { PTRACE(4, "VidInputCore\tAdding Device " << device_name); PWaitAndSignal m(core_mutex); VideoInputDevice device; for (std::set<VideoInputManager *>::iterator iter = managers.begin (); iter != managers.end (); iter++) { if ((*iter)->has_device (source, device_name, capabilities, device)) { if ( desired_device == device ) { internal_set_device(device, current_channel, current_format); boost::shared_ptr<Ekiga::Notification> notif (new Ekiga::Notification (Ekiga::Notification::Info, _("New device detected"), device.GetString ())); notification_core->push_notification (notif); } else { boost::shared_ptr<Ekiga::Notification> notif (new Ekiga::Notification (Ekiga::Notification::Info, _("New device detected"), device.GetString (), _("Use it"), boost::bind (&VideoInputCore::on_set_device, (VideoInputCore*) this, device))); notification_core->push_notification (notif); } device_added(device, desired_device == device); } } }
void VideoInputCore::on_set_device (const VideoInputDevice & device) { gm_conf_set_string (VIDEO_DEVICES_KEY "input_device", device.GetString ().c_str ()); }
void VideoInputCore::on_set_device (const VideoInputDevice & device) { g_settings_set_string (device_settings->get_g_settings (), "input-device", device.GetString ().c_str ()); }