blob: e5a137b8bd8056c149dabe0937c0cef431859660 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_VIDEO_ENGINE_VIE_FRAME_PROVIDER_BASE_H_
12#define WEBRTC_VIDEO_ENGINE_VIE_FRAME_PROVIDER_BASE_H_
13
14#include <vector>
15
pbos@webrtc.org281cff82013-05-17 13:44:48 +000016#include "webrtc/common_types.h"
17#include "webrtc/system_wrappers/interface/scoped_ptr.h"
18#include "webrtc/typedefs.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000019
20namespace webrtc {
21
22class CriticalSectionWrapper;
23class VideoEncoder;
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000024class I420VideoFrame;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000025
26// ViEFrameCallback shall be implemented by all classes receiving frames from a
27// frame provider.
28class ViEFrameCallback {
29 public:
30 virtual void DeliverFrame(int id,
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000031 I420VideoFrame* video_frame,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000032 int num_csrcs = 0,
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000033 const uint32_t CSRC[kRtpCsrcSize] = NULL) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000034
35 // The capture delay has changed from the provider. |frame_delay| is given in
36 // ms.
37 virtual void DelayChanged(int id, int frame_delay) = 0;
38
39 // Get the width, height and frame rate preferred by this observer.
40 virtual int GetPreferedFrameSettings(int* width,
41 int* height,
42 int* frame_rate) = 0;
43
44 // ProviderDestroyed is called when the frame is about to be destroyed. There
45 // must not be any more calls to the frame provider after this.
46 virtual void ProviderDestroyed(int id) = 0;
47
48 virtual ~ViEFrameCallback() {}
49};
50
51// ViEFrameProviderBase is a base class that will deliver frames to all
52// registered ViEFrameCallbacks.
53class ViEFrameProviderBase {
54 public:
55 ViEFrameProviderBase(int Id, int engine_id);
56 virtual ~ViEFrameProviderBase();
57
58 // Returns the frame provider id.
59 int Id();
60
61 // Register frame callbacks, i.e. a receiver of the captured frame.
62 virtual int RegisterFrameCallback(int observer_id,
63 ViEFrameCallback* callback_object);
64
65 virtual int DeregisterFrameCallback(const ViEFrameCallback* callback_object);
66
67 virtual bool IsFrameCallbackRegistered(
68 const ViEFrameCallback* callback_object);
69
70 int NumberOfRegisteredFrameCallbacks();
71
72 // FrameCallbackChanged
73 // Inherited classes should check for new frame_settings and reconfigure
74 // output if possible.
75 virtual int FrameCallbackChanged() = 0;
76
77 protected:
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000078 void DeliverFrame(I420VideoFrame* video_frame,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000079 int num_csrcs = 0,
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000080 const uint32_t CSRC[kRtpCsrcSize] = NULL);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000081 void SetFrameDelay(int frame_delay);
82 int FrameDelay();
83 int GetBestFormat(int* best_width,
84 int* best_height,
85 int* best_frame_rate);
86
87 int id_;
88 int engine_id_;
89
90 // Frame callbacks.
91 typedef std::vector<ViEFrameCallback*> FrameCallbacks;
92 FrameCallbacks frame_callbacks_;
93 scoped_ptr<CriticalSectionWrapper> provider_cs_;
94
95 private:
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000096 scoped_ptr<I420VideoFrame> extra_frame_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000097 int frame_delay_;
98};
99
100} // namespace webrtc
101
102#endif // WEBRTC_VIDEO_ENGINE_VIE_FRAME_PROVIDER_BASE_H_