[FFmpeg-devel] [PATCH 1/2] file: operate in blocks, check for interrupts

Andrey Utkin andrey.krieger.utkin at gmail.com
Mon Jul 8 17:41:22 CEST 2013


2013/7/8 Michael Niedermayer <michaelni at gmx.at>:
> isnt it sufficient to simply limit size without any loop ?

Yes, it is sufficient.

> also, by how much does this patch improve reactiveness ?

Currently i have such facts:
1. File reading is works through retry_transfer_wrapper(). There it
tries to read full block _first_. I.e. avio.interrupt_callback is not
checked before reading the block, and also no interrupt_callback check
if block is fully read. This is usually the case with generic files.
2. avformat_find_stream_info() on mpegts file reads the file in blocks of 32768.
3. avformat_find_stream_info() calls subroutine
estimate_timings_from_pts(), which ignores AVERROR_EXIT it its loops.

My conclusions:
1. It is not optimal for reactiveness to have interrupt check after
I/O processing. But this is optimal for performance, so we can live
with it. Also it is undesirable to change this behaviour because some
applications may depend on the above fact.
2. To the above: if there are more voices for it, we could optionize
this behaviour (so user can choose between performance and
reactiveness optimization).
3. Returning block of limited size on read request of larger size
reduces needed time, but still takes its time to read the block,
because interrupt check is done in retry_transfer_wrapper() _after_
the block is read. The same check may be added inside of
file_read()/file_write(), but that is a sort of code duplication.

You can reproduce my observations with attached file_reading.c. It
uses recent libavformat, with patch which i attach, too.

Below goes the output of file_reading.c compiled. Tests were run with
simply locally stored file, so timings are not representative for net
disks case; but note the log messages which represent real amounts of
read data, and general consistency/adequacy of behaviour.
The point of test is that before avformat_find_stream_info() we set up
an interrupt callback which returns true after countdown from 10 to 0.
Please read file_reading.c code first to better understand meaning of
output. Sorry that output messages are not intuitive.

The run with blocksize option disabled (current upstream behaviour):

 $ ./a.out
avio_open2: 72 mcs
[file @ 0xa98b540] requested read of 32768 bytes, returning 32768
avformat_open_input: 1524 mcs
avformat triggered. countdown 10
avformat triggered. countdown 9
avformat triggered. countdown 8
avformat triggered. countdown 7
avformat triggered. countdown 6
avformat triggered. countdown 5
avformat triggered. countdown 4
avformat triggered. countdown 3
avformat triggered. countdown 2
avformat triggered. countdown 1
avformat triggered. countdown 0
[file @ 0xa98b540] requested read of 32768 bytes, returning 32768
[file @ 0xa98b540] requested read of 32768 bytes, returning 32768
[file @ 0xa98b540] requested read of 32768 bytes, returning 32768
[file @ 0xa98b540] requested read of 32768 bytes, returning 32768
[file @ 0xa98b540] requested read of 32768 bytes, returning 32768
[file @ 0xa98b540] requested read of 32768 bytes, returning 32768
[file @ 0xa98b540] requested read of 32768 bytes, returning 32768
[file @ 0xa98b540] requested read of 32768 bytes, returning 20624
avio triggered. countdown -1
avformat_find_stream_info: 12081 mcs



The run with blocksize=4096

 $ ./a.out
avio_open2: 106 mcs
[file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. [file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. [file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. avformat_open_input: 2675 mcs
avformat triggered. countdown 10
[file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. countdown 9
avformat triggered. countdown 8
avformat triggered. countdown 7
avformat triggered. countdown 6
avformat triggered. countdown 5
avformat triggered. countdown 4
avformat triggered. countdown 3
avformat triggered. countdown 2
avformat triggered. countdown 1
avformat triggered. countdown 0
[file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. countdown -1
[file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. countdown -2
[file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. countdown -3
[file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. countdown -4
[file @ 0xad5c640] requested read of 32768 bytes, returning 4096
avio triggered. countdown -5
avformat_find_stream_info: 11217 mcs

--
Andrey Utkin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file_reading.c
Type: text/x-csrc
Size: 2024 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130708/5007c816/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-file-operate-in-blocks-check-for-interrupts.patch
Type: application/octet-stream
Size: 2088 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130708/5007c816/attachment.obj>


More information about the ffmpeg-devel mailing list