henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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 | |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_ |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 13 | |
henrike@webrtc.org | 88fbb2d | 2014-05-21 21:18:46 +0000 | [diff] [blame] | 14 | #include "webrtc/base/constructormagic.h" |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 15 | #include "webrtc/modules/audio_coding/neteq/packet.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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, |
minyue@webrtc.org | b28bfa7 | 2014-03-21 12:07:40 +0000 | [diff] [blame] | 35 | kRedLengthMismatch = -4, |
| 36 | kFecSplitError = -5, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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 | |
minyue@webrtc.org | b28bfa7 | 2014-03-21 12:07:40 +0000 | [diff] [blame] | 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 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 74 | size_t bytes_per_ms, |
| 75 | uint32_t timestamps_per_ms, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 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, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 82 | size_t bytes_per_frame, |
| 83 | uint32_t timestamps_per_frame, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 84 | PacketList* new_packets); |
| 85 | |
| 86 | DISALLOW_COPY_AND_ASSIGN(PayloadSplitter); |
| 87 | }; |
| 88 | |
| 89 | } // namespace webrtc |
henrik.lundin@webrtc.org | 9c55f0f | 2014-06-09 08:10:28 +0000 | [diff] [blame] | 90 | #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_ |