Question

I've got some trouble with the media backend (mostly Stagefrightplayer) in Android, and I'd like to understand why it throws the errors it does. The errors are usually device spesific, so debugging on an emulator wouldn't be sufficient.

Example:

I/AwesomePlayer(  147): mConnectingDataSource->connect() returned -1004
V/MediaPlayerService(  147): [332] notify (0x272830, 100, 1, -1004)
E/MediaPlayer(24881): error (1, -1004)
E/MediaPlayer(24881): Error (1,-1004)
W/PlayerListener(24881): Received error: what = 1, extra = -1004

Example 2:

E/MediaPlayer(  941): error (1, -2147483648)

I've also gotten the player to bork completely and spit out a traces.txt.

Is there a way to debug what's happening, just like I debug Java code? Thanks.

Was it helpful?

Solution

Quite a few things you can do.

If you believe the error is in the framework itself, then get the source and dig http://source.android.com/

Otherwise, the best debugger for Android is DDMS, it can work with the emulator, but also with the real device. http://developer.android.com/guide/developing/tools/ddms.html

dumpstate through adb (http://developer.android.com/guide/developing/tools/adb.html) will also give you a full snapshot of what is happening on the device, but it will difficult for you to get the exact point when the error happens.

Although that will still not give you source level debugging as GDB would (or I am not sure what you mean by your usual way of debugging Java code).

If you really mean kernel as kernel, then you are not really in Android anymore but more in Linux world but I don't think you need to go that far.

If you have trouble with a specific Android application (that's out of the open source and is not your own), I am afraid you are out of luck.

For the MediaPlayer part, the file for Eclair is located in https://android.googlesource.com/platform/frameworks/base/+/eclair-release/media/java/android/media/MediaPlayer.java, but cannot find the specific error message you put there.

OTHER TIPS

Not that this directly answers your question, but this information might be useful to you.

So based upon your -1004 error code, you had an I/O Error trying to stream. As far as the -2147483648 error code, can't help you much. You would have to look at all of the log output from the media player to see why you are getting that code since it isn't defined. I've seen it from having the decoder choke on the video encoding.

Borrowed from: /frameworks/base/include/media/stagefright/MediaErrors.h

MEDIA_ERROR_BASE = -1000,

ERROR_ALREADY_CONNECTED = MEDIA_ERROR_BASE,
ERROR_NOT_CONNECTED     = MEDIA_ERROR_BASE - 1,
ERROR_UNKNOWN_HOST      = MEDIA_ERROR_BASE - 2,
ERROR_CANNOT_CONNECT    = MEDIA_ERROR_BASE - 3,
ERROR_IO                = MEDIA_ERROR_BASE - 4,
ERROR_CONNECTION_LOST   = MEDIA_ERROR_BASE - 5,
ERROR_MALFORMED         = MEDIA_ERROR_BASE - 7,
ERROR_OUT_OF_RANGE      = MEDIA_ERROR_BASE - 8,
ERROR_BUFFER_TOO_SMALL  = MEDIA_ERROR_BASE - 9,
ERROR_UNSUPPORTED       = MEDIA_ERROR_BASE - 10,
ERROR_END_OF_STREAM     = MEDIA_ERROR_BASE - 11,

Remote debugging (gdbserver on target + gdb on host) can be used to step-through C/C++ userland code running on real hardware. It offers all 'usual' options like breakpoints, backtrace, view/set variables, tracepoints.

For details, look at 'gdbclient' shell function of Android build system, pre-build eabi gdb and maybe DDD or another frontend. Eclipse should be ok.

Even if you are not able to debug on kernel level, tracking down the cryptic error number to the correct header file (and descriptive define) can still be useful.

-1004 means ERROR_IO and can be found in MediaErrors.h:
https://android.googlesource.com/platform/frameworks/base/+/eclair-release/include/media/stagefright/MediaErrors.h#32

-2147483648 probably is UNKNOWN_ERROR which can be found in Errors.h:
https://android.googlesource.com/platform/frameworks/base/+/eclair-release/include/utils/Errors.h#49

As you can see in Errors.h, it includes errno.h which includes kernel level error codes, /kernel/include/asm-generic/errno.h.

For example, if connect() returns the error code -110 you will know it's because of a timeout since it's defined as:

#define ETIMEDOUT       110     /* Connection timed out */

Although Android does support remote GDB sessions, this probably will not work for Kernel Side Code. Your best bet is to use a JTAG connection which can be used to perform Stop Mode Debugging. Since stop mode debugging effectively halts the execution of your CPU, you might find this causes problems with Watchdog Timers.

Alternatively, inserting tracing into the kernel code may be easier.

You can do this in couple of different ways. First you need to find out the service you want to debug is in Java framework service like system_server or in pure native application like surfaceflinger.

If it is pure native service, please check Debugging android platform native applications article.

If the service is Java code hosted in system_server process, please check Debugging Android Java framework services article.

If the code you want to debug is native library loaded by Java service through JNI implicitly, please check Debugging Android framework native libraries article.

Unless you want to debug at the assembly level, you'll probably have to build a kernel yourself with debugging + debug symbols enabled. I would think most kernels in a small device would avoid doing that by default, since it makes the kernel a lot bigger. At that point you could enable the kernel debugger...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top