-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVBRHeader.cpp
75 lines (58 loc) · 2.02 KB
/
VBRHeader.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
// GNU LESSER GENERAL PUBLIC LICENSE
// Version 3, 29 June 2007
//
// Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
//
// Everyone is permitted to copy and distribute verbatim copies of this license
// document, but changing it is not allowed.
//
// This version of the GNU Lesser General Public License incorporates the terms
// and conditions of version 3 of the GNU General Public License, supplemented
// by the additional permissions listed below.
#include "stdafx.h"
#include "MPAHeader.h"
#include <algorithm>
#include "XINGHeader.h"
#include "VBRIHeader.h"
// first test with this static method, if it does exist
CVBRHeader* CVBRHeader::FindHeader(const CMPAFrame* frame) {
assert(frame);
CVBRHeader* header = CXINGHeader::FindHeader(frame);
if (!header) header = CVBRIHeader::FindHeader(frame);
return header;
}
CVBRHeader::CVBRHeader(CMPAStream* stream, unsigned offset)
: m_dwBytes(0),
m_dwFrames(0),
m_pStream(stream),
m_dwOffset(offset),
m_dwQuality(0),
m_pnToc(nullptr),
m_dwTableSize(0) {}
bool CVBRHeader::CheckID(CMPAStream* stream, unsigned offset, char ch0,
char ch1, char ch2, char ch3) {
const unsigned char* buffer{stream->ReadBytes(4U, offset, false)};
if (buffer[0] == ch0 && buffer[1] == ch1 && buffer[2] == ch2 &&
buffer[3] == ch3)
return true;
return false;
}
/*
// currently not used
bool CVBRHeader::ExtractLAMETag( unsigned offset )
{
// LAME ID found?
if( !CheckID( m_pMPAFile, offset, 'L', 'A', 'M', 'E' ) && !CheckID(
m_pMPAFile, offset, 'G', 'O', 'G', 'O' ) ) return false;
return true;
}*/
CVBRHeader::~CVBRHeader() { delete[] m_pnToc; }
// get byte position for percentage value (percent) of file
bool CVBRHeader::SeekPosition(float& percent, unsigned& seek_point) const {
if (!m_pnToc || m_dwBytes == 0) return false;
// check range of percent
if (percent < 0.0f) percent = 0.0f;
if (percent > 99.0f) percent = 99.0f;
seek_point = SeekPosition(percent);
return true;
}