From: Devesh <[email protected]>

---
 libavformat/gsmdec.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libavformat/gsmdec.c b/libavformat/gsmdec.c
index d13327d..1942ac1 100644
--- a/libavformat/gsmdec.c
+++ b/libavformat/gsmdec.c
@@ -28,12 +28,25 @@
 #define GSM_BLOCK_SIZE    33
 #define GSM_BLOCK_SAMPLES 160
 #define GSM_SAMPLE_RATE   8000
+#define GSM_MAGIC_NUM 0xD
 
 typedef struct GSMDemuxerContext {
     AVClass *class;
     int sample_rate;
 } GSMDemuxerContext;
 
+static int gsm_probe(AVProbeData *p)
+{
+    /* check file size.  */
+    if (p->buf_size < GSM_BLOCK_SIZE)
+        return 0;
+
+    if (((*p->buf & 0xF0)>>4) == GSM_MAGIC_NUM)
+        return AVPROBE_SCORE_MAX ;
+    return 0;
+}
+
+
 static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret, size;
@@ -94,6 +107,7 @@ AVInputFormat ff_gsm_demuxer = {
     .priv_data_size = sizeof(GSMDemuxerContext),
     .read_header    = gsm_read_header,
     .read_packet    = gsm_read_packet,
+    .read_probe     = gsm_probe,
     .flags          = AVFMT_GENERIC_INDEX,
     .extensions     = "gsm",
     .raw_codec_id   = AV_CODEC_ID_GSM,
-- 
1.9.1


From 86ff714a525b9678ac61a2088e90d2b4ab5997e9 Mon Sep 17 00:00:00 2001
From: Devesh Singh <[email protected]>
Date: Sat, 28 Jan 2017 00:28:01 +0530
Subject: [PATCH 2/2] BugID 555: Fix to detect gsm packet data type, made check
 more robust

---
 libavformat/gsmdec.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/libavformat/gsmdec.c b/libavformat/gsmdec.c
index 1942ac1..979318b 100644
--- a/libavformat/gsmdec.c
+++ b/libavformat/gsmdec.c
@@ -28,21 +28,76 @@
 #define GSM_BLOCK_SIZE    33
 #define GSM_BLOCK_SAMPLES 160
 #define GSM_SAMPLE_RATE   8000
-#define GSM_MAGIC_NUM 0xD
+#define GSM_MAGIC_NIBBLE 0xD
+#define ODD 1
+#define EVEN 0
 
 typedef struct GSMDemuxerContext {
     AVClass *class;
     int sample_rate;
 } GSMDemuxerContext;
 
+#define IS_MAGIC_NUM_PRESENT(a, b) b ? (((a & 0xF0) >> 4) == GSM_MAGIC_NIBBLE) 
: ((a & 0x0F) == GSM_MAGIC_NIBBLE)
+
+static int gsm_check_every_nibble(AVProbeData *p, int index_first_frame, 
uint8_t nibble)
+{
+    int indx, success;
+    
+    success = 0x1;
+
+    for (indx = index_first_frame ; indx < p->buf_size; indx += 
GSM_BLOCK_SIZE) {
+
+        if (IS_MAGIC_NUM_PRESENT(*(p->buf + indx), nibble)) {
+
+            success &= 0x1;
+
+        } else {
+
+            success &= 0x0;
+            break;
+
+        }
+    }
+
+    return success;
+}    
+
 static int gsm_probe(AVProbeData *p)
 {
+    int index_first_frame;
+    int success;
+
     /* check file size.  */
     if (p->buf_size < GSM_BLOCK_SIZE)
         return 0;
 
-    if (((*p->buf & 0xF0)>>4) == GSM_MAGIC_NUM)
-        return AVPROBE_SCORE_MAX ;
+    index_first_frame = 0;  
+    success = 1;
+
+    /* Check if nibble is equal to GSM_MAGIC_NIBBLE and all other nibble at 
offset of multiples of GSM_BLOCK_SIZE 
+       are equal to GSM_MAGIC_NIBBLE */
+
+    for(index_first_frame = 0; index_first_frame < GSM_BLOCK_SIZE; 
index_first_frame++) {
+
+        if (IS_MAGIC_NUM_PRESENT(*(p->buf + index_first_frame),ODD)) {
+
+            success = gsm_check_every_nibble(p, index_first_frame, ODD);
+
+        } else if (IS_MAGIC_NUM_PRESENT(*(p->buf + index_first_frame), EVEN)) {
+
+            success = gsm_check_every_nibble(p, index_first_frame, EVEN);
+
+        } else {
+
+            success = 0x0;
+        }
+       
+        if(success & 0x1) {
+
+            return AVPROBE_SCORE_MAX;
+        }
+    }
+
     return 0;
 }
 
-- 
1.9.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to