2

Does the native code of the VideoView give access to the received packets of the video before or after decoding it? I need to access these packets in order to transmit them to another device. The initial solution is to modify the Android native code. Other possible solutions that I found are to use GStreamer or FFmpeg libraries. I need bit guidance in order to achieve that goal.

Assume the phone is rooted.

Ziad Halabi
  • 964
  • 11
  • 31

1 Answers1

2

Short answer is no, not that I know of.

Long answer is that you haven't given enough detail. What data exactly do you need access to? Are you writing an application, or modifying your OS to do this to other applications?

The code that actually fetches a remote video is in MediaPlayer and is native. See the following method in MediaPlayer:

private void setDataSource(/* snip */) throws /* snip */ {
    /* snip */
    else if (scheme != null) {
        // handle non-file sources
        nativeSetDataSource(
            MediaHTTPService.createHttpServiceBinderIfNecessary(path),
            path,
            keys,
            values);
        return;
    }
    /* snip */

Unfortunately for you, almost all of the relevant MediaPlayer code is native, and if not, it is private (so subclassing will not work here).

However, depending on what you need to do, you could possibly override VideoView method setVideoURI(Uri, Map<String, String>), which is public. Here you can grab the URI and then proxy it through your own web service, or something. This isn't quite what you were asking, though.

Or, you could possibly look into modifying the Surface that is drawn to by MediaPlayer. Most of the relevant code is still native though.

The final possibility that I'll mention (there are probably hundreds of possible approaches) would be to modify the MediaHTTPService class. This appears to be used by MediaPlayer, but I can't be sure because if it's used, it's used in native code.

This answer recommends finding the native code at androidxref.com

Edit:

As requested, here is a little more detail about what the "proxy server" solution might look like. I don't know the implementation details on Android.

Basically, when you get a URL to play in the VideoView, you pass it to your own server instead. Something like startProxyServer(videoUrl). This starts a server, which downloads and then re-hosts the video. To get this working locally, start a webserver listening on localhost. The server just downloads the video at videoUrl, saves it locally, and then hosts it at localhost:port/?video=${videoUrl}.

So in very high-level pseudo-code the server could look like.

public void startProxyServer(String videoUrl) {
  int PORT = 28641; // random port
  File f = downloadFile(videoUrl);
  saveFile(f, '/path/to/server/storage');
  startWebServer('localhost', PORT);
}

So now you give localhost:port/?video=${videoUrl} as url to the videoView instead. Also, now other videoView instances can download from that same localhost url.

To make it work with other phones, your server of course couldn't run on localhost.
Of course I've not implemented this, but it's just one solution I can think of.

Community
  • 1
  • 1
William
  • 2,917
  • 5
  • 30
  • 47
  • What I am trying to do is the following: The App is streaming a video from the server and at the same time it is acting as a server that is streaming the same video to other clients. So I thought, I can modify the existing methods that stream a video on Android by adding some code to let the App forward the packets of the video while streaming it. This method requires the least amount of coding since the streaming and video displaying is already done. So forwarding the packet is the only thing left. Note: I have no problem with modifying the Native code or re-compiling the whole OS. – Ziad Halabi Mar 17 '15 at 19:47
  • Then you can check the [native code](http://androidxref.com/5.1.0_r1/xref/frameworks/av/media/libmedia/IMediaHTTPService.cpp) for `HTTPMediaService`. It might be easier to simply implement a proxy server to stream & buffer the file then serve it to multiple clients (including possibly localhost) – William Mar 17 '15 at 22:03
  • Can you please give more details about the proxy server solution? (There is a reward of 100 points of reputation for your answer) – Ziad Halabi Mar 22 '15 at 09:13
  • @ZiadHalabi I added some more high level details about how it might work simply. There are many additional layers of complexity to this (such as streaming the video download and then hosting that partially downloaded file). Sorry, but the exact details are beyond my knowledge :). Best of luck – William Mar 22 '15 at 17:25