/
ijkplayer_android.c
127 lines (102 loc) · 3.81 KB
/
ijkplayer_android.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* ijkplayer_android.c
*
* Copyright (c) 2013 Bilibili
* Copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "ijkplayer_android.h"
#include <assert.h>
#include "ijksdl/android/ijksdl_android.h"
#include "../ff_fferror.h"
#include "../ff_ffplay.h"
#include "../ijkplayer_internal.h"
#include "../pipeline/ffpipeline_ffplay.h"
#include "pipeline/ffpipeline_android.h"
IjkMediaPlayer *ijkmp_android_create(int(*msg_loop)(void*))
{
IjkMediaPlayer *mp = ijkmp_create(msg_loop);
if (!mp)
goto fail;
mp->ffplayer->vout = SDL_VoutAndroid_CreateForAndroidSurface();
if (!mp->ffplayer->vout)
goto fail;
mp->ffplayer->pipeline = ffpipeline_create_from_android(mp->ffplayer);
if (!mp->ffplayer->pipeline)
goto fail;
ffpipeline_set_vout(mp->ffplayer->pipeline, mp->ffplayer->vout);
return mp;
fail:
ijkmp_dec_ref_p(&mp);
return NULL;
}
void ijkmp_android_set_surface_l(JNIEnv *env, IjkMediaPlayer *mp, jobject android_surface)
{
if (!mp || !mp->ffplayer || !mp->ffplayer->vout)
return;
SDL_VoutAndroid_SetAndroidSurface(env, mp->ffplayer->vout, android_surface);
ffpipeline_set_surface(env, mp->ffplayer->pipeline, android_surface);
}
void ijkmp_android_set_surface(JNIEnv *env, IjkMediaPlayer *mp, jobject android_surface)
{
if (!mp)
return;
MPTRACE("ijkmp_set_android_surface(surface=%p)", (void*)android_surface);
pthread_mutex_lock(&mp->mutex);
ijkmp_android_set_surface_l(env, mp, android_surface);
pthread_mutex_unlock(&mp->mutex);
MPTRACE("ijkmp_set_android_surface(surface=%p)=void", (void*)android_surface);
}
void ijkmp_android_set_volume(JNIEnv *env, IjkMediaPlayer *mp, float left, float right)
{
if (!mp)
return;
MPTRACE("ijkmp_android_set_volume(%f, %f)", left, right);
pthread_mutex_lock(&mp->mutex);
if (mp && mp->ffplayer && mp->ffplayer->pipeline) {
ffpipeline_set_volume(mp->ffplayer->pipeline, left, right);
}
pthread_mutex_unlock(&mp->mutex);
MPTRACE("ijkmp_android_set_volume(%f, %f)=void", left, right);
}
int ijkmp_android_get_audio_session_id(JNIEnv *env, IjkMediaPlayer *mp)
{
int audio_session_id = 0;
if (!mp)
return audio_session_id;
MPTRACE("%s()", __func__);
pthread_mutex_lock(&mp->mutex);
if (mp && mp->ffplayer && mp->ffplayer->aout) {
audio_session_id = SDL_AoutGetAudioSessionId(mp->ffplayer->aout);
}
pthread_mutex_unlock(&mp->mutex);
MPTRACE("%s()=%d", __func__, audio_session_id);
return audio_session_id;
}
void ijkmp_android_set_mediacodec_select_callback(IjkMediaPlayer *mp, bool (*callback)(void *opaque, ijkmp_mediacodecinfo_context *mcc), void *opaque)
{
if (!mp)
return;
MPTRACE("ijkmp_android_set_mediacodec_select_callback()");
pthread_mutex_lock(&mp->mutex);
if (mp && mp->ffplayer && mp->ffplayer->pipeline) {
ffpipeline_set_mediacodec_select_callback(mp->ffplayer->pipeline, callback, opaque);
}
pthread_mutex_unlock(&mp->mutex);
MPTRACE("ijkmp_android_set_mediacodec_select_callback()=void");
}