1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/engine_configurations.h"
#if defined(CARBON_RENDERING)
#ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_
#define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_
#include "webrtc/modules/video_render/include/video_render_defines.h"
#define NEW_HIVIEW_PARENT_EVENT_HANDLER 1
#define NEW_HIVIEW_EVENT_HANDLER 1
#define USE_STRUCT_RGN
#include <AGL/agl.h>
#include <Carbon/Carbon.h>
#include <OpenGL/OpenGL.h>
#include <OpenGL/glext.h>
#include <OpenGL/glu.h>
#include <list>
#include <map>
class VideoRenderAGL;
namespace webrtc {
class CriticalSectionWrapper;
class EventWrapper;
class ThreadWrapper;
class VideoChannelAGL : public VideoRenderCallback {
public:
VideoChannelAGL(AGLContext& aglContext, int iId, VideoRenderAGL* owner);
virtual ~VideoChannelAGL();
virtual int FrameSizeChange(int width, int height, int numberOfStreams);
virtual int DeliverFrame(const I420VideoFrame& videoFrame);
virtual int UpdateSize(int width, int height);
int SetStreamSettings(int streamId, float startWidth, float startHeight,
float stopWidth, float stopHeight);
int SetStreamCropSettings(int streamId, float startWidth, float startHeight,
float stopWidth, float stopHeight);
int RenderOffScreenBuffer();
int IsUpdated(bool& isUpdated);
virtual int UpdateStretchSize(int stretchHeight, int stretchWidth);
virtual int32_t RenderFrame(const uint32_t streamId,
I420VideoFrame& videoFrame);
private:
AGLContext _aglContext;
int _id;
VideoRenderAGL* _owner;
int _width;
int _height;
int _stretchedWidth;
int _stretchedHeight;
float _startHeight;
float _startWidth;
float _stopWidth;
float _stopHeight;
int _xOldWidth;
int _yOldHeight;
int _oldStretchedHeight;
int _oldStretchedWidth;
unsigned char* _buffer;
size_t _bufferSize;
size_t _incomingBufferSize;
bool _bufferIsUpdated;
bool _sizeInitialized;
int _numberOfStreams;
bool _bVideoSizeStartedChanging;
GLenum _pixelFormat;
GLenum _pixelDataType;
unsigned int _texture;
};
class VideoRenderAGL {
public:
VideoRenderAGL(WindowRef windowRef, bool fullscreen, int iId);
VideoRenderAGL(HIViewRef windowRef, bool fullscreen, int iId);
~VideoRenderAGL();
int Init();
VideoChannelAGL* CreateAGLChannel(int channel, int zOrder, float startWidth,
float startHeight, float stopWidth,
float stopHeight);
VideoChannelAGL* ConfigureAGLChannel(int channel, int zOrder,
float startWidth, float startHeight,
float stopWidth, float stopHeight);
int DeleteAGLChannel(int channel);
int DeleteAllAGLChannels();
int StopThread();
bool IsFullScreen();
bool HasChannels();
bool HasChannel(int channel);
int GetChannels(std::list<int>& channelList);
void LockAGLCntx();
void UnlockAGLCntx();
static int GetOpenGLVersion(int& aglMajor, int& aglMinor);
// ********** new module functions ************ //
int ChangeWindow(void* newWindowRef);
int32_t ChangeUniqueID(int32_t id);
int32_t StartRender();
int32_t StopRender();
int32_t DeleteAGLChannel(const uint32_t streamID);
int32_t GetChannelProperties(const uint16_t streamId, uint32_t& zOrder,
float& left, float& top, float& right,
float& bottom);
protected:
static bool ScreenUpdateThreadProc(void* obj);
bool ScreenUpdateProcess();
int GetWindowRect(Rect& rect);
private:
int CreateMixingContext();
int RenderOffScreenBuffers();
int SwapAndDisplayBuffers();
int UpdateClipping();
int CalculateVisibleRegion(ControlRef control, RgnHandle& visibleRgn,
bool clipChildren);
bool CheckValidRegion(RgnHandle rHandle);
void ParentWindowResized(WindowRef window);
// Carbon GUI event handlers
static pascal OSStatus sHandleWindowResized(
EventHandlerCallRef nextHandler, EventRef theEvent, void* userData);
static pascal OSStatus sHandleHiViewResized(
EventHandlerCallRef nextHandler, EventRef theEvent, void* userData);
HIViewRef _hiviewRef;
WindowRef _windowRef;
bool _fullScreen;
int _id;
webrtc::CriticalSectionWrapper& _renderCritSec;
webrtc::ThreadWrapper* _screenUpdateThread;
webrtc::EventWrapper* _screenUpdateEvent;
bool _isHIViewRef;
AGLContext _aglContext;
int _windowWidth;
int _windowHeight;
int _lastWindowWidth;
int _lastWindowHeight;
int _lastHiViewWidth;
int _lastHiViewHeight;
int _currentParentWindowHeight;
int _currentParentWindowWidth;
Rect _currentParentWindowBounds;
bool _windowHasResized;
Rect _lastParentWindowBounds;
Rect _currentHIViewBounds;
Rect _lastHIViewBounds;
Rect _windowRect;
std::map<int, VideoChannelAGL*> _aglChannels;
std::multimap<int, int> _zOrderToChannel;
EventHandlerRef _hiviewEventHandlerRef;
EventHandlerRef _windowEventHandlerRef;
HIRect _currentViewBounds;
HIRect _lastViewBounds;
bool _renderingIsPaused;
unsigned int _threadID;
};
} // namespace webrtc
#endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_
#endif // CARBON_RENDERING
|