blob: 6023d4e007fce6536326e2ecdf0c0a36eedb8794 [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
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.org9c55f0f2014-06-09 08:10:28 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013
henrike@webrtc.org88fbb2d2014-05-21 21:18:46 +000014#include "webrtc/base/constructormagic.h"
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000015#include "webrtc/modules/audio_coding/neteq/packet.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000016
17namespace webrtc {
18
19// Forward declarations.
20class 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.
27class PayloadSplitter {
28 public:
29 enum SplitterReturnCodes {
30 kOK = 0,
31 kNoSplit = 1,
32 kTooLargePayload = -1,
33 kFrameSplitError = -2,
34 kUnknownPayloadType = -3,
minyue@webrtc.orgb28bfa72014-03-21 12:07:40 +000035 kRedLengthMismatch = -4,
36 kFecSplitError = -5,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000037 };
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.orgb28bfa72014-03-21 12:07:40 +000051 // 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.orgd94659d2013-01-29 12:09:21 +000057 // 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.org4591fbd2014-11-20 22:28:14 +000074 size_t bytes_per_ms,
75 uint32_t timestamps_per_ms,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000076 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.org4591fbd2014-11-20 22:28:14 +000082 size_t bytes_per_frame,
83 uint32_t timestamps_per_frame,
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000084 PacketList* new_packets);
85
86 DISALLOW_COPY_AND_ASSIGN(PayloadSplitter);
87};
88
89} // namespace webrtc
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000090#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_PAYLOAD_SPLITTER_H_