forked from ponchio/untrunc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.h
118 lines (85 loc) · 3.22 KB
/
codec.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
114
115
116
117
118
#ifndef CODEC_H
#define CODEC_H
#include <string>
#include <vector>
#include "codecstats.h"
extern "C" {
#include <stdint.h>
}
struct AVCodecContext;
struct AVCodec;
class Atom;
struct Match {
int64_t offset; //used for simulate only.
uint32_t id = 0;
uint32_t length = 0;
uint32_t duration = 0; //audio often provide a duration for the packet.
float chances = 0.0f; //1/chances is the probability to NOT be a match
bool keyframe = false;
bool operator<(const Match &b) { return chances < b.chances; }
};
//the last one is the chosen candidate.
struct MatchGroup: public std::vector<Match> {
int64_t offset;
};
class Codec {
public:
std::string name;
AVCodecContext *context;
AVCodec *codec;
/* Codec properties */
uint32_t pcm_bytes_per_sample = 0; //sample size.
bool pcm = false;
bool tmcd_seen = false;
// bool knows_start = false;
// bool guess_start = false;
// bool knows_length = false;
CodecStats stats;
Codec();
bool parse(Atom *trak);
void clear();
Match match(const unsigned char *start, int maxlength);
Match search(const unsigned char *start, int maxlength);
//sometimes (maybe) rtp info is present without a track
static Match rtpMatch(const unsigned char *start, int maxlength);
Match avc1Match(const unsigned char *start, int maxlength);
Match avc1Search(const unsigned char *start, int maxlength);
Match mp4aMatch(const unsigned char *start, int maxlength);
Match mp4vMatch(const unsigned char *start, int maxlength);
Match mp4vSearch(const unsigned char *start, int maxlength);
Match alacMatch(const unsigned char *start, int maxlength);
Match mbexMatch(const unsigned char *start, int maxlength);
Match pcmMatch(const unsigned char *start, int maxlength);
Match textMatch(const unsigned char *start, int maxlength);
Match fdscMatch(const unsigned char *start, int maxlength); //GOPRO proprietary codec, still has problems.
Match fdscSearch(const unsigned char *start, int maxlength);
Match apchMatch(const unsigned char *start, int maxlength);
Match apchSearch(const unsigned char *start, int maxlength);
Match hev1Match(const unsigned char *start, int maxlength);
Match tmcdMatch(const unsigned char *start, int maxlength);
Match gpmdMatch(const unsigned char *start, int maxlength);
Match gpmdSearch(const unsigned char *start, int maxlength);
Match mijdMatch(const unsigned char *start, int maxlength);
Match mijdSearch(const unsigned char *start, int maxlength);
//we just hope statistics on beginning and lenght is enough
Match unknownMatch(const unsigned char *start, int maxlength);
// Used by mp4a.
int mask1;
int mask0;
};
// Read an unaligned, big-endian value.
// A compiler will optimize this (at -O2) to a single instruction if possible.
template<class T>
static inline T readBE(const uint8_t *p, size_t i = 0) {
return (i >= sizeof(T)) ? T(0) :
(T(*p) << ((sizeof(T) - 1 - i) * 8)) | readBE<T>(p + 1, i + 1);
};
template<class T>
static inline void readBE(T &result, const uint8_t *p) { result = readBE<T>(p); };
// Write an unaligned, big-endian value.
template<class T>
static inline void writeBE(uint8_t *p, T value, size_t i = 0) {
(i >= sizeof(T)) ? void(0) :
(*p = ((value >> ((sizeof(T) - 1 - i) * 8)) & 0xFF) , writeBE(p + 1, value, i + 1));
};
#endif // CODEC_H