Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

IOS #254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

IOS #254

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions api/iOS/VCSimpleSession.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ of this software and associated documentation files (the "Software"), to deal
# include <videocore/transforms/Apple/MP4Multiplexer.h>
# include <videocore/transforms/Apple/H264Encode.h>
# include <videocore/sources/Apple/PixelBufferSource.h>
# include <videocore/mixers/Apple/GLVideoMixer.h>
# include <videocore/transforms/Apple/AACEncode.h>
# ifdef TARGET_OS_IPHONE
# include <videocore/sources/iOS/CameraSource.h>
# include <videocore/sources/iOS/MicSource.h>
# include <videocore/mixers/iOS/GLESVideoMixer.h>
# include <videocore/transforms/iOS/AACEncode.h>
# include <videocore/transforms/iOS/H264Encode.h>

# else /* OS X */
Expand Down Expand Up @@ -681,7 +681,7 @@ - (void) setupGraph

{
// Add video mixer
m_videoMixer = std::make_shared<videocore::iOS::GLESVideoMixer>(self.videoSize.width,
m_videoMixer = std::make_shared<videocore::Apple::GLVideoMixer>(self.videoSize.width,
self.videoSize.height,
frameDuration);

Expand Down Expand Up @@ -763,7 +763,7 @@ - (void) addEncodersAndPacketizers
{
// Add encoders

m_aacEncoder = std::make_shared<videocore::iOS::AACEncode>(self.audioSampleRate, self.audioChannelCount, 96000);
m_aacEncoder = std::make_shared<videocore::Apple::AACEncode>(self.audioSampleRate, self.audioChannelCount, 96000);
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
// If >= iOS 8.0 use the VideoToolbox encoder that does not write to disk.
m_h264Encoder = std::make_shared<videocore::Apple::H264Encode>(self.videoSize.width,
Expand Down
94 changes: 80 additions & 14 deletions filters/Basic/BasicVideoFilterBGRA.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@

#include <videocore/filters/Basic/BasicVideoFilterBGRA.h>

#include <TargetConditionals.h>


#ifdef TARGET_OS_IPHONE

#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES3/gl.h>
#include <videocore/sources/iOS/GLESUtil.h>
#include <videocore/filters/FilterFactory.h>

#ifdef __APPLE__
# include <TargetConditionals.h>
# if (TARGET_OS_IPHONE)
# include <OpenGLES/ES2/gl.h>
# include <OpenGLES/ES3/gl.h>
# include <videocore/sources/iOS/GLESUtil.h>
# else
# include <OpenGL/gl3.h>
# include <OpenGL/gl3ext.h>
# include <videocore/sources/iOS/GLESUtil.h>
# define glDeleteVertexArraysOES glDeleteVertexArrays
# define glGenVertexArraysOES glGenVertexArrays
# define glBindVertexArrayOES glBindVertexArray
# endif
#endif


#include <videocore/filters/FilterFactory.h>

namespace videocore { namespace filters {

bool BasicVideoFilterBGRA::s_registered = BasicVideoFilterBGRA::registerFilter();
Expand All @@ -31,39 +41,66 @@ namespace videocore { namespace filters {
}
BasicVideoFilterBGRA::~BasicVideoFilterBGRA()
{
glDeleteProgram(m_program);
glDeleteVertexArraysOES(1, &m_vao);
if(m_initialized) {
glDeleteProgram(m_program);
glDeleteVertexArraysOES(1, &m_vao);
}
}

const char * const
BasicVideoFilterBGRA::vertexKernel() const
{

KERNEL(GL_ES2_3, m_language,
FKERNEL(GL_ES2_3, m_language,
attribute vec2 aPos;
attribute vec2 aCoord;
varying vec2 vCoord;
uniform mat4 uMat;
void main(void) {
gl_Position = uMat * vec4(aPos,0.,1.);
vCoord = aCoord;
}
},
""
)
FKERNEL(GL_3, m_language,
in vec2 aPos;
in vec2 aCoord;
out vec2 vCoord;
uniform mat4 uMat;
void main(void) {
gl_Position = uMat * vec4(aPos,0.,1.);
vCoord = aCoord;
},
"#version 150"
)

return nullptr;
}

const char * const
BasicVideoFilterBGRA::pixelKernel() const
{

KERNEL(GL_ES2_3, m_language,
FKERNEL(GL_ES2_3, m_language,
precision mediump float;
varying vec2 vCoord;
uniform sampler2D uTex0;
void main(void) {
gl_FragData[0] = texture2D(uTex0, vCoord);
}
},
""
)
FKERNEL(GL_3, m_language,

in vec2 vCoord;
uniform sampler2DRect uTex0;
out vec4 fragColor;
uniform vec2 uImageSize;
void main(void) {

vec4 color = texture(uTex0, vCoord * uImageSize);
fragColor = color;
},
"#version 150"
)

return nullptr;
Expand All @@ -90,6 +127,26 @@ namespace videocore { namespace filters {
}
break;
case GL_3:
{
setProgram(build_program(vertexKernel(), pixelKernel()));

glGenVertexArraysOES(1, &m_vao);
glBindVertexArrayOES(m_vao);
glUseProgram(m_program);
m_uMatrix = glGetUniformLocation(m_program, "uMat");
int attrpos = glGetAttribLocation(m_program, "aPos");
int attrtex = glGetAttribLocation(m_program, "aCoord");
int unitex = glGetUniformLocation(m_program, "uTex0");
m_uImageSize = glGetUniformLocation(m_program, "uImageSize");

glUniform1i(unitex, 0);
glEnableVertexAttribArray(attrpos);
glEnableVertexAttribArray(attrtex);
glVertexAttribPointer(attrpos, BUFFER_SIZE_POSITION, GL_FLOAT, GL_FALSE, BUFFER_STRIDE, BUFFER_OFFSET_POSITION);
glVertexAttribPointer(attrtex, BUFFER_SIZE_POSITION, GL_FLOAT, GL_FALSE, BUFFER_STRIDE, BUFFER_OFFSET_TEXTURE);
m_initialized = true;

}
break;
}
}
Expand All @@ -109,6 +166,15 @@ namespace videocore { namespace filters {
glUniformMatrix4fv(m_uMatrix, 1, GL_FALSE, &m_matrix[0][0]);
break;
case GL_3:
if(!m_bound) {
if(!initialized()) {
initialize();
}
glUseProgram(m_program);
glBindVertexArrayOES(m_vao);
}
glUniformMatrix4fv(m_uMatrix, 1, GL_FALSE, &m_matrix[0][0]);
glUniform2f(m_uImageSize, m_dimensions.w, m_dimensions.h);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions filters/Basic/BasicVideoFilterBGRA.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace videocore {

unsigned int m_vao;
unsigned int m_uMatrix;
unsigned int m_uImageSize;
bool m_initialized;
bool m_bound;

Expand Down
38 changes: 22 additions & 16 deletions filters/Basic/BasicVideoFilterBGRAinYUVAout.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#include <videocore/filters/Basic/BasicVideoFilterBGRAinYUVAout.h>

#ifdef __APPLE__
#include <TargetConditionals.h>
# ifdef TARGET_OS_IPHONE
# include <OpenGLES/ES2/gl.h>
# include <OpenGLES/ES3/gl.h>
# include <videocore/sources/iOS/GLESUtil.h>
# include <videocore/filters/FilterFactory.h>
# include <TargetConditionals.h>
# if (TARGET_OS_IPHONE)
# include <OpenGLES/ES2/gl.h>
# include <OpenGLES/ES3/gl.h>
# include <videocore/sources/iOS/GLESUtil.h>
# else
# include <OpenGL/gl3.h>
# include <OpenGL/gl3ext.h>
# include <videocore/sources/iOS/GLESUtil.h>
# define glDeleteVertexArraysOES glDeleteVertexArrays
# define glGenVertexArraysOES glGenVertexArrays
# define glBindVertexArrayOES glBindVertexArray
# endif
#endif

#include <videocore/filters/FilterFactory.h>
namespace videocore { namespace filters {

bool BasicVideoFilterBGRAinYUVAout::s_registered = BasicVideoFilterBGRAinYUVAout::registerFilter();
Expand All @@ -29,22 +35,22 @@ namespace videocore { namespace filters {
BasicVideoFilterBGRAinYUVAout::~BasicVideoFilterBGRAinYUVAout()
{
glDeleteProgram(m_program);
glDeleteVertexArrays(1, &m_vao);
glDeleteVertexArraysOES(1, &m_vao);
}

const char * const
BasicVideoFilterBGRAinYUVAout::vertexKernel() const
{

KERNEL(GL_ES2_3, m_language,
FKERNEL(GL_ES2_3, m_language,
attribute vec2 aPos;
attribute vec2 aCoord;
varying vec2 vCoord;
uniform mat4 uMat;
void main(void) {
gl_Position = uMat * vec4(aPos,0.,1.);
vCoord = aCoord;
}
}, ""
)

return nullptr;
Expand All @@ -54,7 +60,7 @@ namespace videocore { namespace filters {
BasicVideoFilterBGRAinYUVAout::pixelKernel() const
{

KERNEL(GL_ES2_3, m_language,
FKERNEL(GL_ES2_3, m_language,
precision mediump float;
varying vec2 vCoord;
uniform sampler2D uTex0;
Expand All @@ -64,7 +70,7 @@ namespace videocore { namespace filters {
0.0625, 0.500, 0.500, 1.0 );
void main(void) {
gl_FragData[0] = texture2D(uTex0, vCoord) * RGBtoYUV;
}
}, ""
)

return nullptr;
Expand All @@ -76,8 +82,8 @@ namespace videocore { namespace filters {
case GL_ES2_3:
case GL_2: {
setProgram(build_program(vertexKernel(), pixelKernel()));
glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);
glGenVertexArraysOES(1, &m_vao);
glBindVertexArrayOES(m_vao);
m_uMatrix = glGetUniformLocation(m_program, "uMat");
int attrpos = glGetAttribLocation(m_program, "aPos");
int attrtex = glGetAttribLocation(m_program, "aCoord");
Expand Down Expand Up @@ -105,7 +111,7 @@ namespace videocore { namespace filters {
initialize();
}
glUseProgram(m_program);
glBindVertexArray(m_vao);
glBindVertexArrayOES(m_vao);
}
glUniformMatrix4fv(m_uMatrix, 1, GL_FALSE, &m_matrix[0][0]);
break;
Expand All @@ -119,4 +125,4 @@ namespace videocore { namespace filters {
m_bound = false;
}
}
}
}
33 changes: 19 additions & 14 deletions filters/Basic/GrayscaleVideoFilter.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@

#include <videocore/filters/Basic/GrayscaleVideoFilter.h>

#include <TargetConditionals.h>


#ifdef TARGET_OS_IPHONE

#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES3/gl.h>
#include <videocore/sources/iOS/GLESUtil.h>
#include <videocore/filters/FilterFactory.h>

#ifdef __APPLE__
# include <TargetConditionals.h>
# if (TARGET_OS_IPHONE)
# include <OpenGLES/ES2/gl.h>
# include <OpenGLES/ES3/gl.h>
# include <videocore/sources/iOS/GLESUtil.h>
# else
# include <OpenGL/gl3.h>
# include <OpenGL/gl3ext.h>
# include <videocore/sources/iOS/GLESUtil.h>
# define glDeleteVertexArraysOES glDeleteVertexArrays
# define glGenVertexArraysOES glGenVertexArrays
# define glBindVertexArrayOES glBindVertexArray
# endif
#endif
#include <videocore/filters/FilterFactory.h>

namespace videocore { namespace filters {

Expand Down Expand Up @@ -39,15 +44,15 @@ namespace videocore { namespace filters {
GrayscaleVideoFilter::vertexKernel() const
{

KERNEL(GL_ES2_3, m_language,
FKERNEL(GL_ES2_3, m_language,
attribute vec2 aPos;
attribute vec2 aCoord;
varying vec2 vCoord;
uniform mat4 uMat;
void main(void) {
gl_Position = uMat * vec4(aPos,0.,1.);
vCoord = aCoord;
}
}, ""
)

return nullptr;
Expand All @@ -57,15 +62,15 @@ namespace videocore { namespace filters {
GrayscaleVideoFilter::pixelKernel() const
{

KERNEL(GL_ES2_3, m_language,
FKERNEL(GL_ES2_3, m_language,
precision mediump float;
varying vec2 vCoord;
uniform sampler2D uTex0;
void main(void) {
vec4 color = texture2D(uTex0, vCoord);
float gray = dot(color.rgb, vec3(0.3, 0.59, 0.11));
gl_FragColor = vec4(gray, gray, gray, color.a);
}
}, ""
)

return nullptr;
Expand Down
Loading