summaryrefslogtreecommitdiff
path: root/src/lib/vp9_pcm_block.cc
blob: a606b4f9331e0621e7b11166ad07c29da880baf3 (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
/*
    Copyright (C) 2022 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


#include "constants.h"
#include "dcpomatic_assert.h"
#include "util.h"
#include "vp9_pcm_block.h"


using std::vector;


auto constexpr pcm_block_size = SIGN_LANGUAGE_AUDIO_FRAME_RATE * AUDIO_BYTES_PER_SAMPLE * SIGN_LANGUAGE_CHUNK_LENGTH_IN_SECONDS;


VP9PCMBlock::VP9PCMBlock(uint8_t const* vp9_segment, int vp9_segment_size, vector<uint8_t> const& ebml_header)
	: _data(pcm_block_size)
{
	uint32_t const ebml_header_size = ebml_header.size();

	DCPOMATIC_ASSERT(vp9_segment_size < static_cast<int>((pcm_block_size - 20 - ebml_header_size)));

	// H_1
	_data[0] = 0xff;
	_data[1] = 0xff;
	_data[2] = 0xff;
	_data[3] = 0xff;
	// Length of VP9 segment, big-endian, unsigned
	_data[4] = (vp9_segment_size >> 24) & 0xff;
	_data[5] = (vp9_segment_size >> 16) & 0xff;
	_data[6] = (vp9_segment_size >> 8) & 0xff;
	_data[7] = (vp9_segment_size >> 0) & 0xff;
	// Length of PCM block, big-endian, unsigned
	_data[8] = (pcm_block_size >> 24) & 0xff;
	_data[9] = (pcm_block_size >> 16) & 0xff;
	_data[10] = (pcm_block_size >> 8) & 0xff;
	_data[11] = (pcm_block_size >> 0) & 0xff;
	// Length of VP9 EBML header, big-endian, unsigned
	_data[12] = (ebml_header_size >> 24) & 0xff;
	_data[13] = (ebml_header_size >> 16) & 0xff;
	_data[14] = (ebml_header_size >> 8) & 0xff;
	_data[15] = (ebml_header_size >> 0) & 0xff;
	// H_2
	_data[16] = 0xff;
	_data[17] = 0xff;
	_data[18] = 0xff;
	_data[19] = 0xff;
	// VP9 EBML header
	std::copy(ebml_header.begin(), ebml_header.end(), _data.begin() + 20);
	// VP9 payload
	memcpy(_data.data() + 20 + ebml_header.size(), vp9_segment, vp9_segment_size);
}