I am designing an android app where i receive live mp3 data as stream from Red5 server and i need to play it.
I cant play it using media player class as i don't have any url for the stream, nor i cant use files. Another option is to use Audio track class, but requires PCM data only. So need to convert mp3 to pcm, so using ffmpeg.
My code for conversion is
AVCodec *codec;
AVCodecContext *c= NULL;
int out_size, len;
uint8_t *outbuf;
int iplen=(*env)->GetArrayLength(env, mp3buf);
int16_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
AVPacket avpkt;
av_init_packet(&avpkt);
av_register_all();
avcodec_register_all();
codec = avcodec_find_decoder(CODEC_ID_MP3);
if(!codec){
__android_log_print(ANDROID_LOG_DEBUG, "logfromjni", "Codec not found");
}
c = avcodec_alloc_context();
outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
avpkt.data = (*env)->GetByteArrayElements(env,mp3buf,NULL);
avpkt.size = (*env)->GetArrayLength(env, mp3buf);
out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
int ao=avcodec_open(c, codec);
if (ao < 0) {
__android_log_print(ANDROID_LOG_DEBUG, "logfromjni", "avcodec not open");
}
len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt);
The Problem is avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt);
returns -1 always.
Cant figure out whats wrong.
Any help appreciated.