[FFmpeg-devel] Patch to close ticket 2873 (enhancement)
Nicolas George
george at nsup.org
Mon Jan 6 09:14:37 CET 2014
Le septidi 17 nivôse, an CCXXII, kad kadmandu a écrit :
> 2014/1/6 kad kadmandu <kadmandux at gmail.com>
Please remember not to top-post.
> diff -r -u a/libavformat/avformat.h b/libavformat/avformat.h
"git format-patch" or "git send-email" is the recommended way of preparing
patches, since it allow for easy inclusion, with author information and so.
> --- a/libavformat/avformat.h 2014-01-06 01:10:24.000000000 +0000
> +++ b/libavformat/avformat.h 2014-01-06 01:19:31.000000000 +0000
> @@ -1484,6 +1484,9 @@
> * @}
> */
>
> +int av_compare_streams(const void *st1, const void *st2);
> +void av_sort_streams_by_id(AVFormatContext *s);
I really think these should not be public. Especially the first one, with
its strange types for arguments (yes, I know how qsort works).
And if they are public, the documentation is missing.
> +
>
> #if FF_API_ALLOC_OUTPUT_CONTEXT
> /**
> diff -r -u a/libavformat/utils.c b/libavformat/utils.c
> --- a/libavformat/utils.c 2014-01-06 01:10:09.000000000 +0000
> +++ b/libavformat/utils.c 2014-01-06 02:04:01.000000000 +0000
> @@ -3215,6 +3215,11 @@
> if(ic->pb)
> av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n",
> avio_tell(ic->pb), ic->pb->bytes_read, ic->pb->seek_count, count);
> +
> + /* Reorder streams if the format requires it.*/
> + if (ic->ctx_flags & AVFMTCTX_NOHEADER)
> + av_sort_streams_by_id(ic);
Did you check that doing that actually works? Right there, I can see that
you will leave the AVStream.index inconsistent, and I suspect that the
packets already read by avformat_find_stream_info() will be inconsistent
too.
Also, I do not think that it should be done for MPEG-TS, where the streams
are actually declared in a particular order.
Last: what happens if the application has read frames by itself before
calling avformat_find_stream_info()? In that case, I am afraid the order of
the streams will change underfoot.
> +
> return ret;
> }
>
> @@ -3472,6 +3477,20 @@
> return st;
> }
>
> +int av_compare_streams(const void *st1, const void *st2)
> +{
> + return (((*(AVStream **)st1)->id > (*(AVStream **)st2)->id) ? 1 :
> + ((*(AVStream **)st1)->id < (*(AVStream **)st2)->id) ? -1 : 0);
> +}
> +
> +void av_sort_streams_by_id(AVFormatContext *s)
> +{
> + qsort((void *)s->streams, s->nb_streams, sizeof(s->streams[0]), av_compare_streams);
> + /*Adjust the indexes */
> + for (int i=0;i<s->nb_streams;i++)
> + s->streams[i]->index = i;
> +}
> +
> AVProgram *av_new_program(AVFormatContext *ac, int id)
> {
> AVProgram *program=NULL;
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140106/23c3f9ec/attachment.asc>
More information about the ffmpeg-devel
mailing list