10e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org/* 20e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * libjingle 30e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * Copyright 2012, Google Inc. 40e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 50e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * Redistribution and use in source and binary forms, with or without 60e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * modification, are permitted provided that the following conditions are met: 70e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 80e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 90e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * this list of conditions and the following disclaimer. 100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * this list of conditions and the following disclaimer in the documentation 120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * and/or other materials provided with the distribution. 130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 3. The name of the author may not be used to endorse or promote products 140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * derived from this software without specific prior written permission. 150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org */ 270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 284ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org#ifndef TALK_APP_WEBRTC_VIDEOSOURCE_H_ 294ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org#define TALK_APP_WEBRTC_VIDEOSOURCE_H_ 300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/app/webrtc/mediastreaminterface.h" 320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/app/webrtc/notifier.h" 330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/app/webrtc/videosourceinterface.h" 344ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org#include "talk/app/webrtc/videotrackrenderers.h" 350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/media/base/videocapturer.h" 360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/media/base/videocommon.h" 37cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "webrtc/base/scoped_ptr.h" 38cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "webrtc/base/sigslot.h" 390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 404ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org// VideoSource implements VideoSourceInterface. It owns a 410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// cricket::VideoCapturer and make sure the camera is started at a resolution 420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// that honors the constraints. 430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// The state is set depending on the result of starting the capturer. 440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// If the constraint can't be met or the capturer fails to start, the state 450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// transition to kEnded, otherwise it transitions to kLive. 460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace cricket { 480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass ChannelManager; 500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org} // namespace cricket 520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace webrtc { 540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass MediaConstraintsInterface; 560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 574ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.orgclass VideoSource : public Notifier<VideoSourceInterface>, 584ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org public sigslot::has_slots<> { 590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public: 604ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org // Creates an instance of VideoSource. 614ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org // VideoSource take ownership of |capturer|. 620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // |constraints| can be NULL and in that case the camera is opened using a 630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // default resolution. 642a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org static rtc::scoped_refptr<VideoSource> Create( 650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org cricket::ChannelManager* channel_manager, 660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org cricket::VideoCapturer* capturer, 670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org const webrtc::MediaConstraintsInterface* constraints); 680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual SourceState state() const { return state_; } 700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual const cricket::VideoOptions* options() const { return &options_; } 714ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org virtual cricket::VideoRenderer* FrameInput(); 720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual cricket::VideoCapturer* GetVideoCapturer() { 740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org return video_capturer_.get(); 750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org } 760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // |output| will be served video frames as long as the underlying capturer 770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // is running video frames. 780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void AddSink(cricket::VideoRenderer* output); 790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void RemoveSink(cricket::VideoRenderer* output); 800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org protected: 824ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org VideoSource(cricket::ChannelManager* channel_manager, 834ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org cricket::VideoCapturer* capturer); 844ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org virtual ~VideoSource(); 854ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org void Initialize(const webrtc::MediaConstraintsInterface* constraints); 860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org private: 880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org void OnStateChange(cricket::VideoCapturer* capturer, 890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org cricket::CaptureState capture_state); 900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org void SetState(SourceState new_state); 910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org cricket::ChannelManager* channel_manager_; 932a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org rtc::scoped_ptr<cricket::VideoCapturer> video_capturer_; 942a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org rtc::scoped_ptr<cricket::VideoRenderer> frame_input_; 950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org cricket::VideoFormat format_; 970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org cricket::VideoOptions options_; 980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org SourceState state_; 990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org}; 1000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 1010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org} // namespace webrtc 1020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 1034ba8b9ea10385f43b19d6ed7408f4a09bdc1cbdawu@webrtc.org#endif // TALK_APP_WEBRTC_VIDEOSOURCE_H_ 104