I’ve been told of a patch for ffmpeg that fixes an issue when streaming to FLV players.
Around line 2314 of rtmpproto.c there is the following expression:
if (rt->flv_header_bytes < 11)
break;
The fix is to change it to include this additional requirement:
if (rt->flv_header_bytes < 11 && !rt->flv_off)
break;
However I’m curious about the logic of this statement. The first statement checks to see if the FLV header is less than 11 bytes, but wouldn’t it be more efficient to check to see if the flv stream is turned on first before it checks how many bytes big the header is?
if (!rt->flv_off && rt->flv_header_bytes < 11)
break;
Alternatively what about changing the statement to be like so?
if (rt->flv_off || (!rt->flv_off && rt->flv_header_bytes < 11)
break;
Would that be more efficient or could it break the code somehow?
It depends on which condition fails most often, and whether or not the compiler respects the order in which you’ve typed the conditions. Assuming the later is true (a big assumption), it’s probably more efficient to check the header size first, since presumably the FLV player is usually on.
More specifics would be necessary for a complete evaluation…although none of this probably matters anyway, since (a) the time “wasted” is almost certainly insignificant and (b) the compiler will most likely do a much better job optimizing than you will.
If you want to use an OR as in your third statement, just apply DeMorgan’s law and write
But again, this isn’t something to really worry about.