15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * libjingle 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright 2012, Google Inc. 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright notice, 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this list of conditions and the following disclaimer. 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright notice, 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this list of conditions and the following disclaimer in the documentation 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * and/or other materials provided with the distribution. 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 3. The name of the author may not be used to endorse or promote products 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * derived from this software without specific prior written permission. 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// This file contains the class CaptureRenderAdapter. The class connects a 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// VideoCapturer to any number of VideoRenders such that the former feeds the 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// latter. 315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)// CaptureRenderAdapter is Thread-unsafe. This means that none of its APIs may 325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)// be called concurrently. 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 34a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#ifndef TALK_MEDIA_BASE_CAPTURERENDERADAPTER_H_ 35a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define TALK_MEDIA_BASE_CAPTURERENDERADAPTER_H_ 3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <vector> 385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "talk/media/base/videocapturer.h" 405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "webrtc/base/criticalsection.h" 415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "webrtc/base/sigslot.h" 425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)namespace cricket { 445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 455267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class VideoCapturer; 465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class VideoProcessor; 475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class VideoRenderer; 485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 495267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class CaptureRenderAdapter : public sigslot::has_slots<> { 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) public: 5151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) static CaptureRenderAdapter* Create(VideoCapturer* video_capturer); 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ~CaptureRenderAdapter(); 535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) bool AddRenderer(VideoRenderer* video_renderer); 555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool RemoveRenderer(VideoRenderer* video_renderer); 565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 575267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) VideoCapturer* video_capturer() { return video_capturer_; } 585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) private: 59a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) struct VideoRendererInfo { 605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) explicit VideoRendererInfo(VideoRenderer* r) 615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) : renderer(r), 625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) render_width(0), 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) render_height(0) { 6451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) VideoRenderer* renderer; 665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) size_t render_width; 67 size_t render_height; 68 }; 69 70 // Just pointers since ownership is not handed over to this class. 71 typedef std::vector<VideoRendererInfo> VideoRenderers; 72 73 explicit CaptureRenderAdapter(VideoCapturer* video_capturer); 74 void Init(); 75 76 // Callback for frames received from the capturer. 77 void OnVideoFrame(VideoCapturer* capturer, const VideoFrame* video_frame); 78 79 void MaybeSetRenderingSize(const VideoFrame* frame); 80 81 bool IsRendererRegistered(const VideoRenderer& video_renderer) const; 82 83 VideoRenderers video_renderers_; 84 VideoCapturer* video_capturer_; 85 // Critical section synchronizing the capture thread. 86 mutable rtc::CriticalSection capture_crit_; 87}; 88 89} // namespace cricket 90 91#endif // TALK_MEDIA_BASE_CAPTURERENDERADAPTER_H_ 92