Skip to content

Commit

Permalink
Merge pull request bilibili#20 from befovy/feature/oes
Browse files Browse the repository at this point in the history
feat: add gles ose render for android mediacodec buffers
  • Loading branch information
befovy committed Apr 19, 2020
2 parents f6c863c + b1f924f commit d953d1b
Show file tree
Hide file tree
Showing 54 changed files with 1,408 additions and 85 deletions.
2 changes: 2 additions & 0 deletions android/ijkplayer/ijkplayer-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ dependencies {
implementation 'com.android.support:support-annotations:28.0.0'

implementation 'com.squareup:otto:1.3.8'
implementation 'com.github.anrwatchdog:anrwatchdog:1.4.0'


implementation project(':fijkplayer-full')
implementation project(':ijkplayer-exo')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".application.IjkApp"
android:theme="@style/AppTheme">
<activity
android:name="tv.danmaku.ijk.media.example.activities.FileExplorerActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.Image;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand All @@ -34,10 +36,14 @@
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TextView;

import tv.danmaku.ijk.media.player.IMediaPlayer;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import tv.danmaku.ijk.media.player.misc.ITrackInfo;
import tv.danmaku.ijk.media.example.R;
Expand All @@ -60,6 +66,9 @@ public class VideoActivity extends AppCompatActivity implements TracksFragment.I
private TableLayout mHudView;
private DrawerLayout mDrawerLayout;
private ViewGroup mRightDrawer;
private Button mBtnSnapShot;

private ImageView mImageView;

private Settings mSettings;
private boolean mBackPressed;
Expand Down Expand Up @@ -133,6 +142,16 @@ protected void onCreate(Bundle savedInstanceState) {

mDrawerLayout.setScrimColor(Color.TRANSPARENT);

mBtnSnapShot = findViewById(R.id.btn_snap_shot);
mBtnSnapShot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mVideoView.snapshot();
}
});

mImageView = findViewById(R.id.iv_snapshot);

// init player
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
Expand All @@ -150,6 +169,14 @@ else if (mVideoUri != null)
finish();
return;
}

mVideoView.setOnSnapShotListener(new IMediaPlayer.OnSnapShotListener() {
@Override
public void onSnapShot(IMediaPlayer mp, Bitmap bm, int width, int height) {
mImageView.setImageBitmap(bm);
}
});

mVideoView.start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 Befovy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package tv.danmaku.ijk.media.example.application;

import android.app.Application;
import android.os.StrictMode;

import com.github.anrwatchdog.ANRWatchDog;

import tv.danmaku.ijk.media.example.BuildConfig;

public class IjkApp extends Application {

@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
new ANRWatchDog().setIgnoreDebugger(true).start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public boolean getUsingMediaCodec() {
return mSharedPreferences.getBoolean(key, false);
}

public boolean getRenderAMCBufferUsingEGL() {
String key = mAppContext.getString(R.string.pref_key_amc_oes_render);
return mSharedPreferences.getBoolean(key, false);
}

public boolean getUsingMediaCodecAutoRotate() {
String key = mAppContext.getString(R.string.pref_key_using_media_codec_auto_rotate);
return mSharedPreferences.getBoolean(key, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
Expand All @@ -45,9 +46,10 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import tv.danmaku.ijk.media.example.R;
import tv.danmaku.ijk.media.example.application.Settings;
import tv.danmaku.ijk.media.example.services.MediaPlayerService;
import tv.danmaku.ijk.media.exo.IjkExoMediaPlayer;
import tv.danmaku.ijk.media.player.AndroidMediaPlayer;
import tv.danmaku.ijk.media.player.IMediaPlayer;
Expand All @@ -58,9 +60,6 @@
import tv.danmaku.ijk.media.player.misc.IMediaFormat;
import tv.danmaku.ijk.media.player.misc.ITrackInfo;
import tv.danmaku.ijk.media.player.misc.IjkMediaFormat;
import tv.danmaku.ijk.media.example.R;
import tv.danmaku.ijk.media.example.application.Settings;
import tv.danmaku.ijk.media.example.services.MediaPlayerService;

public class IjkVideoView extends FrameLayout implements MediaController.MediaPlayerControl {
private String TAG = "IjkVideoView";
Expand Down Expand Up @@ -100,6 +99,7 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
private int mCurrentBufferPercentage;
private IMediaPlayer.OnErrorListener mOnErrorListener;
private IMediaPlayer.OnInfoListener mOnInfoListener;
private IMediaPlayer.OnSnapShotListener mOnSnapShotListener;
private int mSeekWhenPrepared; // recording the seek position while preparing
private boolean mCanPause = true;
private boolean mCanSeekBack = true;
Expand Down Expand Up @@ -323,6 +323,7 @@ private void openVideo() {
// REMOVED: SubtitleController

// REMOVED: mAudioSession
mMediaPlayer.setOnSnapShotListener(mSnapShotListener);
mMediaPlayer.setOnPreparedListener(mPreparedListener);
mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
mMediaPlayer.setOnCompletionListener(mCompletionListener);
Expand Down Expand Up @@ -411,7 +412,8 @@ public void onVideoSizeChanged(IMediaPlayer mp, int width, int height, int sarNu
IMediaPlayer.OnPreparedListener mPreparedListener = new IMediaPlayer.OnPreparedListener() {
public void onPrepared(IMediaPlayer mp) {
mPrepareEndTime = System.currentTimeMillis();
mHudViewHolder.updateLoadCost(mPrepareEndTime - mPrepareStartTime);
if (mHudViewHolder != null)
mHudViewHolder.updateLoadCost(mPrepareEndTime - mPrepareStartTime);
mCurrentState = STATE_PREPARED;

// Get the capabilities of the player for this stream
Expand Down Expand Up @@ -464,6 +466,16 @@ public void onPrepared(IMediaPlayer mp) {
}
};

private IMediaPlayer.OnSnapShotListener mSnapShotListener =
new IMediaPlayer.OnSnapShotListener() {
@Override
public void onSnapShot(IMediaPlayer mp, Bitmap bm, int width, int height) {
if (mOnSnapShotListener != null) {
mOnSnapShotListener.onSnapShot(mp, bm, width, height);
}
}
};

private IMediaPlayer.OnCompletionListener mCompletionListener =
new IMediaPlayer.OnCompletionListener() {
public void onCompletion(IMediaPlayer mp) {
Expand Down Expand Up @@ -593,7 +605,8 @@ public void onBufferingUpdate(IMediaPlayer mp, int percent) {
@Override
public void onSeekComplete(IMediaPlayer mp) {
mSeekEndTime = System.currentTimeMillis();
mHudViewHolder.updateSeekCost(mSeekEndTime - mSeekStartTime);
if (mHudViewHolder != null)
mHudViewHolder.updateSeekCost(mSeekEndTime - mSeekStartTime);
}
};

Expand Down Expand Up @@ -648,6 +661,10 @@ public void setOnInfoListener(IMediaPlayer.OnInfoListener l) {
mOnInfoListener = l;
}

public void setOnSnapShotListener(IMediaPlayer.OnSnapShotListener l) {
mOnSnapShotListener = l;
}

// REMOVED: mSHCallback
private void bindSurfaceHolder(IMediaPlayer mp, IRenderView.ISurfaceHolder holder) {
if (mp == null)
Expand Down Expand Up @@ -807,6 +824,12 @@ public void start() {
mTargetState = STATE_PLAYING;
}

public void snapshot() {
if (isInPlaybackState()) {
mMediaPlayer.snapShot();
}
}

@Override
public void pause() {
if (isInPlaybackState()) {
Expand Down Expand Up @@ -1037,6 +1060,8 @@ public IMediaPlayer createPlayer(int playerType) {
ijkMediaPlayer = new IjkMediaPlayer();
ijkMediaPlayer.native_setLogLevel(IjkMediaPlayer.IJK_LOG_DEBUG);

if (mSettings.getRenderAMCBufferUsingEGL())
ijkMediaPlayer.setAmcGlesRender();
if (mSettings.getUsingMediaCodec()) {
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
if (mSettings.getUsingMediaCodecAutoRotate()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"></tv.danmaku.ijk.media.example.widget.media.IjkVideoView>
android:layout_gravity="center"/>

<TextView
android:id="@+id/toast_text_view"
Expand Down Expand Up @@ -46,6 +46,20 @@
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
tools:context=".toolbar_widget" />

<Button
android:id="@+id/btn_snap_shot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:text="@string/snap_shot" />

<ImageView
android:id="@+id/iv_snapshot"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_gravity="start|bottom"/>

</FrameLayout>

<!-- The navigation drawer -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string name="seek_load_cost">seek_load_cost</string>
<string name="tcp_speed">tcp_speed</string>
<string name="bit_rate">bit_rate</string>
<string name="snap_shot">Snapshot</string>

<string name="media_information">Media Information</string>
<string name="mi_player">Player</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<string name="pref_key_using_android_player">pref.using_android_player</string>
<string name="pref_title_using_android_player">Using system player</string>
<string name="pref_summary_using_android_player"></string>
<string name="pref_summary_using_android_player"/>

<string name="pref_key_player">pref.player</string>
<string name="pref_title_player">Choose Player</string>
Expand Down Expand Up @@ -37,15 +37,15 @@

<string name="pref_key_using_media_codec">pref.using_media_codec</string>
<string name="pref_title_using_media_codec">Using MediaCodec</string>
<string name="pref_summary_using_media_codec"></string>
<string name="pref_summary_using_media_codec"/>

<string name="pref_key_using_media_codec_auto_rotate">pref.using_media_codec_auto_rotate</string>
<string name="pref_title_using_media_codec_auto_rotate">Using MediaCodec auto rotate</string>
<string name="pref_summary_using_media_codec_auto_rotate"></string>
<string name="pref_summary_using_media_codec_auto_rotate"/>

<string name="pref_key_media_codec_handle_resolution_change">pref.media_codec_handle_resolution_change</string>
<string name="pref_title_media_codec_handle_resolution_change">MediaCodec handle resolution change</string>
<string name="pref_summary_media_codec_handle_resolution_change"></string>
<string name="pref_summary_media_codec_handle_resolution_change"/>

<string name="pref_key_pixel_format">pref.pixel_format</string>
<string name="pref_title_pixel_format">Pixel Format</string>
Expand Down Expand Up @@ -79,32 +79,36 @@

<string name="pref_key_using_opensl_es">pref.using_opensl_es</string>
<string name="pref_title_using_opensl_es">Using OpenSL ES</string>
<string name="pref_summary_using_opensl_es"></string>
<string name="pref_summary_using_opensl_es"/>


<string name="pref_key_amc_oes_render">pref.amc_oes_renderer</string>
<string name="pref_title_amc_oes_render">Render AMC Buffer using EGL</string>
<string name="pref_summary_amc_oes_render"/>
<!-- -->
<string name="pref_title_render_view">RenderView</string>

<string name="pref_key_enable_no_view">pref.enable_no_view</string>
<string name="pref_title_enable_no_view">Enable NoView</string>
<string name="pref_summary_enable_no_view"></string>
<string name="pref_summary_enable_no_view"/>

<string name="pref_key_enable_surface_view">pref.enable_surface_view</string>
<string name="pref_title_enable_surface_view">Enable SurfaceView</string>
<string name="pref_summary_enable_surface_view"></string>
<string name="pref_summary_enable_surface_view"/>

<string name="pref_key_enable_texture_view">pref.enable_texture_view</string>
<string name="pref_title_enable_texture_view">Enable TextureView</string>
<string name="pref_summary_enable_texture_view"></string>
<string name="pref_summary_enable_texture_view"/>

<string name="pref_key_enable_detached_surface_texture">pref.enable_detached_surface_texture</string>
<string name="pref_title_enable_detached_surface_texture">Enable detached SurfaceTexture</string>
<string name="pref_summary_enable_detached_surface_texture"></string>
<string name="pref_summary_enable_detached_surface_texture"/>

<!-- -->
<string name="pref_title_misc">Misc</string>
<string name="pref_key_using_mediadatasource">pref.using_mediadatasource</string>
<string name="pref_title_using_mediadatasource">Using MediaDataSource</string>
<string name="pref_summary_using_mediadatasource"></string>
<string name="pref_summary_using_mediadatasource"/>

<!-- -->
<string name="pref_key_last_directory"></string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
android:persistent="true"
android:summary="@string/pref_summary_media_codec_handle_resolution_change"
android:title="@string/pref_title_media_codec_handle_resolution_change" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key_amc_oes_render"
android:persistent="true"
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public void setDataSource(Context context, Uri uri) {
mRendererBuilder = getRendererBuilder();
}

@Override
public void snapShot(){
notifyOnError(MEDIA_ERROR_SNAP_SHOT, MEDIA_ERROR_UNSUPPORTED);
}

@Override
public void setDataSource(Context context, Uri uri, Map<String, String> headers) {
// TODO: handle headers
Expand Down

0 comments on commit d953d1b

Please sign in to comment.