This topic describes how to integrate RTS SDK with third-party players that are based on FFmpeg. ijkplayer is used as an example.

Prerequisites

You have read and compiled ijkplayer at GitHub. For more information, visit ijkplayer GitHub.

Background information

  • If you use a third-party player, you must integrate RTS SDK as a plug-in into the player to support the ARTC protocol. To minimize development workload, RTS allows you to integrate RTS SDK as the demuxer plug-in into a player that is based on FFmpeg. This plug-in is encapsulated by rtsdec.c. For information about RTS SDK for a mobile client, see Download SDK.
  • RTS SDK for Android provide shared libraries only for ARMv7-A and ARM64.
  • The following procedure is based on ijkplayer tag k:0.8.8.

Integrate RTS SDK for Android with third-party players

  1. Integrate RTS SDK as a plug-in into ijkplayer.

    Two integration methods are provided. The following table describes their benefits and drawbacks.

    Integration method Benefit Drawback
    Extend FFmpeg by adding a demuxer plug-in This method simplifies the development process. You do not need to develop extra logic code for ARTC-based URLs. You must compile FFmpeg.
    Extend ijkplayer by adding AVInputFormat If you select this method, you do not need to compile FFmpeg. You must add logic code to ff_player.c.
    • Extend FFmpeg.
      1. Modify pull_fork in the init-android.sh script in the ijkplayer directory to delete architectures except for ARMv7-A and ARM64. Then, run the modified script.001
      2. Modify FF_ACT_ARCHS_64 in the compile-ffmpeg.sh script in the ijkplayer/Android/contrib directory to delete architectures except for ARMv7-A and ARM64.002
      3. Copy rtsdec.c that is provided by RTS to the ijkplayer/android/contrib/ffmpeg-arm64/libavformat and ijkplayer/android/contrib/ffmpeg-armv7a/libavformat directories.
      4. Modify the Makefile files to compile rtsdec.c.

        Modify the Makefile files in the ijkplayer/android/contrib/ffmpeg-arm64/libavformat/ and ijkplayer/android/contrib/ffmpeg-arm64/libavformat/ directories, as shown in the following figure.

        003
      5. Modify the allformats.c files to support the ARTC protocol.

        Modify the allformats.c files in the ijkplayer/android/contrib/ffmpeg-arm64/libavformat/ and ijkplayer/android/contrib/ffmpeg-arm64/libavformat/ directories, as shown in the following figure.

        004
            extern AVInputFormat ff_rtc_demuxer;
            av_register_input_format(&ff_rtc_demuxer);
      6. Modify the compilation script of FFmpeg to support pulse-code modulation (PCM) decoding. In this case, RTS SDK is used to export PCM data.

        Add the following code to the module-lite.sh script in the /config directory:

        # aliyun rts
        export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-decoder=pcm_s16be_planar"
        export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-decoder=pcm_s16le"
        export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-decoder=pcm_s16le_planar"
      7. Compile FFmpeg.

        Add the ANDROID_NDK environment variable. In this example, ANDROID_NDK is set to android-ndk-r12b. Run the ./compile-ffmpeg.sh all command in the ijkplayer/android/contrib/ directory.

      8. Check whether an output file of FFmpeg compilation exists in the ijkplayer/android/contrib/build directory.
      9. Modify ACT_ABI_64 in the ijkplayer/Android/compile-ijk.sh script to delete architectures except for ARMv7-A and ARM64004
      10. Add the shared libraries of RTS.

        Add the shared libraries of RTS to the ijkplayer/android/contrib/build/ffmpeg-arm64/output and ijkplayer/android/contrib/build/ffmpeg-armv7a/output directories based on the architecture. Then, copy the rts_api.h and rts_messages.h header files to the ijkplayer/android/contrib/build/ffmpeg-arm64/output/include and ijkplayer/android/contrib/build/ffmpeg-armv7a/output/include directories.

      11. Import the shared libraries of RTS.
        Modify the Android.mk files in the ijkplayer/android/ijkplayer/ijkplayer-armv7a/src/main/jni/ffmpeg/ and ijkplayer/android/ijkplayer/ijkplayer-arm64/src/main/jni/ffmpeg/ directories.005
        include $(CLEAR_VARS)
        LOCAL_MODULE := rtssdk
        LOCAL_SRC_FILES := $(MY_APP_FFMPEG_OUTPUT_PATH)/libRtsSDK.so
        include $(PREBUILT_SHARED_LIBRARY)
      12. Add the shared libraries of RTS to ijkplayer as dependencies.
        Modify the Android.mk files in the ijkplayer/ijkmedia/ijkplayer/ directory.006
      13. Add the logic code of RTS to ff_fflay.c.

        Configure a function pointer to AVInputFormat if streaming URLs start with artc://. Modify the ff_ffplay.c files in the ijkplayer/ijkmedia/ijkplayer/ directory.

        007
            extern AVInputFormat ff_rtc_demuxer;
            extern int artc_reload(AVFormatContext *ctx);
            extern void av_set_rts_demuxer_funcs(const struct rts_glue_funcs *funcs);
            extern void artc_set_rts_param(char* key, char* value);
            extern long long artc_get_state(AVFormatContext *ctx, int key);
        
            int version = 2;
            const struct rts_glue_funcs* rts_funcs = get_rts_funcs(version);
            // set to ffmpeg plugin
            av_set_rts_demuxer_funcs(rts_funcs);
            artc_set_rts_param((char*)"AutoReconnect", (char*)"false");
      14. Compile ijkplayer.

        Run the ./compile-ijk.sh all command in the ijkplayer/android directory.

    • Extend ijkplayer
      1. Modify the compilation script of FFmpeg to support PCM decoding. Then, compile FFmpeg. In this case, you do not need to add RTS SDK dependencies.

        Add the following code to the module-lite.sh script in the /config directory:

        # aliyun rts
        export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-decoder=pcm_s16be_planar"
        export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-decoder=pcm_s16le"
        export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-decoder=pcm_s16le_planar"
      2. Add RTS dependencies to ijkplayer.

        Add the dynamic frameworks of RTS SDK to the project and modify the Android.mk files. For more information, see Extend FFmpeg.

      3. Add the logic code of RTS to ff_fflay.c. If streaming URLs start with artc://, call the AVInputFormat function.008
        if(strncmp(is->filename, "artc://", 7) == 0) {
                extern AVInputFormat ff_rtc_demuxer;
                extern int artc_reload(AVFormatContext *ctx);
                extern void av_set_rts_demuxer_funcs(const struct rts_glue_funcs *funcs);
                extern void artc_set_rts_param(char* key, char* value);
                extern long long artc_get_state(AVFormatContext *ctx, int key);
        
                int version = 2;
                const struct rts_glue_funcs* rts_funcs = get_rts_funcs(version);
                // set to ffmpeg plugin
                av_set_rts_demuxer_funcs(rts_funcs);
                artc_set_rts_param((char*)"AutoReconnect", (char*)"false");
                is->iformat = &ff_rtc_demuxer;
            }
            else {
                if(ffp->iformat_name)
                    is->iformat = av_find_input_format(ffp->iformat_name);
            }
      4. Copy rtsdec.c to the ijkplayer/ijkmedia/ijkplayer directory. Modify the android.mk file in the directory to add the rtsdec.c file.
        LOCAL_SRC_FILES += rtsdec.c
  2. Integrate ijkplayer in a project.
    1. Import the RtsNetSDK.jar file to the project.
    2. Add System.loadLibrary("RtsSDK"); to the required activity.
      static {
          System.loadLibrary("RtsSDK");
      }
      You must import the following modules: ijkplayer-arm64, ijkplayer-armv7a, and ijkplayer-java.009
  3. Call the API of ijkplayer.
    1. Create ijkplayer.
      mIjkPlayer = new IjkMediaPlayer();
    2. Configure callbacks.
      mIjkPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
          @Override
          public void onPrepared(IMediaPlayer iMediaPlayer) {
              
          }
      });
      
      mIjkPlayer.setOnInfoListener(new IMediaPlayer.OnInfoListener() {
          @Override
          public boolean onInfo(IMediaPlayer iMediaPlayer, int arg1, int arg2) {
              
      });
      
      mIjkPlayer.setOnVideoSizeChangedListener(new IMediaPlayer.OnVideoSizeChangedListener() {
          @Override
          public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int width, int height, int sarNum, int sarDen) {
             
          }
      });
      
      mIjkPlayer.setOnErrorListener(new IMediaPlayer.OnErrorListener() {
          @Override
          public boolean onError(IMediaPlayer iMediaPlayer, int framework_err, int impl_err) {
              
              return false;
          }
      });
    3. Configure the UI view.
      mIjkPlayer.setSurface(surface);
    4. Configure the playback source.
      mIjkPlayer.setDataSource("artc://xxx");
    5. Configure playback control.
      public void prepare() {
          if(mIjkPlayer ! = null){
              mIjkPlayer.prepareAsync();
          }
      }
      
      @Override
      public void start() {
          if(mIjkPlayer ! = null){
              mIjkPlayer.start();
          }
      }
      
      public void pause() {
          if(mIjkPlayer ! = null){
              mIjkPlayer.pause();
          }
      }
      
      public void stop() {
          if(mIjkPlayer ! = null){
              mIjkPlayer.stop();
          }
      }
      public void release() {
          if(mIjkPlayer ! = null){
              mIjkPlayer.release();
          }
      }

Integrate RTS SDK for iOS with third-party players that are based on FFmpeg

  1. Integrate RTS SDK as a plug-in into ijkplayer

    Two integration methods are provided. The following table describes their benefits and drawbacks.

    Integration method Benefit Drawback
    Extend FFmpeg by adding a demuxer plug-in This method simplifies the development process. You do not need to develop extra logic code for ARTC-based URLs. You must compile FFmpeg.
    Extend ijkplayer by adding AVInputFormat If you select this method, you do not need to compile FFmpeg. You must add logic code to ff_player.c.
    • Extend FFmpeg.
      1. Run the init-ios.sh command in the ijkplayer directory.
      2. Go to the ijkplayer/ios directory. Copy rtsdec.c to the ffmpeg-$arch/libavformat directory. Then, modify libavformat/Makefile and allformat.c. For more information, see Extend FFmpeg.
      3. Compile ijkplayer.

        Run the ./compile-ffmpeg.sh all command in the ijkplayer/ios directory.

      4. Check whether an output file of FFmpeg compilation exists in the ijkplayer/ios/build/universal/ directory.
      5. Add RtsSDK.framework to the ijkplayer//ios/IJKMediaDemo/IJKMediaDemo directory.
      6. Open ios/IJKMediaDemo/IJKMediaDemo.xcodeproj in Xcode.
      7. Add RtsSDK.framework as a dependency to IJKMediaPlayer.xcodeproj.010
      8. Add the logic code of RTS to ff_fflay.c. For more information, see Extend FFmpeg.
    • Extend ijkplayer
      1. In this case, you do not need to use RTS SDK to extend FFmpeg.
      2. Add RTS dependencies to ijkplayer. For more information, see Extend FFmpeg.
      3. Import rtsdec.c to your project.011
      4. Modify the code in ff_ffplay.c. For more information, see Extend FFmpeg.
  2. Integrate ijkplayer and RTS SDK in a project
    Import the frameworks of ijkplayer and the frameworks of RTS SDK to your project.012
  3. Call the API of ijkplayer.
    1. Create ijkplayer.
      _ijkPlayer = [[IJKFFMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:_url] withOptions:options];
      _ijkPlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
      _ijkPlayer.view.frame = self.basePlayerView.playerView.bounds;
      _ijkPlayer.scalingMode = IJKMPMovieScalingModeAspectFit; // Configure the scaling mode.
      _ijkPlayer.shouldAutoplay = YES; // Enable autoplay.
    2. Configure playback control.
      - (void)prepareToPlay;
      - (void)play;
      - (void)pause;
      - (void)stop;