Changeset 1773
- Timestamp:
- Feb 2, 2008 4:37:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/jbuf2/pjmedia/src/pjmedia/jbuf2.c
r1770 r1773 452 452 { 453 453 PJ_UNUSED_ARG(jb); 454 PJ_ASSERT_RETURN(jb, PJ_EINVAL); 454 455 455 456 return PJ_SUCCESS; … … 881 882 } 882 883 883 884 /* Find matching samples pattern */ 884 /* Window len for matching samples */ 885 885 #define MATCH_WINDOW_LEN 8 886 886 887 /* Find matching samples pattern, longest possible distance for !left_ref */ 887 888 static pj_status_t find_matched_window(jb_vbuf *buf, pj_bool_t left_ref, 889 int pref_dist, 890 unsigned *ref_, unsigned *match_) 891 { 892 const int MATCH_THRESHOLD = MATCH_WINDOW_LEN*1200; 893 unsigned ref, ptr, end; 894 int i, similarity, s1, s2; 895 896 if (buf->size/2 < MATCH_WINDOW_LEN * 2) { 897 TRACE__((THIS_FILE, "Buf size too small (%d) to perform matching", 898 buf->size)); 899 return PJ_ENOTFOUND; 900 } 901 902 /* Check minimum distance */ 903 pj_assert(pref_dist >= MATCH_WINDOW_LEN); 904 905 if (left_ref) { 906 ref = 0; 907 end = MATCH_WINDOW_LEN - 1; 908 if (buf->size/2 > pref_dist + MATCH_WINDOW_LEN) 909 ptr = pref_dist; 910 else 911 ptr = buf->size/2 - MATCH_WINDOW_LEN; 912 } else { 913 ref = buf->size/2 - MATCH_WINDOW_LEN; 914 915 /* do not +1, this is for insertion, inserting 0 sample is no use */ 916 end = ref - MATCH_WINDOW_LEN; 917 if ((int)ref > pref_dist) 918 ptr = ref - pref_dist; 919 else 920 ptr = 0; 921 } 922 923 *ref_ = ref; 924 925 while (ptr != end) { 926 similarity = 0; 927 for (i = 0; i < MATCH_WINDOW_LEN; ++i) { 928 s1 = jb_vbuf_get_sample(buf, ref+i); 929 s2 = jb_vbuf_get_sample(buf, ptr+i); 930 similarity += PJ_ABS(s1 - s2); 931 if (similarity >= MATCH_THRESHOLD) 932 break; 933 } 934 935 if (similarity <= MATCH_THRESHOLD) { 936 *match_ = ptr; 937 return PJ_SUCCESS; 938 } 939 ptr += left_ref ? -1 : 1; 940 } 941 942 return PJ_ENOTFOUND; 943 } 944 945 /* Find matching samples pattern, shortest possible distance for !left_ref */ 946 static pj_status_t find_matched_window2(jb_vbuf *buf, pj_bool_t left_ref, 888 947 int pref_dist, 889 948 unsigned *ref_, unsigned *match_) … … 910 969 ptr = buf->size/2 - MATCH_WINDOW_LEN - 1; 911 970 } else { 912 ref = buf->size/2 - MATCH_WINDOW_LEN - 1; 913 914 /* do not +1, this is for insertion, inserting 0 sample is no use */ 915 end = ref - MATCH_WINDOW_LEN; 916 if ((int)ref > pref_dist) 917 ptr = ref - pref_dist; 918 else 919 ptr = 0; 971 ref = buf->size/2 - MATCH_WINDOW_LEN; 972 end = -1; 973 ptr = ref - MATCH_WINDOW_LEN; 920 974 } 921 975 … … 936 990 return PJ_SUCCESS; 937 991 } 938 ptr += left_ref ? -1 : 1;992 ptr += left_ref ? -1 : -1; 939 993 } 940 994
Note: See TracChangeset
for help on using the changeset viewer.