12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #include "stdafx.h"
- #include "mp4info.h"
- static unsigned int big_to_small_endian_32bit(unsigned int const big)
- {
- unsigned int data = big;
- unsigned int uret = 0;
- uret += (data >> 0 & 0xff) << 24;
- uret += (data >> 8 & 0xff) << 16;
- uret += (data >> 16 & 0xff) << 8;
- uret += (data >> 24 & 0xff) << 0;
- return uret;
- }
- //ftyp, free, mdat box not encryt
- unsigned int get_noencrypt_boxs_size(FILE* pSrcFile, const filecryption_callback_t* pcallback, bool bgetmoov)
- {
- unsigned int uret = 0;
- if (NULL == pSrcFile) {
- return uret;
- }
- int ipostion = ftell(pSrcFile);
- //ftyp box
- box_head_t box_head;
- fread(&box_head, sizeof(box_head_t), 1, pSrcFile);
- unsigned int uboxsize = big_to_small_endian_32bit(box_head.ibox_size);
- if (BOX_FTYP != big_to_small_endian_32bit(box_head.box_type)) {
- safe_log(pcallback, "get ftyp box failed.");
- return 0;
- }
- safe_log(pcallback, "get ftyp box success, box size is %d.", uboxsize);
- uret += uboxsize;
- fseek(pSrcFile, uboxsize - sizeof(box_head_t), SEEK_CUR);
- //free box
- fread(&box_head, sizeof(box_head_t), 1, pSrcFile);
- uboxsize = big_to_small_endian_32bit(box_head.ibox_size);
- if (FREE_BOX != big_to_small_endian_32bit(box_head.box_type)) {
- safe_log(pcallback, "get free box failed.");
- return 0;
- }
- safe_log(pcallback, "get free box success, box size is %d.", uboxsize);
- uret += uboxsize;
- fseek(pSrcFile, uboxsize - sizeof(box_head_t), SEEK_CUR);
- //mdat box
- fread(&box_head, sizeof(box_head_t), 1, pSrcFile);
- uboxsize = big_to_small_endian_32bit(box_head.ibox_size);
- if (MDAT_BOX != big_to_small_endian_32bit(box_head.box_type)) {
- safe_log(pcallback, "get mdat box failed.");
- return 0;
- }
- safe_log(pcallback, "get mdat box success, box size is %d.", uboxsize);
- uret += uboxsize;
- safe_log(pcallback, "ftyp box, free box and mdat box total size is %u.", uret);
- //moov box
- if (bgetmoov) {
- fseek(pSrcFile, uboxsize - sizeof(box_head_t), SEEK_CUR);
- fread(&box_head, sizeof(box_head_t), 1, pSrcFile);
- uboxsize = big_to_small_endian_32bit(box_head.ibox_size);
- if (MOOV_BOX != big_to_small_endian_32bit(box_head.box_type)) {
- safe_log(pcallback, "get moov box failed.");
- return 0;
- }
- safe_log(pcallback, "get moov box success, box size is %d.", uboxsize);
- }
- fseek(pSrcFile, ipostion, SEEK_SET);
- return uret;
- }
|