0

all... I want to try ffmpeg hw accelerate with libstagefright_h264 for android device. Seems that the source code has a little bit old with ffmpeg 2.2.1 and android 4.2.2. So I try to update the source code but when I only write just a little code like following:

struct FFSource : public MediaSource {                                                                                   
    virtual status_t start(MetaData *params) { return -1; }                      
    virtual status_t stop() { return -1; }                                        
    virtual sp<MetaData> getFormat() { return sp<MetaData>(); }                  
    virtual status_t read(                                                                                               
            MediaBuffer **buffer, const ReadOptions *options) { return -1; }     
};

static av_cold int Stagefright_init(AVCodecContext *avctx)                                                            
{                                                                                                                        
    av_log(avctx, AV_LOG_ERROR, "In function: %s\n", __FUNCTION__);                                                      
    FFSource *decoder;                                                                                                   
    sp<MediaSource> mediaSource;

    decoder = new FFSource();                                                        
    return -1;
}

it tells me like following when I run the code: cannot locate symbol "_ZTIN7android11MediaSourceE" referenced by "libavcodec-55.so"...

And the result show the nm command for libavcodec-55.so:

[cxm@ubuntu ffmpeg-2.2.1.lsc]$nm ./libavcodec/libavcodec.so  | grep Source

003a31a8 t _ZN7android11MediaSource10setBuffersERKNS_6VectorIPNS_11MediaBufferEEE
003a319c t _ZN7android11MediaSource5pauseEv
         U _ZN7android11MediaSourceC2Ev
         U _ZN7android11MediaSourceD0Ev
         U _ZN7android11MediaSourceD1Ev
         U _ZN7android11MediaSourceD2Ev
003a31d0 t _ZN8FFSource4readEPPN7android11MediaBufferEPKNS0_11MediaSource11ReadOptionsE
003a31bc t _ZN8FFSource4stopEv
003a31b4 t _ZN8FFSource5startEPN7android8MetaDataE
003a31c4 t _ZN8FFSource9getFormatEv
003a3340 t _ZN8FFSourceD0Ev
003a32e0 t _ZN8FFSourceD1Ev
007b29f0 d _ZTC8FFSource0_N7android11MediaSourceE
007b29e0 d _ZTI8FFSource
         U _ZTIN7android11MediaSourceE
006ac028 r _ZTS8FFSource
007b2970 d _ZTT8FFSource
         U _ZTv0_n12_N7android11MediaSourceD0Ev
         U _ZTv0_n12_N7android11MediaSourceD1Ev
003a3330 t _ZTv0_n12_N8FFSourceD0Ev
003a32d0 t _ZTv0_n12_N8FFSourceD1Ev
007b2980 d _ZTV8FFSource

Also I cannot find _ZTIN7android11MediaSourceE in libstagefright.so. I think there's any mistake I have in writing the source code instead of mis-link the stagefright library. I use android standalone toolchain to compile ffmpeg source. Like following configuration:

    function config_lsf                                                                                                                                                                             
    {
        # build flags                                                                                                                                                                               
        PREFIX=/home/cxm/work/Android/proj/dy-proj-careye/dy-proj-careye/jni/src/lib/android/            FLAGS="--prefix=$PREFIX"                                                                                                                                                                    
        FLAGS="$FLAGS --disable-static"                                                                                                                                                             
        FLAGS="$FLAGS --disable-doc"                                                                                                                                                                
        FLAGS="$FLAGS --disable-programs"                                                                                                                                                           
        FLAGS="$FLAGS --disable-avdevice"                                                                                                                                                           
        FLAGS="$FLAGS --disable-symver"                                                                                                                                                             
        FLAGS="$FLAGS --enable-shared"                                                                                                                                                              
        FLAGS="$FLAGS --cross-prefix=arm-linux-androideabi-"                                                                                                                                        
        FLAGS="$FLAGS --target-os=linux"                                                                                                                                                            
        FLAGS="$FLAGS --arch=arm"                                                                                                                                                                   
        FLAGS="$FLAGS --enable-cross-compile"                                                                                                                                                       

        FLAGS="$FLAGS --disable-decoder=h264"                                                                                                                                                       
        FLAGS="$FLAGS --disable-decoder=h264_vdpau"                                                                                                                                                 
        FLAGS="$FLAGS --enable-libstagefright-h264"                                                                                                                                                 

        # cflags                                                                                                                                                                                    
        CFLAGS="-Os -fpic -marm"                                                                                                 
        ANDROID_SOURCE=../mokesoures/                                                                                                                                                               
        ANDROID_LIBS=../android-libs                                                                                                                                                                
        CFLAGS="$CFLAGS -I$ANDROID_SOURCE/frameworks/av/include"                                                                                                                                    
        CFLAGS="$CFLAGS -I$ANDROID_SOURCE/frameworks/native/include/"                                                                                                                               
        CFLAGS="$CFLAGS -I$ANDROID_SOURCE/system/core/include"                                                                                                                                      
        CFLAGS="$CFLAGS -I$ANDROID_SOURCE/hardware/libhardware/include"                                                                                                                             
        CFLAGS="$CFLAGS -I$ANDROID_SOURCE/frameworks/native/include/media/openmax/"                                                                                                                 

        # ld flags                                                                                                                                                                                  
        LDFLAGS="-Wl,--fix-cortex-a8"                                                                                                                                                               
        LDFLAGS="$LDFLAGS -lstdc++ -lgnustl_shared -lstagefright -lutils -lbinder"                                                                                                                  
        LDFLAGS="$LDFLAGS -L$ANDROID_LIBS"                                                                                                                                                          
        LDFLAGS="$LDFLAGS -Wl,-rpath-link,$ANDROID_LIBS"                                                                                                                   

        ./configure.android $FLAGS --extra-cflags="$CFLAGS" \                                                                                                                                       
            --extra-ldflags="$LDFLAGS" \                                                                                                                                                            

        sed -i 's/#define\ HAVE_POSIX_MEMALIGN\ 1/#define\ HAVE_POSIX_MEMALIGN\ 0/' ./config.h                                                                                                      
        make -j4 V=1 2>&1 | tee log                                                                                                                                                                 
        make install                                                                                                                                                                                
    }                                                                                                                                                                                               

Please help about this topic. Thanks very much.

user3051473
  • 75
  • 1
  • 11
  • Can you please share your `Android.mk` file? – Ganesh Jul 14 '14 at 04:55
  • Because I use android standalone toolchain to compile ffmpeg so I have no Android.mk. I just reedit this topic to add my configuration. Thanks very much. – user3051473 Jul 14 '14 at 05:56
  • 1
    I don't see where you enable rtti in your `confg_lsf`. And `build_libstagefright` script explicitly sets `EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti"`. – Alex Cohn Jul 14 '14 at 07:12

1 Answers1

4

_ZTIN7android11MediaSourceE is typeinfo for android::MediaSource. You probably have -frtti enabled in your build configuration, but Android libraries do not include run-time type information; so, you should remove this flag at least from FFSource class.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Dear Alex, you must be very expert on C/C++ because that you point the rtti by the symbol name! I'm wondering that how does the compiler translate the c++ function into c function? Can you give my any advice about this topic? Thanks very much... – user3051473 Jul 14 '14 at 06:48
  • What do you mean by "translate C++ function to C"? To have a C++ function _callable_ from C, simply add `extern "C"` before function _declaration_. (Note that C does not understand this; therefore we usually wrap it in `#ifdef __cplusplus` in header files that are included both from **.c** and **.cpp**) – Alex Cohn Jul 14 '14 at 07:10
  • As far as I study from my college book, the c++ code should be translate to c code first during compiling. For example, member function F() of class C should be translate to c style function such as F(C *this). if class C is under the namespace of N, I think function F() should be translate to c style function as: N::F(C *this), all right? – user3051473 Jul 14 '14 at 07:46
  • This is not an exact description. It was true for the first generation of C++ compilers, but today they do not generate intermediate C code. Why do you ask? There still is some _symbol mangling_, where compilers produce strange symbol names (e.g. `_ZTIN7android11MediaSourceE`) for C++ methods and entities. You can use `nm -C` to see these symbols in human readable form. Note that the _mangling rules_ are compiler-specific implementation detail. – Alex Cohn Jul 14 '14 at 08:30
  • Only for study use, I want to get more information about how the compiler works. Thanks very much. – user3051473 Jul 14 '14 at 08:34