mp4meta.cpp
来自「6410BSP1」· C++ 代码 · 共 1,005 行 · 第 1/2 页
CPP
1,005 行
bool MP4File::SetMetadataGenre(const char* value){ u_int16_t genreIndex = 0; unsigned char t[3]; MP4BytesProperty *pMetadataProperty = NULL; MP4Atom *pMetaAtom = NULL; genreIndex = StringToGenre(value); const char *s = "moov.udta.meta.ilst.gnre.data"; const char *sroot = "moov.udta.meta.ilst.gnre"; const char *s2 = "moov.udta.meta.ilst.\251gen.data"; const char *s2root = "moov.udta.meta.ilst.\251gen"; if (genreIndex != 0) { pMetaAtom = m_pRootAtom->FindAtom(s); if (!pMetaAtom) { if (!CreateMetadataAtom("gnre")) return false; pMetaAtom = m_pRootAtom->FindAtom(s); } memset(t, 0, 3*sizeof(unsigned char)); t[0] = (unsigned char)(genreIndex>>8)&0xFF; t[1] = (unsigned char)(genreIndex)&0xFF; pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty); ASSERT(pMetadataProperty); pMetadataProperty->SetValue((u_int8_t*)t, 2); // remove other style of genre atom, if this one is added pMetaAtom = m_pRootAtom->FindAtom(s2root); if (pMetaAtom != NULL) { MP4Atom *pParent = pMetaAtom->GetParentAtom(); pParent->DeleteChildAtom(pMetaAtom); delete pMetaAtom; } (void)DeleteMetadataAtom( "\251gen" ); return true; } else { pMetaAtom = m_pRootAtom->FindAtom(s2); if (!pMetaAtom) { if (!CreateMetadataAtom("\251gen")) return false; pMetaAtom = m_pRootAtom->FindAtom(s2); } pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty); ASSERT(pMetadataProperty); pMetadataProperty->SetValue((u_int8_t*)value, strlen(value)); // remove other gnre atom if this one is entered pMetaAtom = m_pRootAtom->FindAtom(sroot); if (pMetaAtom != NULL) { MP4Atom *pParent = pMetaAtom->GetParentAtom(); pParent->DeleteChildAtom(pMetaAtom); delete pMetaAtom; } return true; } return false;}bool MP4File::GetMetadataGenre(char** value){ u_int16_t genreIndex = 0; unsigned char *val = NULL; u_int32_t valSize = 0; const char *t = "moov.udta.meta.ilst.gnre"; const char *s = "moov.udta.meta.ilst.gnre.data.metadata"; *value = NULL; MP4Atom *gnre = FindAtom(t); if (gnre) { GetBytesProperty(s, (u_int8_t**)&val, &valSize); if (valSize != 2) return false; genreIndex = (u_int16_t)(val[1]); genreIndex += (u_int16_t)(val[0]<<8); GenreToString(value, genreIndex); (void)DeleteMetadataAtom( "gnre" ); return true; } else { const char *s2 = "moov.udta.meta.ilst.\251gen.data.metadata"; val = NULL; valSize = 0; GetBytesProperty(s2, (u_int8_t**)&val, &valSize); if (valSize > 0) { *value = (char*)malloc((valSize+1)*sizeof(unsigned char)); memset(*value, 0, (valSize+1)*sizeof(unsigned char)); memcpy(*value, val, valSize*sizeof(unsigned char)); return true; } else { return false; } } return false;}bool MP4File::DeleteMetadataGenre(){ bool val1 = DeleteMetadataAtom("\251gen"); bool val2 = DeleteMetadataAtom("gnre"); return val1 || val2;}bool MP4File::SetMetadataGrouping(const char* value){ return SetMetadataString("\251grp", value);}bool MP4File::GetMetadataGrouping(char** value){ return GetMetadataString("\251grp", value);}bool MP4File::DeleteMetadataGrouping(){ return DeleteMetadataAtom("\251grp");}bool MP4File::SetMetadataTempo(u_int16_t tempo){ unsigned char t[3]; const char *s = "moov.udta.meta.ilst.tmpo.data"; MP4BytesProperty *pMetadataProperty = NULL; MP4Atom *pMetaAtom = NULL; pMetaAtom = m_pRootAtom->FindAtom(s); if (!pMetaAtom) { if (!CreateMetadataAtom("tmpo")) return false; pMetaAtom = m_pRootAtom->FindAtom(s); } memset(t, 0, 3*sizeof(unsigned char)); t[0] = (unsigned char)(tempo>>8)&0xFF; t[1] = (unsigned char)(tempo)&0xFF; pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty); ASSERT(pMetadataProperty); pMetadataProperty->SetValue((u_int8_t*)t, 2); return true;}bool MP4File::GetMetadataTempo(u_int16_t* tempo){ unsigned char *val = NULL; u_int32_t valSize = 0; const char *s = "moov.udta.meta.ilst.tmpo.data.metadata"; *tempo = 0; GetBytesProperty(s, (u_int8_t**)&val, &valSize); if (valSize != 2) return false; *tempo = (u_int16_t)(val[1]); *tempo += (u_int16_t)(val[0]<<8); return true;}bool MP4File::DeleteMetadataTempo(){ return DeleteMetadataAtom("tmpo");}bool MP4File::SetMetadataCompilation(u_int8_t compilation){ const char *s = "moov.udta.meta.ilst.cpil.data"; MP4BytesProperty *pMetadataProperty = NULL; MP4Atom *pMetaAtom = NULL; pMetaAtom = m_pRootAtom->FindAtom(s); if (!pMetaAtom) { if (!CreateMetadataAtom("cpil")) return false; pMetaAtom = m_pRootAtom->FindAtom(s); } pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty); ASSERT(pMetadataProperty); compilation &= 0x1; pMetadataProperty->SetValue((u_int8_t*)&compilation, 1); return true;}bool MP4File::GetMetadataCompilation(u_int8_t* compilation){ unsigned char *val = NULL; u_int32_t valSize = 0; const char *s = "moov.udta.meta.ilst.cpil.data.metadata"; *compilation = 0; GetBytesProperty(s, (u_int8_t**)&val, &valSize); if (valSize != 1) return false; *compilation = (u_int16_t)(val[0]); return true;}bool MP4File::DeleteMetadataCompilation(){ return DeleteMetadataAtom("cpil");}bool MP4File::SetMetadataCoverArt(u_int8_t *coverArt, u_int32_t size){ const char *s = "moov.udta.meta.ilst.covr.data"; MP4BytesProperty *pMetadataProperty = NULL; MP4Atom *pMetaAtom = NULL; pMetaAtom = m_pRootAtom->FindAtom(s); if (!pMetaAtom) { if (!CreateMetadataAtom("covr")) return false; pMetaAtom = m_pRootAtom->FindAtom(s); } pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty); ASSERT(pMetadataProperty); pMetadataProperty->SetValue(coverArt, size); return true;}bool MP4File::GetMetadataCoverArt(u_int8_t **coverArt, u_int32_t *size){ const char *s = "moov.udta.meta.ilst.covr.data.metadata"; *coverArt = NULL; *size = 0; GetBytesProperty(s, coverArt, size); if (size == 0) return false; return true;}u_int32_t MP4File::GetMetadataCoverArtCount (void){ MP4Atom *pMetaAtom = m_pRootAtom->FindAtom("moov.udta.meta.ilst.covr"); if (!pMetaAtom) return 0; return pMetaAtom->GetNumberOfChildAtoms();}bool MP4File::DeleteMetadataCoverArt(){ return DeleteMetadataAtom("covr");}bool MP4File::SetMetadataFreeForm(char *name, u_int8_t* pValue, u_int32_t valueSize){ MP4Atom *pMetaAtom = NULL; MP4BytesProperty *pMetadataProperty = NULL; char s[256]; int i = 0; while (1) { MP4BytesProperty *pMetadataProperty; sprintf(s, "moov.udta.meta.ilst.----[%u].name", i); MP4Atom *pTagAtom = m_pRootAtom->FindAtom(s); if (!pTagAtom) break; pTagAtom->FindProperty("name.metadata", (MP4Property**)&pMetadataProperty); if (pMetadataProperty) { u_int8_t* pV; u_int32_t VSize = 0; pMetadataProperty->GetValue(&pV, &VSize); if (VSize != 0) { if (memcmp(pV, name, VSize) == 0) { sprintf(s, "moov.udta.meta.ilst.----[%u].data.metadata", i); SetBytesProperty(s, pValue, valueSize); return true; } } } i++; } /* doesn't exist yet, create it */ char t[256]; sprintf(t, "udta.meta.ilst.----[%u]", i); sprintf(s, "moov.udta.meta.ilst.----[%u].data", i); AddDescendantAtoms("moov", t); pMetaAtom = m_pRootAtom->FindAtom(s); if (!pMetaAtom) return false; pMetaAtom->SetFlags(0x1); MP4Atom *pHdlrAtom = m_pRootAtom->FindAtom("moov.udta.meta.hdlr"); MP4StringProperty *pStringProperty = NULL; MP4BytesProperty *pBytesProperty = NULL; ASSERT(pHdlrAtom); pHdlrAtom->FindProperty( "hdlr.handlerType", (MP4Property**)&pStringProperty); ASSERT(pStringProperty); pStringProperty->SetValue("mdir"); u_int8_t val[12]; memset(val, 0, 12*sizeof(u_int8_t)); val[0] = 0x61; val[1] = 0x70; val[2] = 0x70; val[3] = 0x6c; pHdlrAtom->FindProperty( "hdlr.reserved2", (MP4Property**)&pBytesProperty); ASSERT(pBytesProperty); pBytesProperty->SetReadOnly(false); pBytesProperty->SetValue(val, 12); pBytesProperty->SetReadOnly(true); pMetaAtom = m_pRootAtom->FindAtom(s); pMetaAtom->FindProperty("data.metadata", (MP4Property**)&pMetadataProperty); ASSERT(pMetadataProperty); pMetadataProperty->SetValue(pValue, valueSize); sprintf(s, "moov.udta.meta.ilst.----[%u].name", i); pMetaAtom = m_pRootAtom->FindAtom(s); pMetaAtom->FindProperty("name.metadata", (MP4Property**)&pMetadataProperty); ASSERT(pMetadataProperty); pMetadataProperty->SetValue((u_int8_t*)name, strlen(name)); sprintf(s, "moov.udta.meta.ilst.----[%u].mean", i); pMetaAtom = m_pRootAtom->FindAtom(s); pMetaAtom->FindProperty("mean.metadata", (MP4Property**)&pMetadataProperty); ASSERT(pMetadataProperty); pMetadataProperty->SetValue((u_int8_t*)"com.apple.iTunes", 16); /* ?? */ return true;}bool MP4File::GetMetadataFreeForm(char *name, u_int8_t** ppValue, u_int32_t *pValueSize){ char s[256]; int i = 0; *ppValue = NULL; *pValueSize = 0; while (1) { MP4BytesProperty *pMetadataProperty; sprintf(s, "moov.udta.meta.ilst.----[%u].name", i); MP4Atom *pTagAtom = m_pRootAtom->FindAtom(s); if (!pTagAtom) return false; pTagAtom->FindProperty("name.metadata", (MP4Property**)&pMetadataProperty); if (pMetadataProperty) { u_int8_t* pV; u_int32_t VSize = 0; pMetadataProperty->GetValue(&pV, &VSize); if (VSize != 0) { if (memcmp(pV, name, VSize) == 0) { sprintf(s, "moov.udta.meta.ilst.----[%u].data.metadata", i); GetBytesProperty(s, ppValue, pValueSize); return true; } } } i++; }}bool MP4File::DeleteMetadataFreeForm(char *name){ char s[256]; int i = 0; while (1) { MP4BytesProperty *pMetadataProperty; sprintf(s, "moov.udta.meta.ilst.----[%u].name", i); MP4Atom *pTagAtom = m_pRootAtom->FindAtom(s); if (!pTagAtom) return false; pTagAtom->FindProperty("name.metadata", (MP4Property**)&pMetadataProperty); if (pMetadataProperty) { u_int8_t* pV; u_int32_t VSize = 0; pMetadataProperty->GetValue(&pV, &VSize); if (VSize != 0) { if (memcmp(pV, name, VSize) == 0) { sprintf(s, "----[%u]", i); return DeleteMetadataAtom(s); } } } i++; }}bool MP4File::MetadataDelete(){ MP4Atom *pMetaAtom = NULL; char s[256]; sprintf(s, "moov.udta.meta"); pMetaAtom = m_pRootAtom->FindAtom(s); /* if it exists, delete it */ if (pMetaAtom) { MP4Atom *pParent = pMetaAtom->GetParentAtom(); pParent->DeleteChildAtom(pMetaAtom); delete pMetaAtom; return true; } return false;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?