-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathmp4util.h
113 lines (84 loc) · 3.19 KB
/
mp4util.h
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
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is MPEG4IP.
*
* The Initial Developer of the Original Code is Cisco Systems Inc.
* Portions created by Cisco Systems Inc. are
* Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved.
*
* Contributor(s):
* Dave Mackie [email protected]
*/
#ifndef MP4V2_IMPL_MP4UTIL_H
#define MP4V2_IMPL_MP4UTIL_H
namespace mp4v2 { namespace impl {
///////////////////////////////////////////////////////////////////////////////
#include <assert.h>
#define LIBMPV42_STRINGIFY(x) #x
#ifndef ASSERT
# define ASSERT(expr) \
if (!(expr)) { \
throw new Exception("assert failure: " LIBMPV42_STRINGIFY((expr)), __FILE__, __LINE__, __FUNCTION__ ); \
}
#endif
#define WARNING(expr) \
if (expr) { \
log.errorf("Warning (%s) in %s at line %u", \
LIBMPV42_STRINGIFY(expr), __FILE__, __LINE__); \
}
///////////////////////////////////////////////////////////////////////////////
#define CHECK_AND_FREE(a) if ((a) != NULL) { free((void *)(a)); (a) = NULL;}
#define NUM_ELEMENTS_IN_ARRAY(name) ((sizeof((name))) / (sizeof(*(name))))
///////////////////////////////////////////////////////////////////////////////
inline void* MP4Malloc(size_t size) {
if (size == 0) return NULL;
void* p = malloc(size);
if (p == NULL && size > 0) {
throw new PlatformException("malloc failed",errno,__FILE__,__LINE__,__FUNCTION__);
}
return p;
}
inline void* MP4Calloc(size_t size) {
if (size == 0) return NULL;
return memset(MP4Malloc(size), 0, size);
}
inline char* MP4Stralloc(const char* s1) {
char* s2 = (char*)MP4Malloc(strlen(s1) + 1);
strcpy(s2, s1);
return s2;
}
inline void* MP4Realloc(void* p, uint32_t newSize) {
// workaround library bug
if (p == NULL && newSize == 0) {
return NULL;
}
void* temp = realloc(p, newSize);
if (temp == NULL && newSize > 0) {
throw new PlatformException("malloc failed",errno,__FILE__,__LINE__,__FUNCTION__);
}
return temp;
}
uint32_t STRTOINT32( const char* );
void INT32TOSTR( uint32_t, char* );
MP4Timestamp MP4GetAbsTimestamp();
uint64_t MP4ConvertTime(uint64_t t,
uint32_t oldTimeScale, uint32_t newTimeScale);
bool MP4NameFirstMatches(const char* s1, const char* s2);
bool MP4NameFirstIndex(const char* s, uint32_t* pIndex);
char* MP4NameFirst(const char *s);
const char* MP4NameAfterFirst(const char *s);
char* MP4ToBase16(const uint8_t* pData, uint32_t dataSize);
char* MP4ToBase64(const uint8_t* pData, uint32_t dataSize);
const char* MP4NormalizeTrackType(const char* type);
///////////////////////////////////////////////////////////////////////////////
}} // namespace mp4v2::impl
#endif // MP4V2_IMPL_MP4UTIL_H