-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFLVAudioTag.cpp
116 lines (104 loc) · 2.94 KB
/
FLVAudioTag.cpp
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
//
// Created by raytine on 2019/4/11.
//
#include "FLVAudioTag.h"
#include <algorithm>
#include <iostream>
FLVAudioTag::FLVAudioTag(char *data, uint32_t length_) {
char *pt = data;
soundFlags = *pt++;
int soundFormat = (soundFlags >> 4) & 0b00001111;
if (soundFormat == 10) { //AAC
aacPacketType = *pt++;
} else {
aacPacketType = 0;
}
size_t length = length_ - (pt - data);
body = new char[length];
std::copy(pt, pt + length, body);
delete[](data);
}
FLVAudioTag::FLVAudioTag(const FLVAudioTag &tag) {
soundFlags = tag.soundFlags;
aacPacketType = tag.aacPacketType;
body = new char[tag.bodyLength];
std::copy(tag.body, tag.body + tag.bodyLength, body);
}
FLVAudioTag &FLVAudioTag::operator=(const FLVAudioTag &tag) {
if (this == &tag) {
delete[](body);
soundFlags = tag.soundFlags;
aacPacketType = tag.aacPacketType;
body = new char[tag.bodyLength];
std::copy(tag.body, tag.body + tag.bodyLength, body);
}
return *this;
}
FLVAudioTag::~FLVAudioTag() {
delete[](body);
}
std::string FLVAudioTag::soundFormatName() const {
int soundFormat = (soundFlags >> 4) & 0b00001111;
switch (soundFormat) {
case 0:
return "Linear PCM, platform endian";
case 1:
return "ADPCM";
case 2:
return "MP3";
case 3:
return "Linear PCM, litter endian";
case 4:
case 5:
case 6:
return "Nellymoser";
case 7:
case 8:
return "G.711";
case 9:
return "Reserverd";
case 10:
return "AAC";
case 11:
return "Speex";
case 14:
return "MP3 8kHz";
case 15:
return "Device-Specific sound";
default:
return "Unknown sound format " + soundFormat;
}
}
std::string FLVAudioTag::soundRateName() const {
int sampleRate = (soundFlags & 0b00001100) >> 2;
switch (sampleRate) {
case 0:
return "5.5kHz";
case 1:
return "11 kHz";
case 2:
return "22 kHz";
case 3:
return "44 kHz";
default:
return "Unknow sample rate type: " + sampleRate;
}
}
std::string FLVAudioTag::soundSizeName() const {
int bitDepth = (soundFlags & 0b00000010) >> 1;
switch (bitDepth) {
case 0:
return "8-bit samples";
case 1:
return "16-bit samples";
default:
return "Unknow bit depth type:" + bitDepth;
}
}
std::string FLVAudioTag::desc() const {
return "Format:" + soundFormatName() + ", " + soundRateName() + ", " + soundSizeName()
+ ", " + (isStereo() ? "Stereo" : "Mono");
}
bool FLVAudioTag::isStereo() const {
return soundFlags & 0b00000001;
}