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/base/platform_thread.h" 19 #include "webrtc/modules/video_render/i_video_render.h" 20 21 22 namespace webrtc { 23 24 //#define ANDROID_LOG 25 26 class CriticalSectionWrapper; 27 class EventWrapper; 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 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 ChangeWindow(void* window); 53 54 virtual VideoRenderCallback* AddIncomingRenderStream( 55 const uint32_t streamId, 56 const uint32_t zOrder, 57 const float left, const float top, 58 const float right, const float bottom); 59 60 virtual int32_t DeleteIncomingRenderStream( 61 const uint32_t streamId); 62 63 virtual int32_t GetIncomingRenderStreamProperties( 64 const uint32_t streamId, 65 uint32_t& zOrder, 66 float& left, float& top, 67 float& right, float& bottom) const; 68 69 virtual int32_t StartRender(); 70 71 virtual int32_t StopRender(); 72 73 virtual void ReDraw(); 74 75 // Properties 76 77 virtual VideoRenderType RenderType(); 78 79 virtual RawVideoType PerferedVideoType(); 80 81 virtual bool FullScreen(); 82 83 virtual int32_t GetGraphicsMemory( 84 uint64_t& totalGraphicsMemory, 85 uint64_t& availableGraphicsMemory) const; 86 87 virtual int32_t GetScreenResolution( 88 uint32_t& screenWidth, 89 uint32_t& screenHeight) const; 90 91 virtual uint32_t RenderFrameRate(const uint32_t streamId); 92 93 virtual int32_t SetStreamCropping(const uint32_t streamId, 94 const float left, const float top, 95 const float right, const float bottom); 96 97 virtual int32_t SetTransparentBackground(const bool enable); 98 99 virtual int32_t ConfigureRenderer(const uint32_t streamId, 100 const unsigned int zOrder, 101 const float left, const float top, 102 const float right, const float bottom); 103 104 virtual int32_t SetText(const uint8_t textId, 105 const uint8_t* text, 106 const int32_t textLength, 107 const uint32_t textColorRef, 108 const uint32_t backgroundColorRef, 109 const float left, const float top, 110 const float rigth, const float bottom); 111 112 virtual int32_t SetBitmap(const void* bitMap, 113 const uint8_t pictureId, 114 const void* colorKey, const float left, 115 const float top, const float right, 116 const float bottom); 117 static JavaVM* g_jvm; 118 119 protected: 120 virtual AndroidStream* CreateAndroidRenderChannel( 121 int32_t streamId, 122 int32_t zOrder, 123 const float left, 124 const float top, 125 const float right, 126 const float bottom, 127 VideoRenderAndroid& renderer) = 0; 128 129 int32_t _id; 130 CriticalSectionWrapper& _critSect; 131 VideoRenderType _renderType; 132 jobject _ptrWindow; 133 134 private: 135 static bool JavaRenderThreadFun(void* obj); 136 bool JavaRenderThreadProcess(); 137 138 // Map with streams to render. 139 typedef std::map<int32_t, AndroidStream*> AndroidStreamMap; 140 AndroidStreamMap _streamsMap; 141 // True if the _javaRenderThread thread shall be detached from the JVM. 142 bool _javaShutDownFlag; 143 EventWrapper& _javaShutdownEvent; 144 EventWrapper& _javaRenderEvent; 145 int64_t _lastJavaRenderEvent; 146 JNIEnv* _javaRenderJniEnv; // JNIEnv for the java render thread. 147 // TODO(pbos): Remove scoped_ptr and use the member directly. 148 rtc::scoped_ptr<rtc::PlatformThread> _javaRenderThread; 149 }; 150 151 } // namespace webrtc 152 153 #endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_ANDROID_VIDEO_RENDER_ANDROID_IMPL_H_ 154