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_SURFACE_VIEW_H_
12 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_ANDROID_VIDEO_RENDER_ANDROID_SURFACE_VIEW_H_
13 
14 #include <jni.h>
15 
16 #include "webrtc/modules/video_render/android/video_render_android_impl.h"
17 #include "webrtc/modules/video_render/video_render_defines.h"
18 
19 namespace webrtc {
20 
21 class CriticalSectionWrapper;
22 
23 class AndroidSurfaceViewChannel : public AndroidStream {
24  public:
25   AndroidSurfaceViewChannel(uint32_t streamId,
26                             JavaVM* jvm,
27                             VideoRenderAndroid& renderer,
28                             jobject javaRenderObj);
29   ~AndroidSurfaceViewChannel();
30 
31   int32_t Init(int32_t zOrder, const float left, const float top,
32                const float right, const float bottom);
33 
34   //Implement VideoRenderCallback
35   virtual int32_t RenderFrame(const uint32_t streamId,
36                               const VideoFrame& videoFrame);
37 
38   //Implements AndroidStream
39   virtual void DeliverFrame(JNIEnv* jniEnv);
40 
41  private:
42   uint32_t _id;
43   CriticalSectionWrapper& _renderCritSect;
44 
45   VideoFrame _bufferToRender;
46   VideoRenderAndroid& _renderer;
47   JavaVM* _jvm;
48   jobject _javaRenderObj;
49 
50   jobject _javaByteBufferObj;
51   unsigned char* _directBuffer;
52   jmethodID _createByteBufferCid;
53   jmethodID _drawByteBufferCid;
54 
55   jmethodID _setCoordinatesCid;
56   int _bitmapWidth;
57   int _bitmapHeight;
58 };
59 
60 class AndroidSurfaceViewRenderer : private VideoRenderAndroid {
61  public:
62   AndroidSurfaceViewRenderer(const int32_t id,
63                              const VideoRenderType videoRenderType,
64                              void* window,
65                              const bool fullscreen);
66   ~AndroidSurfaceViewRenderer();
67   int32_t Init();
68   virtual AndroidStream* CreateAndroidRenderChannel(
69       int32_t streamId,
70       int32_t zOrder,
71       const float left,
72       const float top,
73       const float right,
74       const float bottom,
75       VideoRenderAndroid& renderer);
76  private:
77   jobject _javaRenderObj;
78   jclass _javaRenderClass;
79 };
80 
81 }  // namespace webrtc
82 
83 #endif  // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_ANDROID_VIDEO_RENDER_ANDROID_SURFACE_VIEW_H_
84