Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: media/formats/webm/opus_packet_builder.cc

Issue 883403002: Parsing of encoded duration for unencrypted opus streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing feedback, round 3. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/logging.h"
6 #include "media/formats/webm/opus_packet_builder.h"
7 #include "media/formats/webm/webm_cluster_parser.h"
8
9 namespace media {
10
11 // From Opus RFC. See https://tools.ietf.org/html/rfc6716#page-14
12 enum OpusConstants {
13 kNumPossibleOpusConfigs = 32,
14 kMinOpusPacketFrameCount = 1,
15 kMaxOpusPacketFrameCount = 48
16 };
17
18 OpusPacket::OpusPacket(uint8_t config, uint8_t frame_count, bool is_VBR) {
19 DCHECK_GE(config, 0);
20 DCHECK_LT(config, kNumPossibleOpusConfigs);
21 DCHECK_GE(frame_count, kMinOpusPacketFrameCount);
22 DCHECK_LE(frame_count, kMaxOpusPacketFrameCount);
23
24 duration_ms_ = frame_count *
25 WebMClusterParser::kOpusFrameDurationsMu[config] /
26 static_cast<float>(1000);
27
28 uint8_t frame_count_code;
29 uint8_t frame_count_byte;
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_t opus_toc_byte = (config << 3) | frame_count_code;
42 data_.push_back(opus_toc_byte);
43
44 // For code 3 packets, the number of frames is signaled in the "frame
45 // count byte".
46 if (frame_count_code == 3) {
47 data_.push_back(frame_count_byte);
48 }
49
50 // Packet will only conform to layout specification for the TOC byte
51 // and optional frame count bytes appended above. This last byte
52 // is purely dummy padding where frame size data or encoded data might
53 // otherwise start.
54 data_.push_back(static_cast<uint8_t>(0));
55 }
56
57 OpusPacket::~OpusPacket() {
58 }
59
60 const uint8_t* OpusPacket::data() const {
61 return &(data_[0]);
62 }
63
64 int OpusPacket::size() const {
65 return data_.size();
66 }
67
68 double OpusPacket::duration_ms() const {
69 return duration_ms_;
70 }
71
72 ScopedVector<OpusPacket> BuildAllOpusPackets() {
73 ScopedVector<OpusPacket> opus_packets;
74
75 for (int frame_count = kMinOpusPacketFrameCount;
76 frame_count <= kMaxOpusPacketFrameCount; frame_count++) {
77 for (int opus_config_num = 0; opus_config_num < kNumPossibleOpusConfigs;
78 opus_config_num++) {
79 bool is_VBR = false;
80 opus_packets.push_back(
81 new OpusPacket(opus_config_num, frame_count, is_VBR));
82
83 if (frame_count >= 2) {
84 // Add another packet with VBR flag toggled. For frame counts >= 2,
85 // VBR triggers changes to packet framing.
86 is_VBR = true;
87 opus_packets.push_back(
88 new OpusPacket(opus_config_num, frame_count, is_VBR));
89 }
90 }
91 }
92
93 return opus_packets.Pass();
94 }
95
96 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698