Skip to content

Commit

Permalink
Merge pull request #23 from befovy/feature/snapshot
Browse files Browse the repository at this point in the history
feat: add snapshot api
  • Loading branch information
befovy authored May 3, 2020
2 parents 41bc441 + a79c754 commit 3de55d9
Show file tree
Hide file tree
Showing 26 changed files with 214 additions and 45 deletions.
2 changes: 1 addition & 1 deletion android/ijkplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.2'

classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
Expand Down
1 change: 1 addition & 0 deletions android/ijkplayer/fijkplayer-full/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
.cxx/
.externalNativeBuild/
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
android:summary="@string/pref_summary_amc_oes_render"
android:title="@string/pref_title_amc_oes_render"/>
<tv.danmaku.ijk.media.example.widget.preference.IjkListPreference
android:defaultValue=""
android:entries="@array/pref_entries_pixel_format"
android:entryValues="@array/pref_entry_values_pixel_format"
android:key="@string/pref_key_pixel_format"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@ public void setDisplay(SurfaceHolder sh) {
} else {
surface = null;
}
if (mMediaCodecSurface == null && isAmcUsingGlesRender()) {
if (surface == null) {
if (mMediaCodecSurface != null) {
// mMediaCodecSurface.release();
mMediaCodecSurface = null;
}
} else if (mMediaCodecSurface == null && isAmcUsingGlesRender()) {
mMediaCodecSurface = new MediaCodecSurface();
_setMediaCodecSurface(mMediaCodecSurface);
}
Expand Down Expand Up @@ -348,7 +353,12 @@ public void setSurface(Surface surface) {
DebugLog.w(TAG,
"setScreenOnWhilePlaying(true) is ineffective for Surface");
}
if (mMediaCodecSurface == null && isAmcUsingGlesRender()) {
if (surface == null) {
if (mMediaCodecSurface != null) {
// mMediaCodecSurface.release();
mMediaCodecSurface = null;
}
} else if (mMediaCodecSurface == null && isAmcUsingGlesRender()) {
mMediaCodecSurface = new MediaCodecSurface();
_setMediaCodecSurface(mMediaCodecSurface);
}
Expand Down Expand Up @@ -1028,17 +1038,17 @@ public void setCacheShare(int share) {
public void setAmcGlesRender() {
_setPropertyLong(FFP_PROP_INT64_AMC_GLES_OES_VOUT, 1);
}

private boolean isAmcUsingGlesRender() {
return _getPropertyLong(FFP_PROP_INT64_AMC_GLES_OES_VOUT, 0) > 0;
}


private static class EventHandler extends Handler {
private final WeakReference<IjkMediaPlayer> mWeakPlayer;

public EventHandler(IjkMediaPlayer mp, Looper looper) {
super(looper);
mWeakPlayer = new WeakReference<IjkMediaPlayer>(mp);
mWeakPlayer = new WeakReference<>(mp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ public void detachFromGLContext() {
public void release() {
DebugLog.d("MediaCodecSurface", "release()," + mReleased);
mReleased = true;
mSurfaceTexture.detachFromGLContext();
mSurfaceTexture.release();
mSurfaceTexture = null;
mSurface.release();
mSurface = null;
//mSurfaceTexture.detachFromGLContext();
if (mSurfaceTexture != null) {
mSurfaceTexture.release();
mSurfaceTexture = null;
}
if (mSurface != null) {
mSurface.release();
mSurface = null;
}
}
}
6 changes: 3 additions & 3 deletions desktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ set(IJK_DESKTOP_UNI ON)
set(FIJKPLAYER_SOURCE
${CMAKE_CURRENT_LIST_DIR}/sources/ijkplayer_desktop.h
${CMAKE_CURRENT_LIST_DIR}/sources/ijkplayer_desktop.c
#${CMAKE_CURRENT_LIST_DIR}/glad/include/glad/glad.h
# ${CMAKE_CURRENT_LIST_DIR}/glad/include/glad/glad.h
${CMAKE_CURRENT_LIST_DIR}/glfw/deps/glad_gl.c
)

Expand All @@ -108,8 +108,8 @@ add_subdirectory(../ijkmedia ijkmedia)
target_include_directories(IjkPlayer PRIVATE ${IJKROOT_PATH}/ijkmedia)
target_include_directories(IjkPlayer PRIVATE ${IJK_FFMPAG_BUILD_DIR}/include)
target_include_directories(IjkPlayer PRIVATE "${IJK_DESKTOP_PTHREAD_BUILD_DIR}/../../include")
#target_include_directories(IjkPlayer PRIVATE glad/include)
target_include_directories(IjkPlayer PRIVATE glfw/deps)
target_include_directories(IjkPlayer PRIVATE glfw/include)

target_link_libraries(IjkPlayer ijksdl_static ijkplayer_static yuv)

Expand Down Expand Up @@ -198,7 +198,7 @@ add_subdirectory(glfw)
#target_link_libraries(IjkPlayer glfw)

add_executable(tuidemo WIN32 MACOSX_BUNDLE ${CMAKE_CURRENT_LIST_DIR}/sources/ijkplayer_demo.c)
# target_include_directories(tuidemo PRIVATE glad/include)
target_include_directories(tuidemo PRIVATE glad/include)
target_include_directories(tuidemo PRIVATE glfw/include)
target_include_directories(tuidemo PRIVATE glfw/deps)

Expand Down
2 changes: 1 addition & 1 deletion desktop/sources/ijkplayer_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) {
info.fp = fp;
ijkff_set_event_cb(fp, &info, demo_event_cb);

ijkff_set_option(fp, "fcc-i420", "overlay-format", IJK_OPT_CATEGORY_PLAYER);
ijkff_set_option(fp, "fcc-bgra", "overlay-format", IJK_OPT_CATEGORY_PLAYER);
ijkff_set_data_source(fp, "https://player.alicdn.com/video/aliyunmedia.mp4");

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_AUDIO);
Expand Down
4 changes: 4 additions & 0 deletions ijkmedia/ijkplayer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ else ()
set(IJKPLAYER_LIB_NAME ijkplayer)
endif ()

if (IJK_DESKTOP_UNI)
target_include_directories(${IJKPLAYER_LIB_NAME} PRIVATE ${IJKROOT_PATH}/desktop/glfw/deps)
target_include_directories(${IJKPLAYER_LIB_NAME} PRIVATE ${IJKROOT_PATH}/desktop/glfw/include)
endif ()
target_include_directories(${IJKPLAYER_LIB_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(${IJKPLAYER_LIB_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/..)
target_include_directories(${IJKPLAYER_LIB_NAME} PRIVATE ${IJK_FFMPAG_BUILD_DIR}/include)
Expand Down
9 changes: 7 additions & 2 deletions ijkmedia/ijkplayer/ff_ffplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -3823,15 +3823,20 @@ static int video_refresh_thread(void *arg)
double remaining_time = 0.0;
while (!is->abort_request) {
if (remaining_time > 0.0)
av_usleep((int)(int64_t)(remaining_time * 1000000.0));
av_usleep((uint)(uint64_t)(remaining_time * 1000000.0));
remaining_time = REFRESH_RATE;
if (ffp->cover_after_prepared && !ffp->first_video_frame_rendered) {
is->force_refresh = true;
}
if (is->paused) {
SDL_Delay(1000/24);
is->force_refresh = true;
}
if (is->show_mode != SHOW_MODE_NONE && (!is->paused || is->force_refresh))
video_refresh(ffp, &remaining_time);
}

if (ffp->vout)
SDL_VoutFreeContext(ffp->vout);
return 0;
}

Expand Down
9 changes: 6 additions & 3 deletions ijkmedia/ijkplayer/ff_ffplay_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ typedef struct Decoder {
int first_frame_decoded;
} Decoder;


typedef enum ShowMode {
SHOW_MODE_NONE = -1, SHOW_MODE_VIDEO = 0, SHOW_MODE_WAVES, SHOW_MODE_RDFT, SHOW_MODE_NB
} ShowMode;

typedef struct VideoState {
SDL_Thread *read_tid;
AVInputFormat *iformat;
Expand Down Expand Up @@ -336,9 +341,7 @@ typedef struct VideoState {
int frame_drops_late;
int continuous_frame_drops_early;

enum ShowMode {
SHOW_MODE_NONE = -1, SHOW_MODE_VIDEO = 0, SHOW_MODE_WAVES, SHOW_MODE_RDFT, SHOW_MODE_NB
} show_mode;
ShowMode show_mode;
int16_t sample_array[SAMPLE_ARRAY_SIZE];
int sample_array_index;
int last_i_start;
Expand Down
2 changes: 1 addition & 1 deletion ijkmedia/ijksdl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ if (IJK_DESKTOP_UNI)
cmake_print_variables(SDL2_INCLUDE_DIRS)

target_include_directories(ijksdl_static PRIVATE ${IJKROOT_PATH}/desktop/glfw/include)
# target_include_directories(ijksdl_static PRIVATE ${IJKROOT_PATH}/desktop/glad/include)
target_include_directories(ijksdl_static PRIVATE ${IJKROOT_PATH}/desktop/glad/include)
target_include_directories(ijksdl_static PRIVATE ${IJKROOT_PATH}/desktop/glfw/deps)
else ()
add_library(ijksdl SHARED ${IJK_SDL_SOURCES})
Expand Down
52 changes: 43 additions & 9 deletions ijkmedia/ijksdl/android/ijksdl_vout_android_nativewindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static void SDL_AMediaCodecBufferProxy_invalidate(SDL_AMediaCodecBufferProxy *pr
}

typedef struct SDL_Vout_Opaque {
ANativeWindow *new_window;
ANativeWindow *native_window;
SDL_AMediaCodec *acodec;
int null_native_window_warned; // reduce log for null window
Expand Down Expand Up @@ -113,6 +114,22 @@ static SDL_VoutOverlay *func_create_overlay(int width, int height, int frame_for
return overlay;
}

static void func_free_context_l(SDL_Vout *vout)
{
if (!vout)
return;

SDL_Vout_Opaque *opaque = vout->opaque;
if (opaque) {
IJK_EGL_freep(&opaque->egl);

if (opaque->native_window) {
ANativeWindow_release(opaque->native_window);
opaque->native_window = NULL;
}
}
}

static void func_free_l(SDL_Vout *vout)
{
if (!vout)
Expand All @@ -128,13 +145,6 @@ static void func_free_l(SDL_Vout *vout)
ISDL_Array__clear(&opaque->overlay_pool);
ISDL_Array__clear(&opaque->overlay_manager);

if (opaque->native_window) {
ANativeWindow_release(opaque->native_window);
opaque->native_window = NULL;
}

IJK_EGL_freep(&opaque->egl);

SDL_AMediaCodec_decreaseReferenceP(&opaque->acodec);
}

Expand All @@ -144,6 +154,16 @@ static void func_free_l(SDL_Vout *vout)
static int func_display_overlay_l(SDL_Vout *vout, SDL_VoutOverlay *overlay)
{
SDL_Vout_Opaque *opaque = vout->opaque;

if (opaque->new_window != NULL) {
if (opaque->native_window) {
ANativeWindow_release(opaque->native_window);
}
opaque->native_window = opaque->new_window;
opaque->new_window = NULL;
IJK_EGL_terminate(opaque->egl);
}

ANativeWindow *native_window = opaque->native_window;

if (!native_window) {
Expand Down Expand Up @@ -244,7 +264,7 @@ SDL_Vout *SDL_VoutAndroid_CreateForANativeWindow()
vout->free_l = func_free_l;
vout->display_overlay = func_display_overlay;
vout->get_renderer = func_get_renderer;

vout->free_context_l = func_free_context_l;
return vout;
fail:
func_free_l(vout);
Expand Down Expand Up @@ -283,8 +303,19 @@ static void SDL_VoutAndroid_SetNativeWindow_l(SDL_Vout *vout, ANativeWindow *nat
return;
}

if (vout->vout_type & SDL_VOUT_AMC_OES_EGL)
SDL_VoutAndroid_invalidateAllBuffers_l(vout);

if (opaque->new_window)
ANativeWindow_release(opaque->new_window);
if (native_window)
ANativeWindow_acquire(native_window);

opaque->new_window = native_window;
opaque->null_native_window_warned = 0;
/*
IJK_EGL_terminate(opaque->egl);
SDL_VoutAndroid_invalidateAllBuffers_l(vout);
if (opaque->native_window)
ANativeWindow_release(opaque->native_window);
Expand All @@ -294,6 +325,8 @@ static void SDL_VoutAndroid_SetNativeWindow_l(SDL_Vout *vout, ANativeWindow *nat
opaque->native_window = native_window;
opaque->null_native_window_warned = 0;
*/
}

void SDL_VoutAndroid_SetNativeWindow(SDL_Vout *vout, ANativeWindow *native_window)
Expand All @@ -319,6 +352,7 @@ void SDL_VoutAndroid_SetSurfaceTexture(SDL_Vout *vout, JNIEnv *env, jobject amc_
}
if (amc_surface)
opaque->egl->amc_surface = J4A_NewGlobalRef__catchAll(env, amc_surface);
opaque->egl->amc_surface_changed = 1;
SDL_UnlockMutex(vout->mutex);
}

Expand Down
44 changes: 37 additions & 7 deletions ijkmedia/ijksdl/desktop/ijksdl_vout_sdl2_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,33 @@ static int sdl2_display(SDL_Vout_Opaque *opaque, SDL_VoutOverlay *overlay) {

SDL_Renderer *renderer = opaque->renderer;

assert(overlay->format == SDL_FCC_I420);
int dest_sdl2_format = SDL_PIXELFORMAT_UNKNOWN;
bool is_yuv = false;
switch (overlay->format) {
case SDL_FCC_I420:
case SDL_FCC_IYUV:
dest_sdl2_format = SDL_PIXELFORMAT_IYUV;
is_yuv = true;
break;
case SDL_FCC_RV16:
dest_sdl2_format = SDL_PIXELFORMAT_RGB565;
break;
case SDL_FCC_RV24:
dest_sdl2_format = SDL_PIXELFORMAT_RGB888;
break;
case SDL_FCC_RV32:
dest_sdl2_format = SDL_PIXELFORMAT_BGRX8888;
break;
case SDL_FCC_BGRA:
dest_sdl2_format = SDL_PIXELFORMAT_BGRA32;
break;
case SDL_FCC_RGBA:
dest_sdl2_format = SDL_PIXELFORMAT_RGBA32;
break;
default:
break;
}
assert(dest_sdl2_format != SDL_PIXELFORMAT_UNKNOWN);

Uint32 format = 0;
int access = 0, w = 0, h = 0, ret = 0;
Expand All @@ -74,18 +100,22 @@ static int sdl2_display(SDL_Vout_Opaque *opaque, SDL_VoutOverlay *overlay) {
if (ret < 0 || format != opaque->format || w != overlay->w || h != overlay->h) {
if (opaque->texture)
SDL_DestroyTexture(opaque->texture);
opaque->texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, overlay->w,
opaque->texture = SDL_CreateTexture(renderer, dest_sdl2_format, SDL_TEXTUREACCESS_STREAMING, overlay->w,
overlay->h);
opaque->format = SDL_PIXELFORMAT_IYUV;
opaque->format = dest_sdl2_format;
}
if (opaque->texture == NULL) {
return -1;
}
SDL_Texture *texture = opaque->texture;
SDL_UpdateYUVTexture(texture, NULL,
overlay->pixels[0], overlay->pitches[0],
overlay->pixels[1], overlay->pitches[1],
overlay->pixels[2], overlay->pitches[2]);
if (is_yuv) {
SDL_UpdateYUVTexture(texture, NULL,
overlay->pixels[0], overlay->pitches[0],
overlay->pixels[1], overlay->pitches[1],
overlay->pixels[2], overlay->pitches[2]);
} else {
SDL_UpdateTexture(texture, NULL, overlay->pixels[0], overlay->pitches[0]);
}
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
return 0;
Expand Down
8 changes: 4 additions & 4 deletions ijkmedia/ijksdl/ffmpeg/ijksdl_vout_overlay_ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static int func_fill_frame(SDL_VoutOverlay *overlay, const AVFrame *frame)
}
break;
case SDL_FCC_RV32:
dst_format = AV_PIX_FMT_0BGR32;
dst_format = AV_PIX_FMT_0RGB;
break;
case SDL_FCC_RV24:
dst_format = AV_PIX_FMT_RGB24;
Expand All @@ -202,10 +202,10 @@ static int func_fill_frame(SDL_VoutOverlay *overlay, const AVFrame *frame)
dst_format = AV_PIX_FMT_RGB565;
break;
case SDL_FCC_BGRA:
dst_format = AV_PIX_FMT_BGR32_1;
dst_format = AV_PIX_FMT_BGRA;
break;
case SDL_FCC_RGBA:
dst_format = AV_PIX_FMT_RGB32_1;
dst_format = AV_PIX_FMT_RGBA;
break;
default:
ALOGE("SDL_VoutFFmpeg_ConvertPicture: unexpected overlay format %s(%d)",
Expand Down Expand Up @@ -393,7 +393,7 @@ SDL_VoutOverlay *SDL_VoutFFmpeg_CreateOverlay(int width, int height, int frame_f
break;
}
case SDL_FCC_RV32: {
ff_format = AV_PIX_FMT_0BGR32;
ff_format = AV_PIX_FMT_0RGB;
buf_width = IJKALIGN(width, 4); // 4 bytes per pixel
opaque->planes = 1;
break;
Expand Down
Loading

0 comments on commit 3de55d9

Please sign in to comment.