Skip to content

Commit 9953769

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

File tree

14 files changed

+367
-189
lines changed

14 files changed

+367
-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: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
This software module was originally developed by Google LLC.
3+
in the course of development of MPEG-4.
4+
This software module is an implementation of a part of one or
5+
more MPEG-4 tools as specified by MPEG-4.
6+
ISO/IEC gives users of MPEG-4 free license to this
7+
software module or modifications thereof for use in hardware
8+
or software products claiming conformance to MPEG-4.
9+
Those intending to use this software module in hardware or software
10+
products are advised that its use may infringe existing patents.
11+
The original developer of this software module and his/her company,
12+
the subsequent editors and their companies, and ISO/IEC have no
13+
liability for use of this software module or modifications thereof
14+
in an implementation.
15+
Copyright is not released for non MPEG-4 conforming
16+
products. Google LLC retains full right to use the code for its own
17+
purpose, assign or donate the code to a third party and to
18+
inhibit third parties from using the code for non
19+
MPEG-4 conforming products.
20+
This copyright notice must be included in all copies or
21+
derivative works. Copyright (c) 2026.
22+
*/
23+
24+
#include "MP4Atoms.h"
25+
#include <stdlib.h>
26+
#include <stdint.h>
27+
28+
static void destroy(MP4AtomPtr s)
29+
{
30+
MP4HumanReadableStreamDescriptionAtomPtr self;
31+
self = (MP4HumanReadableStreamDescriptionAtomPtr)s;
32+
if(self == NULL) return;
33+
34+
if(self->description)
35+
{
36+
free(self->description);
37+
self->description = NULL;
38+
}
39+
40+
if(self->super) self->super->destroy(s);
41+
}
42+
43+
static MP4Err serialize(struct MP4Atom *s, char *buffer)
44+
{
45+
MP4Err err = MP4NoErr;
46+
MP4HumanReadableStreamDescriptionAtomPtr self = (MP4HumanReadableStreamDescriptionAtomPtr)s;
47+
size_t len;
48+
49+
err = MP4SerializeCommonBaseAtomFields(s, buffer);
50+
if(err) goto bail;
51+
buffer += self->bytesWritten;
52+
assert(self->type == MP4HumanReadableStreamDescriptionAtomType);
53+
54+
len = strlen(self->description);
55+
if(self->description == NULL || len == 0 || len >= UINT32_MAX - 1)
56+
{
57+
err = MP4BadParamErr;
58+
goto bail;
59+
}
60+
/* Write description as null-terminated UTF-8 string */
61+
PUTBYTES(self->description, (u32)len + 1); /* Include null terminator */
62+
63+
assert(self->bytesWritten == self->size);
64+
bail:
65+
TEST_RETURN(err);
66+
67+
return err;
68+
}
69+
70+
static MP4Err calculateSize(struct MP4Atom *s)
71+
{
72+
MP4Err err;
73+
MP4HumanReadableStreamDescriptionAtomPtr self = (MP4HumanReadableStreamDescriptionAtomPtr)s;
74+
err = MP4NoErr;
75+
76+
err = MP4CalculateBaseAtomFieldSize(s);
77+
if(err) goto bail;
78+
79+
if(self->description == NULL || strlen(self->description) == 0)
80+
{
81+
err = MP4BadParamErr;
82+
goto bail;
83+
}
84+
/* Add description size (null-terminated string) */
85+
self->size += (u32)strlen(self->description) + 1; /* Including '\0' */
86+
87+
bail:
88+
TEST_RETURN(err);
89+
90+
return err;
91+
}
92+
93+
static MP4Err createFromInputStream(MP4AtomPtr s, MP4AtomPtr proto, MP4InputStreamPtr inputStream)
94+
{
95+
MP4Err err;
96+
MP4HumanReadableStreamDescriptionAtomPtr self = (MP4HumanReadableStreamDescriptionAtomPtr)s;
97+
s64 bytesToRead;
98+
u32 nullPos;
99+
u32 descLen;
100+
u8 *buf = NULL;
101+
u32 i;
102+
103+
if(self == NULL) BAILWITHERROR(MP4BadParamErr)
104+
err = self->super->createFromInputStream(s, proto, (char *)inputStream);
105+
if(err) goto bail;
106+
107+
/* Read all remaining bytes into a flat buffer, then split on the first null byte.
108+
* Scanning byte-by-byte and "rewinding" by adjusting only bytesRead (while leaving
109+
* the stream cursor in place) does not work — readData always reads from the current
110+
* stream position. */
111+
bytesToRead = (s64)(self->size - self->bytesRead);
112+
if(bytesToRead < 0) BAILWITHERROR(MP4BadDataErr);
113+
114+
if(bytesToRead > 0)
115+
{
116+
buf = (u8 *)calloc((u32)bytesToRead, 1);
117+
TESTMALLOC(buf);
118+
err = inputStream->readData(inputStream, (u32)bytesToRead, (char *)buf, NULL);
119+
if(err) goto bail;
120+
self->bytesRead += (u32)bytesToRead;
121+
122+
/* Find the null terminator that ends the description field */
123+
nullPos = (u32)bytesToRead; /* default: no null found */
124+
for(i = 0; i < (u32)bytesToRead; i++)
125+
{
126+
if(buf[i] == 0)
127+
{
128+
nullPos = i;
129+
break;
130+
}
131+
}
132+
133+
/* Description: bytes [0 .. nullPos] (including the null terminator) */
134+
descLen = nullPos + 1; /* length including null */
135+
self->description = (char *)calloc(descLen, 1);
136+
TESTMALLOC(self->description);
137+
memcpy(self->description, buf, descLen);
138+
}
139+
140+
bail:
141+
free(buf);
142+
TEST_RETURN(err);
143+
return err;
144+
}
145+
146+
MP4Err
147+
MP4CreateHumanReadableStreamDescriptionAtom(MP4HumanReadableStreamDescriptionAtomPtr *outAtom)
148+
{
149+
MP4Err err;
150+
MP4HumanReadableStreamDescriptionAtomPtr self;
151+
152+
self = (MP4HumanReadableStreamDescriptionAtomPtr)calloc(
153+
1, sizeof(MP4HumanReadableStreamDescriptionAtom));
154+
TESTMALLOC(self);
155+
156+
err = MP4CreateBaseAtom((MP4AtomPtr)self);
157+
if(err) goto bail;
158+
self->type = MP4HumanReadableStreamDescriptionAtomType;
159+
self->name = "HumanReadableStreamDescription";
160+
self->createFromInputStream = (cisfunc)createFromInputStream;
161+
self->destroy = destroy;
162+
self->calculateSize = calculateSize;
163+
self->serialize = serialize;
164+
165+
self->description = NULL;
166+
167+
*outAtom = self;
168+
bail:
169+
TEST_RETURN(err);
170+
171+
return err;
172+
}

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)