• 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_MODULES_VIDEO_RENDER_MAIN_SOURCE_ANDROID_VIDEO_RENDER_ANDROID_IMPL_H_
12 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_ANDROID_VIDEO_RENDER_ANDROID_IMPL_H_
13 
14 #include <jni.h>
15 
16 #include <map>
17 
18 #include "webrtc/modules/video_render/i_video_render.h"
19 
20 
21 namespace webrtc {
22 
23 //#define ANDROID_LOG
24 
25 class CriticalSectionWrapper;
26 class EventWrapper;
27 class ThreadWrapper;
28 
29 // The object a module user uses to send new frames to the java renderer
30 // Base class for android render streams.
31 
32 class AndroidStream : public VideoRenderCallback {
33  public:
34   // DeliverFrame is called from a thread connected to the Java VM.
35   // Used for Delivering frame for rendering.
36   virtual void DeliverFrame(JNIEnv* jniEnv)=0;
37 
~AndroidStream()38   virtual ~AndroidStream() {};
39 };
40 
41 class VideoRenderAndroid: IVideoRender {
42  public:
43   VideoRenderAndroid(const int32_t id,
44                      const VideoRenderType videoRenderType,
45                      void* window,
46                      const bool fullscreen);
47 
48   virtual ~VideoRenderAndroid();
49 
50   virtual int32_t Init()=0;
51 
52   virtual int32_t ChangeUniqueId(const int32_t id);
53 
54   virtual int32_t ChangeWindow(void* window);
55 
56   virtual VideoRenderCallback* AddIncomingRenderStream(
57       const uint32_t streamId,
58       const uint32_t zOrder,
59       const float left, const float top,
60       const float right, const float bottom);
61 
62   virtual int32_t DeleteIncomingRenderStream(
63       const uint32_t streamId);
64 
65   virtual int32_t GetIncomingRenderStreamProperties(
66       const uint32_t streamId,
67       uint32_t& zOrder,
68       float& left, float& top,
69       float& right, float& bottom) const;
70 
71   virtual int32_t StartRender();
72 
73   virtual int32_t StopRender();
74 
75   virtual void ReDraw();
76 
77   // Properties
78 
79   virtual VideoRenderType RenderType();
80 
81   virtual RawVideoType PerferedVideoType();
82 
83   virtual bool FullScreen();
84 
85   virtual int32_t GetGraphicsMemory(
86       uint64_t& totalGraphicsMemory,
87       uint64_t& availableGraphicsMemory) const;
88 
89   virtual int32_t GetScreenResolution(
90       uint32_t& screenWidth,
91       uint32_t& screenHeight) const;
92 
93   virtual uint32_t RenderFrameRate(const uint32_t streamId);
94 
95   virtual int32_t SetStreamCropping(const uint32_t streamId,
96                                     const float left, const float top,
97                                     const float right, const float bottom);
98 
99   virtual int32_t SetTransparentBackground(const bool enable);
100 
101   virtual int32_t ConfigureRenderer(const uint32_t streamId,
102                                     const unsigned int zOrder,
103                                     const float left, const float top,
104                                     const float right, const float bottom);
105 
106   virtual int32_t SetText(const uint8_t textId,
107                           const uint8_t* text,
108                           const int32_t textLength,
109                           const uint32_t textColorRef,
110                           const uint32_t backgroundColorRef,
111                           const float left, const float top,
112                           const float rigth, const float bottom);
113 
114   virtual int32_t SetBitmap(const void* bitMap,
115                             const uint8_t pictureId,
116                             const void* colorKey, const float left,
117                             const float top, const float right,
118                             const float bottom);
119   static JavaVM* g_jvm;
120 
121  protected:
122   virtual AndroidStream* CreateAndroidRenderChannel(
123       int32_t streamId,
124       int32_t zOrder,
125       const float left,
126       const float top,
127       const float right,
128       const float bottom,
129       VideoRenderAndroid& renderer) = 0;
130 
131   int32_t _id;
132   CriticalSectionWrapper& _critSect;
133   VideoRenderType _renderType;
134   jobject _ptrWindow;
135 
136  private:
137   static bool JavaRenderThreadFun(void* obj);
138   bool JavaRenderThreadProcess();
139 
140   // Map with streams to render.
141   typedef std::map<int32_t, AndroidStream*> AndroidStreamMap;
142   AndroidStreamMap _streamsMap;
143   // True if the _javaRenderThread thread shall be detached from the JVM.
144   bool _javaShutDownFlag;
145   EventWrapper& _javaShutdownEvent;
146   EventWrapper& _javaRenderEvent;
147   int64_t _lastJavaRenderEvent;
148   JNIEnv* _javaRenderJniEnv; // JNIEnv for the java render thread.
149   ThreadWrapper* _javaRenderThread;
150 };
151 
152 }  // namespace webrtc
153 
154 #endif  // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_ANDROID_VIDEO_RENDER_ANDROID_IMPL_H_
155