首页 > 代码库 > FFmpeg总结(十一)用ffmpeg进行转格式,Android下播放网络音频流

FFmpeg总结(十一)用ffmpeg进行转格式,Android下播放网络音频流

技术分享

图:杭州西湖

思路: 
1、mp3转成pcm(音频数据),ffmpeg做的事 
2、OpenSL ES引擎创建AudioPlayer,实际调用了AudioTrack

遇到的错误: 
Error #include nested too deeply 
原因:c文件互相引用 
解决方案:

  • 1、将两个头文件共用的那一部分抽出来单独建一个头文件。

  • 2、加预处理#ifndef.. #define…#endif

x86平台没有编译出来so,怀疑存在版本不兼容,编译别的相关so,x86下没有异常。有空这里再更新下原因

技术分享

studio写ndk相当方便:

技术分享

技术分享

工程结构:

技术分享

Java代码:

  1. package com.hejunlin.ffmpegaudio;

  2.  

  3. import android.support.v7.app.AppCompatActivity;

  4. import android.os.Bundle;

  5. import android.view.View;

  6. import android.widget.EditText;

  7. import android.widget.TextView;

  8.  

  9. public class MainActivity extends AppCompatActivity {

  10.  

  11.    private EditText mInput;

  12.  

  13.    @Override

  14.    protected void onCreate(Bundle savedInstanceState) {

  15.        super.onCreate(savedInstanceState);

  16.        setContentView(R.layout.activity_main);

  17.        mInput = (EditText) findViewById(R.id.et_input);

  18.     mInput.setText("http://qzone.60dj.com/huiyuan/201704/19/201704190533197825_35285.mp3");

  19.        findViewById(R.id.bt_play).setOnClickListener(new View.OnClickListener() {

  20.            @Override

  21.            public void onClick(View view) {

  22.                NativePlayer.play(mInput.getText().toString().trim());

  23.            }

  24.        });

  25.        findViewById(R.id.bt_pause).setOnClickListener(new View.OnClickListener() {

  26.            @Override

  27.            public void onClick(View view) {

  28.                NativePlayer.stop();

  29.            }

  30.        });

  31.    }

  32. }

 

NativePlayer:

  1. package com.hejunlin.ffmpegaudio;

  2.  

  3. /**

  4. * Created by hejunlin on 17/5/6.

  5. */

  6.  

  7. public class NativePlayer {

  8.  

  9.    static {

  10.        System.loadLibrary("NativePlayer");

  11.    }

  12.  

  13.    public static native void play(String url);

  14.    public static native void stop();

  15. }

 

布局文件:

  1. <?xml version="1.0" encoding="utf-8"?>

  2. <RelativeLayout

  3.    xmlns:android="http://schemas.android.com/apk/res/android"

  4.    xmlns:tools="http://schemas.android.com/tools"

  5.    android:id="@+id/activity_main"

  6.    android:layout_width="match_parent"

  7.    android:layout_height="match_parent"

  8.    tools:context="com.hejunlin.ffmpegaudio.MainActivity">

  9.  

  10.    <TextView

  11.        android:id="@+id/tv_input"

  12.        android:layout_width="wrap_content"

  13.        android:layout_height="wrap_content"

  14.        android:padding="10dp"

  15.        android:layout_marginTop="30dp"

  16.        android:text="播放链接:"

  17.        android:textSize="20sp"/>

  18.  

  19.    <EditText

  20.        android:id="@+id/et_input"

  21.        android:layout_width="match_parent"

  22.        android:layout_height="wrap_content"

  23.        android:layout_toRightOf="@id/tv_input"

  24.        android:padding="10dp"/>

  25.  

  26.    <LinearLayout

  27.        android:layout_width="match_parent"

  28.        android:layout_height="wrap_content"

  29.        android:layout_below="@id/et_input"

  30.        android:orientation="horizontal">

  31.  

  32.  

  33.        <Button

  34.            android:id="@+id/bt_play"

  35.            android:layout_width="wrap_content"

  36.            android:layout_height="wrap_content"

  37.            android:layout_marginTop="10dp"

  38.            android:layout_marginLeft="60dp"

  39.            android:background="@drawable/button_shape"

  40.            android:textColor="@color/white"

  41.            android:text="播放" />

  42.  

  43.        <Button

  44.            android:id="@+id/bt_pause"

  45.            android:layout_width="wrap_content"

  46.            android:layout_height="wrap_content"

  47.            android:layout_marginTop="10dp"

  48.            android:background="@drawable/button_shape"

  49.            android:textColor="@color/white"

  50.            android:layout_marginLeft="80dp"

  51.            android:text="暂停" />

  52.    </LinearLayout>

  53.  

  54. </RelativeLayout>

jni相关代码: OpenSLESCore.c

  1. //

  2. // Created by hejunlin on 17/5/6.

  3. //

  4.  

  5. #include "OpenSL_ES_Core.h"

  6. #include "FFmpegCore.h"

  7. #include <assert.h>

  8. #include <jni.h>

  9. #include <string.h>

  10.  

  11. #include <SLES/OpenSLES.h>

  12. #include <SLES/OpenSLES_Android.h>

  13.  

  14. // for native asset manager

  15. #include <sys/types.h>

  16. #include <android/asset_manager.h>

  17. #include <android/asset_manager_jni.h>

  18. #include "log.h"

  19.  

  20. // engine interfaces

  21. static SLObjectItf engineObject = NULL;

  22. static SLEngineItf engineEngine;

  23.  

  24. // output mix interfaces

  25. static SLObjectItf outputMixObject = NULL;

  26. static SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL;

  27.  

  28. // buffer queue player interfaces

  29. static SLObjectItf bqPlayerObject = NULL;

  30. static SLPlayItf bqPlayerPlay;

  31. static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;

  32. static SLEffectSendItf bqPlayerEffectSend;

  33. static SLMuteSoloItf bqPlayerMuteSolo;

  34. static SLVolumeItf bqPlayerVolume;

  35.  

  36. // aux effect on the output mix, used by the buffer queue player

  37. static const SLEnvironmentalReverbSettings reverbSettings =

  38.        SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;

  39.  

  40. static void *buffer;

  41. static size_t bufferSize;

  42.  

  43. // this callback handler is called every time a buffer finishes playing

  44. void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)

  45. {

  46.    LOGD(">> buffere queue callback");

  47.    assert(bq == bqPlayerBufferQueue);

  48.    bufferSize = 0;

  49.    //assert(NULL == context);

  50.    getPCM(&buffer, &bufferSize);

  51.    // for streaming playback, replace this test by logic to find and fill the next buffer

  52.    if (NULL != buffer && 0 != bufferSize) {

  53.        SLresult result;

  54.        // enqueue another buffer

  55.        result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer,

  56.                                                 bufferSize);

  57.        // the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT,

  58.        // which for this code example would indicate a programming error

  59.        assert(SL_RESULT_SUCCESS == result);

  60.  

  61.        (void)result;

  62.    }

  63. }

  64.  

  65. void initOpenSLES()

  66. {

  67.    LOGD(">> initOpenSLES...");

  68.    SLresult result;

  69.  

  70.    // 1、create engine

  71.    result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);

  72.    LOGD(">> initOpenSLES... step 1, result = %d", result);

  73.  

  74.    // 2、realize the engine

  75.    result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);

  76.    LOGD(">> initOpenSLES...step 2, result = %d", result);

  77.  

  78.    // 3、get the engine interface, which is needed in order to create other objects

  79.    result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);

  80.    LOGD(">> initOpenSLES...step 3, result = %d", result);

  81.  

  82.    // 4、create output mix, with environmental reverb specified as a non-required interface

  83.    const SLInterfaceID ids[1] = {SL_IID_ENVIRONMENTALREVERB};

  84.    const SLboolean req[1] = {SL_BOOLEAN_FALSE};

  85.    result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, 0, 0);

  86.    LOGD(">> initOpenSLES...step 4, result = %d", result);

  87.  

  88.    // 5、realize the output mix

  89.    result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);

  90.    LOGD(">> initOpenSLES...step 5, result = %d", result);

  91.  

  92.    // 6、get the environmental reverb interface

  93.    // this could fail if the environmental reverb effect is not available,

  94.    // either because the feature is not present, excessive CPU load, or

  95.    // the required MODIFY_AUDIO_SETTINGS permission was not requested and granted

  96.    result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB,

  97.                                              &outputMixEnvironmentalReverb);

  98.    if (SL_RESULT_SUCCESS == result) {

  99.        result = (*outputMixEnvironmentalReverb)->SetEnvironmentalReverbProperties(

  100.                outputMixEnvironmentalReverb, &reverbSettings);

  101.        LOGD(">> initOpenSLES...step 6, result = %d", result);

  102.    }

  103.  

  104. }

  105.  

  106. // init buffer queue

  107. void initBufferQueue(int rate, int channel, int bitsPerSample)

  108. {

  109.    LOGD(">> initBufferQueue");

  110.    SLresult result;

  111.  

  112.    // configure audio source

  113.    SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};

  114.    SLDataFormat_PCM format_pcm;

  115.    format_pcm.formatType = SL_DATAFORMAT_PCM;

  116.    format_pcm.numChannels = channel;

  117.    format_pcm.samplesPerSec = rate * 1000;

  118.    format_pcm.bitsPerSample = bitsPerSample;

  119.    format_pcm.containerSize = 16;

  120.    if (channel == 2)

  121.        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;

  122.    else

  123.        format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER;

  124.    format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;

  125.    SLDataSource audioSrc = {&loc_bufq, &format_pcm};

  126.  

  127.    // configure audio sink

  128.    SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};

  129.    SLDataSink audioSnk = {&loc_outmix, NULL};

  130.  

  131.    // create audio player

  132.    const SLInterfaceID ids[3] = {SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND,

  133.            /*SL_IID_MUTESOLO,*/ SL_IID_VOLUME};

  134.    const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE,

  135.            /*SL_BOOLEAN_TRUE,*/ SL_BOOLEAN_TRUE};

  136.    result = (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk,

  137.                                                3, ids, req);

  138.    assert(SL_RESULT_SUCCESS == result);

  139.    (void)result;

  140.  

  141.    // realize the player

  142.    result = (*bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE);

  143.    assert(SL_RESULT_SUCCESS == result);

  144.    (void)result;

  145.  

  146.    // get the play interface

  147.    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay);

  148.    assert(SL_RESULT_SUCCESS == result);

  149.    (void)result;

  150.  

  151.    // get the buffer queue interface

  152.    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_BUFFERQUEUE,

  153.                                             &bqPlayerBufferQueue);

  154.    assert(SL_RESULT_SUCCESS == result);

  155.    (void)result;

  156.  

  157.    // register callback on the buffer queue

  158.    result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, NULL);

  159.    assert(SL_RESULT_SUCCESS == result);

  160.    (void)result;

  161.  

  162.    // get the effect send interface

  163.    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_EFFECTSEND,

  164.                                             &bqPlayerEffectSend);

  165.    assert(SL_RESULT_SUCCESS == result);

  166.    (void)result;

  167.  

  168.    // get the volume interface

  169.    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_VOLUME, &bqPlayerVolume);

  170.    assert(SL_RESULT_SUCCESS == result);

  171.    (void)result;

  172.  

  173.    // set the player‘s state to playing

  174.    result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);

  175.    assert(SL_RESULT_SUCCESS == result);

  176.    (void)result;

  177. }

  178.  

  179. // stop the native audio system

  180. void stop()

  181. {

  182.    // destroy buffer queue audio player object, and invalidate all associated interfaces

  183.    if (bqPlayerObject != NULL) {

  184.        (*bqPlayerObject)->Destroy(bqPlayerObject);

  185.        bqPlayerObject = NULL;

  186.        bqPlayerPlay = NULL;

  187.        bqPlayerBufferQueue = NULL;

  188.        bqPlayerEffectSend = NULL;

  189.        bqPlayerMuteSolo = NULL;

  190.        bqPlayerVolume = NULL;

  191.    }

  192.  

  193.    // destroy output mix object, and invalidate all associated interfaces

  194.    if (outputMixObject != NULL) {

  195.        (*outputMixObject)->Destroy(outputMixObject);

  196.        outputMixObject = NULL;

  197.        outputMixEnvironmentalReverb = NULL;

  198.    }

  199.  

  200.    // destroy engine object, and invalidate all associated interfaces

  201.    if (engineObject != NULL) {

  202.        (*engineObject)->Destroy(engineObject);

  203.        engineObject = NULL;

  204.        engineEngine = NULL;

  205.    }

  206.  

  207.    // 释放FFmpeg解码器

  208.    releaseFFmpeg();

  209. }

  210.  

  211. void play(char *url)

  212. {

  213.    int rate, channel;

  214.    LOGD("...get url=%s", url);

  215.    // 1、初始化FFmpeg解码器

  216.    initFFmpeg(&rate, &channel, url);

  217.  

  218.    // 2、初始化OpenSLES

  219.    initOpenSLES();

  220.  

  221.    // 3、初始化BufferQueue

  222.    initBufferQueue(rate, channel, SL_PCMSAMPLEFORMAT_FIXED_16);

  223.  

  224.    // 4、启动音频播放

  225.    bqPlayerCallback(bqPlayerBufferQueue, NULL);

  226. }

 

FFmpegCore.c

  1. #include "log.h"

  2. #include "FFmpegCore.h"

  3. #include "libavcodec/avcodec.h"

  4. #include "libavformat/avformat.h"

  5. #include "libswscale/swscale.h"

  6. #include "libswresample/swresample.h"

  7. #include "libavutil/samplefmt.h"

  8. #include <SLES/OpenSLES.h>

  9. #include <SLES/OpenSLES_Android.h>

  10.  

  11. uint8_t *outputBuffer;

  12. size_t outputBufferSize;

  13.  

  14. AVPacket packet;

  15. int audioStream;

  16. AVFrame *aFrame;

  17. SwrContext *swr;

  18. AVFormatContext *aFormatCtx;

  19. AVCodecContext *aCodecCtx;

  20.  

  21. int initFFmpeg(int *rate, int *channel, char *url) {

  22.  

  23.    av_register_all();

  24.    aFormatCtx = avformat_alloc_context();

  25.    LOGD("ffmpeg get url=:%s", url);

  26.    // 网络音频流

  27.    char *file_name = url;

  28.  

  29.    // Open audio file

  30.    if (avformat_open_input(&aFormatCtx, file_name, NULL, NULL) != 0) {

  31.        LOGE("Couldn‘t open file:%s\n", file_name);

  32.        return -1; // Couldn‘t open file

  33.    }

  34.  

  35.    // Retrieve stream information

  36.    if (avformat_find_stream_info(aFormatCtx, NULL) < 0) {

  37.        LOGE("Couldn‘t find stream information.");

  38.        return -1;

  39.    }

  40.  

  41.    // Find the first audio stream

  42.    int i;

  43.    audioStream = -1;

  44.    for (i = 0; i < aFormatCtx->nb_streams; i++) {

  45.        if (aFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO &&

  46.            audioStream < 0) {

  47.            audioStream = i;

  48.        }

  49.    }

  50.    if (audioStream == -1) {

  51.        LOGE("Couldn‘t find audio stream!");

  52.        return -1;

  53.    }

  54.  

  55.    // Get a pointer to the codec context for the video stream

  56.    aCodecCtx = aFormatCtx->streams[audioStream]->codec;

  57.  

  58.    // Find the decoder for the audio stream

  59.    AVCodec *aCodec = avcodec_find_decoder(aCodecCtx->codec_id);

  60.    if (!aCodec) {

  61.        fprintf(stderr, "Unsupported codec!\n");

  62.        return -1;

  63.    }

  64.  

  65.    if (avcodec_open2(aCodecCtx, aCodec, NULL) < 0) {

  66.        LOGE("Could not open codec.");

  67.        return -1; // Could not open codec

  68.    }

  69.  

  70.    aFrame = av_frame_alloc();

  71.  

  72.    // 设置格式转换

  73.    swr = swr_alloc();

  74.    av_opt_set_int(swr, "in_channel_layout",  aCodecCtx->channel_layout, 0);

  75.    av_opt_set_int(swr, "out_channel_layout", aCodecCtx->channel_layout,  0);

  76.    av_opt_set_int(swr, "in_sample_rate",     aCodecCtx->sample_rate, 0);

  77.    av_opt_set_int(swr, "out_sample_rate",    aCodecCtx->sample_rate, 0);

  78.    av_opt_set_sample_fmt(swr, "in_sample_fmt",  aCodecCtx->sample_fmt, 0);

  79.    av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16,  0);

  80.    swr_init(swr);

  81.  

  82.    // 分配PCM数据缓存

  83.    outputBufferSize = 8196;

  84.    outputBuffer = (uint8_t *) malloc(sizeof(uint8_t) * outputBufferSize);

  85.  

  86.    // 返回sample rate和channels

  87.    *rate = aCodecCtx->sample_rate;

  88.    *channel = aCodecCtx->channels;

  89.    return 0;

  90. }

  91.  

  92. // 获取PCM数据, 自动回调获取

  93. int getPCM(void **pcm, size_t *pcmSize) {

  94.    LOGD(">> getPcm");

  95.    while (av_read_frame(aFormatCtx, &packet) >= 0) {

  96.  

  97.        int frameFinished = 0;

  98.        // Is this a packet from the audio stream?

  99.        if (packet.stream_index == audioStream) {

  100.            avcodec_decode_audio4(aCodecCtx, aFrame, &frameFinished, &packet);

  101.  

  102.            if (frameFinished) {

  103.                // data_size为音频数据所占的字节数

  104.                int data_size = av_samples_get_buffer_size(

  105.                        aFrame->linesize, aCodecCtx->channels,

  106.                        aFrame->nb_samples, aCodecCtx->sample_fmt, 1);

  107.                LOGD(">> getPcm data_size=%d", data_size);

  108.                // 这里内存再分配可能存在问题

  109.                if (data_size > outputBufferSize) {

  110.                    outputBufferSize = data_size;

  111.                    outputBuffer = (uint8_t *) realloc(outputBuffer,

  112.                                                       sizeof(uint8_t) * outputBufferSize);

  113.                }

  114.  

  115.                // 音频格式转换

  116.                swr_convert(swr, &outputBuffer, aFrame->nb_samples,

  117.                            (uint8_t const **) (aFrame->extended_data),

  118.                        aFrame->nb_samples);

  119.  

  120.                // 返回pcm数据

  121.                *pcm = outputBuffer;

  122.                *pcmSize = data_size;

  123.                return 0;

  124.            }

  125.        }

  126.    }

  127.    return -1;

  128. }

  129.  

  130. // 释放相关资源

  131. int releaseFFmpeg()

  132. {

  133.    av_packet_unref(&packet);

  134.    av_free(outputBuffer);

  135.    av_free(aFrame);

  136.    avcodec_close(aCodecCtx);

  137.    avformat_close_input(&aFormatCtx);

  138.    return 0;

NativePlayer.c

  1. //

  2. // Created by hejunlin on 17/5/6.

  3. //

  4. #include "log.h"

  5. #include "com_hejunlin_ffmpegaudio_NativePlayer.h"

  6. #include "OpenSL_ES_Core.h"

  7.  

  8. JNIEXPORT void JNICALL

  9. Java_com_hejunlin_ffmpegaudio_NativePlayer_play(JNIEnv *env, jclass type, jstring url_) {

  10.    const char *url = (*env)->GetStringUTFChars(env, url_, 0);

  11.    LOGD("start playaudio... url=%s", url);

  12.  

  13.    play(url);

  14.    (*env)->ReleaseStringUTFChars(env, url_, url);

  15. }

  16.  

  17. JNIEXPORT void JNICALL

  18. Java_com_hejunlin_ffmpegaudio_NativePlayer_stop(JNIEnv *env, jclass type) {

  19.  

  20.    LOGD("stop");

  21.    stop();

  22. }

通过cmake,或ndk-build都可以编译,会生成一个NativePlayer.so

技术分享

效果图:

技术分享

log输出如下:

    1. 05-07 10:14:04.573 D/Surface: Surface::setBuffersDimensions(this=0xf45b6300,w=1080,h=1920)

    2. 05-07 10:14:04.577 W/linker: libNativePlayer.so: unused DT entry: type 0x6ffffffe arg 0x1414

    3. 05-07 10:14:04.577 W/linker: libNativePlayer.so: unused DT entry: type 0x6fffffff arg 0x4

    4. 05-07 10:14:04.578 W/linker: libavcodec-57.so: unused DT entry: type 0x6ffffffe arg 0x5da4

    5. 05-07 10:14:04.578 W/linker: libavcodec-57.so: unused DT entry: type 0x6fffffff arg 0x2

    6. 05-07 10:14:04.578 W/linker: libavformat-57.so: unused DT entry: type 0x6ffffffe arg 0x6408

    7. 05-07 10:14:04.578 W/linker: libavformat-57.so: unused DT entry: type 0x6fffffff arg 0x2

    8. 05-07 10:14:04.578 W/linker: libswresample-2.so: unused DT entry: type 0x6ffffffe arg 0xcd4

    9. 05-07 10:14:04.578 W/linker: libswresample-2.so: unused DT entry: type 0x6fffffff arg 0x1

    10. 05-07 10:14:04.578 W/linker: libswscale-4.so: unused DT entry: type 0x6ffffffe arg 0xd70

    11. 05-07 10:14:04.578 W/linker: libswscale-4.so: unused DT entry: type 0x6fffffff arg 0x1

    12. 05-07 10:14:04.589 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/NativePlayer.c: Java_com_hejunlin_ffmpegaudio_NativePlayer_play:start playaudio... url=http://qzone.60dj.com/huiyuan/201704/19/201704190533197825_35285.mp3

    13. 05-07 10:14:04.589 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: play:...get url=http://qzone.60dj.com/huiyuan/201704/19/201704190533197825_35285.mp3

    14. 05-07 10:14:04.590 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: initFFmpeg:ffmpeg get url=:http://qzone.60dj.com/huiyuan/201704/19/201704190533197825_35285.mp3

    15. 05-07 10:14:04.696 D/libc-netbsd: getaddrinfo: qzone.60dj.com get result from proxy >>

    16. 05-07 10:14:04.949 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: initOpenSLES:>> initOpenSLES...

    17. 05-07 10:14:04.950 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: initOpenSLES:>> initOpenSLES... step 1, result = 0

    18. 05-07 10:14:04.950 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: initOpenSLES:>> initOpenSLES...step 2, result = 0

    19. 05-07 10:14:04.950 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: initOpenSLES:>> initOpenSLES...step 3, result = 0

    20. 05-07 10:14:04.950 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: initOpenSLES:>> initOpenSLES...step 4, result = 0

    21. 05-07 10:14:04.950 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: initOpenSLES:>> initOpenSLES...step 5, result = 0

    22. 05-07 10:14:04.950 W/libOpenSLES: Leaving Object::GetInterface (SL_RESULT_FEATURE_UNSUPPORTED)

    23. 05-07 10:14:04.950 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: initBufferQueue:>> initBufferQueue

    24. 05-07 10:14:04.951 V/AudioTrack: set(): streamType 3, sampleRate 44100, format 0x1, channelMask 0x3, frameCount 0, flags #0, notificationFrames 0, sessionId 774, transferType 0

    25. 05-07 10:14:04.951 V/AudioTrack: set() streamType 3 frameCount 0 flags 0000

    26. 05-07 10:14:04.951 D/AudioTrack: audiotrack 0xf459cd80 set Type 3, rate 44100, fmt 1, chn 3, fcnt 0, flags 0000

    27. 05-07 10:14:04.951 D/AudioTrack: mChannelMask 0x3

    28. 05-07 10:14:04.953 V/AudioTrack: createTrack_l() output 2 afLatency 21

    29. 05-07 10:14:04.953 V/AudioTrack: afFrameCount=1024, minBufCount=1, afSampleRate=48000, afLatency=21

    30. 05-07 10:14:04.953 V/AudioTrack: minFrameCount: 2822, afFrameCount=1024, minBufCount=3, sampleRate=44100, afSampleRate=48000, afLatency=21

    31. 05-07 10:14:04.954 D/AudioTrackCenter: addTrack, trackId:0xdaf0c000, frameCount:2822, sampleRate:44100, trackPtr:0xf459cd80

    32. 05-07 10:14:04.954 D/AudioTrackCenter: mAfSampleRate 48000, sampleRate 44100, AfFrameCount 1024 , mAfSampleRate 48000, frameCount 2822

    33. 05-07 10:14:04.979 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: bqPlayerCallback:>> buffere queue callback

    34. 05-07 10:14:04.979 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: getPCM:>> getPcm

    35. 05-07 10:14:04.979 D/AudioTrackShared: front(0x0), mIsOut 1, avail 2822, mFrameCount 2822, filled 0

    36. 05-07 10:14:04.979 V/AudioTrack: obtainBuffer(940) returned 2822 = 940 + 1882 err 0

    37. 05-07 10:14:04.979 D/AudioTrackShared: front(0x0), mIsOut 1, interrupt() FUTEX_WAKE

    38. 05-07 10:14:04.979 D/AudioTrack: audiotrack 0xf459cd80 stop done

    39. 05-07 10:14:04.980 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: getPCM:>> getPcm data_size=188

    40. 05-07 10:14:04.980 D/AudioTrackShared: front(0x0), mIsOut 1, avail 2822, mFrameCount 2822, filled 0

    41. 05-07 10:14:04.980 V/AudioTrack: obtainBuffer(940) returned 2822 = 940 + 1882 err 0

    42. 05-07 10:14:04.980 D/AudioTrackShared: front(0x0), mIsOut 1, avail 2775, mFrameCount 2822, filled 47

    43. 05-07 10:14:04.980 V/AudioTrack: obtainBuffer(893) returned 2775 = 893 + 1882 err 0

    44. 05-07 10:14:04.980 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: bqPlayerCallback:>> buffere queue callback

    45. 05-07 10:14:04.980 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: getPCM:>> getPcm

    46. 05-07 10:14:04.980 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: getPCM:>> getPcm data_size=4608

    47. 05-07 10:14:04.980 D/AudioTrackShared: front(0x0), mIsOut 1, avail 1882, mFrameCount 2822, filled 940

    48. 05-07 10:14:04.980 V/AudioTrack: obtainBuffer(940) returned 1882 = 940 + 942 err 0

    49. 05-07 10:14:04.980 D/AudioTrackShared: front(0x0), mIsOut 1, avail 1623, mFrameCount 2822, filled 1199

    50. 05-07 10:14:04.980 V/AudioTrack: obtainBuffer(681) returned 1623 = 681 + 942 err 0

    51. 05-07 10:14:04.980 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: bqPlayerCallback:>> buffere queue callback

    52. 05-07 10:14:04.980 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: getPCM:>> getPcm

    53. 05-07 10:14:04.981 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: getPCM:>> getPcm data_size=4608

    54. 05-07 10:14:04.981 D/AudioTrackShared: front(0x0), mIsOut 1, avail 942, mFrameCount 2822, filled 1880

    55. 05-07 10:14:04.981 V/AudioTrack: obtainBuffer(940) returned 942 = 940 + 2 err 0

    56. 05-07 10:14:04.981 D/AudioTrackShared: front(0x0), mIsOut 1, avail 471, mFrameCount 2822, filled 2351

    57. 05-07 10:14:04.981 V/AudioTrack: obtainBuffer(469) returned 471 = 469 + 2 err 0

    58. 05-07 10:14:04.981 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/OpenSL_ES_Core.c: bqPlayerCallback:>> buffere queue callback

    59. 05-07 10:14:04.981 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: getPCM:>> getPcm

    60. 05-07 10:14:04.981 D//Users/hejunlin/AndroidStudioProjects/FFmpegAudio/app/src/main/jni/FFmpegCore.c: getPCM:>> getPcm data_size=4608

    61. http://blog.renren.com/blog/937184755/994083793
      http://blog.renren.com/blog/937184755/994083886
      http://blog.renren.com/blog/937184755/994084167
      http://gamebbs.51.com/thread-324928-1-1.html
      http://blog.163.com/m13094739605_1/blog/static/27240604620174100133493/
      http://blog.163.com/m13094739605_1/blog/static/2724060462017410028912/
      http://blog.163.com/m13094739605_1/blog/static/27240604620174100237428/
      http://blog.163.com/m13094739605_1/blog/static/27240604620174100315903/
      http://www.230la.com/com/wz801234567/news/itemid-3253535.html

 

FFmpeg总结(十一)用ffmpeg进行转格式,Android下播放网络音频流