Skip to content

Commit ffc9327

Browse files
committed
Add t35_identifier_length and move descr to hrsd
1 parent 7dbb3ef commit ffc9327

File tree

14 files changed

+360
-189
lines changed

14 files changed

+360
-189
lines changed

IsoLib/isoiff_tool/w32/isoiff/isoiff.dsp

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IsoLib/libisomediafile/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ add_library(
7171
src/H263SpecificInfoAtom.c
7272
src/HandlerAtom.c
7373
src/HEVCConfigAtom.c
74+
src/HumanReadableStreamDescriptionAtom.c
7475
src/LHEVCConfigAtom.c
7576
src/VVCConfigAtom.c
7677
src/VVCNALUConfigAtom.c

IsoLib/libisomediafile/linux/libisomediafile/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ sources = \
158158
TextMetaSampleEntry.c \
159159
XMLMetaSampleEntry.c \
160160
BitRateAtom.c \
161+
HumanReadableStreamDescriptionAtom.c \
161162
AMRWPSpecificInfoAtom.c \
162163
AMRSpecificInfoAtom.c \
163164
H263SpecificInfoAtom.c \

IsoLib/libisomediafile/macosx/libisomediafile/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ sources = \
158158
TextMetaSampleEntry.c \
159159
XMLMetaSampleEntry.c \
160160
BitRateAtom.c \
161+
HumanReadableStreamDescriptionAtom.c \
161162
AMRWPSpecificInfoAtom.c \
162163
AMRSpecificInfoAtom.c \
163164
H263SpecificInfoAtom.c \
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
Copyright 2026 Google LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include "MP4Atoms.h"
18+
#include <stdlib.h>
19+
#include <stdint.h>
20+
21+
static void destroy(MP4AtomPtr s)
22+
{
23+
MP4HumanReadableStreamDescriptionAtomPtr self;
24+
self = (MP4HumanReadableStreamDescriptionAtomPtr)s;
25+
if(self == NULL) return;
26+
27+
if(self->description)
28+
{
29+
free(self->description);
30+
self->description = NULL;
31+
}
32+
33+
if(self->super) self->super->destroy(s);
34+
}
35+
36+
static MP4Err serialize(struct MP4Atom *s, char *buffer)
37+
{
38+
MP4Err err = MP4NoErr;
39+
MP4HumanReadableStreamDescriptionAtomPtr self = (MP4HumanReadableStreamDescriptionAtomPtr)s;
40+
size_t len;
41+
42+
err = MP4SerializeCommonBaseAtomFields(s, buffer);
43+
if(err) goto bail;
44+
buffer += self->bytesWritten;
45+
assert(self->type == MP4HumanReadableStreamDescriptionAtomType);
46+
47+
len = strlen(self->description);
48+
if(self->description == NULL || len == 0 || len >= UINT32_MAX - 1)
49+
{
50+
err = MP4BadParamErr;
51+
goto bail;
52+
}
53+
/* Write description as null-terminated UTF-8 string */
54+
PUTBYTES(self->description, (u32)len + 1); /* Include null terminator */
55+
56+
assert(self->bytesWritten == self->size);
57+
bail:
58+
TEST_RETURN(err);
59+
60+
return err;
61+
}
62+
63+
static MP4Err calculateSize(struct MP4Atom *s)
64+
{
65+
MP4Err err;
66+
MP4HumanReadableStreamDescriptionAtomPtr self = (MP4HumanReadableStreamDescriptionAtomPtr)s;
67+
err = MP4NoErr;
68+
69+
err = MP4CalculateBaseAtomFieldSize(s);
70+
if(err) goto bail;
71+
72+
if(self->description == NULL || strlen(self->description) == 0)
73+
{
74+
err = MP4BadParamErr;
75+
goto bail;
76+
}
77+
/* Add description size (null-terminated string) */
78+
self->size += (u32)strlen(self->description) + 1; /* Including '\0' */
79+
80+
bail:
81+
TEST_RETURN(err);
82+
83+
return err;
84+
}
85+
86+
static MP4Err createFromInputStream(MP4AtomPtr s, MP4AtomPtr proto, MP4InputStreamPtr inputStream)
87+
{
88+
MP4Err err;
89+
MP4HumanReadableStreamDescriptionAtomPtr self = (MP4HumanReadableStreamDescriptionAtomPtr)s;
90+
s64 bytesToRead;
91+
u32 nullPos;
92+
u32 descLen;
93+
u8 *buf = NULL;
94+
u32 i;
95+
96+
if(self == NULL) BAILWITHERROR(MP4BadParamErr)
97+
err = self->super->createFromInputStream(s, proto, (char *)inputStream);
98+
if(err) goto bail;
99+
100+
/* Read all remaining bytes into a flat buffer, then split on the first null byte.
101+
* Scanning byte-by-byte and "rewinding" by adjusting only bytesRead (while leaving
102+
* the stream cursor in place) does not work — readData always reads from the current
103+
* stream position. */
104+
bytesToRead = (s64)(self->size - self->bytesRead);
105+
if(bytesToRead < 0) BAILWITHERROR(MP4BadDataErr);
106+
107+
if(bytesToRead > 0)
108+
{
109+
buf = (u8 *)calloc((u32)bytesToRead, 1);
110+
TESTMALLOC(buf);
111+
err = inputStream->readData(inputStream, (u32)bytesToRead, (char *)buf, NULL);
112+
if(err) goto bail;
113+
self->bytesRead += (u32)bytesToRead;
114+
115+
/* Find the null terminator that ends the description field */
116+
nullPos = (u32)bytesToRead; /* default: no null found */
117+
for(i = 0; i < (u32)bytesToRead; i++)
118+
{
119+
if(buf[i] == 0)
120+
{
121+
nullPos = i;
122+
break;
123+
}
124+
}
125+
126+
/* Description: bytes [0 .. nullPos] (including the null terminator) */
127+
descLen = nullPos + 1; /* length including null */
128+
self->description = (char *)calloc(descLen, 1);
129+
TESTMALLOC(self->description);
130+
memcpy(self->description, buf, descLen);
131+
}
132+
133+
bail:
134+
free(buf);
135+
TEST_RETURN(err);
136+
return err;
137+
}
138+
139+
MP4Err
140+
MP4CreateHumanReadableStreamDescriptionAtom(MP4HumanReadableStreamDescriptionAtomPtr *outAtom)
141+
{
142+
MP4Err err;
143+
MP4HumanReadableStreamDescriptionAtomPtr self;
144+
145+
self = (MP4HumanReadableStreamDescriptionAtomPtr)calloc(
146+
1, sizeof(MP4HumanReadableStreamDescriptionAtom));
147+
TESTMALLOC(self);
148+
149+
err = MP4CreateBaseAtom((MP4AtomPtr)self);
150+
if(err) goto bail;
151+
self->type = MP4HumanReadableStreamDescriptionAtomType;
152+
self->name = "HumanReadableStreamDescription";
153+
self->createFromInputStream = (cisfunc)createFromInputStream;
154+
self->destroy = destroy;
155+
self->calculateSize = calculateSize;
156+
self->serialize = serialize;
157+
158+
self->description = NULL;
159+
160+
*outAtom = self;
161+
bail:
162+
TEST_RETURN(err);
163+
164+
return err;
165+
}

IsoLib/libisomediafile/src/ISOMovies.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -877,20 +877,16 @@ extern "C"
877877
* @ingroup SampleDescr
878878
*
879879
* Properly deserializes the handle returned by MP4GetMediaSampleDescription() and extracts
880-
* the T.35 identifier bytes and optional description string. The caller is responsible for
881-
* freeing *outIdentifier and *outDescription with free().
880+
* the T.35 identifier bytes. The caller is responsible for freeing *outIdentifier with free().
882881
*
883882
* @param sampleEntryH Handle containing the serialized 'it35' sample entry.
884883
* @param outIdentifier Output; receives a newly allocated copy of the t35_identifier bytes.
885-
* @param outIdentifierSize Output; receives the number of bytes in *outIdentifier.
886-
* @param outDescription Optional output; receives a newly allocated description string, or NULL
887-
* if no description is present. Pass NULL to ignore.
884+
* @param outIdentifierLength Output; receives the number of bytes in *outIdentifier.
888885
* @return MP4NoErr on success, MP4NotFoundErr if no identifier is present, MP4BadParamErr on
889886
* invalid input.
890887
*/
891888
ISO_EXTERN(ISOErr)
892-
ISOGetT35SampleEntryFields(MP4Handle sampleEntryH, u8 **outIdentifier, u32 *outIdentifierSize,
893-
char **outDescription);
889+
ISOGetT35SampleEntryFields(MP4Handle sampleEntryH, u8 **outIdentifier, u32 *outIdentifierLength);
894890

895891
/*************************************************************************************************
896892
* VVC Sample descriptions

0 commit comments

Comments
 (0)