我正在尝试使用FFMPEG(Fetching,decoding.etc)播放网络流并尝试使用SDL渲染它。
当我运行我的应用程序时,它正常启动,但是一旦我调用OpenFile()
,其中包含用于打开网络流并创建SDL_Window和SDL_Renderer的代码,但它在SDL_CreateWindow()
上给出了一个错误说:< / p>
Window not created: [Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?].
即使我已加入SDL_main.h
。
#include <SDL.h>
#include <SDL_main.h>
..... //other header files
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
SDL_Window *window;
SDL_Renderer *renderer;
int main(int argc, char *argv[])
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
{
LOGE("Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
return 0;
}
void Java_com_my_app_MainActivity_openFile(JNIEnv * env, jobject this, jstring url)
{
......
...... //FFMPEG code
//---------------------------SDL part -------------------------//
window = SDL_CreateWindow("Window", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 0, 0,
SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
if(window == NULL)
{
LOGE("Window not created: [%s]", SDL_GetError());
return;
}
LOGE("Window created");
renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
if(renderer == NULL)
{
LOGE("renderer not created: [%s]", SDL_GetError());
return;
}
LOGE("Rendering Created...");
}
此处的代码来自我尝试过的另一个项目(在this教程之后),其中我不在我的MainActivity
中我工作正常
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "SDL.h"
typedef struct Sprite
{
SDL_Texture* texture;
Uint16 w;
Uint16 h;
} Sprite;
Sprite LoadSprite(const char* file, SDL_Renderer* renderer)
{
Sprite result;
result.texture = NULL;
result.w = 0;
result.h = 0;
SDL_Surface* temp;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL)
{
fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
return result;
}
result.w = temp->w;
result.h = temp->h;
/* Create texture from the image */
result.texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!result.texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return result;
}
SDL_FreeSurface(temp);
return result;
}
void draw(SDL_Window* window, SDL_Renderer* renderer, const Sprite sprite)
{
int w, h;
SDL_GetWindowSize(window, &w, &h);
SDL_Rect destRect = {w/2 - sprite.w/2, h/2 - sprite.h/2, sprite.w, sprite.h};
/* Blit the sprite onto the screen */
SDL_RenderCopy(renderer, sprite.texture, NULL, &destRect);
}
int main(int argc, char *argv[])
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
{
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
SDL_Window *window;
SDL_Renderer *renderer;
if(SDL_CreateWindowAndRenderer(0, 0, 0, &window, &renderer) < 0)
exit(2);
Sprite sprite = LoadSprite("image.bmp", renderer);
if(sprite.texture == NULL)
exit(2);
/* Main render loop */
Uint8 done = 0;
SDL_Event event;
while(!done)
{
/* Check for events */
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT || event.type == SDL_KEYDOWN )//|| event.type == SDL_FINGERDOWN)
{
done = 1;
}
}
/* Draw a gray background */
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
draw(window, renderer, sprite);
/* Update the screen! */
SDL_RenderPresent(renderer);
SDL_Delay(10);
}
exit(0);
}
注意:我从这个精细的工作项目中创建了第一个项目(给出错误的项目)
我尝试使用#undef main删除SDL_main.h&#39;但它们都不起作用。现在它开始给我一个错误说'java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "SDL_main" referenced by "libmain.so"...
我的Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
SDL_PATH := ../SDL
MY_FILES_PATH := ../src
LOCAL_MODULE := main
# Add your application source files here...
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
$(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/src/*.c))
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -ljnigraphics -lGLESv1_CM -lGLESv2 -llog -lz -lm
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
LOCAL_SHARED_LIBRARIES := SDL2
LOCAL_SHARED_LIBRARIES += ffmpeg
include $(BUILD_SHARED_LIBRARY)
答案 0 :(得分:0)
不需要包含SDL_main.h,因为它包含在SDL.h中,我认为问题在于你的主函数。
我尝试了你的代码,在Visual Studio中编译得很好。
制作新项目并按照以下步骤http://www.willusher.io/sdl2%20tutorials/2013/08/15/lesson-0-setting-up-sdl/
执行