How to disable buffering on a stream?
For file streams, you can use pubsetbuf
for that :
std::ifstream f;
f.rdbuf()->pubsetbuf(0, 0);
f.open("test");
Explanation
The C++ standard says the following about the effect of setbuf
(and thus pubsetbuf
) for file streams :
If
setbuf(0,0)
is called on a stream before any I/O has occurred on that stream, the stream
becomes unbuffered. Otherwise the results are implementation-defined. “Unbuffered” means that
pbase()
andpptr()
always return null and output to the file should appear as soon as possible.
The first sentence guarantees that the above code makes the stream unbuffered. Note that some compilers (eg. gcc) see opening a file as an I/O operation on the stream, so pubsetbuf
should be called before opening the file (as above).
The last sentence, however, seems to imply that that would only be for output, and not for input. I'm not sure if that was an oversight, or whether that was intended. Consulting your compiler documentation might be useful. For gcc eg., both input and output are made unbuffered (ref. GNU C++ Library Manual - Stream Buffers).
Disabling Chrome buffering when streaming text data
Add X-Content-Type-Options: nosniff
to your headers and let me know how it goes for you.
According to Mozilla Docs:
The
X-Content-Type-Options
response HTTP header is a marker used by
the server to indicate that the MIME types advertised in the
Content-Type
headers should not be changed and be followed. This
allows to opt-out of MIME type sniffing, or, in other words, it is a
way to say that the webmasters knew what they were doing.
Qt::QMediaPlayer: how to disable frame buffering to reduce the RTSP streaming delay or latency?
Finally!
After a lots of seaching and trying, I finally found a kind of weird way to fix this issue:
Using 'setPlaybackRate()' to set playback rate to zero, other then a
value bigger than the real fps to prevent the RTSP buffering.
void AmbaRemoteCam::slot_btnConnectRtsp_Clicked()
{
m_player->setMedia(QUrl(m_mediaUrl->text()));
m_player->setPlaybackRate(0);
m_player->play();
}
Nobody would think of using this method to prevent the RTSP buffering.
Hope next version of QMediaPlayer has a more humane interface to fix this issue.
Related Topics
How to Make Template Rvalue Reference Parameter Only Bind to Rvalue Reference
How Computer Does Floating Point Arithmetic
How to Use Std::Imbue to Set the Locale for Std::Wcout
C++ Abstract Class Without Pure Virtual Functions
When Extending a Padded Struct, Why Can't Extra Fields Be Placed in the Tail Padding
When Instantiating a Template, Should Members of Its Incomplete Argument Types Be Visible
How to Compare Two Time Stamp in Format "Month Date Hh:Mm:Ss" to Check +Ve or -Ve Value
C++ Error, Undefined Reference Class
Initializing the Size of a C++ Vector
Does 'Auto' Type Assignments of a Pointer in C++11 Require '*'
Does a C/C++ Compiler Optimize Constant Divisions by Power-Of-Two Value into Shifts
Ternary Conditional and Assignment Operator Precedence
Uses for Negative Zero Floating Point Value
Do These Members Have Unspecified Ordering
Arithmetic Right Shift Gives Bogus Result
C++ Read/Write Class From/To Binary File
How to Solve -------Undefined Reference to '_Chkstk_Ms'-------On Mingw