Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6560475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:27:55+00:00 2026-05-25T13:27:55+00:00

I am trying to make http streaming program. So I follow this code at

  • 0

I am trying to make http streaming program.
So I follow this code at this.
However, when i decode, only one frame is decoded.
I think I need call back function.
Do you know how to make a call back function?
I know ‘asf’ packet’s call back function is like int read_data(void *opaque, char *buf, int buf_size)

But the other formats(mp3, ogg, aac, ..) doesn’t work..

Please help me.

Any advice or comment are very appreciated.

#include <stdio.h>
#include <stdlib.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>

int main(int argc, char **argv)
{
        static AVInputFormat *file_iformat;
        static AVFormatContext *pFormatCtx;
        AVFormatParameters params;

        AVCodecContext *pCodecCtx;
        AVCodec *pCodec;

        const char url[] = "http://listen.radionomy.com/feelingfloyd";

        avcodec_register_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_iformat)
        {
                fprintf(stderr, "Unknown input format: %s\n", &url[0]);
                exit(1);
        }

        //file_iformat->flags |= AVFMT_NOFILE; /* ??? */
        params.prealloced_context = 0;

        if (av_open_input_file(&pFormatCtx, &url[0], file_iformat, 0, &params) != 0)
        {
                fprintf(stderr, "err 1\n");
                exit(2);
        }

        /* poulates AVFormatContex structure */
        if (av_find_stream_info(pFormatCtx) < 0)
        {
                fprintf(stderr, "err 2\n");
        }

        /* sanity check (1 stream) */
        if (pFormatCtx->nb_streams != 1 &&
                        pFormatCtx->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO)
        {
                fprintf(stderr, "err 3\n");
        }

        pCodecCtx = pFormatCtx->streams[0]->codec;

        /* find decoder for input audio stream */
        pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
        if (pCodec == NULL)
        {
                fprintf(stderr, "err 4: unsupported codec\n");
        }

        if (pCodec->capabilities & CODEC_CAP_TRUNCATED)
                pCodecCtx->flags |= CODEC_FLAG_TRUNCATED;

        if (avcodec_open(pCodecCtx, pCodec) < 0)
        {
                fprintf(stderr, "err 5\n");
        }

        {
                uint8_t *pAudioBuffer;
                AVPacket pkt;

                int ret;
                int data_size = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE;

                av_init_packet(&pkt);
                //pkt.data=NULL;
                //pkt.size=0;
                //pkt.stream_index = 0;

                pAudioBuffer = av_malloc(data_size * sizeof(int16_t));

                while (av_read_frame(pFormatCtx, &pkt) == 0) {
                        //data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
                        ret = avcodec_decode_audio3(pFormatCtx->streams[pkt.stream_index]->codec,
                                        (int16_t *)pAudioBuffer, &data_size, &pkt);

                        /* got an error (-32) here */
                        if (ret < 0) {
                                av_strerror(ret, (char *)pAudioBuffer, data_size);
                                fprintf(stderr, "err 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(&pkt);
                }

                av_free(pAudioBuffer);
        }

        avcodec_close(pCodecCtx);
        av_close_input_file(pFormatCtx);

        return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:27:55+00:00Added an answer on May 25, 2026 at 1:27 pm

    I figure out this problem by using av_open_input_file.
    I got a this problem when I made a iphone app that play http audio streaming. And the above code didn’t work. only played just some of audio frame. it also means there are so many buffering.
    However After using iphone audio callback function and large audio buffer, it works fine.
    Those who are curious about the final code send me a messege.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a working program from this example: http://msdn.microsoft.com/en-us/library/ms741870.aspx . I think
I'm trying to make a python binding for the this library: http://code.google.com/p/hosterslib/ . I'm
I'm trying to make a http request. The code looks like this: NSString *urlString
I'm trying to make a simple HTTP post a endpoint with ONLY url arguments.
I'm trying to make a connection pool following this link: http://192.9.162.55/developer/onlineTraining/Programming/JDCBook/conpool.html I don't understand
I'm trying to make my URL look like this: http://domain.com/controller/action/123/SomeTextForSEO I tried using an
Im trying to make a simple HTTP URLReqest in Adobe Flex, heres the code
i'm trying to make this address: http://www.mysite.co.uk/Listing/London/34 really look for: http://www.mysite.co.uk/Listing/listed.php?area=London&list=34 behind the scenes.
I'm trying to make this jquery plugin => http://leandrovieira.com/projects/jquery/lightbox/ work with multiple galleries on
I am trying to make it so the container on this page http://s72956.gridserver.com/dev/toggle.html# will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.