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

Unified Diff: webrtc/modules/audio_coding/neteq/payload_splitter.cc

Issue 2326003002: Moved codec-specific audio packet splitting into decoders. (Closed)
Patch Set: Fixed types in packet splitting (size_t vs. uint32_t) Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/neteq/payload_splitter.cc
diff --git a/webrtc/modules/audio_coding/neteq/payload_splitter.cc b/webrtc/modules/audio_coding/neteq/payload_splitter.cc
index 074d1a2f0cfd4a037d478eeed51c52a8cb0cde33..28e561a65f259fb2de9af916db056a498cc23c80 100644
--- a/webrtc/modules/audio_coding/neteq/payload_splitter.cc
+++ b/webrtc/modules/audio_coding/neteq/payload_splitter.cc
@@ -212,214 +212,4 @@ int PayloadSplitter::CheckRedPayloads(PacketList* packet_list,
return num_deleted_packets;
}
-int PayloadSplitter::SplitAudio(PacketList* packet_list,
- const DecoderDatabase& decoder_database) {
- PacketList::iterator it = packet_list->begin();
- // Iterate through all packets in |packet_list|.
- while (it != packet_list->end()) {
- Packet* packet = (*it); // Just to make the notation more intuitive.
- // Get codec type for this payload.
- const DecoderDatabase::DecoderInfo* info =
- decoder_database.GetDecoderInfo(packet->header.payloadType);
- if (!info) {
- LOG(LS_WARNING) << "SplitAudio unknown payload type";
- return kUnknownPayloadType;
- }
- PacketList new_packets;
- switch (info->codec_type) {
- case NetEqDecoder::kDecoderPCMu:
- case NetEqDecoder::kDecoderPCMa: {
- // 8 bytes per ms; 8 timestamps per ms.
- SplitBySamples(packet, 8, 8, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCMu_2ch:
- case NetEqDecoder::kDecoderPCMa_2ch: {
- // 2 * 8 bytes per ms; 8 timestamps per ms.
- SplitBySamples(packet, 2 * 8, 8, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderG722: {
- // 8 bytes per ms; 16 timestamps per ms.
- SplitBySamples(packet, 8, 16, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16B: {
- // 16 bytes per ms; 8 timestamps per ms.
- SplitBySamples(packet, 16, 8, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16Bwb: {
- // 32 bytes per ms; 16 timestamps per ms.
- SplitBySamples(packet, 32, 16, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16Bswb32kHz: {
- // 64 bytes per ms; 32 timestamps per ms.
- SplitBySamples(packet, 64, 32, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16Bswb48kHz: {
- // 96 bytes per ms; 48 timestamps per ms.
- SplitBySamples(packet, 96, 48, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16B_2ch: {
- // 2 * 16 bytes per ms; 8 timestamps per ms.
- SplitBySamples(packet, 2 * 16, 8, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16Bwb_2ch: {
- // 2 * 32 bytes per ms; 16 timestamps per ms.
- SplitBySamples(packet, 2 * 32, 16, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch: {
- // 2 * 64 bytes per ms; 32 timestamps per ms.
- SplitBySamples(packet, 2 * 64, 32, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch: {
- // 2 * 96 bytes per ms; 48 timestamps per ms.
- SplitBySamples(packet, 2 * 96, 48, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderPCM16B_5ch: {
- // 5 * 16 bytes per ms; 8 timestamps per ms.
- SplitBySamples(packet, 5 * 16, 8, &new_packets);
- break;
- }
- case NetEqDecoder::kDecoderILBC: {
- size_t bytes_per_frame;
- int timestamps_per_frame;
- if (packet->payload.size() >= 950) {
- LOG(LS_WARNING) << "SplitAudio too large iLBC payload";
- return kTooLargePayload;
- }
- if (packet->payload.size() % 38 == 0) {
- // 20 ms frames.
- bytes_per_frame = 38;
- timestamps_per_frame = 160;
- } else if (packet->payload.size() % 50 == 0) {
- // 30 ms frames.
- bytes_per_frame = 50;
- timestamps_per_frame = 240;
- } else {
- LOG(LS_WARNING) << "SplitAudio invalid iLBC payload";
- return kFrameSplitError;
- }
- int ret = SplitByFrames(packet, bytes_per_frame, timestamps_per_frame,
- &new_packets);
- if (ret < 0) {
- return ret;
- } else if (ret == kNoSplit) {
- // Do not split at all. Simply advance to the next packet in the list.
- ++it;
- // We do not have any new packets to insert, and should not delete the
- // old one. Skip the code after the switch case, and jump straight to
- // the next packet in the while loop.
- continue;
- }
- break;
- }
- default: {
- // Do not split at all. Simply advance to the next packet in the list.
- ++it;
- // We do not have any new packets to insert, and should not delete the
- // old one. Skip the code after the switch case, and jump straight to
- // the next packet in the while loop.
- continue;
- }
- }
- // Insert new packets into original list, before the element pointed to by
- // iterator |it|.
- packet_list->splice(it, new_packets, new_packets.begin(),
- new_packets.end());
- // Delete old packet payload.
- delete (*it);
- // Remove |it| from the packet list. This operation effectively moves the
- // iterator |it| to the next packet in the list. Thus, we do not have to
- // increment it manually.
- it = packet_list->erase(it);
- }
- return kOK;
-}
-
-void PayloadSplitter::SplitBySamples(const Packet* packet,
- size_t bytes_per_ms,
- uint32_t timestamps_per_ms,
- PacketList* new_packets) {
- assert(packet);
- assert(new_packets);
-
- size_t split_size_bytes = packet->payload.size();
-
- // Find a "chunk size" >= 20 ms and < 40 ms.
- size_t min_chunk_size = bytes_per_ms * 20;
- // Reduce the split size by half as long as |split_size_bytes| is at least
- // twice the minimum chunk size (so that the resulting size is at least as
- // large as the minimum chunk size).
- while (split_size_bytes >= 2 * min_chunk_size) {
- split_size_bytes >>= 1;
- }
- uint32_t timestamps_per_chunk = static_cast<uint32_t>(
- split_size_bytes * timestamps_per_ms / bytes_per_ms);
- uint32_t timestamp = packet->header.timestamp;
-
- const uint8_t* payload_ptr = packet->payload.data();
- size_t len = packet->payload.size();
- while (len >= (2 * split_size_bytes)) {
- Packet* new_packet = new Packet;
- new_packet->header = packet->header;
- new_packet->header.timestamp = timestamp;
- timestamp += timestamps_per_chunk;
- new_packet->primary = packet->primary;
- new_packet->payload.SetData(payload_ptr, split_size_bytes);
- payload_ptr += split_size_bytes;
- new_packets->push_back(new_packet);
- len -= split_size_bytes;
- }
-
- if (len > 0) {
- Packet* new_packet = new Packet;
- new_packet->header = packet->header;
- new_packet->header.timestamp = timestamp;
- new_packet->primary = packet->primary;
- new_packet->payload.SetData(payload_ptr, len);
- new_packets->push_back(new_packet);
- }
-}
-
-int PayloadSplitter::SplitByFrames(const Packet* packet,
- size_t bytes_per_frame,
- uint32_t timestamps_per_frame,
- PacketList* new_packets) {
- if (packet->payload.size() % bytes_per_frame != 0) {
- LOG(LS_WARNING) << "SplitByFrames length mismatch";
- return kFrameSplitError;
- }
-
- if (packet->payload.size() == bytes_per_frame) {
- // Special case. Do not split the payload.
- return kNoSplit;
- }
-
- uint32_t timestamp = packet->header.timestamp;
- const uint8_t* payload_ptr = packet->payload.data();
- size_t len = packet->payload.size();
- while (len > 0) {
- assert(len >= bytes_per_frame);
- Packet* new_packet = new Packet;
- new_packet->header = packet->header;
- new_packet->header.timestamp = timestamp;
- timestamp += timestamps_per_frame;
- new_packet->primary = packet->primary;
- new_packet->payload.SetData(payload_ptr, bytes_per_frame);
- payload_ptr += bytes_per_frame;
- new_packets->push_back(new_packet);
- len -= bytes_per_frame;
- }
- return kOK;
-}
-
} // namespace webrtc
« no previous file with comments | « webrtc/modules/audio_coding/neteq/payload_splitter.h ('k') | webrtc/modules/audio_coding/neteq/payload_splitter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698