andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 281cff8 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 16 | #include "webrtc/common_types.h" |
| 17 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 18 | #include "webrtc/typedefs.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class CriticalSectionWrapper; |
| 23 | class VideoEncoder; |
mikhal@webrtc.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 24 | class I420VideoFrame; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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, |
mikhal@webrtc.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 31 | I420VideoFrame* video_frame, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 32 | int num_csrcs = 0, |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 33 | const uint32_t CSRC[kRtpCsrcSize] = NULL) = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
| 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: |
mikhal@webrtc.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 78 | void DeliverFrame(I420VideoFrame* video_frame, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 79 | int num_csrcs = 0, |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 80 | const uint32_t CSRC[kRtpCsrcSize] = NULL); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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: |
mikhal@webrtc.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 96 | scoped_ptr<I420VideoFrame> extra_frame_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 97 | int frame_delay_; |
| 98 | }; |
| 99 | |
| 100 | } // namespace webrtc |
| 101 | |
| 102 | #endif // WEBRTC_VIDEO_ENGINE_VIE_FRAME_PROVIDER_BASE_H_ |