H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_stdinc.h
#ifndef IJKSDL__IJKSDL_STDINC_H #define IJKSDL__IJKSDL_STDINC_H #include <stddef.h> #include <stdint.h> #include <stdbool.h> typedef int8_t Sint8; typedef uint8_t Uint8; typedef int16_t Sint16; typedef uint16_t Uint16; typedef int32_t Sint32; typedef uint32_t Uint32; typedef int64_t Sint64; typedef uint64_t Uint64; char *SDL_getenv(const char *name); #endif
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_stdinc.c
#include "ijksdl_stdinc.h" char *SDL_getenv(const char *name) { return NULL; }
包含标准库头文件,并定义一些要用的数据类型.
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_mutex.h
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_mutex.c
封装
SDL_mutex
SDL_cond结构体
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_extra_log.c
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_extra_log.h
#include "ijksdl_extra_log.h" #include "ijksdl/android/ijksdl_android_jni.h" #include <stdio.h> #define LOG_BUF_SIZE 1024 #ifdef EXTRA_LOG_PRINT void ffp_log_extra_print(int level, const char *tag, const char *fmt, ...) { JNIEnv *env = NULL; if (JNI_OK != SDL_JNI_SetupThreadEnv(&env)) { return; } va_list ap; char log_buffer[LOG_BUF_SIZE] = {0}; va_start(ap, fmt); vsnprintf(log_buffer, LOG_BUF_SIZE, fmt, ap); va_end(ap); switch (level) { case ANDROID_LOG_UNKNOWN: case ANDROID_LOG_DEFAULT: case ANDROID_LOG_VERBOSE: J4AC_BLog__v__withCString__catchAll(env, tag, log_buffer); break; case ANDROID_LOG_DEBUG: J4AC_BLog__d__withCString__catchAll(env, tag, log_buffer); break; case ANDROID_LOG_INFO: J4AC_BLog__i__withCString__catchAll(env, tag, log_buffer); break; case ANDROID_LOG_WARN: J4AC_BLog__w__withCString__catchAll(env, tag, log_buffer); break; case ANDROID_LOG_FATAL: case ANDROID_LOG_SILENT: case ANDROID_LOG_ERROR: J4AC_BLog__e__withCString__catchAll(env, tag, log_buffer); break; default: break; } } void ffp_log_extra_vprint(int level, const char *tag, const char *fmt, va_list ap) { JNIEnv *env = NULL; if (JNI_OK != SDL_JNI_SetupThreadEnv(&env)) { return; } char log_buffer[LOG_BUF_SIZE] = {0}; vsnprintf(log_buffer, LOG_BUF_SIZE, fmt, ap); switch (level) { case ANDROID_LOG_UNKNOWN: case ANDROID_LOG_DEFAULT: case ANDROID_LOG_VERBOSE: J4AC_BLog__v__withCString__catchAll(env, tag, log_buffer); break; case ANDROID_LOG_DEBUG: J4AC_BLog__d__withCString__catchAll(env, tag, log_buffer); break; case ANDROID_LOG_INFO: J4AC_BLog__i__withCString__catchAll(env, tag, log_buffer); break; case ANDROID_LOG_WARN: J4AC_BLog__w__withCString__catchAll(env, tag, log_buffer); break; case ANDROID_LOG_FATAL: case ANDROID_LOG_SILENT: case ANDROID_LOG_ERROR: J4AC_BLog__e__withCString__catchAll(env, tag, log_buffer); break; default: break; } } #endif // EXTRA_LOG_PRINT
用 EXTRA_LOG_PRINT宏来控制编译
通过java成的 BLog类来实现功能
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_misc.h
#ifndef IJKSDL__IJKSDL_MISC_H #define IJKSDL__IJKSDL_MISC_H #include <stdlib.h> #include <memory.h> #ifndef IJKMAX #define IJKMAX(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef IJKMIN #define IJKMIN(a, b) ((a) < (b) ? (a) : (b)) #endif #ifndef IJKALIGN #define IJKALIGN(x, align) ((( x ) + (align) - 1) / (align) * (align)) #endif #define IJK_CHECK_RET(condition__, retval__, ...) \ if (!(condition__)) { \ ALOGE(__VA_ARGS__); \ return (retval__); \ } #ifndef NELEM #define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) #endif inline static void *mallocz(size_t size) { void *mem = malloc(size); if (!mem) return mem; memset(mem, 0, size); return mem; } inline static void freep(void **mem) { if (mem && *mem) { free(*mem); *mem = NULL; } } #endif
辅助函数,宏定义
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_log.h
#ifndef IJKSDL__IJKSDL_LOG_H #define IJKSDL__IJKSDL_LOG_H #include <stdio.h> #ifdef __ANDROID__ #include <android/log.h> #include "ijksdl_extra_log.h" #define IJK_LOG_UNKNOWN ANDROID_LOG_UNKNOWN #define IJK_LOG_DEFAULT ANDROID_LOG_DEFAULT #define IJK_LOG_VERBOSE ANDROID_LOG_VERBOSE #define IJK_LOG_DEBUG ANDROID_LOG_DEBUG #define IJK_LOG_INFO ANDROID_LOG_INFO #define IJK_LOG_WARN ANDROID_LOG_WARN #define IJK_LOG_ERROR ANDROID_LOG_ERROR #define IJK_LOG_FATAL ANDROID_LOG_FATAL #define IJK_LOG_SILENT ANDROID_LOG_SILENT #ifdef EXTRA_LOG_PRINT #define VLOG(level, TAG, ...) ffp_log_extra_vprint(level, TAG, __VA_ARGS__) #define ALOG(level, TAG, ...) ffp_log_extra_print(level, TAG, __VA_ARGS__) #else #define VLOG(level, TAG, ...) ((void)__android_log_vprint(level, TAG, __VA_ARGS__)) #define ALOG(level, TAG, ...) ((void)__android_log_print(level, TAG, __VA_ARGS__)) #endif #else #define IJK_LOG_UNKNOWN 0 #define IJK_LOG_DEFAULT 1 #define IJK_LOG_VERBOSE 2 #define IJK_LOG_DEBUG 3 #define IJK_LOG_INFO 4 #define IJK_LOG_WARN 5 #define IJK_LOG_ERROR 6 #define IJK_LOG_FATAL 7 #define IJK_LOG_SILENT 8 #define VLOG(level, TAG, ...) ((void)vprintf(__VA_ARGS__)) #define ALOG(level, TAG, ...) ((void)printf(__VA_ARGS__)) #endif #define IJK_LOG_TAG "IJKMEDIA" #define VLOGV(...) VLOG(IJK_LOG_VERBOSE, IJK_LOG_TAG, __VA_ARGS__) #define VLOGD(...) VLOG(IJK_LOG_DEBUG, IJK_LOG_TAG, __VA_ARGS__) #define VLOGI(...) VLOG(IJK_LOG_INFO, IJK_LOG_TAG, __VA_ARGS__) #define VLOGW(...) VLOG(IJK_LOG_WARN, IJK_LOG_TAG, __VA_ARGS__) #define VLOGE(...) VLOG(IJK_LOG_ERROR, IJK_LOG_TAG, __VA_ARGS__) #define ALOGV(...) ALOG(IJK_LOG_VERBOSE, IJK_LOG_TAG, __VA_ARGS__) #define ALOGD(...) ALOG(IJK_LOG_DEBUG, IJK_LOG_TAG, __VA_ARGS__) #define ALOGI(...) ALOG(IJK_LOG_INFO, IJK_LOG_TAG, __VA_ARGS__) #define ALOGW(...) ALOG(IJK_LOG_WARN, IJK_LOG_TAG, __VA_ARGS__) #define ALOGE(...) ALOG(IJK_LOG_ERROR, IJK_LOG_TAG, __VA_ARGS__) #define LOG_ALWAYS_FATAL(...) do { ALOGE(__VA_ARGS__); exit(1); } while (0) #endif
不同条件下日志函数的宏封装
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_inc_internal.h
#ifndef IJKPLAYER__IJKSDL_INC_INTERNAL_H #define IJKPLAYER__IJKSDL_INC_INTERNAL_H #include <stdint.h> #include "ijksdl_log.h" #include "ijksdl_misc.h" #include "ijksdl_stdinc.h" #define SDLTRACE ALOGD #endif
包含SDL库内部要用到的一些头文件
H:\code\ijkplayer-android\ijkmedia\ijksdl\ijksdl_gles2.h
#ifndef IJKSDL__IJKSDL_GLES2_H #define IJKSDL__IJKSDL_GLES2_H #ifdef __APPLE__ #include <OpenGLES/ES2/gl.h> #include <OpenGLES/ES2/glext.h> #else #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> #include <GLES2/gl2platform.h> #endif typedef struct SDL_VoutOverlay SDL_VoutOverlay; /* * Common */ #ifdef DEBUG #define IJK_GLES2_checkError_TRACE(op) #define IJK_GLES2_checkError_DEBUG(op) #else #define IJK_GLES2_checkError_TRACE(op) IJK_GLES2_checkError(op) #define IJK_GLES2_checkError_DEBUG(op) IJK_GLES2_checkError(op) #endif void IJK_GLES2_printString(const char *name, GLenum s); void IJK_GLES2_checkError(const char *op); GLuint IJK_GLES2_loadShader(GLenum shader_type, const char *shader_source); /* * Renderer */ #define IJK_GLES2_MAX_PLANE 3 typedef struct IJK_GLES2_Renderer IJK_GLES2_Renderer; IJK_GLES2_Renderer *IJK_GLES2_Renderer_create(SDL_VoutOverlay *overlay); void IJK_GLES2_Renderer_reset(IJK_GLES2_Renderer *renderer); void IJK_GLES2_Renderer_free(IJK_GLES2_Renderer *renderer); void IJK_GLES2_Renderer_freeP(IJK_GLES2_Renderer **renderer); GLboolean IJK_GLES2_Renderer_setupGLES(); GLboolean IJK_GLES2_Renderer_isValid(IJK_GLES2_Renderer *renderer); GLboolean IJK_GLES2_Renderer_isFormat(IJK_GLES2_Renderer *renderer, int format); GLboolean IJK_GLES2_Renderer_use(IJK_GLES2_Renderer *renderer); GLboolean IJK_GLES2_Renderer_renderOverlay(IJK_GLES2_Renderer *renderer, SDL_VoutOverlay *overlay); #define IJK_GLES2_GRAVITY_RESIZE (0) // Stretch to fill view bounds. #define IJK_GLES2_GRAVITY_RESIZE_ASPECT (1) // Preserve aspect ratio; fit within view bounds. #define IJK_GLES2_GRAVITY_RESIZE_ASPECT_FILL (2) // Preserve aspect ratio; fill view bounds. GLboolean IJK_GLES2_Renderer_setGravity(IJK_GLES2_Renderer *renderer, int gravity, GLsizei view_width, GLsizei view_height); #endif
1. 声明 SDL_VoutOverlay结构
2. IJK_GLES2_printString(const char *name, GLenum s)
输出 name 对应的值s
void IJK_GLES2_checkError(const char* op) { for (GLint error = glGetError(); error; error = glGetError()) { ALOGE("[GLES2] after %s() glError (0x%x)\n", op, error); } } void IJK_GLES2_printString(const char *name, GLenum s) { const char *v = (const char *) glGetString(s); ALOGI("[GLES2] %s = %s\n", name, v); }
3. IJK_GLES2_checkError(const char* op)
输出op后的错误值
4. IJK_GLES2_Renderer结构相关函数的声明
GLES2相关的文件都在gles2目录下.