1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_ 13 14 #include "webrtc/base/constructormagic.h" 15 #include "webrtc/modules/audio_coding/neteq/packet.h" 16 17 namespace webrtc { 18 19 // Forward declarations. 20 class DecoderDatabase; 21 22 // This class handles splitting of payloads into smaller parts. 23 // The class does not have any member variables, and the methods could have 24 // been made static. The reason for not making them static is testability. 25 // With this design, the splitting functionality can be mocked during testing 26 // of the NetEqImpl class. 27 class PayloadSplitter { 28 public: 29 enum SplitterReturnCodes { 30 kOK = 0, 31 kNoSplit = 1, 32 kTooLargePayload = -1, 33 kFrameSplitError = -2, 34 kUnknownPayloadType = -3, 35 kRedLengthMismatch = -4, 36 kFecSplitError = -5, 37 }; 38 39 PayloadSplitter() {} 40 41 virtual ~PayloadSplitter() {} 42 43 // Splits each packet in |packet_list| into its separate RED payloads. Each 44 // RED payload is packetized into a Packet. The original elements in 45 // |packet_list| are properly deleted, and replaced by the new packets. 46 // Note that all packets in |packet_list| must be RED payloads, i.e., have 47 // RED headers according to RFC 2198 at the very beginning of the payload. 48 // Returns kOK or an error. 49 virtual int SplitRed(PacketList* packet_list); 50 51 // Iterates through |packet_list| and, duplicate each audio payload that has 52 // FEC as new packet for redundant decoding. The decoder database is needed to 53 // get information about which payload type each packet contains. 54 virtual int SplitFec(PacketList* packet_list, 55 DecoderDatabase* decoder_database); 56 57 // Checks all packets in |packet_list|. Packets that are DTMF events or 58 // comfort noise payloads are kept. Except that, only one single payload type 59 // is accepted. Any packet with another payload type is discarded. 60 virtual int CheckRedPayloads(PacketList* packet_list, 61 const DecoderDatabase& decoder_database); 62 63 // Iterates through |packet_list| and, if possible, splits each audio payload 64 // into suitable size chunks. The result is written back to |packet_list| as 65 // new packets. The decoder database is needed to get information about which 66 // payload type each packet contains. 67 virtual int SplitAudio(PacketList* packet_list, 68 const DecoderDatabase& decoder_database); 69 70 private: 71 // Splits the payload in |packet|. The payload is assumed to be from a 72 // sample-based codec. 73 virtual void SplitBySamples(const Packet* packet, 74 int bytes_per_ms, 75 int timestamps_per_ms, 76 PacketList* new_packets); 77 78 // Splits the payload in |packet|. The payload will be split into chunks of 79 // size |bytes_per_frame|, corresponding to a |timestamps_per_frame| 80 // RTP timestamps. 81 virtual int SplitByFrames(const Packet* packet, 82 int bytes_per_frame, 83 int timestamps_per_frame, 84 PacketList* new_packets); 85 86 DISALLOW_COPY_AND_ASSIGN(PayloadSplitter); 87 }; 88 89 } // namespace webrtc 90 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_ 91