bool Init( const std::string kind, const std::string label, talk_base::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory, talk_base::scoped_refptr<webrtc::MediaStreamTrackInterface> track) { m_track = track; if (m_track != NULL) { if (kind == kAudioKind) m_source = ((webrtc::AudioTrackInterface *)m_track.get())->GetSource(); else m_source = ((webrtc::VideoTrackInterface *)m_track.get())->GetSource(); return true; } returnv_assert(pc_factory.get(), false); if (kind == kAudioKind) { if (!m_source.get()) { WebrtcMediaConstraints constraints; if (m_constraints.mtype == XRTC_AUDIO && m_constraints.ptr) { audio_constraints_t *audio = (audio_constraints_t *)m_constraints.ptr; if (audio->aec.valid) constraints.AddItem(webrtc::MediaConstraintsInterface::kEchoCancellation, audio->aec.val, audio->aec.optional); if (audio->agc.valid) constraints.AddItem(webrtc::MediaConstraintsInterface::kAutoGainControl, audio->agc.val, audio->agc.optional); if (audio->ns.valid) constraints.AddItem(webrtc::MediaConstraintsInterface::kNoiseSuppression, audio->ns.val, audio->ns.optional); if (audio->highPassFilter.valid) constraints.AddItem(webrtc::MediaConstraintsInterface::kHighpassFilter, audio->highPassFilter.val, audio->highPassFilter.optional); } m_source = pc_factory->CreateAudioSource(&constraints); } m_track = pc_factory->CreateAudioTrack(label, (webrtc::AudioSourceInterface *)(m_source.get())); }else if (kind == kVideoKind) { if (!m_source.get()) { std::string vname = ""; if (m_constraints.mtype == XRTC_VIDEO && m_constraints.ptr) { video_constraints_t *video = (video_constraints_t *)m_constraints.ptr; if (video && video->device.valid) { vname = video->device.val.did; } } // if vname empty, select default device LOGI("vname="<<vname); cricket::VideoCapturer* capturer = OpenVideoCaptureDevice(vname); if (capturer) { m_source = pc_factory->CreateVideoSource(capturer, NULL); } } LOGD("create video track by source"); if (m_source) { m_track = pc_factory->CreateVideoTrack(label, (webrtc::VideoSourceInterface *)(m_source.get())); } } return (m_track != NULL); }