[FFmpeg-devel] [PATCH] Stricter TMV probe

Daniel Verkamp daniel
Tue Sep 15 01:22:20 CEST 2009


On Mon, Sep 14, 2009 at 3:22 PM, Vitor Sessak <vitor1001 at gmail.com> wrote:
> Ronald S. Bultje wrote:
>>
>> Hi,
>>
>> On Mon, Sep 14, 2009 at 3:51 PM, Reimar D?ffinger
>> <Reimar.Doeffinger at gmx.de> wrote:
>>>
>>> Not really related to this specific patch, just because every probe
>>> function checks sample_rate:
>>> A lot of demuxers (including that one) do not validate it in
>>> read_header, ending up with 1/0 as time base. That really is not ok (and
>>> as said, I have the impression a lot of demuxers do that).
>>
>> I think just checking for != 0 isn't enough. A samplerate of 1 might
>> be valid, but isn't. I mean, it wouldn't produce anything audible. A
>> min. samplerate of e.g. 1000 seems appropriate, and for many gaming
>> formats, a max of e.g. 192000 might also be useful.
>
> One can do even better:
>
> if(samplerate < 1000 || samplerate > 192000)
> ? ?return 0;
>
> switch (samplerate) {
> case 8000:
> case 11025:
> case 22050:
> case 44100:
> case 48000:
> ? ?// all known samplerates for the format
> ? ?return AVPROBE_SCORE_MAX;
> default:
> ? ?return AVPROBE_SCORE_MAX / 4; // who knows?
> }
>

For this format, at least, arbitrary sample rates are normal and
valid, since the hardware is being programmed directly; attached is a
patch with a basic range check that approximates the capabilities of
the SoundBlaster (maximum is enforced by the 64k maximum representable
in 16 bits). I've also added a slightly stricter check for audio chunk
size.

In addition, I return AVPROBE_SCORE_MAX only for files that are 40x25
(all other players I know of only support this size), and
AVPROBE_SCORE_MAX / 4 for the rest.

Thanks,
-- Daniel Verkamp
-------------- next part --------------
Index: libavformat/tmv.c
===================================================================
--- libavformat/tmv.c	(revision 19849)
+++ libavformat/tmv.c	(working copy)
@@ -43,10 +43,19 @@
     unsigned stream_index;
 } TMVContext;
 
+#define PROBE_MIN_SAMPLE_RATE 5000
+#define PROBE_MAX_FPS         120
+#define PROBE_MIN_AUDIO_SIZE  (PROBE_MIN_SAMPLE_RATE / PROBE_MAX_FPS)
+
 static int tmv_probe(AVProbeData *p)
 {
-    if (AV_RL32(p->buf) == TMV_TAG)
-        return AVPROBE_SCORE_MAX;
+    if (AV_RL32(p->buf)   == TMV_TAG &&
+        AV_RL16(p->buf+4) >= PROBE_MIN_SAMPLE_RATE &&
+        AV_RL16(p->buf+6) >= PROBE_MIN_AUDIO_SIZE  &&
+               !p->buf[8] && // compression method
+                p->buf[9] && // char cols
+                p->buf[10])  // char rows
+        return AVPROBE_SCORE_MAX / (p->buf[9] == 40 && p->buf[10] == 25)? 1 : 4;
     return 0;
 }
 



More information about the ffmpeg-devel mailing list