8895 return (mp4_i64)stbl->stco->chunkOffset[index]; |
8914 return (mp4_i64)stbl->stco->chunkOffset[index]; |
8896 else |
8915 else |
8897 return stbl->stco64->chunkOffset[index]; |
8916 return stbl->stco64->chunkOffset[index]; |
8898 } |
8917 } |
8899 |
8918 |
|
8919 /* |
|
8920 * Function: |
|
8921 * |
|
8922 * mp4_i32 readMeta(MP4HandleImp handle, |
|
8923 * metaAtom *meta) |
|
8924 * |
|
8925 * Description: |
|
8926 * |
|
8927 * This function parses one META atom. |
|
8928 * |
|
8929 * Parameters: |
|
8930 * |
|
8931 * handle MP4 library handle |
|
8932 * meta META pointer |
|
8933 * |
|
8934 * Return value: |
|
8935 * |
|
8936 * Negative integer Error |
|
8937 * >= 0 Success. Value tells how many bytes were read. |
|
8938 * |
|
8939 */ |
|
8940 mp4_i32 readMeta(MP4HandleImp handle, metaAtom *meta) |
|
8941 { |
|
8942 mp4_i32 bytesread; |
|
8943 mp4_i32 totalbytesread = 0; |
|
8944 |
|
8945 |
|
8946 if ((meta->atomhdr = (atomHeader *)mp4malloc(sizeof(atomHeader))) == NULL) |
|
8947 return -100; |
|
8948 |
|
8949 bytesread = readFullAtomHeader(handle, meta->atomhdr); |
|
8950 if (bytesread < 0) |
|
8951 return -1; |
|
8952 totalbytesread += bytesread; |
|
8953 |
|
8954 if (meta->atomhdr->type != ATOMTYPE_META) |
|
8955 return -1; |
|
8956 |
|
8957 |
|
8958 while ((mp4_u32)totalbytesread < meta->atomhdr->size) |
|
8959 { |
|
8960 mp4_u32 type; |
|
8961 |
|
8962 |
|
8963 if (peekData(handle, handle->buf, 8) < 0) |
|
8964 return -1; |
|
8965 |
|
8966 type = u32endian(*((mp4_u32 *)(handle->buf+4))); |
|
8967 |
|
8968 switch (type) |
|
8969 { |
|
8970 case ATOMTYPE_HDLR: |
|
8971 |
|
8972 if (meta->hdlr) /* HDLR has already been read, more than one is not allowed */ |
|
8973 return -1; |
|
8974 |
|
8975 if ((meta->hdlr = (handlerAtom *)mp4malloc(sizeof(handlerAtom))) == NULL) |
|
8976 return -100; |
|
8977 |
|
8978 bytesread = readHDLR(handle, meta->hdlr); |
|
8979 if (bytesread < 0) |
|
8980 return -1; |
|
8981 totalbytesread += bytesread; |
|
8982 |
|
8983 break; |
|
8984 |
|
8985 case ATOMTYPE_ID32: |
|
8986 |
|
8987 if (meta->ID32) /* ID32 has already been read, more than one is not allowed */ |
|
8988 return -1; |
|
8989 |
|
8990 if ((meta->ID32 = (ID32Atom *)mp4malloc(sizeof(ID32Atom))) == NULL) |
|
8991 return -100; |
|
8992 |
|
8993 bytesread = readID32(handle, meta->ID32); |
|
8994 if (bytesread < 0) |
|
8995 return -1; |
|
8996 totalbytesread += bytesread; |
|
8997 |
|
8998 break; |
|
8999 |
|
9000 default: |
|
9001 |
|
9002 bytesread = readUnknown(handle); |
|
9003 if (bytesread < 0) |
|
9004 return -1; |
|
9005 totalbytesread += bytesread; |
|
9006 |
|
9007 break; |
|
9008 } |
|
9009 } |
|
9010 |
|
9011 return totalbytesread; |
|
9012 } |
|
9013 |
|
9014 /* |
|
9015 * Function: |
|
9016 * |
|
9017 * mp4_i32 readID32(MP4HandleImp handle, |
|
9018 * ID32Atom *ID32) |
|
9019 * |
|
9020 * Description: |
|
9021 * |
|
9022 * This function parses one ID32 atom. |
|
9023 * |
|
9024 * Parameters: |
|
9025 * |
|
9026 * handle MP4 library handle |
|
9027 * ID32 ID32 pointer |
|
9028 * |
|
9029 * Return value: |
|
9030 * |
|
9031 * Negative integer Error |
|
9032 * >= 0 Success. Value tells how many bytes were read. |
|
9033 * |
|
9034 */ |
|
9035 mp4_i32 readID32(MP4HandleImp handle, ID32Atom *ID32) |
|
9036 { |
|
9037 mp4_i32 bytesread; |
|
9038 mp4_i32 totalbytesread = 0; |
|
9039 |
|
9040 |
|
9041 if ((ID32->atomhdr = (atomHeader *)mp4malloc(sizeof(atomHeader))) == NULL) |
|
9042 return -100; |
|
9043 |
|
9044 bytesread = readFullAtomHeader(handle, ID32->atomhdr); |
|
9045 if (bytesread < 0) |
|
9046 return -1; |
|
9047 totalbytesread += bytesread; |
|
9048 |
|
9049 if (ID32->atomhdr->type != ATOMTYPE_ID32) |
|
9050 return -1; |
|
9051 |
|
9052 // next 2 bytes: top bit is padding, remaining 15 bits is Packed ISO-639-2/T language code |
|
9053 bytesread = readData(handle, handle->buf, 2); |
|
9054 if (bytesread < 0) |
|
9055 return -1; |
|
9056 ID32->language = u16endian(*((mp4_u16 *)handle->buf)); |
|
9057 totalbytesread += bytesread; |
|
9058 |
|
9059 if ( handle->file ) |
|
9060 { |
|
9061 ID32->atomcontentloc = handle->diskReadBufStart + handle->diskReadBufPos; |
|
9062 } |
|
9063 else |
|
9064 { |
|
9065 ID32->atomcontentloc = handle->absPosition; |
|
9066 } |
|
9067 |
|
9068 bytesread = discardData(handle, ID32->atomhdr->size - totalbytesread ); |
|
9069 if (bytesread < 0) |
|
9070 return -1; |
|
9071 totalbytesread += bytesread; |
|
9072 |
|
9073 return totalbytesread; |
|
9074 } |
|
9075 |
|
9076 /* |
|
9077 * Function: |
|
9078 * |
|
9079 * mp4_i32 freeMETA(metaAtom *meta) |
|
9080 * |
|
9081 * Description: |
|
9082 * |
|
9083 * This function frees memory for META atom. |
|
9084 * |
|
9085 * Parameters: |
|
9086 * |
|
9087 * meta META atom pointer |
|
9088 * |
|
9089 * Return value: |
|
9090 * |
|
9091 * 0 Success |
|
9092 * Negative Error |
|
9093 * |
|
9094 */ |
|
9095 mp4_i32 freeMETA(metaAtom *meta) |
|
9096 { |
|
9097 if (meta) |
|
9098 { |
|
9099 if (freeAtomHeader(meta->atomhdr) < 0) |
|
9100 return -1; |
|
9101 if (freeHDLR(meta->hdlr) < 0) |
|
9102 return -1; |
|
9103 if (freeID32(meta->ID32) < 0) |
|
9104 return -1; |
|
9105 |
|
9106 mp4free(meta); |
|
9107 } |
|
9108 |
|
9109 return 0; |
|
9110 } |
|
9111 |
|
9112 /* |
|
9113 * Function: |
|
9114 * |
|
9115 * mp4_i32 freeID32(ID32Atom *ID32) |
|
9116 * |
|
9117 * Description: |
|
9118 * |
|
9119 * This function frees memory for ID32 atom. |
|
9120 * |
|
9121 * Parameters: |
|
9122 * |
|
9123 * ID32 ID32 atom pointer |
|
9124 * |
|
9125 * Return value: |
|
9126 * |
|
9127 * 0 Success |
|
9128 * Negative Error |
|
9129 * |
|
9130 */ |
|
9131 mp4_i32 freeID32(ID32Atom *ID32) |
|
9132 { |
|
9133 if (ID32) |
|
9134 { |
|
9135 if (freeAtomHeader(ID32->atomhdr) < 0) |
|
9136 return -1; |
|
9137 |
|
9138 mp4free(ID32); |
|
9139 } |
|
9140 |
|
9141 return 0; |
|
9142 } |
8900 // End of File |
9143 // End of File |