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 https://tools.ietf.org/html/rfc6716#page-14 | |
7 enum OpusConstants { | |
8 kNumPossibleOpusConfigs = 32, | |
9 kMinOpusPacketFrameCount = 1, | |
10 kMaxOpusPacketFrameCount = 48 | |
11 }; | |
12 | |
13 OpusPacket::OpusPacket(int config, int frame_count, bool is_VBR) { | |
wolenetz
2015/02/05 23:05:00
narrow param types (uint8_t config and frame_count
chcunningham
2015/02/06 03:20:09
Done.
| |
14 duration_ms_ = frame_count * | |
wolenetz
2015/02/05 23:04:59
nit: protect borders (DCHECK fail for invalid conf
chcunningham
2015/02/06 03:20:09
Done. Decided to not allow invalid packets at this
| |
15 WebMClusterParser::kOpusFrameDurationsMu[config] / | |
16 static_cast<float>(1000); | |
17 | |
18 int frame_count_code; | |
19 uint8_t frame_count_byte; | |
20 | |
21 if (frame_count == 1) { | |
22 frame_count_code = 0; | |
23 } else if (frame_count == 2) { | |
24 frame_count_code = is_VBR ? 2 : 1; | |
25 } else { | |
26 frame_count_code = 3; | |
27 frame_count_byte = (is_VBR ? 1 << 7 : 0) | frame_count; | |
28 } | |
29 | |
30 // All opus packets must have TOC byte. | |
31 uint8_t opus_toc_byte = (config << 3) | frame_count_code; | |
32 data_.push_back(opus_toc_byte); | |
33 | |
34 // For code 3 packets, the number of frames is signaled in the "frame | |
wolenetz
2015/02/05 23:04:59
For code 2 packets, the compressed length.. is als
chcunningham
2015/02/06 03:20:09
Clarified the comment that we're not really attemp
| |
35 // count byte". | |
36 if (frame_count_code == 3) { | |
37 data_.push_back(frame_count_byte); | |
38 } | |
39 | |
40 // Simulating encoded frame data. | |
41 data_.push_back(static_cast<uint8_t>(0)); | |
42 } | |
43 | |
44 OpusPacket::~OpusPacket() { | |
45 } | |
46 | |
47 const uint8_t* OpusPacket::data() const { | |
48 return &(data_[0]); | |
49 } | |
50 | |
51 int OpusPacket::size() const { | |
52 return data_.size(); | |
53 } | |
54 | |
55 double OpusPacket::duration_ms() const { | |
56 return duration_ms_; | |
57 } | |
58 | |
59 ScopedVector<OpusPacket> BuildAllOpusPackets() { | |
wolenetz
2015/02/05 23:04:59
Are there illegal Opus Packet config + frame_count
chcunningham
2015/02/06 03:20:09
Done.
| |
60 ScopedVector<OpusPacket> opus_packets; | |
61 | |
62 for (int frame_count = kMinOpusPacketFrameCount; | |
63 frame_count <= kMaxOpusPacketFrameCount; frame_count++) { | |
64 for (int opus_config_num = 0; opus_config_num < kNumPossibleOpusConfigs; | |
65 opus_config_num++) { | |
66 bool is_VBR = false; | |
wolenetz
2015/02/05 23:04:59
nit: is_VBR can be inlined in each of the two call
chcunningham
2015/02/06 03:20:09
I like this for self documenting the meaning of th
wolenetz
2015/02/06 19:48:01
Acknowledged.
| |
67 opus_packets.push_back( | |
68 new OpusPacket(opus_config_num, frame_count, is_VBR)); | |
69 | |
70 if (frame_count >= 2) { | |
71 // Add another packet with VBR flag toggled. For frame counts >= 2, | |
72 // VBR triggers changes to packet framing. | |
73 is_VBR = true; | |
74 opus_packets.push_back( | |
75 new OpusPacket(opus_config_num, frame_count, is_VBR)); | |
76 } | |
77 } | |
78 } | |
79 | |
80 return opus_packets.Pass(); | |
81 } | |
82 | |
83 } // namespace media | |
OLD | NEW |