How to access own libmediaplayerservice library from libmedia_jni in Android Gingerbread
Asked Answered
B

2

6

By default android Gigerbread 2.3 use PV_Player(opencore library). I found one solution just it should be patched system build.prop file, but I don't want to patch system. I want to create my own library using android media frame work which will use StageFright player. I know that libmediaplayerservice decides the player selection. Have a look at the media framework

I want to create library according to android framework -

  • libmedia_jni_own
  • libmedia_own
  • libmediaplayerservice_own

    But the problem is that libmedia doesn't directly interact with libmediaplayerservice library, it is not directly dependent with libmediaplayerservice library. So that it is unable to create stagefright player. Libmedia communicates with libmediaplayerservice library via Binder IPC mechanism. How can I patch the libmedia source library, so that it can access my libmediaplayerservice library and able to create StageFright player as well as all access of StageFright recorder etc instead of opencore library.

  • Bystander answered 13/5, 2012 at 7:48 Comment(0)
    Z
    1

    I don't think you can modify how media service work w/o patching the system. As media service and its libraries are on the system partition you don't really have any way to hijack the jni load. If you are running a none-AOSP rom (like stock Samsung, HTC, etc), you won't be able to just swap out the libs as the ones from stock rom contains lots of linkage to proprietary libs.

    Zosima answered 21/5, 2012 at 22:4 Comment(0)
    B
    1

    By looking at the android source code the Binder mechanism you are mentioning you should look at the method 'getMediaPlayerService()' and checkout how service manager handles media service. If you can patch this method and properly define your service you should be ok.

    IMediaDeathNotifier::getMediaPlayerService()
    {
        LOGV("getMediaPlayerService");
        Mutex::Autolock _l(sServiceLock);
        if (sMediaPlayerService.get() == 0) {
            sp<IServiceManager> sm = defaultServiceManager();
            sp<IBinder> binder;
            do {
                binder = sm->getService(String16("media.player"));
                if (binder != 0) {
                    break;
                 }
                 LOGW("Media player service not published, waiting...");
                 usleep(500000); // 0.5 s
            } while(true);
    
            if (sDeathNotifier == NULL) {
            sDeathNotifier = new DeathNotifier();
        }
        binder->linkToDeath(sDeathNotifier);
        sMediaPlayerService = interface_cast<IMediaPlayerService>(binder);
        }
        LOGE_IF(sMediaPlayerService == 0, "no media player service!?");
        return sMediaPlayerService;
    }
    

    The method in question is located in: frameworks/base/media/libmedia/IMediaDeathNotifier.cpp

    Also, the service is set by calling:

     void MediaPlayerService::instantiate() {
                 defaultServiceManager()->addService(
                 String16("media.player"), new MediaPlayerService());
     }
    

    which can be found at: /frameworks/base/media/libmediaplayerservice/MediaPlayerService.cpp

    Bannon answered 22/5, 2012 at 11:20 Comment(4)
    I alreay patched this code and tried to access it from libmedia. But it made crashes. And I tried to access StagefrightPlayer libmedia_jni, but it made crashes in setsurfaceview.Bystander
    You should have mentioned that in your post.Bannon
    I'm building the app on windows using cygwin. Can you tell me if I build the app on Linux platform the libraries will give same performance. Because in case of build so library size on windows is not same as so on linux platform.Bystander
    The build and corresponding compiled code depend from compiler to compiler. How will the code be optimized it is compiler dependent. So the performance will probably be different but it could be the same.Bannon

    © 2022 - 2024 — McMap. All rights reserved.