Line data Source code
1 : /*
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_NETEQ_DECISION_LOGIC_NORMAL_H_
12 : #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECISION_LOGIC_NORMAL_H_
13 :
14 : #include "webrtc/base/constructormagic.h"
15 : #include "webrtc/modules/audio_coding/neteq/decision_logic.h"
16 : #include "webrtc/typedefs.h"
17 :
18 : namespace webrtc {
19 :
20 : // Implementation of the DecisionLogic class for playout modes kPlayoutOn and
21 : // kPlayoutStreaming.
22 0 : class DecisionLogicNormal : public DecisionLogic {
23 : public:
24 : // Constructor.
25 0 : DecisionLogicNormal(int fs_hz,
26 : size_t 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 : const TickTimer* tick_timer)
33 0 : : DecisionLogic(fs_hz,
34 : output_size_samples,
35 : playout_mode,
36 : decoder_database,
37 : packet_buffer,
38 : delay_manager,
39 : buffer_level_filter,
40 0 : tick_timer) {}
41 :
42 : protected:
43 : static const int kReinitAfterExpands = 100;
44 : static const int kMaxWaitForPacket = 10;
45 :
46 : Operations GetDecisionSpecialized(const SyncBuffer& sync_buffer,
47 : const Expand& expand,
48 : size_t decoder_frame_length,
49 : const Packet* next_packet,
50 : Modes prev_mode,
51 : bool play_dtmf,
52 : bool* reset_decoder,
53 : size_t generated_noise_samples) override;
54 :
55 : // Returns the operation to do given that the expected packet is not
56 : // available, but a packet further into the future is at hand.
57 : virtual Operations FuturePacketAvailable(
58 : const SyncBuffer& sync_buffer,
59 : const Expand& expand,
60 : size_t decoder_frame_length,
61 : Modes prev_mode,
62 : uint32_t target_timestamp,
63 : uint32_t available_timestamp,
64 : bool play_dtmf,
65 : size_t generated_noise_samples);
66 :
67 : // Returns the operation to do given that the expected packet is available.
68 : virtual Operations ExpectedPacketAvailable(Modes prev_mode, bool play_dtmf);
69 :
70 : // Returns the operation given that no packets are available (except maybe
71 : // a DTMF event, flagged by setting |play_dtmf| true).
72 : virtual Operations NoPacket(bool play_dtmf);
73 :
74 : private:
75 : // Returns the operation given that the next available packet is a comfort
76 : // noise payload (RFC 3389 only, not codec-internal).
77 : Operations CngOperation(Modes prev_mode,
78 : uint32_t target_timestamp,
79 : uint32_t available_timestamp,
80 : size_t generated_noise_samples);
81 :
82 : // Checks if enough time has elapsed since the last successful timescale
83 : // operation was done (i.e., accelerate or preemptive expand).
84 0 : bool TimescaleAllowed() const {
85 0 : return !timescale_countdown_ || timescale_countdown_->Finished();
86 : }
87 :
88 : // Checks if the current (filtered) buffer level is under the target level.
89 : bool UnderTargetLevel() const;
90 :
91 : // Checks if |timestamp_leap| is so long into the future that a reset due
92 : // to exceeding kReinitAfterExpands will be done.
93 : bool ReinitAfterExpands(uint32_t timestamp_leap) const;
94 :
95 : // Checks if we still have not done enough expands to cover the distance from
96 : // the last decoded packet to the next available packet, the distance beeing
97 : // conveyed in |timestamp_leap|.
98 : bool PacketTooEarly(uint32_t timestamp_leap) const;
99 :
100 : // Checks if num_consecutive_expands_ >= kMaxWaitForPacket.
101 : bool MaxWaitForPacket() const;
102 :
103 : RTC_DISALLOW_COPY_AND_ASSIGN(DecisionLogicNormal);
104 : };
105 :
106 : } // namespace webrtc
107 : #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECISION_LOGIC_NORMAL_H_
|