OldStory/Android
                
              OpenSL ES for ffmpeg
                Alnilam
                 2012. 5. 3. 14:37
              
              
                    
        반응형
    
    
    
  OpenSL ES
- Native language application-level audio API for embedded mobile multimedia devices.
 - Device independent
 - Cross-platform interface for applications to access a devices audio capabilities.
 - Android에서 Platform 9 에서 부터 지원 한다.
 - NDK 풀더의 Platforms/android-9/arch-arm/usr/include/SLES 풀더에 관련 헤더 파일이 있다.
 
Android NDK Native-Audio Sample
- ndk/samples/native-audio 에 위치
 - OpenSL ES 사용하여 mp3 파일 재생, uri 재생, queue 재생 하는 프로그램
 - ffmpeg 에서 디코딩 오디오 데이터를 재생 하려면 queue 재생 방법을 참조 한다.
 - Native Audio.java 에서 queue 재생을 위한 주요 Native 함수는 다음과 같다.
- createEngine() - create the engine and output mix objects
- Java_com_example_nativeaudio_NativeAudio_createEngine() 함수를 호출 한다.
 - Audio player object와 mixer object를 생성 한다.
 
 - createBufferQueueAudioPlayer() - create buffer queue audio player
- Java_com_example_nativeaudio_NativeAudio_createBufferQueueAudioPlayer() 함수를 호출 한다.
 - buffer queue audio player를 생성한다.
 - PCM 데이터의 비트레이트와 채널 수는 SLDataFormat_PCM 구조체를 사용하여 설정 한다.
 - SLAndroidSimpleBufferQueueItf 의 Enqueue() 함수를 통해 지정된 버퍼의 내용을 재생 한다.
 - 지정된 버퍼 재생이 끝나면 SLAndroidSimpleBufferQueueItf 의 RegisterCallback 함수에 등록된 callback 함수가 호출 된다.
 - callback 함수에서 다음 데이터의 버퍼 주소를 넣어 주어 재생이 이루어 진다.
 
 - selectClip() - audio buffer select and loop count setting
- Java_com_example_nativeaudio_NativeAudio_selectClip() 함수를 호출 한다.
 - audio buffer clip를 선택하고 Enqueue() 함수 호출 하여 오디오 재생을 시작 한다.
 
 
 - createEngine() - create the engine and output mix objects
 - SLDataFormat_PCM
/** PCM-type-based data format definition where formatType must be SL_DATAFORMAT_PCM*/
typedef struct SLDataFormat_PCM_ {
SLuint32 formatType;
SLuint32 numChannels;
SLuint32 samplesPerSec;
SLuint32 bitsPerSample;
SLuint32 containerSize;
SLuint32 channelMask;
SLuint32 endianness;
} SLDataFormat_PCM; 
- ffmpeg 에서 디코딩된 오디오 데이터의 형식를 보고 SLDataFormat_PCM 에 정의해 주어야 정상적으로 오디오가 재생 된다.
 - AVCodecContext 의 sample_rate, sample_fmt 와 channel 값등을 참조 하면 된다.
 
반응형