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
280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// This file contains the class CaptureRenderAdapter. The class connects a
290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// VideoCapturer to any number of VideoRenders such that the former feeds the
300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// latter.
310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// CaptureRenderAdapter is Thread-unsafe. This means that none of its APIs may
320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// be called concurrently.
330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#ifndef TALK_MEDIA_BASE_CAPTURERENDERADAPTER_H_
350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#define TALK_MEDIA_BASE_CAPTURERENDERADAPTER_H_
360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <vector>
380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
39cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "talk/media/base/videocapturer.h"
402a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org#include "webrtc/base/criticalsection.h"
412a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org#include "webrtc/base/sigslot.h"
420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace cricket {
440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoCapturer;
460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoProcessor;
470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoRenderer;
480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass CaptureRenderAdapter : public sigslot::has_slots<> {
500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public:
510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  static CaptureRenderAdapter* Create(VideoCapturer* video_capturer);
520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ~CaptureRenderAdapter();
530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool AddRenderer(VideoRenderer* video_renderer);
550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool RemoveRenderer(VideoRenderer* video_renderer);
560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoCapturer* video_capturer() { return video_capturer_; }
580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org private:
590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  struct VideoRendererInfo {
600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    explicit VideoRendererInfo(VideoRenderer* r)
610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        : renderer(r),
620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org          render_width(0),
630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org          render_height(0) {
640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    }
650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    VideoRenderer* renderer;
660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    size_t render_width;
670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    size_t render_height;
680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  };
690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Just pointers since ownership is not handed over to this class.
710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef std::vector<VideoRendererInfo> VideoRenderers;
720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  explicit CaptureRenderAdapter(VideoCapturer* video_capturer);
740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void Init();
750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Callback for frames received from the capturer.
770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void OnVideoFrame(VideoCapturer* capturer, const VideoFrame* video_frame);
780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void MaybeSetRenderingSize(const VideoFrame* frame);
800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool IsRendererRegistered(const VideoRenderer& video_renderer) const;
820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoRenderers video_renderers_;
840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoCapturer* video_capturer_;
850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Critical section synchronizing the capture thread.
862a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  mutable rtc::CriticalSection capture_crit_;
870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org}  // namespace cricket
900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#endif  // TALK_MEDIA_BASE_CAPTURERENDERADAPTER_H_
92