[FFmpeg-devel] [PATCH] Add support for private PES streams in mpegts and support for application decoding the stream
Sebastian Cabot
scabot
Sat May 30 21:42:06 CEST 2009
This patch adds the following
In libavformat/mpegts.c support for private_stream_2, ECM_stream,
EMM_stream and padding_stream
In libavcodec a new codec that will forward the decoding requests to
the application cdproxy.c
Support for a new function avcodec_decode_data
This patch contains changes also to AVCodecContext and AVFormatContext
I use it to parse private data in our streams and in a bug report I
opened bcoudurier suggested that I may upload this as a patch.
Here is an outline on how to use the new functionality (this is only
an illustration I'm not sure it compiles as is)
???? #include <libavcodec/avcodec.h>
???? typedef struct CDProxyContext
???? {
??????? void*??? user_context;
???? }CDProxyContext;
??? int my_decode_init(AVCodecContext *avctx)
??? {
??? ??? CDProxyContext *pC = (CDProxyContext *)avctx->priv_data;
??? ??? MyDecodeContext *q = av_mallocz(sizeof(MyDecodeContext));
??? ??? pC->user_context = q;
??? ??? return 0;
??? }
??? int my_decode_frame(AVCodecContext *avctx,
??? ??? ??? ???????????????????????????? void *data, int *data_size,
??? ??? ??? ???????????????????????????? AVPacket *avpkt)
??? {
??? ??? int ret = 0;
??? ??? const uint8_t *buf = avpkt->data;
??? ??? int buf_size = avpkt->size;
??? ??? AVFrame *data_frame = (AVFrame *)data;
??? ??? int offset = 0;
??? ??? CDProxyContext *pC = (CDProxyContext *)avctx->priv_data;
??? ??? MyDecodeContext *q = (MyDecodeContext *)pC->user_context;
??? ??? /**
??? ??? * PROCESS THE INPUT
??? ??? */
??? ??? return ret;
??? }
??? int my_decode_close(AVCodecContext *avctx)
??? {
??? ??? CDProxyContext *pC = (CDProxyContext *)avctx->priv_data;
??? ??? MyDecodeContext *q = (MyDecodeContext *)pC->user_context;
??? ??? if(q)
??? ??? ??? av_free(q);
??? ??? /* Return 0 if everything is ok, -1 if not */
??? ??? return 0;
??? }
??? int is_stream_supported(int stream_type, void*)
??? {
??? ??? return (stream_type == MY_STREAM_TYPE)?1:0;
??? }
??? int main(int arcx, char** argv)
??? {
??? ??? AVFormatContext *pFormatCtx = avformat_alloc_context();
??? ??? AVFormatParameters aP;
??? ??? AVStream* st = 0;
??? ??? AVCodecContext* pCodecCtx = 0;
??? ??? AVCodec* pCodec;
??? ??? int i, cI, got_data;
??? ??? uint8_t data[1024];
??? ??? AVPacket packet;
??? ??? pFormatCtx->is_user_codec_stream = is_stream_supported;
??? ??? memset(&aP, 0, sizeof(AVFormatParameters));
??? ??? aP.prealloced_context = 1;
??? ??? if(av_open_input_file(&pFormatCtx, argv[0], 0, 0, &aP)!=0)
??? ??? ??? goto error_cleanup;
??? ??? if(!pFormatCtx->nb_streams)
??? ??? ??? goto error_cleanup;
??? ??? if(av_find_stream_info(pFormatCtx)<0 )
??? ??? ??? goto error_cleanup;
??? ??? for(i = 0; i < pFormatCtx->nb_streams; i++)
??? ??? {
??? ??? ??? if(pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_DATA)
??? ??? ??? {
??? ??? ??? ??? cI = i;
??? ??? ??? ??? st = pFormatCtx->streams[i];
??? ??? ??? ??? pCodecCtx = st>codec;
??? ??? ??? ??? break;
??? ??? ??? }
??? ??? }
??? ??? if(pCodecCtx)
??? ??? {
??? ??? ??? memset(&packet, 0, sizeof(packet));
??? ??? ??? pCodecCtx->user_codec_init = elttmd_decode_init;
??? ??? ??? pCodecCtx->user_codec_close = elttmd_decode_close;
??? ??? ??? pCodecCtx->user_codec_decode = elttmd_decode_frame;
??? ??? ??? if(avcodec_open(pCodecCtx, pCodec)<0)
??? ??? ??? ??? goto error_cleanup;
??? ??? ??? for(;;)
??? ??? ??? {
??? ??? ??? ??? if(av_read_frame(pCodecCtx->pFormatCtx, &packet) < 0)
??? ??? ??? ??? ??? break;
??? ??? ??? ??? if(cI == packet.stream_index)
??? ??? ??? ??? {
??? ??? ??? ??? ??? avcodec_decode_data(pCodecCtx, data, &got_data, &packet);
??? ??? ??? ??? ??? if(got_data)
??? ??? ??? ??? ??? ??? /* DO SOMETHING*/
??? ??? ??? ??? }
??? ??? ??? ??? av_free_packet(&packet);
??? ??? ??? }
??? ??? }
??? ??? error_cleanup:
??? ??? return 0;
??? }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: support_private.patch
Type: application/octet-stream
Size: 12739 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090530/bd53b018/attachment.obj>
More information about the ffmpeg-devel
mailing list