5 #include "packager/base/logging.h"
6 #include "packager/media/formats/webm/opus_packet_builder.h"
7 #include "packager/media/formats/webm/webm_cluster_parser.h"
9 namespace edash_packager {
12 OpusPacket::OpusPacket(uint8_t config, uint8_t frame_count,
bool is_VBR) {
14 DCHECK_LT(config, kNumPossibleOpusConfigs);
15 DCHECK_GE(frame_count, kMinOpusPacketFrameCount);
16 DCHECK_LE(frame_count, kMaxOpusPacketFrameCount);
18 duration_ms_ = frame_count *
19 WebMClusterParser::kOpusFrameDurationsMu[config] /
20 static_cast<float>(1000);
22 uint8_t frame_count_code;
23 uint8_t frame_count_byte;
25 if (frame_count == 1) {
27 }
else if (frame_count == 2) {
28 frame_count_code = is_VBR ? 2 : 1;
31 frame_count_byte = (is_VBR ? 1 << 7 : 0) | frame_count;
35 uint8_t opus_toc_byte = (config << 3) | frame_count_code;
36 data_.push_back(opus_toc_byte);
40 if (frame_count_code == 3) {
41 data_.push_back(frame_count_byte);
48 data_.push_back(static_cast<uint8_t>(0));
51 OpusPacket::~OpusPacket() {
54 const uint8_t* OpusPacket::data()
const {
58 int OpusPacket::size()
const {
62 double OpusPacket::duration_ms()
const {
66 ScopedVector<OpusPacket> BuildAllOpusPackets() {
67 ScopedVector<OpusPacket> opus_packets;
69 for (
int frame_count = kMinOpusPacketFrameCount;
70 frame_count <= kMaxOpusPacketFrameCount; frame_count++) {
71 for (
int opus_config_num = 0; opus_config_num < kNumPossibleOpusConfigs;
74 opus_packets.push_back(
75 new OpusPacket(opus_config_num, frame_count, is_VBR));
77 if (frame_count >= 2) {
81 opus_packets.push_back(
82 new OpusPacket(opus_config_num, frame_count, is_VBR));
87 return opus_packets.Pass();