OLD | NEW |
---|---|
(Empty) | |
1 #include "media/formats/webm/opus_packet_builder.h" | |
2 #include "media/formats/webm/webm_cluster_parser.h" | |
3 | |
4 namespace media { | |
5 | |
6 // From Opus RFC. See http://goo.gl/2RmoxA | |
7 enum OpusConstants { | |
8 kNumPossibleOpusConfigs = 32, | |
9 kMinOpusPacketFrameCount = 1, | |
10 kMaxOpusPacketFrameCount = 48 | |
11 }; | |
12 | |
13 OpusPacketInfo::OpusPacketInfo() { | |
14 } | |
15 OpusPacketInfo::~OpusPacketInfo() { | |
16 } | |
17 | |
18 scoped_ptr<OpusPacketInfo> BuildOpusPacket(int config, | |
wolenetz
2015/02/03 22:47:01
ISTM that this could be a constructor. Also, the d
chcunningham
2015/02/05 02:48:20
Done.
| |
19 int frame_count, | |
20 bool is_VBR) { | |
21 scoped_ptr<OpusPacketInfo> packet_info(new OpusPacketInfo()); | |
22 packet_info->toc_config = config; | |
23 packet_info->frame_count = frame_count; | |
24 packet_info->duration_ms = | |
25 frame_count * (WebMClusterParser::kOpusFrameDurationsMu[config] / | |
26 static_cast<float>(1000)); | |
27 | |
28 int frame_count_code; | |
29 uint8 frame_count_byte; | |
wolenetz
2015/02/03 22:47:01
_t
chcunningham
2015/02/05 02:48:21
Done.
| |
30 | |
31 if (frame_count == 1) { | |
32 frame_count_code = 0; | |
33 } else if (frame_count == 2) { | |
34 frame_count_code = is_VBR ? 2 : 1; | |
35 } else { | |
36 frame_count_code = 3; | |
37 frame_count_byte = (is_VBR ? 1 << 7 : 0) | frame_count; | |
38 } | |
39 | |
40 // All opus packets must have TOC byte. | |
41 uint8 opus_toc_byte = (config << 3) | frame_count_code; | |
42 packet_info->data.push_back(opus_toc_byte); | |
43 | |
44 // For code 3 packets, the number of frames is signalled in the "frame | |
45 // count byte". | |
46 if (frame_count_code == 3) { | |
47 packet_info->data.push_back(frame_count_byte); | |
48 } | |
49 | |
50 // Simulating encoded frame data. | |
51 packet_info->data.push_back(static_cast<uint8>(0)); | |
52 | |
53 return packet_info.Pass(); | |
54 } | |
55 | |
56 // Builds an exhaustive collection of Opus packet configurations. | |
wolenetz
2015/02/03 22:47:01
nit: move method comment to .h
chcunningham
2015/02/05 02:48:21
Done.
| |
57 std::vector<scoped_ptr<OpusPacketInfo>> BuildAllOpusPackets() { | |
58 std::vector<scoped_ptr<OpusPacketInfo>> opus_packets; | |
59 | |
60 for (int frame_count = kMinOpusPacketFrameCount; | |
61 frame_count <= kMaxOpusPacketFrameCount; frame_count++) { | |
62 for (int opus_config_num = 0; opus_config_num < kNumPossibleOpusConfigs; | |
63 opus_config_num++) { | |
64 bool is_VBR = false; | |
65 opus_packets.push_back( | |
66 BuildOpusPacket(opus_config_num, frame_count, is_VBR)); | |
67 | |
68 if (frame_count >= 2) { | |
69 // Add another packet with VBR flag toggled. For frame counts >= 2, | |
70 // VBR triggers changes to packet framing. | |
71 is_VBR = true; | |
72 opus_packets.push_back( | |
73 BuildOpusPacket(opus_config_num, frame_count, is_VBR)); | |
74 } | |
75 } | |
76 } | |
77 | |
78 return opus_packets; | |
79 } | |
80 | |
81 } // namespace media | |
OLD | NEW |