[flac-dev] Windows file buffering
Christoph Terasa
cterasa at googlemail.com
Thu Dec 10 09:48:14 PST 2015
On 12/10/2015 5:58 PM, lvqcl wrote:
> Erik de Castro Lopo wrote:
>> lvqcl,
>>
>> Would you be able to have alook at this one? I think its
>> Windows related:
>>
>> https://sourceforge.net/p/flac/feature-requests/114/
>>
>
> The relevant changes are
> <http://git.xiph.org/?p=flac.git;a=commitdiff;h=6a6207b52a86b1d7980a5233e297c0fc948bed7d>
> and
> <http://git.xiph.org/?p=flac.git;a=commitdiff;h=e8632477774f56b4fe7ccab525cad2ceab244b8a>
>
>
> the current code:
>
> #ifdef _WIN32
> /*
> * Windows can suffer quite badly from disk fragmentation. This
> can be
> * reduced significantly by setting the output buffer size to be
> 10MB.
> */
> setvbuf(file, NULL, _IOFBF, 10*1024*1024);
> #endif
>
>
> LRN <lrn1986 at gmail.com> wrote:
>
>> The commit mentioned in the feature request should not cause such
>> behaviour, as it only does short-lived operations (opens a file, does
>> stuff, closes the file immediately after) and is clearly distinguishing
>> between disk files and pipes (which is how you, presumably, stream
>> data to
>> other processes for whatever reasons).
>>
>> I don't claim that FLAC doesn't do buffering, as the OP described, just
>> that this commit is unlikely to be the cause.
>
> Maybe you mean some other commit? For example,
> <http://git.xiph.org/?p=flac.git;a=commitdiff;h=d66f6754bf94bc8ba23d3579d0b5650cd380c9f0>
> ?
> Because setvbuf() should definitely change libFLAC behaviour
> regardless of files/pipes/etc.
>
>
> The attached patch *should* resolve the issue. libFLAC will call
> setvbuf(file, ...)
> only if GetFileType(...file...) == FILE_TYPE_DISK.
I probably don't know enough about the intricates of Win32, but why not
prefer this for clarity:
diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c
index 203a271..0394c26 100644
--- a/src/libFLAC/stream_encoder.c
+++ b/src/libFLAC/stream_encoder.c
@@ -1330,7 +1330,8 @@ static FLAC__StreamEncoderInitStatus
init_FILE_internal_(
* Windows can suffer quite badly from disk fragmentation. This
can be
* reduced significantly by setting the output buffer size to
be 10MB.
*/
- setvbuf(file, NULL, _IOFBF, 10*1024*1024);
+ if(file != stdout)
+ setvbuf(file, NULL, _IOFBF, 10*1024*1024);
#endif
encoder->private_->file = file;
Does libFLAC support other output types except for pipes/stdout and files?
Also, if you want to be really evil you could even just use *else* and
have the #ifdef _WIN32 block depend on the relative position to the if
above...
>
>
> _______________________________________________
> flac-dev mailing list
> flac-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/flac-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/flac-dev/attachments/20151210/183eacb5/attachment.htm
More information about the flac-dev
mailing list