• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
16 #include "webrtc/common_types.h"
17 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
18 #include "webrtc/typedefs.h"
19 
20 namespace webrtc {
21 
22 class CriticalSectionWrapper;
23 class VideoEncoder;
24 class I420VideoFrame;
25 
26 // ViEFrameCallback shall be implemented by all classes receiving frames from a
27 // frame provider.
28 class ViEFrameCallback {
29  public:
30   virtual void DeliverFrame(int id,
31                             I420VideoFrame* video_frame,
32                             int num_csrcs = 0,
33                             const uint32_t CSRC[kRtpCsrcSize] = NULL) = 0;
34 
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 
~ViEFrameCallback()48   virtual ~ViEFrameCallback() {}
49 };
50 
51 // ViEFrameProviderBase is a base class that will deliver frames to all
52 // registered ViEFrameCallbacks.
53 class 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:
78   void DeliverFrame(I420VideoFrame* video_frame,
79                     int num_csrcs = 0,
80                     const uint32_t CSRC[kRtpCsrcSize] = NULL);
81   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:
96   scoped_ptr<I420VideoFrame> extra_frame_;
97   int frame_delay_;
98 };
99 
100 }  // namespace webrtc
101 
102 #endif  // WEBRTC_VIDEO_ENGINE_VIE_FRAME_PROVIDER_BASE_H_
103