diff options
| author | Xiaoqing MA <[email protected]> | 2018-07-10 11:22:54 +0800 |
|---|---|---|
| committer | Xiaoqing MA <[email protected]> | 2018-07-10 11:22:54 +0800 |
| commit | 84eb579e97421727dbff1c054d16a3de852a1faa (patch) | |
| tree | a043afc4fa3d5301c582c9831c8401159c360573 /src | |
| parent | 01244caacaa771bf844fdd7af56bf4a03b6ea44d (diff) | |
new ed3
Diffstat (limited to 'src')
| -rw-r--r-- | src/vdefine.c | 143 | ||||
| -rw-r--r-- | src/vdefine.h | 14 |
2 files changed, 46 insertions, 111 deletions
diff --git a/src/vdefine.c b/src/vdefine.c index ddacaaa..d7ac9c8 100644 --- a/src/vdefine.c +++ b/src/vdefine.c @@ -4,34 +4,26 @@ #define AV_CONTAINER_FLV 2 #define AV_CONTAINER_MP4 3 #define UNKNOWN 4 -#define FIT_TIMES 2 -#define MAX_FLV_FRAME max_flv_frame;//? +#define FIT_TIMES 1//#define FIT_TIMES 2 +#define MAX_FLV_FRAME max_flv_frame; int is_mpeg_ts_each(const char *buff_each, size_t size_each, const char *buff, size_t size) { int ret_ts_each = 0; const char *p = buff_each; - int fit_times = 1;// 0;//special 1;//CH--0; + int fit_times = 1; p += 188; - //if ((buff_each+3)>=(buff_each+size_each)) - // return 0; - //int cont_cout_ori = xtoint(buff_each + 3, 1); - //cont_cout_ori = cont_cout_ori % 16; size_t cont_cout_ori, cont_cout_end, cont_cout_pre, cont_cout_aft; cont_cout_ori = htonl(*(size_t *)buff_each) & 0x0000000f; cont_cout_pre = cont_cout_ori; - //size_t cont_cout_aft;//int cont_cout_aft; - while (p < (buff_each + size_each))//=? + while (p < (buff_each + size_each)) { if (*p == 0x47) { if ((p + 3) < (buff_each + size_each)) { - //cont_cout_aft = xtoint(p + 3, 1); - //cont_cout_aft = cont_cout_aft % 16; cont_cout_aft = htonl(*(size_t *)p) & 0x0000000f; - //cont_cout_aft = (cont_cout_aft == 0 ? 16 : cont_cout_aft); if (cont_cout_aft == (cont_cout_pre + 1) % 16) { fit_times++; @@ -39,7 +31,6 @@ int is_mpeg_ts_each(const char *buff_each, size_t size_each, const char *buff, s else { break; - //return 0; } } if (fit_times > FIT_TIMES) @@ -51,69 +42,52 @@ int is_mpeg_ts_each(const char *buff_each, size_t size_each, const char *buff, s } size_t whole_pack_bites = whole_pack_cout * 188; const char *pack_tail = buff_each + whole_pack_bites; - if (*pack_tail == 0x47) + if (*pack_tail == 0x47 && *(pack_tail-188) == 0x47) { - //if (pack_tail + 3 < buff_each + size_each) - //{ - // cont_cout_end = htonl(*(size_t *)pack_tail) & 0x0000000f; - // if (cont_cout_end != (cont_cout_ori + whole_pack_cout) % 16) - // { - // //ret_ts_each = 0; - // break; - // } - //} ret_ts_each = 1; - break; + //printf("p-buff is %d.\n",p-buff); + //printf("pack_tail - buff is %d.\n",pack_tail-buff); + break; } break; - //ret_ts_each = 1; - //break; - //return 1; } } else { break; - //return 0; } - cont_cout_pre = cont_cout_aft;//cont_cout_ori = cont_cout_aft; + cont_cout_pre = cont_cout_aft; p += 188; } - return ret_ts_each;//return 0; + return ret_ts_each; } int is_mpeg_ts(const char* buff, size_t size) { int ret_ts = 0; - //const char*p = buff; const char *p_each = buff; - //size_t size_move = 0; int ret_ts_each; - while (p_each < buff + size)//while (size_move < size)//while (size_move <= 188) + while (p_each < buff + size) { p_each = memchr(p_each, 0x47, size - (p_each - buff)); if (p_each == NULL) { - //return 0; break; } - else if (p_each +3 >= buff + size)//else if (p_each + 3 >= buff + size || p_each - buff > 187) + else if (p_each +3 >= buff + size) { break; } else { - ret_ts_each = is_mpeg_ts_each(p_each, size - (p_each - buff), buff, size);//int ret = is_mpeg_ts_each(p_each,size-(p_each-buff)); + ret_ts_each = is_mpeg_ts_each(p_each, size - (p_each - buff), buff, size); if (ret_ts_each == 1) { - //printf("p_each... is %x,%x,%x,%x,%x,%x.\n",*p_each,*(p_each+1),*(p_each+2),*(p_each+3),*(p_each+4),*(p_each+5)); - //return 1; ret_ts = 1; break; } p_each++; - //size_move = p_each - buff;//size_move+= (p_each - buff); } } return ret_ts; @@ -125,7 +99,7 @@ void *memchr_flv(const char *buff_each, size_t size_each) void *ret_memflv = NULL; //int i; const char *p = buff_each; - while (p < buff_each + size_each)//for (i = 0; i < size_ each; i++) + while (p < buff_each + size_each) { if (*p == 0x08 || *p == 0x09 || *p == 0x12) { @@ -137,48 +111,40 @@ void *memchr_flv(const char *buff_each, size_t size_each) return ret_memflv; } -int is_flv_each(const char* buff_each, size_t size_each) +int is_flv_each(const char* buff_each, size_t size_each, const char *buff) { int ret_flv_each = 0; const char *p = buff_each; - int fit_times = 1;//CH--0; - //int left_ori; - //unsigned int left; - size_t left;//unsigned int left; - //if ((p+3)>=(buff_each+size_each)) - // return 0; - size_t right = 11 + htonl(*(size_t *)p) & 0x00ffffff;//int right = 11 + xtoint(p + 1, 3); + int fit_times = 1; + size_t left; + size_t right = 11 + htonl(*(size_t *)p) & 0x00ffffff; p += (right + 4); while (p < (buff_each + size_each)) { - //left_ori = xtoint(p - 4, 4); - //left = left_ori; - left = htonl(*(size_t *)(p - 4));// left = xtoint(p - 4, 4); + left = htonl(*(size_t *)(p - 4)); if (right==left&&(*(p) == 0x08 || *(p) == 0x09 || *(p) == 0x12)) { fit_times++; if (fit_times > FIT_TIMES) { ret_flv_each = 1; + //printf("p-buff is %d.\n",p-buff); break; - //return 1; } } else { break; - //return 0; } if ((p + 3) >= (buff_each + size_each)) { break; - //return 0; } - right = 11 + htonl(*(size_t *)p) & 0x00ffffff;//right = 11 + xtoint(p + 1, 3); + right = 11 + htonl(*(size_t *)p) & 0x00ffffff; p += (right + 4); } - return ret_flv_each;//return 0; + return ret_flv_each; } int is_flv(const char* buff, size_t size) @@ -187,16 +153,13 @@ int is_flv(const char* buff, size_t size) int ret_flv_each; const char*p = buff; const char *p_each = buff; - //size_t size_move = 0; - while (p_each < size + buff)//while (size_move < size) + while (p_each < size + buff) { - //int flv_sig[3]={ 0x08, 0x09, 0x12 }; - p_each = memchr_flv(p_each, size - (p_each - buff));// size_move, 3); + p_each = memchr_flv(p_each, size - (p_each - buff)); if (p_each == NULL) { break; - //return 0; } else if (p_each + 3 >= buff + size) { @@ -204,33 +167,27 @@ int is_flv(const char* buff, size_t size) } else { - ret_flv_each = is_flv_each(p_each, size - (p_each - buff)); + ret_flv_each = is_flv_each(p_each, size - (p_each - buff),buff); if (ret_flv_each == 1) { ret_flv = 1; break; - //return 1; } - p_each++;/// - //size_move = p_each - buff;//size_move += (p_each - buff); + p_each++; } } - return ret_flv;//return 0; + return ret_flv; } -int is_mp4_part_spe(const char *buff)//, int count_type) +int is_mp4_part_spe(const char *buff) { int i; - //const char *ret; size_t size_type_h; for (i = 0; i < count_type; i++) { size_type_h = strlen(mp4_box_type_all[i]); - //ret = (const char *)memmem(buff, size_type_h, mp4_box_type_all[i], size_type_h); - //if (ret != NULL) - // return 1; if (memcmp(buff, mp4_box_type_all[i], size_type_h) == 0) return 1; } @@ -253,7 +210,6 @@ int is_mp4_part(const char *buff_part) { if (c_is_mp3(*buff_part) == 1 && c_is_mp3(*(buff_part + 1)) == 1 && c_is_mp3(*(buff_part + 2)) == 1 && c_is_mp3(*(buff_part + 3)) == 1) { - //ret_memmp4 = (void *)p; return 1; } return 0; @@ -265,10 +221,12 @@ void *memmem_mp4(const char *buff_each, size_t size_each) char s; const char *p = buff_each; //int i; - while (p + 3 < buff_each + size_each)//for (i = 0; i < size; i++) + while (p + 3 < buff_each + size_each) { - if (is_mp4_part(p) == 1 && is_mp4_part_spe(p) == 1) - { + if (is_mp4_part_spe(p) == 1) + //if (is_mp4_part(p) == 1 && is_mp4_part_spe(p) == 1) + //if (c_is_mp3(*p) == 1 && is_mp4_part_spe(p) == 1) + { ret_memmp4 = (void *)p; break; } @@ -277,23 +235,21 @@ void *memmem_mp4(const char *buff_each, size_t size_each) return ret_memmp4; } -int is_mp4_each(const char* buff_each, size_t size_each, const char *buff)//, int count_type) +int is_mp4_each(const char* buff_each, size_t size_each, const char *buff) { int ret_mp4_each = 0; int ret_mp4_part; int sig_spe = 0; const char *p = buff_each; - int fit_times = 1;//CH--0; + int fit_times = 1; - //int size_h_ori; - //unsigned int size_h; - size_t size_h;//unsigned int size_h; + size_t size_h; p += 8; while (p + 4 < (buff_each + size_each)) { - ret_mp4_part = is_mp4_part(p);// , count_type); + ret_mp4_part = is_mp4_part(p); if (ret_mp4_part == 1) { fit_times++; @@ -304,21 +260,19 @@ int is_mp4_each(const char* buff_each, size_t size_each, const char *buff)//, in if (fit_times > FIT_TIMES&&sig_spe >= 1) { ret_mp4_each = 1; + //printf("p-buff is %d.\n",p-buff); break; - //return 1; } } else { p -= 8; - //size_h_ori = xtoint(p - 8 - 4, 4); - //size_h = size_h_ori; - size_h = htonl(*(size_t *)(p - 4));//size_h = xtoint(p - 8 - 4, 4); - p += size_h;//p += (size_h - 8); + size_h = htonl(*(size_t *)(p - 4)); + p += size_h; if (p + 4 < buff_each + size_each) { - ret_mp4_part = is_mp4_part(p);// , count_type); + ret_mp4_part = is_mp4_part(p); if (ret_mp4_part == 1) { fit_times++; @@ -330,14 +284,13 @@ int is_mp4_each(const char* buff_each, size_t size_each, const char *buff)//, in { ret_mp4_each = 1; break; - //return 1; } } } } p += 8; } - return ret_mp4_each;//return 0; + return ret_mp4_each; } int is_mp4(const char* buff, size_t size) @@ -346,17 +299,13 @@ int is_mp4(const char* buff, size_t size) int ret_mp4_each; const char *p = buff; const char *p_each = buff; - //size_t size_move = 0; - //int count_type = sizeof(mp4_box_type_all) / sizeof(char *); - //int ret; - while (p_each < buff + size)//while (size_move < size) + while (p_each < buff + size) { - p_each = (const char *)memmem_mp4(p_each, size - (p_each - buff));//size_move, count_type); + p_each = (const char *)memmem_mp4(p_each, size - (p_each - buff)); if (p_each == NULL) { break; - //return 0; } else if (p_each + 12 >= buff + size || p_each - 4 < buff) { @@ -369,13 +318,11 @@ int is_mp4(const char* buff, size_t size) { ret_mp4 = 1; break; - //return 1; } p_each++; - //size_move = p_each - buff;//size_move += (p_each - buff); } } - return ret_mp4;//return 0; + return ret_mp4; } int AV_container_identify(const char* buff, size_t size) diff --git a/src/vdefine.h b/src/vdefine.h index 8ad8c50..35c9549 100644 --- a/src/vdefine.h +++ b/src/vdefine.h @@ -19,24 +19,12 @@ const char *mp4_box_type_all[] = { "ftyp", "pdin", "moov", "mvhd", "trak", "tkhd "ipmc", "moof", "mfhd", "traf", "tfhd", "trun", "sdtp", "sbgp", "subs", "mfra", "tfra", "mfro", "mdat", "free", "skip", "udta", "cprt", "meta", "hdlr", "dinf", "dref", "ipmc", "iloc", "ipro", "sinf", "frma", "imif", "schm", "schi", "iinf", "xml", "bxml", "pitm", "fiin", "paen", "fpar", "fecr", "segr", "gitn", "tsel", "meco", "mere" }; -//const int flv_tag_type_all[] = { 0x08,0x09,0x12 }; int count_type = sizeof(mp4_box_type_all) / sizeof(char *); -/*int xtoint(const char* buff, size_t size); -int is_mpeg_ts_each(const char *buff, size_t size); -int is_mpeg_ts(const char* buff, size_t size); -void * my_memchr_flv(const char * buffer, size_t size, int count_set);//void * my_memchr_flv(const void * buffer, size_t size, int count_set); -int is_flv_each(const char* buff, size_t size); -int is_flv(const char* buff, size_t size); -void * my_memmem_mp4(const char * buf, size_t size, int count_type); -int is_mp4_each_part(const char *buff, int count_type); -int is_mp4_each(const char* buff, size_t size, const char *buff_s, int count_type); -int is_mp4(const char* buff, size_t size); -int AV_container_identify(const char* buff, size_t size);*/ int is_mpeg_ts_each(const char *buff_each, size_t size_each, const char *buff, size_t size); int is_mpeg_ts(const char* buff, size_t size); void *memchr_flv(const char *buff_each, size_t size_each); -int is_flv_each(const char* buff_each, size_t size_each); +int is_flv_each(const char* buff_each, size_t size_each,const char *buff); int is_flv(const char* buff, size_t size); int is_mp4_part_spe(const char *buff);//, int count_type) int c_is_mp3(char c); |
