blob: 783b001fc3e0db0ffe2032c340cac73f3efd5201 [file] [log] [blame]
henrik.lundin@webrtc.org9a400812013-01-29 12:09:21 +00001/*
2 * Copyright (c) 2013 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_DECISION_LOGIC_NORMAL_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ4_DECISION_LOGIC_NORMAL_H_
13
14#include "webrtc/modules/audio_coding/neteq4/decision_logic.h"
15#include "webrtc/system_wrappers/interface/constructor_magic.h"
16#include "webrtc/typedefs.h"
17
18namespace webrtc {
19
20// Implementation of the DecisionLogic class for playout modes kPlayoutOn and
21// kPlayoutStreaming.
22class DecisionLogicNormal : public DecisionLogic {
23 public:
24 // Constructor.
25 DecisionLogicNormal(int fs_hz,
26 int output_size_samples,
27 NetEqPlayoutMode playout_mode,
28 DecoderDatabase* decoder_database,
29 const PacketBuffer& packet_buffer,
30 DelayManager* delay_manager,
31 BufferLevelFilter* buffer_level_filter)
32 : DecisionLogic(fs_hz, output_size_samples, playout_mode,
33 decoder_database, packet_buffer, delay_manager,
34 buffer_level_filter) {
35 }
36
37 // Destructor.
38 virtual ~DecisionLogicNormal() {}
39
40 protected:
41 // Returns the operation that should be done next. |sync_buffer| and |expand|
42 // are provided for reference. |decoder_frame_length| is the number of samples
43 // obtained from the last decoded frame. If there is a packet available, the
44 // packet header should be supplied in |packet_header|; otherwise it should
45 // be NULL. The mode resulting form the last call to NetEqImpl::GetAudio is
46 // supplied in |prev_mode|. If there is a DTMF event to play, |play_dtmf|
47 // should be set to true. The output variable |reset_decoder| will be set to
48 // true if a reset is required; otherwise it is left unchanged (i.e., it can
49 // remain true if it was true before the call).
50 virtual Operations GetDecisionSpecialized(const SyncBuffer& sync_buffer,
51 const Expand& expand,
52 int decoder_frame_length,
53 const RTPHeader* packet_header,
54 Modes prev_mode, bool play_dtmf,
55 bool* reset_decoder);
56
57 private:
58 static const int kAllowMergeWithoutExpandMs = 20; // 20 ms.
59 static const int kReinitAfterExpands = 100;
60 static const int kMaxWaitForPacket = 10;
61
62 // Returns the operation given that the next available packet is a comfort
63 // noise payload (RFC 3389 only, not codec-internal).
64 Operations CngOperation(Modes prev_mode, uint32_t target_timestamp,
65 uint32_t available_timestamp);
66
67 // Returns the operation given that no packets are available (except maybe
68 // a DTMF event, flagged by setting |play_dtmf| true).
69 Operations NoPacket(bool play_dtmf);
70
71 // Returns the operation to do given that the expected packet is available.
72 Operations ExpectedPacketAvailable(Modes prev_mode, bool play_dtmf);
73
74 // Returns the operation to do given that the expected packet is not
75 // available, but a packet further into the future is at hand.
76 Operations FuturePacketAvailable(const SyncBuffer& sync_buffer,
77 const Expand& expand,
78 int decoder_frame_length, Modes prev_mode,
79 uint32_t target_timestamp,
80 uint32_t available_timestamp,
81 bool play_dtmf);
82
83 // Checks if enough time has elapsed since the last successful timescale
84 // operation was done (i.e., accelerate or preemptive expand).
85 bool TimescaleAllowed() const { return timescale_hold_off_ == 0; }
86
87 // Checks if the current (filtered) buffer level is under the target level.
88 bool UnderTargetLevel() const;
89
90 // Checks if |timestamp_leap| is so long into the future that a reset due
91 // to exceeding kReinitAfterExpands will be done.
92 bool ReinitAfterExpands(uint32_t timestamp_leap) const;
93
94 // Checks if we still have not done enough expands to cover the distance from
95 // the last decoded packet to the next available packet, the distance beeing
96 // conveyed in |timestamp_leap|.
97 bool PacketTooEarly(uint32_t timestamp_leap) const;
98
99 // Checks if num_consecutive_expands_ >= kMaxWaitForPacket.
100 bool MaxWaitForPacket() const;
101
102 DISALLOW_COPY_AND_ASSIGN(DecisionLogicNormal);
103};
104
105} // namespace webrtc
106#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ4_DECISION_LOGIC_NORMAL_H_