Access Android's native code of MediaPlayer and MediaPlayerService

1,323 views
Skip to first unread message

purvi

unread,
Dec 14, 2009, 9:44:41 AM12/14/09
to android-ndk
Hi,

I want to access native code of android for MediaPlayer where I can
access to the decode funtion of MediaPlayer and MediaPlayerService.
How can I achieve this?
I tried to clone the media tree for it using git. But I wasnot able to
clone it.
Can anyone please help to access the native code / libraries of
android?

Thanks.
Regards,
Purvi

Sean Hodges

unread,
Dec 14, 2009, 12:19:00 PM12/14/09
to andro...@googlegroups.com
What is the problem you're having? It's a little difficult to help
when the description is "I can't do it". Have you read the
instructions on how to use repo to check out the code
(http://source.android.com/download/using-repo)? Are you getting a
specific error message?

If you only want to view the code, you could just use gitweb, I guess
the decode function you are looking for is at the bottom of
mediaplayer.cpp:

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=media/libmedia/mediaplayer.cpp;h=24e3e6f23432a15194ee3206bbf4a96aa596e7dd;hb=cf4550c3198d6b3d92cdc52707fe70d7cc0caa9f

purvi

unread,
Dec 14, 2009, 1:45:25 PM12/14/09
to android-ndk
Hi,

I am getting the below error when I clone the media/libmedia tree
Error: "fatal: The remote end hung up unexpectedly"

By looking at the .cpp code I was not able to make out how can I have
the access to the decode function. That is the reason I want to get
hold of the native libraries of libmedia or libmedia.so so that I can
use it along with my native code.

Yes I have gone through the documentation for git as well as repo.
I am new to the android native development so I am sorry for my
ignorance but can anyone please tell me if there is any other way to
get the android native libraried except by using git/repo?

Thanks.
Regards,
Purvi

On Dec 14, 12:19 pm, Sean Hodges <seanhodge...@googlemail.com> wrote:
> On Mon, Dec 14, 2009 at 2:44 PM, purvi <purvi.n...@gmail.com> wrote:
> > Hi,
>
> > I want to access native code of android for MediaPlayer where I can
> > access to the decode funtion of MediaPlayer and MediaPlayerService.
> > How can I achieve this?
> > I tried to clone the media tree for it using git. But I wasnot able to
> > clone it.
> > Can anyone please help to access the native code / libraries of
> > android?
>
> What is the problem you're having? It's a little difficult to help
> when the description is "I can't do it". Have you read the
> instructions on how to use repo to check out the code
> (http://source.android.com/download/using-repo)?Are you getting a
> specific error message?
>
> If you only want to view the code, you could just use gitweb, I guess
> the decode function you are looking for is at the bottom of
> mediaplayer.cpp:
>
> http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;...

Sean Hodges

unread,
Dec 15, 2009, 4:39:02 PM12/15/09
to andro...@googlegroups.com
Hello purvi,

A fast-track approach would be to just check out the tree you want directly:

git clone http://android.git.kernel.org/platform/frameworks/base.git

This will provide you with just a read-only checkout of the base code
(including the media player source code you are interested in).

If you want to get the pre-compiled binaries for those libraries (and avoid
compiling/linking them yourself) I'm not so sure on the procedure but you
could probably rip the libraries from one of the ADP builds:

http://developer.htc.com/adp.html
> --
>
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group. To post to this group, send email to
> andro...@googlegroups.com. To unsubscribe from this group, send email
> to android-ndk...@googlegroups.com. For more options, visit this
> group at http://groups.google.com/group/android-ndk?hl=en.
>

purvi

unread,
Dec 15, 2009, 6:04:29 PM12/15/09
to android-ndk
Hi Sean,

Thank you for the help.
I am using the same command as you mentioned to clone the tree. I
reinstalled the git and run it again but this time its a new error

fatal : bad config file line 19 in c/git-1.6.5.6/framework/base/.git/
config

I looked into /base/.git/folder its empty, there is no config file.
yes there is one .git folder into git-1.6.5.6 that have config file in
it. even I didnt find any solution to this in the forums I surfed
(Sorry if I didnt searched enough).

Is anyone who faced the same problem and able to get the solution?

@ ripping the libraries from one of the ADP builds: I went thru the
documentation. I dont think it 'll be a feasible solution for me.

The Android NDK also mentions that the future releases hope to support
linking with audio libraries as it currently have with libraries for
OpenGL ES.

On Dec 15, 4:39 pm, Sean Hodges <seanhodge...@googlemail.com> wrote:
> Hello purvi,
>
> A fast-track approach would be to just check out the tree you want directly:
>
> git clonehttp://android.git.kernel.org/platform/frameworks/base.git
> > > (http://source.android.com/download/using-repo)?Areyou getting a
> > > specific error message?
>
> > > If you only want to view the code, you could just use gitweb, I guess
> > > the decode function you are looking for is at the bottom of
> > > mediaplayer.cpp:
>
> > >http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;...
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> >  "android-ndk" group. To post to this group, send email to
> >  andro...@googlegroups.com. To unsubscribe from this group, send email
> >  to android-ndk...@googlegroups.com. For more options, visit this
> >  group athttp://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -
>
> - Show quoted text -

Sean Hodges

unread,
Dec 16, 2009, 5:40:30 AM12/16/09
to andro...@googlegroups.com
On Tue, Dec 15, 2009 at 11:04 PM, purvi <purvi...@gmail.com> wrote:
> Hi Sean,
>
> Thank you for the help.
> I am using the same command as you mentioned to clone the tree. I
> reinstalled the git and run it again but this time its a new error
>
> fatal : bad config file line 19 in c/git-1.6.5.6/framework/base/.git/
> config
>
> I looked into /base/.git/folder its empty, there is no config file.
> yes there is one .git folder into git-1.6.5.6 that have config file in
> it. even I didnt find any solution to this in the forums I surfed
> (Sorry if I didnt searched enough).

What O/S are you using? I run that "git clone" command in Ubuntu and
it completes perfectly. The config file that is causing you problems
is in the directory that you installed Git, not the directory that you
are checking out to.

If you can find the file, take a look at line 19, if there is nothing
obviously wrong with it then post it up here and myself or someone
else should be able to look at it for you.

purvi

unread,
Dec 16, 2009, 9:45:22 AM12/16/09
to android-ndk
Thanks Sean.

I am using Windows - Cygwin.

I looked into the config file you mentioned. At line 19 I found the
below line

/usr/bin/uname -p = unknown

I am sorry but I have no idea what this means and whats wrong at this
line.
Any help is appreciated.

Thanks.
Regards,
Purvi

On Dec 16, 5:40 am, Sean Hodges <seanhodge...@googlemail.com> wrote:
> >> > > (http://source.android.com/download/using-repo)?Areyougetting a
> >> > > specific error message?
>
> >> > > If you only want to view the code, you could just use gitweb, I guess
> >> > > the decode function you are looking for is at the bottom of
> >> > > mediaplayer.cpp:
>
> >> > >http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;...
>
> >> > --
>
> >> > You received this message because you are subscribed to the Google Groups
> >> >  "android-ndk" group. To post to this group, send email to
> >> >  andro...@googlegroups.com. To unsubscribe from this group, send email
> >> >  to android-ndk...@googlegroups.com. For more options, visit this
> >> >  group athttp://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -

Sean Hodges

unread,
Dec 16, 2009, 10:36:05 AM12/16/09
to andro...@googlegroups.com
I haven't personally used Git in Cygwin for a long time, but if you
are using msysgit, you should make sure you are using the "Git Bash"
shell (which comes pre-installed) instead of a DOS prompt.. I've seen
all sorts of funny things happen when people try to use the Git
commands outside of a Bash shell.

In case that doesn't help, I've taken the liberty of zipping up the
libmedia source files from my checkout and uploading them to my site.
You can download them from here:

http://seanhodges.co.uk/~sean/libmedia.zip

Obviously, this does not give you the entire Android platform code, so
you might have trouble compiling it, but you might still find it
useful.

purvi

unread,
Dec 16, 2009, 11:10:10 AM12/16/09
to android-ndk
Sean,
Thank you for the help and guidance. Finally I was able to clone the
platform/frameworks/base.git. And yes I got libraries as pre-compiled
ones. First I cloned the git's latest development version and then the
android native lib. And got it. I dont know what role does clonning
the git's latest development version played ('ll find it out once I
get sometime).

Now my next step is to get this clone libraries get to my native code.

Again Thanks Sean for the help.

Regards,
Purvi
> >> >> >  group athttp://groups.google.com/group/android-ndk?hl=en.-Hidequoted text -

eugene

unread,
Jan 11, 2010, 11:54:48 PM1/11/10
to android-ndk
Hi Purvi et al,

actually I don't think you can build the android tree under cygwin (it
mentioned that somewhere in the documentation), so I didn't bother
trying.
I didn't just clone the platform/frameworks/base.git tree, I used
repo to get the entire android tree, and I built that using make.
(I followed the instructions on source.android.com/download)
NOTE - so you have to use Linux to build the source - I use VMWare
with Ubuntu 9.10. You must have lots of HDD space free before you run
make (>>10GB I recommend). I also had a few problems like the wrong
packages installed or not available (e.g. you need JDK1.5 NOT 1.6 to
build android). But I fixed things by using google to find out how to
do it (I am not a Linux person).
After it finished building, all the .so libraries are available buried
in the 'out' directory.

I then copied the libmedia.so into
\android-ndk-1.6_r1\build\prebuilt\windows\arm-eabi-4.2.1\arm-eabi\lib
on my Windows box where I am doing the NDK development (using cygwin
to build the JNI part, as per the NDK documentation).
Btw I just guessed to put the library file here (it worked when I did
it). I'm not sure if this is correct.

I added LOCAL_LDLIBS := -lmedia
to the hello-jni sample and wrote some code to make calls to a media
player object (note you need to use extern "C" calling convention
if you are in a cpp file). You will also need to add local include
paths (using LOCAL_C_INCLUDES ) so you can access the media header
files.

Using LOCAL_STATIC_LIBRARIES didn't work because it seems that it
expects the make system to be able to build the required .so files,
but in my case I have already built the libraries previously.

The problem I have is that I wanted to be able to access OpenCore
functionality from native code.
So I copied libopencore_player.so as per above. But when I add -
lopencore_player to the LOCAL_LDLIBS line in my makefile, and
built it and run it, my application crashes on the call to
System.loadLibrary with my JNI library (i.e. System.loadLibrary("hello-
jni"); )

It's strange that I can load my version of libmedia.so, but it crashes
when I load my build of libopencore_player.so.
I'm not sure if it's possible there is some sort of 'clash' or
something happening.

If anyone who has already done this and/or knows what the problem
might be, please let me know :)

Best regards
Eugene

> > >> >> (including themediaplayer source code you are interested in).


>
> > >> >> If you want to get the pre-compiled binaries for those libraries (and avoid
> > >> >> compiling/linking them yourself) I'm not so sure on the procedure but you
> > >> >> could probably rip the libraries from one of the ADP builds:
>
> > >> >>http://developer.htc.com/adp.html
>
> > >> >> On Monday 14 Dec 2009 18:45:25 purvi wrote:
>
> > >> >> > Hi,
>

> > >> >> > I am getting the below error when I clone themedia/libmedia tree


> > >> >> > Error: "fatal: The remote end hung up unexpectedly"
>
> > >> >> > By looking at the .cpp code I was not able to make out how can I have
> > >> >> > the access to the decode function. That is the reason I want to get
> > >> >> > hold of the native libraries of libmedia or libmedia.so so that I can
> > >> >> > use it along with my native code.
>
> > >> >> > Yes I have gone through the documentation for git as well as repo.
> > >> >> > I am new to the android native development so I am sorry for my
> > >> >> > ignorance but can anyone please tell me if there is any other way to
> > >> >> > get the android native libraried except by using git/repo?
>
> > >> >> > Thanks.
> > >> >> > Regards,
> > >> >> > Purvi
>
> > >> >> > On Dec 14, 12:19 pm, Sean Hodges <seanhodge...@googlemail.com> wrote:
> > >> >> > > On Mon, Dec 14, 2009 at 2:44 PM, purvi <purvi.n...@gmail.com> wrote:
> > >> >> > > > Hi,
>
> > >> >> > > > I want to access native code of android for MediaPlayer where I can
> > >> >> > > > access to the decode funtion of MediaPlayer and MediaPlayerService.
> > >> >> > > > How can I achieve this?

> > >> >> > > > I tried to clone themediatree for it using git. But I wasnot able to


> > >> >> > > > clone it.
> > >> >> > > > Can anyone please help to access the native code / libraries of
> > >> >> > > > android?
>
> > >> >> > > What is the problem you're having? It's a little difficult to help
> > >> >> > > when the description is "I can't do it". Have you read the
> > >> >> > > instructions on how to use repo to check out the code
> > >> >> > > (http://source.android.com/download/using-repo)?Areyougettinga
> > >> >> > > specific error message?
>
> > >> >> > > If you only want to view the code, you could just use gitweb, I guess
> > >> >> > > the decode function you are looking for is at the bottom of
> > >> >> > > mediaplayer.cpp:
>
> > >> >> > >http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;...
>
> > >> >> > --
>
> > >> >> > You received this message because you are subscribed to the Google Groups
> > >> >> >  "android-ndk" group. To post to this group, send email to
> > >> >> >  andro...@googlegroups.com. To unsubscribe from this group, send email
> > >> >> >  to android-ndk...@googlegroups.com. For more options, visit this

> > >> >> >  group athttp://groups.google.com/group/android-ndk?hl=en.-Hidequotedtext -

David Turner

unread,
Jan 12, 2010, 7:41:31 AM1/12/10
to andro...@googlegroups.com
Hello Eugune,

No, it's not very surprising that you're experimenting a clash. What you're doing
is not a good idea since things like libmedia.so or libopencore_player.so are
not part of the stable ABI exposed by the NDK.

And I guarantee you that the media framework is under *very* heavy
modifications in Android, you should not try to meddle with its non-public
parts, or else your code will break in the future after the next OTA, or
something like that.

eugene

unread,
Jan 13, 2010, 1:14:02 AM1/13/10
to android-ndk
Hi David, thanks for your reply.

I was intending on building the necessary components of OpenCore and
the media library from source code into my own library to call from my
native code, so that I was relying on those rather than the libraries
within android itself.
Would this not offer some level of stability or 'independence' from
whatever ABI changes are made in the NDK?

Please feel free to set me straight here ;) but I was imagining that
building the opencore_player + necessary dependencies as a static
library, and among several others, linking them all into my own native
library, would give some access to audio/video functionality whilst we
wait for the NDK to be updated to allow easier access to this
functionality.
The reasoning being that we need to demo some audio/video processing
on android now, but once a properly accessible API is available, we
can switch to that.

Kind regards
Eugene


On Jan 12, 11:41 pm, David Turner <di...@android.com> wrote:
> Hello Eugune,
>
> No, it's not very surprising that you're experimenting a clash. What you're
> doing
> is not a good idea since things like libmedia.so or libopencore_player.so
> are
> not part of the stable ABI exposed by the NDK.
>
> And I guarantee you that the media framework is under *very* heavy
> modifications in Android, you should not try to meddle with its non-public
> parts, or else your code will break in the future after the next OTA, or
> something like that.
>

> > > >http://seanhodges.co.uk/~sean/libmedia.zip<http://seanhodges.co.uk/%7Esean/libmedia.zip>

> >http://source.android.com/download/using-repo)?Areyougettinga<http://source.android.com/download/using-repo%29?Areyougettinga>


> > > > >> >> > > specific error message?
>
> > > > >> >> > > If you only want to view the code, you could just use gitweb,
> > I guess
> > > > >> >> > > the decode function you are looking for is at the bottom of
> > > > >> >> > > mediaplayer.cpp:
>
> >http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;...
>
> > > > >> >> > --
>
> > > > >> >> > You received this message because you are subscribed to the
> > Google Groups
> > > > >> >> >  "android-ndk" group. To post to this group, send email to
> > > > >> >> >  andro...@googlegroups.com. To unsubscribe from this group,
> > send email
> > > > >> >> >  to
>

> ...
>
> read more »

Reply all
Reply to author
Forward
0 new messages