audio - Http Streaming from ffmpeg, How to get a sequenced packet? -


I'm trying to create http streaming program.
That's why I follow this code.
However, when I decode, only one frame has been decoded.
I think I need to call the function back.
Do you know how to call back the function?
I know the call back function of 'ASF' packet is such as integer read_data (zero * opaque, four * buf, integer buf_size)

but other formats (MP3 , Ogg, AAC, ..) does not work ..

Please help me.

Any advice or comment is highly appreciated.

  #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Libavcodec / avcodec.h & gt; # Include & lt; Libavformat / avformat.h & gt; # Include & lt; Libavdevice / avdevice.h & gt; Int main (int argc, char ** argv) {static AVInputFormat * file_iformat; Fixed AVFormatContext * pFormatCtx; AVAFormat parameter parameters; AVCodecContext * pCodecCtx; AVCodec * pCodec; Const four URL [] = "http://listen.radionomy.com/feelingfloyd"; Avcodecregister_all (); Avdevice_register_all (); Av_register_all (); Av_log_set_level (av_LOG_VERBOSE); File_iformat = av_find_input_format ("mp3"); / * Mp3 demuxer * / if (! File_formatat) {fprintf (stderr, "unknown input format:% s \ n", and url [0]); Exit (1); } // file_iformat-> Flags | = AVFMT_NOFILE; / * ??? * / Params.prealloced_context = 0; If (av_open_input_file (& amp; pFormatCtx, & amp; URL [0], file_iformat, 0, & amp; parameters) = 0) {fprintf (stderr, "fault1 \ n"); Exit (2); } / * Poulates AVFormatContex structure * / if (av_find_stream_info (pFormatCtx) & lt; 0) {fprintf (stderr, "fault 2 \ n"); } / * Mental health check (1 section) * / if (! PFormatCtx- & gt; nb_streams = 1 & amp; amp; amp; amp; amp; pFormatCtx- & gt; streams [0] -> codec-> codec_type = AVMEDIA_TYPE_AUDIO) {fprintf (stderr, "Error 3 \ n"); } PCodecCtx = pFormatCtx-> Stream [0] - & gt; Codec; / * Find decoder for input audio stream * / pCodec = avcodec_find_decoder (pCodecCtx-> codec_id); If (pCodec == NULL) {fprintf (stderr, "Gail 4: unsupported codec \ n"); } If (pCodec-> Capabilities and CODEC_CAP_TRUNCATED) pCodecCtx-> Flags | = CODEC_FLAG_TRUNCATED; If (avcodec_open (pCodecCtx, pCodec) & lt; 0) {fprintf (stderr, "Error 5 \ n"); } {Uint8_t * pAudioBuffer; AVPKET PKT; Int rate; Int data_ size = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE; Av_init_packet (& amp; pkt); //pkt.data=NULL; //pkt.size=0; //pkt.stream_index = 0; PAudioBuffer = av_malloc (data_ size * sizeof (int16_t)); While (av_read_frame (pFormatCtx, & amp; pkt) == 0) {// data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; Retired = avcodec_decode_audio3 (pFormatCtx-> streams [pkt.stream_index] - & gt; codec, (int16_t *) pAudioBuffer, & amp; data_size, & amp; pkt); / * Got an error (-32) * / if (rate at lieutenant; 0) {av_strerror (ret, (char *) pAudioBuffer, data_size); Fprintf (stderr, "Error 6 (% s) \ n", pAudioBuffer); break; } Printf ("size =% d, stream_index =% d | ret =% d data_size =% d \ n", pkt.size, pkt.stream_index, ret, data_size); Av_free_packet (& amp; pkt); } Av_free (pAudioBuffer); } Avcodec_close (pCodecCtx); Av_close_input_file (pFormatCtx); Return 0; }    

I use this problem by using av_open_input_file Find out
I got a problem when I made an iPhone app that runs HTU audio streaming. And the above code was not working, only played some audio frames, it means that there are so many buffering.
However, after using the iPhone audio callback function and large audio buffer, it works fine.
who are keen about the final code, send me a message.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -