summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiaoqing MA <[email protected]>2018-07-26 11:38:37 +0800
committerXiaoqing MA <[email protected]>2018-07-26 11:38:37 +0800
commit284f177a95bf744ac7d78c02b94c8df557a7af80 (patch)
treee1c6ecdbfb25618946b0b24da42e69845592b7f7
parentaec0d6719e3f27e2a5e72bc3fd2467ff382402e5 (diff)
1.完成各视频格式struct添加使用-待继续修改
-rw-r--r--src/av_format_identify.c77
1 files changed, 51 insertions, 26 deletions
diff --git a/src/av_format_identify.c b/src/av_format_identify.c
index 90c231a..661b35a 100644
--- a/src/av_format_identify.c
+++ b/src/av_format_identify.c
@@ -79,12 +79,15 @@ int is_mpeg_ts_each(const char *buff, size_t size)
special for mpeg-ts cause of the format requirement for two packages together.*/
if (p - buff + MIN_TS_PKT_LEN <= size)
{
- pkg = (const struct ts_pkg_t *)p;
- pid_pre = (htons(*(uint16_t *)(pkg->con_pid))) << 3 >> 3;
- cont_cnt_pre = pkt->con_cnt;
- p += TS_PKT_SIZE;
- fit_times++;
+ return ret;
}
+
+ pkg = (const struct ts_pkg_t *)p;
+ pid_pre = (htons(*(uint16_t *)(pkg->con_pid))) << 3 >> 3;//?
+ cont_cnt_pre = pkt->con_cnt;
+ p += TS_PKT_SIZE;
+ fit_times++;
+
while (p - buff + MIN_TS_PKT_LEN <= size)//while (p < (buff + size))
{
pkg = (const struct ts_pkg_t *)p;
@@ -139,7 +142,7 @@ int is_mpeg_ts(const char* buff, size_t size)
while (p < buff + size)
{
p = memchr(p, TS_SYNC_BYTE, size - (p - buff));
- if (p == NULL||p + 3 >= buff + size)
+ if (p == NULL)
{
break;
}
@@ -172,10 +175,11 @@ void *memchr_flv(const char *buff, size_t size)
struct flv_tag_t
{
+ uint32_t pre_len;
uint8_t tag_type;
uint8_t pyld_len[3];//payload length
};
-#define MIN_FLV_TAG_LEN (sizeof(struct flv_tag_t))
+#define MIN_FLV_TAG_LEN (sizeof(struct flv_tag_t) + 1)//?
int is_flv_each(const char* buff, size_t size)
{
@@ -187,30 +191,39 @@ int is_flv_each(const char* buff, size_t size)
//uint32_t tag_len_show = 0;
//uint32_t tag_len_cnt = 0;// = 11 + (htonl(*(size_t *)p) & 0x00ffffff);
//p += (tag_len_cnt + 4);
+ uint32_t tag_len_cnt = 0;
+ uint32_t tag_len_show = 0;
+ if (p - buff + MIN_TS_PKT_LEN - 4 <= size)
+ {
+ return ret;
+ }
+ tag_len_cnt = 11 + htonl(*(uint32_t *)tag->pyld_len) >> 8;
+ p += tag_len_cnt;//p is the first previous_length after buff
+ fit_times++;
+
while (p - buff + MIN_FLV_TAG_SIZE <= size)//while (p < (buff + size))
{
tag = (const struct flv_tag_t *)p;
+ tag_len_show = htonl(*(uint32_t *)(tag->pre_len));
+
if (*(tag->tag_type) != FLV_TAG_AUDIO && *(tag->tag_type) != FLV_TAG_VIDEO && *(tag->tag_type) != FLV_TAG_SCRIPT_DATA)
{
break;
}
- uint32_t tag_len_cnt = 11 + *(uint32_t *)(tag->pyld_len);//(htonl(*(uint32_t *)tag)) & 0x00ffffff;
- if (p - buff + tag_len_cnt + 4 > size)
- {
- break;
- }
- uint32_t tag_len_show = *(uint32_t *)(p + tag_len_cnt);
if (tag_len_cnt != tag_len_show)
{
break;
}
+
+ uint32_t tag_len_cnt = 11 + htonl(*(uint32_t *)(tag->pyld_len)) >> 8;//(htonl(*(uint32_t *)tag)) & 0x00ffffff;
+
fit_times++;
if (fit_times >= FIT_TIMES)
{
ret = 1;
break;
}
- p += (tag_len_cnt + 4);
+ p += (4 + tag_len_cnt);
}
return ret;
}
@@ -275,18 +288,17 @@ int is_mp4_boxname(const char *buff);// , size_t size)
break;
}
}
- if (raw_filter == 4 || raw_filter == 3)//box type:xmf
+ if (raw_filter == 4)//box type:xmf
+ {
+ return 1;
+ }
+ else if (raw_filter == 3)
{
- if (1 == is_mp4_boxname_deep(buff))
+ if (memecmp(buff, "xmf", 3) == 0)
{
return 1;
}
}
- else
- {
- if (memcpy())
- return 0;
- }
return 0;
}
@@ -322,14 +334,25 @@ int is_mp4_each(const char* buff, size_t size)
int ret = 0;
int fit_times = 0;
const char *p = buff;
+ const char *q = NULL;
const struct mp4_box_t *box=NULL;
+ uint64_t offset = 0;
while (p - buff + MIN_MP4_BOX_SIZE <= size)//while(p-buff+MIN_MP4_BOX_SIZE<size)//at least contain atom_size and name of mp4 box for current p
{
- box=(const struct mp4_box_t *)p;//?
+ box = (const struct mp4_box_t *)p;//?
if(!is_mp4_boxname(box->name)//?,sizeof(box->name))
{
- break;
+ if (offset <= 0xffffffff)
+ {
+ p = q + 8;
+ box = (const struct mp4_box_t *)p;
+ }
+ if (!is_mp4_boxname(box->name)
+ {
+ break;
+ }
+ //break;
}
fit_times++;
@@ -337,7 +360,7 @@ int is_mp4_each(const char* buff, size_t size)
{
if(size-(p-buff)>sizeof(struct mp4_box_t))
{
- p += htonll(&box->large_size);//p+=htonll(box->large_size);//TODO: Implement htonll
+ offset = htonll(&box->large_size);//p += htonll(&box->large_size);//p+=htonll(box->large_size);//TODO: Implement htonll
}
else
{
@@ -346,8 +369,10 @@ int is_mp4_each(const char* buff, size_t size)
}
else
{
- p+=htonl(box->atom_size);
+ offset = htonl(box->atom_size);//p+=htonl(box->atom_size);
}
+ q = p;
+ p += offset;
if (fit_times > FIT_TIMES)
{
ret = 1;
@@ -377,7 +402,7 @@ int is_mp4(const char* buff, size_t size)
{
break;
}
- if (p - 4 < buff)
+ if (p - 4 < buff)//if there is no atom_size for the first box existing, the exit
{
p++;
continue;