blob: 3768c2f2b1cbea91c029ba8f13c2de8c2e33b707 [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
11#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PAYLOAD_SPLITTER_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PAYLOAD_SPLITTER_H_
13
14#include "webrtc/modules/audio_coding/neteq4/packet.h"
15#include "webrtc/system_wrappers/interface/constructor_magic.h"
16
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,
35 kRedLengthMismatch = -4
36 };
37
38 PayloadSplitter() {}
39
40 virtual ~PayloadSplitter() {}
41
42 // Splits each packet in |packet_list| into its separate RED payloads. Each
43 // RED payload is packetized into a Packet. The original elements in
44 // |packet_list| are properly deleted, and replaced by the new packets.
45 // Note that all packets in |packet_list| must be RED payloads, i.e., have
46 // RED headers according to RFC 2198 at the very beginning of the payload.
47 // Returns kOK or an error.
48 virtual int SplitRed(PacketList* packet_list);
49
50 // Checks all packets in |packet_list|. Packets that are DTMF events or
51 // comfort noise payloads are kept. Except that, only one single payload type
52 // is accepted. Any packet with another payload type is discarded.
53 virtual int CheckRedPayloads(PacketList* packet_list,
54 const DecoderDatabase& decoder_database);
55
56 // Iterates through |packet_list| and, if possible, splits each audio payload
57 // into suitable size chunks. The result is written back to |packet_list| as
58 // new packets. The decoder database is needed to get information about which
59 // payload type each packet contains.
60 virtual int SplitAudio(PacketList* packet_list,
61 const DecoderDatabase& decoder_database);
62
63 private:
64 // Splits the payload in |packet|. The payload is assumed to be from a
65 // sample-based codec.
66 virtual void SplitBySamples(const Packet* packet,
67 int bytes_per_ms,
68 int timestamps_per_ms,
69 PacketList* new_packets);
70
71 // Splits the payload in |packet|. The payload will be split into chunks of
72 // size |bytes_per_frame|, corresponding to a |timestamps_per_frame|
73 // RTP timestamps.
74 virtual int SplitByFrames(const Packet* packet,
75 int bytes_per_frame,
76 int timestamps_per_frame,
77 PacketList* new_packets);
78
79 DISALLOW_COPY_AND_ASSIGN(PayloadSplitter);
80};
81
82} // namespace webrtc
83#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_PAYLOAD_SPLITTER_H_