On Thu, 03 Oct 2013 14:34:55 +0300
 "Vitsas Nikolaos" <[email protected]> wrote:
Hi guys.

I'm currently encoding a H264 stream into RTP packets using libavformat and storing them in memory using avio_open_dyn and avio_close_dyn. The thing is that those packets are going to reach a destination going through some intermediate peers using a custom P2P structure. Everything reaches the destination correctly and as expected, but I can' t get the custom I/O setup on the destination to work correctly so that the packets can be decoded.

Here' s what I am doing right now. sdp_desc holds the SDP description and custom_queue is a queue full of RTP Packets as encoded by the source.

// C O D E
fmt_ctx = avformat_alloc_context();     
if(!fmt_ctx) {  
        return false;
}

io_buffer = (BYTE*)av_malloc((IO_BUFFER_SIZE+FF_INPUT_BUFFER_PADDING_SIZE)*sizeof(BYTE)); BYTE* sdp_buffer = (BYTE*)av_malloc((strlen(sdp_desc)+FF_INPUT_BUFFER_PADDING_SIZE)*sizeof(BYTE));

sdp_io_context = avio_alloc_context(sdp_buffer, strlen(sdp_desc), 0, nfo, &ReadFunc, NULL, NULL);
avio_open2(&sdp_io_context, "", AVIO_FLAG_READ, NULL, NULL);

if(!sdp_io_context)
        return false;

sdp_io_context->seekable = 0;
sdp_io_context->write_flag = 0;

strcpy((char*)sdp_buffer, sdp_desc);
AVProbeData probeData;
probeData.buf = sdp_buffer;
probeData.buf_size = strlen(sdp_desc);
probeData.filename = "";

fmt_ctx->pb = sdp_io_context;
fmt_ctx->flags = AVFMT_FLAG_CUSTOM_IO;
fmt_ctx->iformat = av_probe_input_format(&probeData, 1);

AVDictionary *options = NULL;
av_dict_set(&options, "sdpflags", "custom_io", 0);
int err = avformat_open_input(&fmt_ctx, "", NULL, &options);
//int err = avformat_open_input(&fmt_ctx, "", fmt_ctx->iformat, &options);

io_context = avio_alloc_context(io_buffer, IO_BUFFER_SIZE, 1, custom_queue, &ReadRTPFunc, &WriteRTPFunc, NULL);
avio_open2(&io_context, "", AVIO_FLAG_READ_WRITE, NULL, NULL);
if(!io_context)
        return false;
io_context->seekable = 0;

AVInputFormat* fr = av_find_input_format("rtp");

fmt_ctx->pb = io_context;
fmt_ctx->iformat = fr;
video_dec_ctx = fmt_ctx->streams[0]->codec;
video_dec = avcodec_find_decoder(video_dec_ctx->codec_id);
if (!video_dec) {
        printf("Failed to find %s codec\n",
                "H264");
        return false;
}

if ((ret = avcodec_open2(video_dec_ctx, video_dec, NULL)) < 0) {
        printf("Failed to open %s codec\n",
                    "H264");
        return false;
}

thre ReadFunc looks like this
static int ReadFunc(void *opaque, uint8_t *buf, int buf_size) {
        char* sdp = (char*)opaque;

        strcpy((char*)buf, sdp);

        return strlen(sdp);
}

ReadFunc is called and the AVInputFormat in the AvFormatContext correctly gets initialized to SDP and the codec is correctly set to H264. However, ReadFunc is called again requesting more data and the only thing I can do, is return 0 or the same sdp data. Despite the above, av_open_input returns with no error but when I make the switch to the RTP AVIOContext, av_read_frame does not do anything and just returns after a while not calling any of my other callbacks.

Any help would be appreciated. Thank you.
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

To make things simpler, can someone at least verify that setting sdpflags=customio is enough for Custom RTP handling? Is there something else I need to do?

_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to