开发者

Determine opencore or stagefright framework for mediaplayer?

开发者 https://www.devze.com 2023-02-01 21:57 出处:网络
I need to determine if a mediaplayer is using the opencore media framework, so that I can disable seeking for my streams. The opencore framework appears to fail silently with seeking, which I am havin

I need to determine if a mediaplayer is using the opencore media framework, so that I can disable seeking for my streams. The opencore framework appears to fail silently with seeking, which I am having a har开发者_JAVA技巧d time believing they allowed into production, but that seems the case nonetheless.

I wish it were as simple as determining their SDK version, but droid phones that have api 8 seem to use opencore still, so doesn't seem to be a good option. Any ideas?

EDIT:

After the response from Jesus, I came up with this code. It seems to work well in my tests so far. If anybody doesn't think it is a sound method for seeking streams, let me know

    if (Build.VERSION.SDK_INT < 8) //2.1 or earlier, opencore only, no stream seeking
        mStreamSeekable = false;
    else { // 2.2, check to see if stagefright enabled
        mStreamSeekable = false;
        try {
                FileInputStream buildIs = new FileInputStream(new File("/system/build.prop"));
                if (CloudUtils.inputStreamToString(buildIs).contains("media.stagefright.enable-player=true"))
                    mStreamSeekable = true;
            } catch (IOException e) { //problem finding build file
                e.printStackTrace();
            }
        }
    } 


That method does not work on the Samsung Galaxy S, which says Stagefright is enabled but does not use it, at least not for streaming. A more secure check is to open a local socket and connect the MediaPlayer to it and see what it reports as User-Agent.

For instance, this is what I see on my Samsung Galaxy S and the 2.2 Emulator;

Galaxy S: User-Agent: CORE/6.506.4.1 OpenCORE/2.02 (Linux;Android 2.2)

Emulator: User-Agent: stagefright/1.0 (Linux;Android 2.2)

In one thread, do something like this;

    volatile int socketPort;

    ServerSocket serverSocket = new ServerSocket(0);
    socketPort = serverSocket.getLocalPort();

    Socket socket = serverSocket.accept();

    InputStream is = socket.getInputStream();

    byte [] temp = new byte [2048];     
    int bsize = -1;
    while(bsize <= 0) {
        bsize = is.read(temp);
    }
    String res = new String(temp, 0, bsize);

    if(res.indexOf("User-Agent: stagefright") >= 0) {
        // Found stagefright
    }

    socket.close();
    serverSocket.close();

And like this in another thread (makes the blocking accept() call above return);

    MediaPlayer mp = new MediaPlayer();
    mp.setDataSource(String.format("http://127.0.0.1:%d/", socketPort));
    mp.prepare();
    mp.start();


With Android 2.3.5, now the media.stagefright.enable-player property does not exist in /system/build.prop


You might be able to detect if stagefright is enabled for streaming by searching for

media.stagefright.enable-http=true

instead of

media.stagefright.enable-player=true


To get that information you can read the file /system/build.prop of your device. In this file there is a parameter named media.stagefright.enable-player. If that parameter is set to true, then stagefright is active, otherwise your device is using opencore.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号