|
| 1 | +/* This software module was originally developed by Apple Computer, Inc. in the course of |
| 2 | + * development of MPEG-4. This software module is an implementation of a part of one or more MPEG-4 |
| 3 | + * tools as specified by MPEG-4. ISO/IEC gives users of MPEG-4 free license to this software module |
| 4 | + * or modifications thereof for use in hardware or software products claiming conformance to MPEG-4. |
| 5 | + * Those intending to use this software module in hardware or software products are advised that its |
| 6 | + * use may infringe existing patents. The original developer of this software module and his/her |
| 7 | + * company, the subsequent editors and their companies, and ISO/IEC have no liability for use of |
| 8 | + * this software module or modifications thereof in an implementation. Copyright is not released for |
| 9 | + * non MPEG-4 conforming products. Apple Computer, Inc. retains full right to use the code for its |
| 10 | + * own purpose, assign or donate the code to a third party and to inhibit third parties from using |
| 11 | + * the code for non MPEG-4 conforming products. This copyright notice must be included in all copies |
| 12 | + * or derivative works. Copyright (c) 2022. |
| 13 | + */ |
| 14 | + |
| 15 | +#include "MP4Atoms.h" |
| 16 | +#include <stdlib.h> |
| 17 | +#include <string.h> |
| 18 | + |
| 19 | +static void destroy(MP4AtomPtr s) |
| 20 | +{ |
| 21 | + MP4Err err = MP4NoErr; |
| 22 | + MP4BoxedMetadataSampleEntryPtr self = (MP4BoxedMetadataSampleEntryPtr)s; |
| 23 | + if(self == NULL) BAILWITHERROR(MP4BadParamErr) |
| 24 | + |
| 25 | + DESTROY_ATOM_LIST_F(ExtensionAtomList) |
| 26 | + |
| 27 | + if(self->super) self->super->destroy(s); |
| 28 | +bail: |
| 29 | + TEST_RETURN(err); |
| 30 | + return; |
| 31 | +} |
| 32 | + |
| 33 | +static MP4Err serialize(struct MP4Atom *s, char *buffer) |
| 34 | +{ |
| 35 | + MP4Err err; |
| 36 | + MP4BoxedMetadataSampleEntryPtr self = (MP4BoxedMetadataSampleEntryPtr)s; |
| 37 | + |
| 38 | + err = MP4SerializeCommonBaseAtomFields(s, buffer); |
| 39 | + if(err) goto bail; |
| 40 | + buffer += self->bytesWritten; |
| 41 | + |
| 42 | + PUTBYTES(self->reserved, 6); |
| 43 | + PUT16(dataReferenceIndex); |
| 44 | + SERIALIZE_ATOM_LIST(ExtensionAtomList); |
| 45 | + |
| 46 | + assert(self->bytesWritten == self->size); |
| 47 | +bail: |
| 48 | + TEST_RETURN(err); |
| 49 | + return err; |
| 50 | +} |
| 51 | + |
| 52 | +static MP4Err calculateSize(struct MP4Atom *s) |
| 53 | +{ |
| 54 | + MP4Err err; |
| 55 | + MP4BoxedMetadataSampleEntryPtr self = (MP4BoxedMetadataSampleEntryPtr)s; |
| 56 | + |
| 57 | + err = MP4CalculateBaseAtomFieldSize(s); |
| 58 | + if(err) goto bail; |
| 59 | + self->size += (6 + 2); |
| 60 | + ADD_ATOM_LIST_SIZE(ExtensionAtomList); |
| 61 | +bail: |
| 62 | + TEST_RETURN(err); |
| 63 | + return err; |
| 64 | +} |
| 65 | + |
| 66 | +static MP4Err addAtom(MP4BoxedMetadataSampleEntryPtr self, MP4AtomPtr atom) |
| 67 | +{ |
| 68 | + MP4Err err; |
| 69 | + if(atom == NULL) BAILWITHERROR(MP4BadParamErr); |
| 70 | + if(atom->type == MP4MetadataKeyTableBoxType) |
| 71 | + { |
| 72 | + if(self->keyTable != 0) BAILWITHERROR(MP4BadParamErr); |
| 73 | + self->keyTable = (MP4MetadataKeyTableBoxPtr)atom; |
| 74 | + } |
| 75 | + |
| 76 | + err = MP4AddListEntry(atom, self->ExtensionAtomList); |
| 77 | + if(err) goto bail; |
| 78 | + |
| 79 | +bail: |
| 80 | + TEST_RETURN(err); |
| 81 | + return err; |
| 82 | +} |
| 83 | + |
| 84 | +static MP4Err createFromInputStream(MP4AtomPtr s, MP4AtomPtr proto, MP4InputStreamPtr inputStream) |
| 85 | +{ |
| 86 | + MP4Err err; |
| 87 | + MP4BoxedMetadataSampleEntryPtr self = (MP4BoxedMetadataSampleEntryPtr)s; |
| 88 | + |
| 89 | + if(self == NULL) BAILWITHERROR(MP4BadParamErr) |
| 90 | + err = self->super->createFromInputStream(s, proto, (char *)inputStream); |
| 91 | + if(err) goto bail; |
| 92 | + |
| 93 | + GETBYTES(6, reserved); |
| 94 | + GET16(dataReferenceIndex); |
| 95 | + |
| 96 | + while(self->bytesRead < self->size) |
| 97 | + { |
| 98 | + MP4AtomPtr atom; |
| 99 | + err = MP4ParseAtom((MP4InputStreamPtr)inputStream, &atom); |
| 100 | + if(err) goto bail; |
| 101 | + self->bytesRead += atom->size; |
| 102 | + if(((atom->type) == MP4FreeSpaceAtomType) || ((atom->type) == MP4SkipAtomType)) |
| 103 | + atom->destroy(atom); |
| 104 | + else |
| 105 | + { |
| 106 | + err = self->addAtom(self, atom); |
| 107 | + if(err) goto bail; |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + if(self->bytesRead != self->size) BAILWITHERROR(MP4BadDataErr) |
| 112 | + |
| 113 | +bail: |
| 114 | + TEST_RETURN(err); |
| 115 | + return err; |
| 116 | +} |
| 117 | + |
| 118 | +MP4Err MP4CreateMP4BoxedMetadataSampleEntry(MP4BoxedMetadataSampleEntryPtr *outAtom) |
| 119 | +{ |
| 120 | + MP4Err err; |
| 121 | + MP4BoxedMetadataSampleEntryPtr self; |
| 122 | + |
| 123 | + self = (MP4BoxedMetadataSampleEntryPtr)calloc(1, sizeof(MP4BoxedMetadataSampleEntry)); |
| 124 | + TESTMALLOC(self) |
| 125 | + |
| 126 | + err = MP4CreateBaseAtom((MP4AtomPtr)self); |
| 127 | + if(err) goto bail; |
| 128 | + err = MP4MakeLinkedList(&self->ExtensionAtomList); |
| 129 | + if(err) goto bail; |
| 130 | + |
| 131 | + self->type = MP4BoxedMetadataSampleEntryType; |
| 132 | + self->name = "BoxedMetadataSampleEntryType (mebx)"; |
| 133 | + self->createFromInputStream = (cisfunc)createFromInputStream; |
| 134 | + self->destroy = destroy; |
| 135 | + self->calculateSize = calculateSize; |
| 136 | + self->serialize = serialize; |
| 137 | + self->addAtom = addAtom; |
| 138 | + |
| 139 | + *outAtom = self; |
| 140 | +bail: |
| 141 | + TEST_RETURN(err); |
| 142 | + return err; |
| 143 | +} |
0 commit comments