summaryrefslogtreecommitdiff
path: root/gst/isomp4/atomsrecovery.h
blob: 2d9382d16a6a4ccd09d1fb90f0ee8e0e5871aa73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* Quicktime muxer plugin for GStreamer
 * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
/*
 * Unless otherwise indicated, Source Code is licensed under MIT license.
 * See further explanation attached in License Statement (distributed in the file
 * LICENSE).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __ATOMS_RECOVERY_H__
#define __ATOMS_RECOVERY_H__

#include <glib.h>
#include <string.h>
#include <stdio.h>
#include <gst/gst.h>

#include "atoms.h"

/* Version to be incremented each time we decide
 * to change the file layout */
#define ATOMS_RECOV_FILE_VERSION          1

#define ATOMS_RECOV_QUARK (g_quark_from_string ("qtmux-atoms-recovery"))

/* gerror error codes */
#define ATOMS_RECOV_ERR_GENERIC           1
#define ATOMS_RECOV_ERR_FILE              2
#define ATOMS_RECOV_ERR_PARSING           3
#define ATOMS_RECOV_ERR_VERSION           4

/* this struct represents each buffer in a moov file, containing the info
 * that is placed in the stsd children atoms
 * Fields should be writen in BE order, and booleans should be writen as
 * 1byte with 0 for false, anything otherwise */
#define TRAK_BUFFER_ENTRY_INFO_SIZE 34
typedef struct
{
  guint32   track_id;
  guint32   nsamples;
  guint32   delta;
  guint32   size;
  guint64   chunk_offset;
  guint64   pts_offset;
  gboolean  sync;
  gboolean  do_pts;
} TrakBufferEntryInfo;

typedef struct
{
  guint32 trak_id;
  guint32 duration;  /* duration in trak timescale */
  guint32 timescale; /* trak's timescale */

  guint64 file_offset;

  /* need for later updating duration */
  guint64 tkhd_file_offset;
  guint64 mdhd_file_offset;

  /* need these offsets to update size */
  guint32 trak_size;
  guint64 mdia_file_offset;
  guint32 mdia_size;
  guint64 minf_file_offset;
  guint32 minf_size;
  guint64 stbl_file_offset;
  guint32 stbl_size;

  guint64 post_stsd_offset;
  guint32 stsd_size;

  guint32 extra_atoms_size;
  guint32 extra_atoms_offset;

  /* for storing the samples info */
  AtomSTBL stbl;
} TrakRecovData;

typedef struct
{
  FILE * file;
  gboolean rawfile;

  /* results from parsing the input file */
  guint64   data_size;
  guint32   mdat_header_size;
  guint     mdat_start;

  guint64   mdat_size;
} MdatRecovFile;

typedef struct
{
  FILE * file;
  guint32 timescale;

  guint32 mvhd_pos;
  guint32 mvhd_size;
  guint32 prefix_size; /* prefix + ftyp total size */

  gint num_traks;
  TrakRecovData *traks_rd;
} MoovRecovFile;

gboolean atoms_recov_write_trak_info      (FILE * f, AtomTRAK * trak);
gboolean atoms_recov_write_headers        (FILE * f, AtomFTYP * ftyp,
                                           GstBuffer * prefix, AtomMOOV * moov,
                                           guint32 timescale,
                                           guint32 traks_number);
gboolean atoms_recov_write_trak_samples   (FILE * f, AtomTRAK * trak,
                                           guint32 nsamples, guint32 delta,
                                           guint32 size, guint64 chunk_offset,
                                           gboolean sync, gboolean do_pts,
                                           gint64 pts_offset);

MdatRecovFile * mdat_recov_file_create   (FILE * file, gboolean datafile,
                                          GError ** err);
void            mdat_recov_file_free     (MdatRecovFile * mrf);
MoovRecovFile * moov_recov_file_create   (FILE * file, GError ** err);
void            moov_recov_file_free     (MoovRecovFile * moovrf);
gboolean        moov_recov_parse_buffers (MoovRecovFile * moovrf,
                                          MdatRecovFile * mdatrf,
                                          GError ** err);
gboolean        moov_recov_write_file    (MoovRecovFile * moovrf,
                                          MdatRecovFile * mdatrf, FILE * outf,
                                          GError ** err);

#endif /* __ATOMS_RECOVERY_H__ */