Android Audio Debug相关方法

  1. Audio的FW和HAL层dump PCM数据(非offload的场景,对应offload,dump出来的还是原数据)
1.抓取Systrace
  <1>怎么加参考:frameworks/av/services/audioflinger/Threads.cpp
    #define ATRACE_TAG ATRACE_TAG_AUDIO
     ATRACE_BEGIN("write");
     //代码。。。
     ATRACE_END();
  <2>怎么使用Systrace参考:
     https://maoao530.github.io/2017/02/06/systrace/
2.混音之前dump PCM数据
  frameworks/av/media/libmedia/AudioTrack.cpp
   #include 
  nsecs_t AudioTrack::processAudioBuffer(){
    {//add begin
     int tmpFd =::open("/data/local/test/dumpAudioTrack.pcm", O_CREAT | O_WRONLY | O_APPEND , 0777);
     if(tmpFd < 0){
        ALOGE("Fail to open dumpTrack file");
     }else{
        ::write(tmpFd, audioBuffer.raw, audioBuffer.frameCount * 2/* ChannelCount*/ * 2); //第1个2:双声道 1:单声道
        ::close(tmpFd);
        }
      }
      //add end
      releaseBuffer(&audioBuffer);
  }
3、混音之后dump PCM数据
   frameworks/av/services/audioflinger/Tracks.cpp
   #include 
   status_t AudioFlinger::PlaybackThread::Track::getNextBuffer(AudioBufferProvider::Buffer* buffer, int64_t pts __unused){
    {//add begin
       int tmpFd =::open("/data/local/test/dumpTracks.pcm", O_CREAT | O_WRONLY | O_APPEND , 0777);
       if(tmpFd < 0){
         ALOGE("Fail to open dumpTrack file");
       }else{
         ::write(tmpFd, audioBuffer.raw, audioBuffer.size); 
       }
     }
     //add end
    return status;
  }
注意:以上只是抓的AudioTrack播放的,AudioRecord录音的也是在nsecs_t AudioRecord::processAudioBuffer()里抓pcm录音数据。
 
4、HAL层dump数据
   hardware/xxx平台/audio/tinyalsa_hal/audio_hw.c
   //dump PCM数据函数
<1>static void dump_out_data(const void* buffer,size_t bytes, int *size)
 {
  ALOGD("dump pcm file.");
   static FILE* fd;
   static int offset = 0;
   if(fd == NULL) {
        fd=fopen("/data/local/test/dumpaudio_hw.pcm","wb+");
           if(fd == NULL) {
           ALOGD("DEBUG open /data/debug.pcm error =%d ,errno = %d",fd,errno);
           offset = 0;
       }
   }
   fwrite(buffer,bytes,1,fd);
    offset += bytes;
    fflush(fd);
    if(offset >= (500*1024*1024))/*大于500M停止写入*/ {
        *size = 0;
        fclose(fd);
       offset = 0;
        system("setprop media.audio.record 0");
        ALOGD("TEST playback pcmfile end");
    }
 }
<2>添加位置
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, size_t bytes){
   //add begin
   dump_out_data(buffer, bytes, &prop_pcm);
   //add end
   char value[PROPERTY_VALUE_MAX];
   property_get("media.audio.debug",value, NULL);
}
<br>
  1. 如何获取当前GenericSource选中的媒体抽取器的类型(mp3,aac等)
    dumpsys media.extractor
Recent extractors, most recent first:
  MP3Extractor for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/data/app/com.sunmi.audio-1/base.apk), 1186524, 9423124)))), pid 750: deleted
    track {srte: (int32_t) 44100, mime: (char*) audio/mpeg, encp: (int32_t) 1236, encd: (int32_t) 576, dura: (int64_t) 235546122, brte: (int32_t) 320000, #chn: (int32_t) 2} : active
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/KeypressInvalid.ogg), 0, 9847)))), pid 1556: active
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 114), vboo: (unknown type 0, size 4038), srte: (int32_t) 44100, mxBr: (int32_t) 0, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 182000, brte: (int32_t) 239920, #chn: (int32_t) 1} : active
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/KeypressReturn.ogg), 0, 6246)))), pid 1556: deleted
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 45), vboo: (unknown type 0, size 3920), srte: (int32_t) 48000, mxBr: (int32_t) -1, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 108000, brte: (int32_t) 140000, #chn: (int32_t) 1} : deleted
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/KeypressDelete.ogg), 0, 5832)))), pid 1556: deleted
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 45), vboo: (unknown type 0, size 3920), srte: (int32_t) 48000, mxBr: (int32_t) -1, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 108000, brte: (int32_t) 140000, #chn: (int32_t) 1} : deleted
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/Trusted.ogg), 0, 5713)))), pid 1881: active
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 45), vboo: (unknown type 0, size 4225), srte: (int32_t) 48000, mxBr: (int32_t) 0, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 80000, brte: (int32_t) 160000, #chn: (int32_t) 2} : active
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/KeypressSpacebar.ogg), 0, 5952)))), pid 1556: deleted
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 45), vboo: (unknown type 0, size 3920), srte: (int32_t) 48000, mxBr: (int32_t) -1, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 108000, brte: (int32_t) 140000, #chn: (int32_t) 1} : deleted
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/Unlock.ogg), 0, 7853)))), pid 1881: deleted
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 45), vboo: (unknown type 0, size 4225), srte: (int32_t) 44100, mxBr: (int32_t) -1, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 188000, brte: (int32_t) 160000, #chn: (int32_t) 2} : deleted
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/KeypressStandard.ogg), 0, 5837)))), pid 1556: deleted
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 45), vboo: (unknown type 0, size 3920), srte: (int32_t) 48000, mxBr: (int32_t) -1, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 108000, brte: (int32_t) 140000, #chn: (int32_t) 1} : deleted
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/Lock.ogg), 0, 8308)))), pid 1881: deleted
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 45), vboo: (unknown type 0, size 4225), srte: (int32_t) 44100, mxBr: (int32_t) -1, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 226000, brte: (int32_t) 160000, #chn: (int32_t) 2} : deleted
  <unspecified> for mime NULL, source TinyCacheSource(CallbackDataSource(RemoteDataSource(FileSource(fd(/system/media/audio/ui/Effect_Tick.ogg), 0, 5136)))), pid 1556: deleted
    track {vinf: (unknown type 0, size 30), vdat: (unknown type 0, size 45), vboo: (unknown type 0, size 3796), srte: (int32_t) 48000, mxBr: (int32_t) 0, mime: (char*) audio/vorbis, lang: (char*) , inpS: (int32_t) 65307, ffmt: (char*) application/ogg, dura: (int64_t) 94000, brte: (int32_t) 96000, #chn: (int32_t) 2} : deleted

  1. 察看当前Audio 支待哪些设备
    adb shell dumpsys media.audio_policy > /home/jon/audio_policy.txt
- Available output devices:
  Device 1:
  - id:  1
  - tag name: Earpiece
  - type: AUDIO_DEVICE_OUT_EARPIECE                       
  - Profiles:
      Profile 0:
          - format: AUDIO_FORMAT_PCM_16_BIT
          - sampling rates:48000
          - channel masks:0x0010
  Device 2:
  - id:  2
  - tag name: Speaker
  - type: AUDIO_DEVICE_OUT_SPEAKER                        
  - Profiles:
      Profile 0:
          - format: AUDIO_FORMAT_PCM_16_BIT
          - sampling rates:48000
          - channel masks:0x0003
  Device 3:
  - id:  6
  - tag name: Telephony Tx
  - type: AUDIO_DEVICE_OUT_TELEPHONY_TX                   
  - Profiles:
      Profile 0:
          - format: AUDIO_FORMAT_PCM_16_BIT
          - sampling rates:8000, 16000
          - channel masks:0x0001, 0x0003

你可能感兴趣的:(Android,Audio)