Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1 | /* Quicktime muxer plugin for GStreamer |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 2 | * Copyright (C) 2008-2010 Thiago Santos <thiagoss@embedded.ufcg.edu.br> |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public |
| 15 | * License along with this library; if not, write to the |
Tim-Philipp Müller | 230cf41 | 2012-11-04 00:07:18 +0000 | [diff] [blame] | 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 18 | */ |
Mark Nauwelaerts | 9b0cbfe | 2008-12-19 18:33:47 +0000 | [diff] [blame] | 19 | /* |
| 20 | * Unless otherwise indicated, Source Code is licensed under MIT license. |
| 21 | * See further explanation attached in License Statement (distributed in the file |
| 22 | * LICENSE). |
| 23 | * |
| 24 | * Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 25 | * this software and associated documentation files (the "Software"), to deal in |
| 26 | * the Software without restriction, including without limitation the rights to |
| 27 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 28 | * of the Software, and to permit persons to whom the Software is furnished to do |
| 29 | * so, subject to the following conditions: |
| 30 | * |
| 31 | * The above copyright notice and this permission notice shall be included in all |
| 32 | * copies or substantial portions of the Software. |
| 33 | * |
| 34 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 35 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 36 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 37 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 38 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 39 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 40 | * SOFTWARE. |
| 41 | */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 42 | |
| 43 | #ifndef __ATOMS_H__ |
| 44 | #define __ATOMS_H__ |
| 45 | |
| 46 | #include <glib.h> |
| 47 | #include <string.h> |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 48 | #include <gst/video/video.h> |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 49 | |
| 50 | #include "descriptors.h" |
| 51 | #include "properties.h" |
| 52 | #include "fourcc.h" |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 53 | |
Mark Nauwelaerts | 150f9ad | 2010-01-26 17:54:28 +0100 | [diff] [blame] | 54 | /* helper storage struct */ |
| 55 | #define ATOM_ARRAY(struct_type) \ |
| 56 | struct { \ |
| 57 | guint size; \ |
| 58 | guint len; \ |
| 59 | struct_type *data; \ |
| 60 | } |
| 61 | |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 62 | /* storage helpers */ |
| 63 | |
| 64 | #define atom_array_init(array, reserve) \ |
| 65 | G_STMT_START { \ |
| 66 | (array)->len = 0; \ |
| 67 | (array)->size = reserve; \ |
| 68 | (array)->data = g_malloc (sizeof (*(array)->data) * reserve); \ |
| 69 | } G_STMT_END |
| 70 | |
| 71 | #define atom_array_append(array, elmt, inc) \ |
| 72 | G_STMT_START { \ |
| 73 | g_assert ((array)->data); \ |
| 74 | g_assert (inc > 0); \ |
| 75 | if (G_UNLIKELY ((array)->len == (array)->size)) { \ |
| 76 | (array)->size += inc; \ |
| 77 | (array)->data = \ |
| 78 | g_realloc ((array)->data, sizeof (*((array)->data)) * (array)->size); \ |
| 79 | } \ |
| 80 | (array)->data[(array)->len] = elmt; \ |
| 81 | (array)->len++; \ |
| 82 | } G_STMT_END |
| 83 | |
| 84 | #define atom_array_get_len(array) ((array)->len) |
| 85 | #define atom_array_index(array, index) ((array)->data[index]) |
| 86 | |
| 87 | #define atom_array_clear(array) \ |
| 88 | G_STMT_START { \ |
| 89 | (array)->size = (array)->len = 0; \ |
| 90 | g_free ((array)->data); \ |
| 91 | (array)->data = NULL; \ |
| 92 | } G_STMT_END |
| 93 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 94 | /* light-weight context that may influence header atom tree construction */ |
| 95 | typedef enum _AtomsTreeFlavor |
| 96 | { |
| 97 | ATOMS_TREE_FLAVOR_MOV, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 98 | ATOMS_TREE_FLAVOR_ISOM, |
Marc-André Lureau | 7a447b4 | 2010-09-02 13:58:05 +0200 | [diff] [blame] | 99 | ATOMS_TREE_FLAVOR_3GP, |
| 100 | ATOMS_TREE_FLAVOR_ISML |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 101 | } AtomsTreeFlavor; |
| 102 | |
| 103 | typedef struct _AtomsContext |
| 104 | { |
| 105 | AtomsTreeFlavor flavor; |
| 106 | } AtomsContext; |
| 107 | |
| 108 | AtomsContext* atoms_context_new (AtomsTreeFlavor flavor); |
| 109 | void atoms_context_free (AtomsContext *context); |
| 110 | |
| 111 | #define METADATA_DATA_FLAG 0x0 |
| 112 | #define METADATA_TEXT_FLAG 0x1 |
| 113 | |
| 114 | /* atom defs and functions */ |
| 115 | |
Sebastian Dröge | e12c940 | 2017-01-10 18:19:55 +0200 | [diff] [blame] | 116 | typedef struct _AtomInfo AtomInfo; |
| 117 | |
Stefan Sauer | 12930c2 | 2015-07-07 16:59:20 +0200 | [diff] [blame] | 118 | /* |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 119 | * Used for storing time related values for some atoms. |
| 120 | */ |
| 121 | typedef struct _TimeInfo |
| 122 | { |
| 123 | guint64 creation_time; |
| 124 | guint64 modification_time; |
| 125 | guint32 timescale; |
| 126 | guint64 duration; |
| 127 | } TimeInfo; |
| 128 | |
| 129 | typedef struct _Atom |
| 130 | { |
| 131 | guint32 size; |
| 132 | guint32 type; |
| 133 | guint64 extended_size; |
| 134 | } Atom; |
| 135 | |
| 136 | typedef struct _AtomFull |
| 137 | { |
| 138 | Atom header; |
| 139 | |
| 140 | guint8 version; |
| 141 | guint8 flags[3]; |
| 142 | } AtomFull; |
| 143 | |
| 144 | /* |
| 145 | * Generic extension atom |
| 146 | */ |
| 147 | typedef struct _AtomData |
| 148 | { |
| 149 | Atom header; |
| 150 | |
| 151 | /* not written */ |
| 152 | guint32 datalen; |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 153 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 154 | guint8 *data; |
| 155 | } AtomData; |
| 156 | |
Thiago Santos | 7065a65 | 2010-09-15 17:54:49 -0300 | [diff] [blame] | 157 | typedef struct _AtomUUID |
| 158 | { |
| 159 | Atom header; |
| 160 | |
| 161 | guint8 uuid[16]; |
| 162 | |
| 163 | /* not written */ |
| 164 | guint32 datalen; |
| 165 | |
| 166 | guint8 *data; |
| 167 | } AtomUUID; |
| 168 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 169 | typedef struct _AtomFTYP |
| 170 | { |
| 171 | Atom header; |
| 172 | guint32 major_brand; |
| 173 | guint32 version; |
| 174 | guint32 *compatible_brands; |
| 175 | |
| 176 | /* not written */ |
| 177 | guint32 compatible_brands_size; |
| 178 | } AtomFTYP; |
| 179 | |
| 180 | typedef struct _AtomMVHD |
| 181 | { |
| 182 | AtomFull header; |
| 183 | |
| 184 | /* version 0: 32 bits */ |
| 185 | TimeInfo time_info; |
| 186 | |
| 187 | guint32 prefered_rate; /* ISO: 0x00010000 */ |
| 188 | guint16 volume; /* ISO: 0x0100 */ |
| 189 | guint16 reserved3; /* ISO: 0x0 */ |
| 190 | guint32 reserved4[2]; /* ISO: 0, 0 */ |
| 191 | /* ISO: identity matrix = |
| 192 | * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */ |
| 193 | guint32 matrix[9]; |
| 194 | |
| 195 | /* ISO: all 0 */ |
| 196 | guint32 preview_time; |
| 197 | guint32 preview_duration; |
| 198 | guint32 poster_time; |
| 199 | guint32 selection_time; |
| 200 | guint32 selection_duration; |
| 201 | guint32 current_time; |
| 202 | |
| 203 | guint32 next_track_id; |
| 204 | } AtomMVHD; |
| 205 | |
| 206 | typedef struct _AtomTKHD |
| 207 | { |
| 208 | AtomFull header; |
| 209 | |
| 210 | /* version 0: 32 bits */ |
| 211 | /* like the TimeInfo struct, but it has this track_ID inside */ |
| 212 | guint64 creation_time; |
| 213 | guint64 modification_time; |
| 214 | guint32 track_ID; |
| 215 | guint32 reserved; |
| 216 | guint64 duration; |
| 217 | |
| 218 | guint32 reserved2[2]; |
| 219 | guint16 layer; |
| 220 | guint16 alternate_group; |
| 221 | guint16 volume; |
| 222 | guint16 reserved3; |
| 223 | |
| 224 | /* ISO: identity matrix = |
| 225 | * { 0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0, 0x40000000 } */ |
| 226 | guint32 matrix[9]; |
| 227 | guint32 width; |
| 228 | guint32 height; |
| 229 | } AtomTKHD; |
| 230 | |
| 231 | typedef struct _AtomMDHD |
| 232 | { |
| 233 | AtomFull header; |
| 234 | |
| 235 | /* version 0: 32 bits */ |
| 236 | TimeInfo time_info; |
| 237 | |
| 238 | /* ISO: packed ISO-639-2/T language code (first bit must be 0) */ |
| 239 | guint16 language_code; |
| 240 | /* ISO: 0 */ |
| 241 | guint16 quality; |
| 242 | } AtomMDHD; |
| 243 | |
| 244 | typedef struct _AtomHDLR |
| 245 | { |
| 246 | AtomFull header; |
| 247 | |
| 248 | /* ISO: 0 */ |
| 249 | guint32 component_type; |
| 250 | guint32 handler_type; |
| 251 | guint32 manufacturer; |
| 252 | guint32 flags; |
| 253 | guint32 flags_mask; |
| 254 | gchar *name; |
Thiago Santos | 5adedf9 | 2014-01-09 11:56:31 -0300 | [diff] [blame] | 255 | |
| 256 | AtomsTreeFlavor flavor; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 257 | } AtomHDLR; |
| 258 | |
| 259 | typedef struct _AtomVMHD |
| 260 | { |
| 261 | AtomFull header; /* ISO: flags = 1 */ |
| 262 | |
| 263 | guint16 graphics_mode; |
| 264 | /* RGB */ |
| 265 | guint16 opcolor[3]; |
| 266 | } AtomVMHD; |
| 267 | |
| 268 | typedef struct _AtomSMHD |
| 269 | { |
| 270 | AtomFull header; |
| 271 | |
| 272 | guint16 balance; |
| 273 | guint16 reserved; |
| 274 | } AtomSMHD; |
| 275 | |
| 276 | typedef struct _AtomHMHD |
| 277 | { |
| 278 | AtomFull header; |
| 279 | |
| 280 | guint16 max_pdu_size; |
| 281 | guint16 avg_pdu_size; |
| 282 | guint32 max_bitrate; |
| 283 | guint32 avg_bitrate; |
| 284 | guint32 sliding_avg_bitrate; |
| 285 | } AtomHMHD; |
| 286 | |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 287 | typedef struct _AtomTCMI |
| 288 | { |
| 289 | AtomFull header; |
| 290 | |
| 291 | guint16 text_font; |
| 292 | guint16 text_face; |
| 293 | guint16 text_size; |
| 294 | guint16 text_color[3]; |
| 295 | guint16 bg_color[3]; |
| 296 | gchar *font_name; |
| 297 | } AtomTCMI; |
| 298 | |
| 299 | typedef struct _AtomTMCD |
| 300 | { |
| 301 | Atom header; |
| 302 | |
| 303 | AtomTCMI tcmi; |
| 304 | } AtomTMCD; |
| 305 | |
| 306 | typedef struct _AtomGMIN |
| 307 | { |
| 308 | AtomFull header; |
| 309 | |
| 310 | guint16 graphics_mode; |
| 311 | guint16 opcolor[3]; |
| 312 | guint8 balance; |
| 313 | guint8 reserved; |
| 314 | |
| 315 | } AtomGMIN; |
| 316 | |
| 317 | typedef struct _AtomGMHD |
| 318 | { |
| 319 | Atom header; |
| 320 | |
| 321 | AtomGMIN gmin; |
| 322 | AtomTMCD tmcd; |
| 323 | |
| 324 | } AtomGMHD; |
| 325 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 326 | typedef struct _AtomURL |
| 327 | { |
| 328 | AtomFull header; |
| 329 | |
| 330 | gchar *location; |
| 331 | } AtomURL; |
| 332 | |
| 333 | typedef struct _AtomDREF |
| 334 | { |
| 335 | AtomFull header; |
| 336 | |
| 337 | GList *entries; |
| 338 | } AtomDREF; |
| 339 | |
| 340 | typedef struct _AtomDINF |
| 341 | { |
| 342 | Atom header; |
| 343 | |
| 344 | AtomDREF dref; |
| 345 | } AtomDINF; |
| 346 | |
| 347 | typedef struct _STTSEntry |
| 348 | { |
| 349 | guint32 sample_count; |
| 350 | gint32 sample_delta; |
| 351 | } STTSEntry; |
| 352 | |
| 353 | typedef struct _AtomSTTS |
| 354 | { |
| 355 | AtomFull header; |
| 356 | |
Mark Nauwelaerts | 150f9ad | 2010-01-26 17:54:28 +0100 | [diff] [blame] | 357 | ATOM_ARRAY (STTSEntry) entries; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 358 | } AtomSTTS; |
| 359 | |
| 360 | typedef struct _AtomSTSS |
| 361 | { |
| 362 | AtomFull header; |
| 363 | |
Mark Nauwelaerts | 150f9ad | 2010-01-26 17:54:28 +0100 | [diff] [blame] | 364 | ATOM_ARRAY (guint32) entries; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 365 | } AtomSTSS; |
| 366 | |
| 367 | typedef struct _AtomESDS |
| 368 | { |
| 369 | AtomFull header; |
| 370 | |
| 371 | ESDescriptor es; |
| 372 | } AtomESDS; |
| 373 | |
| 374 | typedef struct _AtomFRMA |
| 375 | { |
| 376 | Atom header; |
| 377 | |
| 378 | guint32 media_type; |
| 379 | } AtomFRMA; |
| 380 | |
| 381 | typedef enum _SampleEntryKind |
| 382 | { |
| 383 | UNKNOWN, |
| 384 | AUDIO, |
Thiago Santos | d644cda | 2014-02-06 12:09:01 -0300 | [diff] [blame] | 385 | VIDEO, |
| 386 | SUBTITLE, |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 387 | TIMECODE |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 388 | } SampleEntryKind; |
| 389 | |
| 390 | typedef struct _SampleTableEntry |
| 391 | { |
| 392 | Atom header; |
| 393 | |
| 394 | guint8 reserved[6]; |
| 395 | guint16 data_reference_index; |
| 396 | |
Thiago Santos | d644cda | 2014-02-06 12:09:01 -0300 | [diff] [blame] | 397 | /* type of entry */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 398 | SampleEntryKind kind; |
| 399 | } SampleTableEntry; |
| 400 | |
| 401 | typedef struct _AtomHintSampleEntry |
| 402 | { |
| 403 | SampleTableEntry se; |
| 404 | guint32 size; |
| 405 | guint8 *data; |
| 406 | } AtomHintSampleEntry; |
| 407 | |
| 408 | typedef struct _SampleTableEntryMP4V |
| 409 | { |
| 410 | SampleTableEntry se; |
| 411 | |
| 412 | guint16 version; |
| 413 | guint16 revision_level; |
| 414 | |
| 415 | guint32 vendor; /* fourcc code */ |
| 416 | guint32 temporal_quality; |
| 417 | guint32 spatial_quality; |
| 418 | |
| 419 | guint16 width; |
| 420 | guint16 height; |
| 421 | |
| 422 | guint32 horizontal_resolution; |
| 423 | guint32 vertical_resolution; |
| 424 | guint32 datasize; |
| 425 | |
| 426 | guint16 frame_count; /* usually 1 */ |
| 427 | |
| 428 | guint8 compressor[32]; /* pascal string, i.e. first byte = length */ |
| 429 | |
| 430 | guint16 depth; |
| 431 | guint16 color_table_id; |
| 432 | |
| 433 | /* (optional) list of AtomInfo */ |
| 434 | GList *extension_atoms; |
| 435 | } SampleTableEntryMP4V; |
| 436 | |
| 437 | typedef struct _SampleTableEntryMP4A |
| 438 | { |
| 439 | SampleTableEntry se; |
| 440 | |
| 441 | guint16 version; |
| 442 | guint16 revision_level; |
| 443 | guint32 vendor; |
| 444 | |
| 445 | guint16 channels; |
| 446 | guint16 sample_size; |
| 447 | guint16 compression_id; |
| 448 | guint16 packet_size; |
| 449 | |
| 450 | guint32 sample_rate; /* fixed point 16.16 */ |
| 451 | |
| 452 | guint32 samples_per_packet; |
| 453 | guint32 bytes_per_packet; |
| 454 | guint32 bytes_per_frame; |
| 455 | guint32 bytes_per_sample; |
| 456 | |
| 457 | /* (optional) list of AtomInfo */ |
| 458 | GList *extension_atoms; |
| 459 | } SampleTableEntryMP4A; |
| 460 | |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 461 | typedef struct _AtomNAME |
| 462 | { |
| 463 | Atom header; |
| 464 | |
| 465 | guint8 language_code; |
| 466 | gchar *name; |
| 467 | } AtomNAME; |
| 468 | |
| 469 | typedef struct _SampleTableEntryTMCD |
| 470 | { |
| 471 | SampleTableEntry se; |
| 472 | |
| 473 | guint32 tc_flags; |
| 474 | guint32 timescale; |
| 475 | guint32 frame_duration; |
| 476 | guint8 n_frames; |
| 477 | |
| 478 | AtomNAME name; |
| 479 | |
| 480 | } SampleTableEntryTMCD; |
| 481 | |
Thiago Santos | d644cda | 2014-02-06 12:09:01 -0300 | [diff] [blame] | 482 | typedef struct _SampleTableEntryTX3G |
| 483 | { |
| 484 | SampleTableEntry se; |
| 485 | |
| 486 | guint32 display_flags; |
| 487 | guint64 default_text_box; |
| 488 | guint16 font_id; |
| 489 | guint8 font_face; /* bold=0x1, italic=0x2, underline=0x4 */ |
| 490 | guint8 font_size; /* should always be 0.05 multiplied by the video track header height */ |
| 491 | guint32 foreground_color_rgba; |
| 492 | |
| 493 | } SampleTableEntryTX3G; |
| 494 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 495 | typedef struct _AtomSTSD |
| 496 | { |
| 497 | AtomFull header; |
| 498 | |
| 499 | guint n_entries; |
| 500 | /* list of subclasses of SampleTableEntry */ |
| 501 | GList *entries; |
| 502 | } AtomSTSD; |
| 503 | |
| 504 | typedef struct _AtomSTSZ |
| 505 | { |
| 506 | AtomFull header; |
| 507 | |
| 508 | guint32 sample_size; |
| 509 | |
| 510 | /* need the size here because when sample_size is constant, |
| 511 | * the list is empty */ |
| 512 | guint32 table_size; |
Mark Nauwelaerts | 150f9ad | 2010-01-26 17:54:28 +0100 | [diff] [blame] | 513 | ATOM_ARRAY (guint32) entries; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 514 | } AtomSTSZ; |
| 515 | |
| 516 | typedef struct _STSCEntry |
| 517 | { |
| 518 | guint32 first_chunk; |
| 519 | guint32 samples_per_chunk; |
| 520 | guint32 sample_description_index; |
| 521 | } STSCEntry; |
| 522 | |
| 523 | typedef struct _AtomSTSC |
| 524 | { |
| 525 | AtomFull header; |
| 526 | |
Mark Nauwelaerts | 150f9ad | 2010-01-26 17:54:28 +0100 | [diff] [blame] | 527 | ATOM_ARRAY (STSCEntry) entries; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 528 | } AtomSTSC; |
| 529 | |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 530 | /* FIXME: this can support multiple tracks */ |
| 531 | typedef struct _AtomTREF |
| 532 | { |
| 533 | Atom header; |
| 534 | |
| 535 | guint32 reftype; |
| 536 | ATOM_ARRAY (guint32) entries; |
| 537 | } AtomTREF; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 538 | |
| 539 | /* |
| 540 | * used for both STCO and CO64 |
| 541 | * if used as STCO, entries should be truncated to use only 32bits |
| 542 | */ |
| 543 | typedef struct _AtomSTCO64 |
| 544 | { |
| 545 | AtomFull header; |
Jan Schmidt | 1d058c7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 546 | /* Global offset to add to entries when serialising */ |
| 547 | guint32 chunk_offset; |
Mark Nauwelaerts | 150f9ad | 2010-01-26 17:54:28 +0100 | [diff] [blame] | 548 | ATOM_ARRAY (guint64) entries; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 549 | } AtomSTCO64; |
| 550 | |
| 551 | typedef struct _CTTSEntry |
| 552 | { |
| 553 | guint32 samplecount; |
| 554 | guint32 sampleoffset; |
| 555 | } CTTSEntry; |
| 556 | |
| 557 | typedef struct _AtomCTTS |
| 558 | { |
| 559 | AtomFull header; |
| 560 | |
| 561 | /* also entry count here */ |
Mark Nauwelaerts | 150f9ad | 2010-01-26 17:54:28 +0100 | [diff] [blame] | 562 | ATOM_ARRAY (CTTSEntry) entries; |
Mark Nauwelaerts | b6945d4 | 2011-01-03 16:56:57 +0100 | [diff] [blame] | 563 | gboolean do_pts; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 564 | } AtomCTTS; |
| 565 | |
Sebastian Dröge | e717705 | 2018-02-02 13:51:49 +0200 | [diff] [blame] | 566 | typedef struct _AtomSVMI |
| 567 | { |
| 568 | AtomFull header; |
| 569 | |
| 570 | guint8 stereoscopic_composition_type; |
| 571 | gboolean is_left_first; |
| 572 | } AtomSVMI; |
| 573 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 574 | typedef struct _AtomSTBL |
| 575 | { |
| 576 | Atom header; |
| 577 | |
| 578 | AtomSTSD stsd; |
| 579 | AtomSTTS stts; |
| 580 | AtomSTSS stss; |
| 581 | AtomSTSC stsc; |
| 582 | AtomSTSZ stsz; |
| 583 | /* NULL if not present */ |
| 584 | AtomCTTS *ctts; |
Sebastian Dröge | e717705 | 2018-02-02 13:51:49 +0200 | [diff] [blame] | 585 | /* NULL if not present */ |
| 586 | AtomSVMI *svmi; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 587 | |
| 588 | AtomSTCO64 stco64; |
| 589 | } AtomSTBL; |
| 590 | |
| 591 | typedef struct _AtomMINF |
| 592 | { |
| 593 | Atom header; |
| 594 | |
| 595 | /* only (exactly) one of those must be present */ |
| 596 | AtomVMHD *vmhd; |
| 597 | AtomSMHD *smhd; |
| 598 | AtomHMHD *hmhd; |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 599 | AtomGMHD *gmhd; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 600 | |
| 601 | AtomHDLR *hdlr; |
| 602 | AtomDINF dinf; |
| 603 | AtomSTBL stbl; |
| 604 | } AtomMINF; |
| 605 | |
Thiago Santos | 22e4fb9 | 2009-11-05 21:35:56 -0300 | [diff] [blame] | 606 | typedef struct _EditListEntry |
| 607 | { |
| 608 | /* duration in movie's timescale */ |
| 609 | guint32 duration; |
| 610 | /* start time in media's timescale, -1 for empty */ |
| 611 | guint32 media_time; |
| 612 | guint32 media_rate; /* fixed point 32 bit */ |
| 613 | } EditListEntry; |
| 614 | |
| 615 | typedef struct _AtomELST |
| 616 | { |
| 617 | AtomFull header; |
| 618 | |
| 619 | /* number of entries is implicit */ |
| 620 | GSList *entries; |
| 621 | } AtomELST; |
| 622 | |
| 623 | typedef struct _AtomEDTS |
| 624 | { |
| 625 | Atom header; |
| 626 | AtomELST elst; |
| 627 | } AtomEDTS; |
| 628 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 629 | typedef struct _AtomMDIA |
| 630 | { |
| 631 | Atom header; |
| 632 | |
| 633 | AtomMDHD mdhd; |
| 634 | AtomHDLR hdlr; |
| 635 | AtomMINF minf; |
| 636 | } AtomMDIA; |
| 637 | |
| 638 | typedef struct _AtomILST |
| 639 | { |
| 640 | Atom header; |
| 641 | |
| 642 | /* list of AtomInfo */ |
| 643 | GList* entries; |
| 644 | } AtomILST; |
| 645 | |
| 646 | typedef struct _AtomTagData |
| 647 | { |
| 648 | AtomFull header; |
| 649 | guint32 reserved; |
| 650 | |
| 651 | guint32 datalen; |
| 652 | guint8* data; |
| 653 | } AtomTagData; |
| 654 | |
| 655 | typedef struct _AtomTag |
| 656 | { |
| 657 | Atom header; |
| 658 | |
| 659 | AtomTagData data; |
| 660 | } AtomTag; |
| 661 | |
| 662 | typedef struct _AtomMETA |
| 663 | { |
| 664 | AtomFull header; |
| 665 | AtomHDLR hdlr; |
| 666 | AtomILST *ilst; |
| 667 | } AtomMETA; |
| 668 | |
| 669 | typedef struct _AtomUDTA |
| 670 | { |
| 671 | Atom header; |
| 672 | |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 673 | /* list of AtomInfo */ |
| 674 | GList* entries; |
| 675 | /* or list is further down */ |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 676 | AtomMETA *meta; |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 677 | |
| 678 | AtomsContext *context; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 679 | } AtomUDTA; |
| 680 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 681 | enum TrFlags |
| 682 | { |
| 683 | TR_DATA_OFFSET = 0x01, /* data-offset-present */ |
| 684 | TR_FIRST_SAMPLE_FLAGS = 0x04, /* first-sample-flags-present */ |
| 685 | TR_SAMPLE_DURATION = 0x0100, /* sample-duration-present */ |
| 686 | TR_SAMPLE_SIZE = 0x0200, /* sample-size-present */ |
| 687 | TR_SAMPLE_FLAGS = 0x0400, /* sample-flags-present */ |
| 688 | TR_COMPOSITION_TIME_OFFSETS = 0x0800 /* sample-composition-time-offsets-presents */ |
| 689 | }; |
| 690 | |
| 691 | enum TfFlags |
| 692 | { |
| 693 | TF_BASE_DATA_OFFSET = 0x01, /* base-data-offset-present */ |
| 694 | TF_SAMPLE_DESCRIPTION_INDEX = 0x02, /* sample-description-index-present */ |
| 695 | TF_DEFAULT_SAMPLE_DURATION = 0x08, /* default-sample-duration-present */ |
| 696 | TF_DEFAULT_SAMPLE_SIZE = 0x010, /* default-sample-size-present */ |
| 697 | TF_DEFAULT_SAMPLE_FLAGS = 0x020, /* default-sample-flags-present */ |
Thiago Santos | bb33684 | 2015-07-26 02:09:24 -0300 | [diff] [blame] | 698 | TF_DURATION_IS_EMPTY = 0x010000, /* sample-composition-time-offsets-presents */ |
| 699 | TF_DEFAULT_BASE_IS_MOOF = 0x020000 /* default-base-is-moof */ |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 700 | }; |
| 701 | |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 702 | /* Timecode flags */ |
| 703 | enum TcFlags |
| 704 | { |
| 705 | TC_DROP_FRAME = 0x0001, /* Drop-frame timecode */ |
| 706 | TC_24H_MAX = 0x0002, /* Whether the timecode wraps after 24 hours */ |
| 707 | TC_NEGATIVE_OK = 0x0004, /* Whether negative time values are OK */ |
| 708 | TC_COUNTER = 0x0008 /* Whether the time value corresponds to a tape counter value */ |
| 709 | }; |
| 710 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 711 | typedef struct _AtomTRAK |
| 712 | { |
| 713 | Atom header; |
| 714 | |
| 715 | AtomTKHD tkhd; |
Sebastian Dröge | e12c940 | 2017-01-10 18:19:55 +0200 | [diff] [blame] | 716 | AtomInfo *tapt; |
Thiago Santos | 22e4fb9 | 2009-11-05 21:35:56 -0300 | [diff] [blame] | 717 | AtomEDTS *edts; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 718 | AtomMDIA mdia; |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 719 | AtomUDTA udta; |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 720 | AtomTREF *tref; |
Mark Nauwelaerts | 7ab5ff9 | 2009-06-01 22:42:08 +0200 | [diff] [blame] | 721 | |
| 722 | /* some helper info for structural conformity checks */ |
| 723 | gboolean is_video; |
| 724 | gboolean is_h264; |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 725 | |
| 726 | AtomsContext *context; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 727 | } AtomTRAK; |
| 728 | |
Marc-André Lureau | 2618cb0 | 2009-09-28 16:11:35 +0200 | [diff] [blame] | 729 | typedef struct _AtomTREX |
| 730 | { |
| 731 | AtomFull header; |
| 732 | |
| 733 | guint32 track_ID; |
| 734 | guint32 default_sample_description_index; |
| 735 | guint32 default_sample_duration; |
| 736 | guint32 default_sample_size; |
| 737 | guint32 default_sample_flags; |
| 738 | } AtomTREX; |
| 739 | |
| 740 | typedef struct _AtomMEHD |
| 741 | { |
| 742 | AtomFull header; |
| 743 | |
| 744 | guint64 fragment_duration; |
| 745 | } AtomMEHD; |
| 746 | |
| 747 | |
| 748 | typedef struct _AtomMVEX |
| 749 | { |
| 750 | Atom header; |
| 751 | |
| 752 | AtomMEHD mehd; |
| 753 | |
| 754 | /* list of AtomTREX */ |
| 755 | GList *trexs; |
| 756 | } AtomMVEX; |
| 757 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 758 | typedef struct _AtomMFHD |
| 759 | { |
| 760 | AtomFull header; |
| 761 | |
| 762 | guint32 sequence_number; |
| 763 | } AtomMFHD; |
| 764 | |
| 765 | typedef struct _AtomTFHD |
| 766 | { |
| 767 | AtomFull header; |
| 768 | |
| 769 | guint32 track_ID; |
| 770 | guint64 base_data_offset; |
| 771 | guint32 sample_description_index; |
| 772 | guint32 default_sample_duration; |
| 773 | guint32 default_sample_size; |
| 774 | guint32 default_sample_flags; |
| 775 | } AtomTFHD; |
| 776 | |
Jan Schmidt | 12ad37f | 2017-01-08 01:13:32 +1100 | [diff] [blame] | 777 | typedef struct _AtomTFDT |
| 778 | { |
| 779 | AtomFull header; |
| 780 | |
| 781 | guint64 base_media_decode_time; |
| 782 | } AtomTFDT; |
| 783 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 784 | typedef struct _TRUNSampleEntry |
| 785 | { |
| 786 | guint32 sample_duration; |
| 787 | guint32 sample_size; |
| 788 | guint32 sample_flags; |
| 789 | guint32 sample_composition_time_offset; |
| 790 | } TRUNSampleEntry; |
| 791 | |
| 792 | typedef struct _AtomTRUN |
| 793 | { |
| 794 | AtomFull header; |
| 795 | |
| 796 | guint32 sample_count; |
| 797 | gint32 data_offset; |
| 798 | guint32 first_sample_flags; |
| 799 | |
| 800 | /* array of fields */ |
| 801 | ATOM_ARRAY (TRUNSampleEntry) entries; |
| 802 | } AtomTRUN; |
| 803 | |
Mark Nauwelaerts | 92b8a00 | 2010-11-19 17:41:41 +0100 | [diff] [blame] | 804 | typedef struct _AtomSDTP |
| 805 | { |
| 806 | AtomFull header; |
| 807 | |
| 808 | /* not serialized */ |
| 809 | guint32 sample_count; |
| 810 | |
| 811 | /* array of fields */ |
| 812 | ATOM_ARRAY (guint8) entries; |
| 813 | } AtomSDTP; |
| 814 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 815 | typedef struct _AtomTRAF |
| 816 | { |
| 817 | Atom header; |
| 818 | |
| 819 | AtomTFHD tfhd; |
| 820 | |
Jan Schmidt | 12ad37f | 2017-01-08 01:13:32 +1100 | [diff] [blame] | 821 | AtomTFDT tfdt; |
| 822 | |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 823 | /* list of AtomTRUN */ |
| 824 | GList *truns; |
Mark Nauwelaerts | 92b8a00 | 2010-11-19 17:41:41 +0100 | [diff] [blame] | 825 | /* list of AtomSDTP */ |
| 826 | GList *sdtps; |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 827 | } AtomTRAF; |
| 828 | |
| 829 | typedef struct _AtomMOOF |
| 830 | { |
| 831 | Atom header; |
| 832 | |
| 833 | AtomMFHD mfhd; |
| 834 | |
| 835 | /* list of AtomTRAF */ |
| 836 | GList *trafs; |
| 837 | } AtomMOOF; |
| 838 | |
| 839 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 840 | typedef struct _AtomMOOV |
| 841 | { |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 842 | /* style */ |
| 843 | AtomsContext context; |
| 844 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 845 | Atom header; |
| 846 | |
| 847 | AtomMVHD mvhd; |
Marc-André Lureau | 2618cb0 | 2009-09-28 16:11:35 +0200 | [diff] [blame] | 848 | AtomMVEX mvex; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 849 | |
| 850 | /* list of AtomTRAK */ |
| 851 | GList *traks; |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 852 | AtomUDTA udta; |
Marc-André Lureau | 2618cb0 | 2009-09-28 16:11:35 +0200 | [diff] [blame] | 853 | |
| 854 | gboolean fragmented; |
Jan Schmidt | 1d058c7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 855 | guint32 chunks_offset; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 856 | } AtomMOOV; |
| 857 | |
| 858 | typedef struct _AtomWAVE |
| 859 | { |
| 860 | Atom header; |
| 861 | |
| 862 | /* list of AtomInfo */ |
| 863 | GList *extension_atoms; |
| 864 | } AtomWAVE; |
| 865 | |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 866 | typedef struct _TFRAEntry |
| 867 | { |
| 868 | guint64 time; |
| 869 | guint64 moof_offset; |
| 870 | guint32 traf_number; |
| 871 | guint32 trun_number; |
| 872 | guint32 sample_number; |
| 873 | } TFRAEntry; |
| 874 | |
| 875 | typedef struct _AtomTFRA |
| 876 | { |
| 877 | AtomFull header; |
| 878 | |
| 879 | guint32 track_ID; |
| 880 | guint32 lengths; |
| 881 | /* array of entries */ |
| 882 | ATOM_ARRAY (TFRAEntry) entries; |
| 883 | } AtomTFRA; |
| 884 | |
| 885 | typedef struct _AtomMFRA |
| 886 | { |
| 887 | Atom header; |
| 888 | |
| 889 | /* list of tfra */ |
| 890 | GList *tfras; |
| 891 | } AtomMFRA; |
| 892 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 893 | /* |
| 894 | * Function to serialize an atom |
| 895 | */ |
| 896 | typedef guint64 (*AtomCopyDataFunc) (Atom *atom, guint8 **buffer, guint64 *size, guint64 *offset); |
| 897 | |
| 898 | /* |
| 899 | * Releases memory allocated by an atom |
| 900 | */ |
| 901 | typedef guint64 (*AtomFreeFunc) (Atom *atom); |
| 902 | |
| 903 | /* |
| 904 | * Some atoms might have many optional different kinds of child atoms, so this |
| 905 | * is useful for enabling generic handling of any atom. |
| 906 | * All we need are the two functions (copying it to an array |
| 907 | * for serialization and the memory releasing function). |
| 908 | */ |
Sebastian Dröge | e12c940 | 2017-01-10 18:19:55 +0200 | [diff] [blame] | 909 | struct _AtomInfo |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 910 | { |
| 911 | Atom *atom; |
| 912 | AtomCopyDataFunc copy_data_func; |
| 913 | AtomFreeFunc free_func; |
Sebastian Dröge | e12c940 | 2017-01-10 18:19:55 +0200 | [diff] [blame] | 914 | }; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 915 | |
Sebastian Dröge | 7709920 | 2017-02-27 13:55:58 +0200 | [diff] [blame] | 916 | guint64 atoms_get_current_qt_time (void); |
| 917 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 918 | guint64 atom_copy_data (Atom *atom, guint8 **buffer, |
| 919 | guint64 *size, guint64* offset); |
| 920 | |
| 921 | AtomFTYP* atom_ftyp_new (AtomsContext *context, guint32 major, |
| 922 | guint32 version, GList *brands); |
| 923 | guint64 atom_ftyp_copy_data (AtomFTYP *ftyp, guint8 **buffer, |
| 924 | guint64 *size, guint64 *offset); |
| 925 | void atom_ftyp_free (AtomFTYP *ftyp); |
| 926 | |
| 927 | AtomTRAK* atom_trak_new (AtomsContext *context); |
| 928 | void atom_trak_add_samples (AtomTRAK * trak, guint32 nsamples, guint32 delta, |
| 929 | guint32 size, guint64 chunk_offset, gboolean sync, |
Mark Nauwelaerts | b6945d4 | 2011-01-03 16:56:57 +0100 | [diff] [blame] | 930 | gint64 pts_offset); |
Jan Schmidt | 3d7b343 | 2015-04-01 00:58:52 +1100 | [diff] [blame] | 931 | void atom_trak_set_elst_entry (AtomTRAK * trak, gint index, guint32 duration, |
Thiago Santos | 8d80e93 | 2009-11-06 10:34:39 -0300 | [diff] [blame] | 932 | guint32 media_time, guint32 rate); |
Sebastian Dröge | 1426a55 | 2017-02-08 17:24:26 +0200 | [diff] [blame] | 933 | void atom_trak_edts_clear (AtomTRAK * trak); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 934 | guint32 atom_trak_get_timescale (AtomTRAK *trak); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 935 | guint32 atom_trak_get_id (AtomTRAK * trak); |
Sebastian Dröge | 55f9496 | 2017-03-09 10:15:34 +0200 | [diff] [blame] | 936 | void atom_trak_set_constant_size_samples (AtomTRAK * trak, guint32 sample_size); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 937 | void atom_stbl_add_samples (AtomSTBL * stbl, guint32 nsamples, |
| 938 | guint32 delta, guint32 size, |
| 939 | guint64 chunk_offset, gboolean sync, |
Mark Nauwelaerts | b6945d4 | 2011-01-03 16:56:57 +0100 | [diff] [blame] | 940 | gint64 pts_offset); |
Sebastian Dröge | 55f9496 | 2017-03-09 10:15:34 +0200 | [diff] [blame] | 941 | void atom_stsc_add_new_entry (AtomSTSC * stsc, |
| 942 | guint32 first_chunk, guint32 nsamples); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 943 | |
| 944 | AtomMOOV* atom_moov_new (AtomsContext *context); |
| 945 | void atom_moov_free (AtomMOOV *moov); |
| 946 | guint64 atom_moov_copy_data (AtomMOOV *atom, guint8 **buffer, guint64 *size, guint64* offset); |
| 947 | void atom_moov_update_timescale (AtomMOOV *moov, guint32 timescale); |
| 948 | void atom_moov_update_duration (AtomMOOV *moov); |
Marc-André Lureau | 2618cb0 | 2009-09-28 16:11:35 +0200 | [diff] [blame] | 949 | void atom_moov_set_fragmented (AtomMOOV *moov, gboolean fragmented); |
Jan Schmidt | 1d058c7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 950 | void atom_moov_chunks_set_offset (AtomMOOV *moov, guint32 offset); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 951 | void atom_moov_add_trak (AtomMOOV *moov, AtomTRAK *trak); |
Jan Schmidt | 1d058c7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 952 | guint atom_moov_get_trak_count (AtomMOOV *moov); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 953 | |
Sebastian Dröge | e51c08b | 2017-04-14 13:38:53 +0300 | [diff] [blame] | 954 | guint atom_framerate_to_timescale (gint fps_n, gint fps_d); |
| 955 | |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 956 | guint64 atom_mvhd_copy_data (AtomMVHD * atom, guint8 ** buffer, |
| 957 | guint64 * size, guint64 * offset); |
Jan Schmidt | 1d058c7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 958 | void atom_stco64_chunks_set_offset (AtomSTCO64 * stco64, guint32 offset); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 959 | guint64 atom_trak_copy_data (AtomTRAK * atom, guint8 ** buffer, |
| 960 | guint64 * size, guint64 * offset); |
| 961 | void atom_stbl_clear (AtomSTBL * stbl); |
| 962 | void atom_stbl_init (AtomSTBL * stbl); |
| 963 | guint64 atom_stss_copy_data (AtomSTSS *atom, guint8 **buffer, |
| 964 | guint64 *size, guint64* offset); |
| 965 | guint64 atom_stts_copy_data (AtomSTTS *atom, guint8 **buffer, |
| 966 | guint64 *size, guint64* offset); |
| 967 | guint64 atom_stsc_copy_data (AtomSTSC *atom, guint8 **buffer, |
| 968 | guint64 *size, guint64* offset); |
| 969 | guint64 atom_stsz_copy_data (AtomSTSZ *atom, guint8 **buffer, |
| 970 | guint64 *size, guint64* offset); |
| 971 | guint64 atom_ctts_copy_data (AtomCTTS *atom, guint8 **buffer, |
| 972 | guint64 *size, guint64* offset); |
Sebastian Dröge | e717705 | 2018-02-02 13:51:49 +0200 | [diff] [blame] | 973 | guint64 atom_svmi_copy_data (AtomSVMI *atom, guint8 **buffer, |
| 974 | guint64 *size, guint64* offset); |
| 975 | AtomSVMI * atom_svmi_new (guint8 stereoscopic_composition_type, gboolean is_left_first); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 976 | guint64 atom_stco64_copy_data (AtomSTCO64 *atom, guint8 **buffer, |
| 977 | guint64 *size, guint64* offset); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 978 | AtomMOOF* atom_moof_new (AtomsContext *context, guint32 sequence_number); |
| 979 | void atom_moof_free (AtomMOOF *moof); |
| 980 | guint64 atom_moof_copy_data (AtomMOOF *moof, guint8 **buffer, guint64 *size, guint64* offset); |
| 981 | AtomTRAF * atom_traf_new (AtomsContext * context, guint32 track_ID); |
| 982 | void atom_traf_free (AtomTRAF * traf); |
Jan Schmidt | 12ad37f | 2017-01-08 01:13:32 +1100 | [diff] [blame] | 983 | void atom_traf_set_base_decode_time (AtomTRAF * traf, guint64 base_decode_time); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 984 | void atom_traf_add_samples (AtomTRAF * traf, guint32 delta, |
Mark Nauwelaerts | b6945d4 | 2011-01-03 16:56:57 +0100 | [diff] [blame] | 985 | guint32 size, gboolean sync, gint64 pts_offset, |
Mark Nauwelaerts | 92b8a00 | 2010-11-19 17:41:41 +0100 | [diff] [blame] | 986 | gboolean sdtp_sync); |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 987 | guint32 atom_traf_get_sample_num (AtomTRAF * traf); |
Mark Nauwelaerts | 4b64dc2 | 2010-11-15 15:17:59 +0100 | [diff] [blame] | 988 | void atom_moof_add_traf (AtomMOOF *moof, AtomTRAF *traf); |
Thiago Santos | b692f9f | 2009-12-12 16:07:15 -0300 | [diff] [blame] | 989 | |
Mark Nauwelaerts | 26a281b | 2010-11-18 16:48:06 +0100 | [diff] [blame] | 990 | AtomMFRA* atom_mfra_new (AtomsContext *context); |
| 991 | void atom_mfra_free (AtomMFRA *mfra); |
| 992 | AtomTFRA* atom_tfra_new (AtomsContext *context, guint32 track_ID); |
| 993 | void atom_tfra_add_entry (AtomTFRA *tfra, guint64 dts, guint32 sample_num); |
| 994 | void atom_tfra_update_offset (AtomTFRA * tfra, guint64 offset); |
| 995 | void atom_mfra_add_tfra (AtomMFRA *mfra, AtomTFRA *tfra); |
| 996 | guint64 atom_mfra_copy_data (AtomMFRA *mfra, guint8 **buffer, guint64 *size, guint64* offset); |
| 997 | |
| 998 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 999 | /* media sample description related helpers */ |
| 1000 | |
| 1001 | typedef struct |
| 1002 | { |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 1003 | guint16 version; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1004 | guint32 fourcc; |
| 1005 | guint width; |
| 1006 | guint height; |
| 1007 | guint depth; |
| 1008 | guint frame_count; |
| 1009 | gint color_table_id; |
Mark Nauwelaerts | 65b69dd | 2009-06-01 23:00:44 +0200 | [diff] [blame] | 1010 | guint par_n; |
| 1011 | guint par_d; |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1012 | |
| 1013 | GstBuffer *codec_data; |
| 1014 | } VisualSampleEntry; |
| 1015 | |
| 1016 | typedef struct |
| 1017 | { |
| 1018 | guint32 fourcc; |
| 1019 | guint version; |
| 1020 | gint compression_id; |
| 1021 | guint sample_rate; |
| 1022 | guint channels; |
| 1023 | guint sample_size; |
| 1024 | guint bytes_per_packet; |
| 1025 | guint samples_per_packet; |
| 1026 | guint bytes_per_sample; |
| 1027 | guint bytes_per_frame; |
| 1028 | |
| 1029 | GstBuffer *codec_data; |
| 1030 | } AudioSampleEntry; |
| 1031 | |
Thiago Santos | d644cda | 2014-02-06 12:09:01 -0300 | [diff] [blame] | 1032 | typedef struct |
| 1033 | { |
| 1034 | guint32 fourcc; |
| 1035 | |
| 1036 | guint8 font_face; /* bold=0x1, italic=0x2, underline=0x4 */ |
| 1037 | guint8 font_size; |
| 1038 | guint32 foreground_color_rgba; |
| 1039 | } SubtitleSampleEntry; |
| 1040 | |
| 1041 | void subtitle_sample_entry_init (SubtitleSampleEntry * entry); |
| 1042 | |
Thiago Santos | ab18f50 | 2015-06-10 22:27:27 -0300 | [diff] [blame] | 1043 | SampleTableEntryMP4A * atom_trak_set_audio_type (AtomTRAK * trak, AtomsContext * context, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1044 | AudioSampleEntry * entry, guint32 scale, |
| 1045 | AtomInfo * ext, gint sample_size); |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 1046 | |
Thiago Santos | ab18f50 | 2015-06-10 22:27:27 -0300 | [diff] [blame] | 1047 | SampleTableEntryMP4V * atom_trak_set_video_type (AtomTRAK * trak, AtomsContext * context, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1048 | VisualSampleEntry * entry, guint32 rate, |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 1049 | GList * ext_atoms_list); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1050 | |
Thiago Santos | ab18f50 | 2015-06-10 22:27:27 -0300 | [diff] [blame] | 1051 | SampleTableEntryTX3G * atom_trak_set_subtitle_type (AtomTRAK * trak, AtomsContext * context, |
Thiago Santos | d644cda | 2014-02-06 12:09:01 -0300 | [diff] [blame] | 1052 | SubtitleSampleEntry * entry); |
| 1053 | |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 1054 | SampleTableEntryTMCD * |
Vivia Nikolaidou | 379059b | 2018-01-19 15:05:26 +0200 | [diff] [blame] | 1055 | atom_trak_set_timecode_type (AtomTRAK * trak, AtomsContext * context, guint trak_timescale, GstVideoTimeCode * tc); |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 1056 | |
Thiago Santos | 7a143ea | 2011-09-28 11:41:49 -0300 | [diff] [blame] | 1057 | void atom_trak_update_bitrates (AtomTRAK * trak, guint32 avg_bitrate, |
| 1058 | guint32 max_bitrate); |
| 1059 | |
Thiago Santos | d644cda | 2014-02-06 12:09:01 -0300 | [diff] [blame] | 1060 | void atom_trak_tx3g_update_dimension (AtomTRAK * trak, guint32 width, |
| 1061 | guint32 height); |
| 1062 | |
Thiago Santos | ab18f50 | 2015-06-10 22:27:27 -0300 | [diff] [blame] | 1063 | void sample_table_entry_add_ext_atom (SampleTableEntry * ste, AtomInfo * ext); |
| 1064 | |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 1065 | AtomInfo * build_codec_data_extension (guint32 fourcc, const GstBuffer * codec_data); |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 1066 | AtomInfo * build_mov_aac_extension (AtomTRAK * trak, const GstBuffer * codec_data, |
| 1067 | guint32 avg_bitrate, guint32 max_bitrate); |
Luis de Bethencourt | e731fe4 | 2015-12-10 17:41:46 +0000 | [diff] [blame] | 1068 | AtomInfo * build_mov_alac_extension (const GstBuffer * codec_data); |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 1069 | AtomInfo * build_esds_extension (AtomTRAK * trak, guint8 object_type, |
Arun Raghavan | 4b4398c | 2010-07-05 14:09:50 +0530 | [diff] [blame] | 1070 | guint8 stream_type, const GstBuffer * codec_data, |
| 1071 | guint32 avg_bitrate, guint32 max_bitrate); |
Arun Raghavan | 9e5c575 | 2010-07-06 14:48:08 +0530 | [diff] [blame] | 1072 | AtomInfo * build_btrt_extension (guint32 buffer_size_db, guint32 avg_bitrate, |
| 1073 | guint32 max_bitrate); |
Luis de Bethencourt | e731fe4 | 2015-12-10 17:41:46 +0000 | [diff] [blame] | 1074 | AtomInfo * build_jp2h_extension (gint width, gint height, const gchar *colorspace, |
| 1075 | gint ncomp, const GValue * cmap_array, |
Thiago Santos | c5f6e74 | 2009-12-10 22:20:45 -0300 | [diff] [blame] | 1076 | const GValue * cdef_array); |
| 1077 | |
| 1078 | AtomInfo * build_jp2x_extension (const GstBuffer * prefix); |
Sebastian Dröge | 0584a71 | 2016-09-29 18:16:18 +0300 | [diff] [blame] | 1079 | AtomInfo * build_fiel_extension (GstVideoInterlaceMode mode, GstVideoFieldOrder order); |
Sebastian Dröge | 53e4368 | 2016-09-29 21:56:18 +0300 | [diff] [blame] | 1080 | AtomInfo * build_colr_extension (const GstVideoColorimetry *colorimetry, gboolean is_mp4); |
Sebastian Dröge | a2c6921 | 2016-09-30 17:58:37 +0300 | [diff] [blame] | 1081 | AtomInfo * build_clap_extension (gint width_n, gint width_d, gint height_n, gint height_d, gint h_off_n, gint h_off_d, gint v_off_n, gint v_off_d); |
Sebastian Dröge | e12c940 | 2017-01-10 18:19:55 +0200 | [diff] [blame] | 1082 | AtomInfo * build_tapt_extension (gint clef_width, gint clef_height, gint prof_width, gint prof_height, gint enof_width, gint enof_height); |
| 1083 | |
| 1084 | |
Thiago Santos | ab18f50 | 2015-06-10 22:27:27 -0300 | [diff] [blame] | 1085 | AtomInfo * build_ac3_extension (guint8 fscod, guint8 bsid, |
| 1086 | guint8 bsmod, guint8 acmod, |
| 1087 | guint8 lfe_on, guint8 bitrate_code); |
Luis de Bethencourt | 5ed8cba | 2015-11-16 13:26:50 +0000 | [diff] [blame] | 1088 | AtomInfo * build_opus_extension (guint32 rate, guint8 channels, guint8 mapping_family, |
| 1089 | guint8 stream_count, guint8 coupled_count, |
| 1090 | guint8 channel_mapping[256], guint16 pre_skip, |
| 1091 | guint16 output_gain); |
| 1092 | |
Benjamin Otte | 62be917 | 2010-03-21 21:39:18 +0100 | [diff] [blame] | 1093 | AtomInfo * build_amr_extension (void); |
| 1094 | AtomInfo * build_h263_extension (void); |
Thiago Santos | 496bd01 | 2009-10-29 08:36:02 -0300 | [diff] [blame] | 1095 | AtomInfo * build_gama_atom (gdouble gamma); |
| 1096 | AtomInfo * build_SMI_atom (const GstBuffer *seqh); |
Michael Smith | d74567c | 2009-12-08 17:55:56 -0800 | [diff] [blame] | 1097 | AtomInfo * build_ima_adpcm_extension (gint channels, gint rate, |
| 1098 | gint blocksize); |
Thiago Santos | aba8000 | 2011-03-21 10:56:51 -0300 | [diff] [blame] | 1099 | AtomInfo * build_uuid_xmp_atom (GstBuffer * xmp); |
Mark Nauwelaerts | 3f72fad | 2008-11-14 20:17:10 +0000 | [diff] [blame] | 1100 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1101 | |
| 1102 | /* |
| 1103 | * Meta tags functions |
| 1104 | */ |
Jan Schmidt | 1d058c7 | 2015-04-01 11:15:38 +1100 | [diff] [blame] | 1105 | void atom_udta_clear_tags (AtomUDTA *udta); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1106 | void atom_udta_add_str_tag (AtomUDTA *udta, guint32 fourcc, const gchar *value); |
| 1107 | void atom_udta_add_uint_tag (AtomUDTA *udta, guint32 fourcc, guint32 flags, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1108 | guint32 value); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1109 | void atom_udta_add_tag (AtomUDTA *udta, guint32 fourcc, guint32 flags, |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1110 | const guint8 * data, guint size); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1111 | void atom_udta_add_blob_tag (AtomUDTA *udta, guint8 *data, guint size); |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1112 | |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1113 | void atom_udta_add_3gp_str_tag (AtomUDTA *udta, guint32 fourcc, const gchar * value); |
| 1114 | void atom_udta_add_3gp_uint_tag (AtomUDTA *udta, guint32 fourcc, guint16 value); |
| 1115 | void atom_udta_add_3gp_str_int_tag (AtomUDTA *udta, guint32 fourcc, const gchar * value, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1116 | gint16 ivalue); |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1117 | void atom_udta_add_3gp_tag (AtomUDTA *udta, guint32 fourcc, guint8 * data, |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1118 | guint size); |
| 1119 | |
Thiago Santos | 6321cde | 2015-01-31 13:14:44 -0300 | [diff] [blame] | 1120 | void atom_udta_add_xmp_tags (AtomUDTA *udta, GstBuffer * xmp); |
Thiago Santos | a740adc | 2010-02-22 16:45:34 -0300 | [diff] [blame] | 1121 | |
Vivia Nikolaidou | cdb7649 | 2016-06-24 16:32:37 +0300 | [diff] [blame] | 1122 | AtomTREF * atom_tref_new (guint32 reftype); |
| 1123 | void atom_tref_add_entry (AtomTREF * tref, guint32 sample); |
| 1124 | |
Tim-Philipp Müller | d62019f | 2013-01-24 21:08:51 +0000 | [diff] [blame] | 1125 | #define GST_QT_MUX_DEFAULT_TAG_LANGUAGE "und" /* undefined/unknown */ |
Mark Nauwelaerts | 7c9a609 | 2009-06-10 12:42:44 +0200 | [diff] [blame] | 1126 | guint16 language_code (const char * lang); |
| 1127 | |
Thiago Sousa Santos | c991a04 | 2008-11-08 02:00:58 +0000 | [diff] [blame] | 1128 | #endif /* __ATOMS_H__ */ |