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
11#include "webrtc/voice_engine/voe_neteq_stats_impl.h"
12
13#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
14#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
15#include "webrtc/system_wrappers/include/trace.h"
16#include "webrtc/voice_engine/channel.h"
17#include "webrtc/voice_engine/include/voe_errors.h"
18#include "webrtc/voice_engine/voice_engine_impl.h"
19
20namespace webrtc {
21
22VoENetEqStats* VoENetEqStats::GetInterface(VoiceEngine* voiceEngine) {
23#ifndef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
24  return NULL;
25#else
26  if (NULL == voiceEngine) {
27    return NULL;
28  }
29  VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
30  s->AddRef();
31  return s;
32#endif
33}
34
35#ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
36
37VoENetEqStatsImpl::VoENetEqStatsImpl(voe::SharedData* shared)
38    : _shared(shared) {
39  WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
40               "VoENetEqStatsImpl::VoENetEqStatsImpl() - ctor");
41}
42
43VoENetEqStatsImpl::~VoENetEqStatsImpl() {
44  WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
45               "VoENetEqStatsImpl::~VoENetEqStatsImpl() - dtor");
46}
47
48int VoENetEqStatsImpl::GetNetworkStatistics(int channel,
49                                            NetworkStatistics& stats) {
50  if (!_shared->statistics().Initialized()) {
51    _shared->SetLastError(VE_NOT_INITED, kTraceError);
52    return -1;
53  }
54  voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
55  voe::Channel* channelPtr = ch.channel();
56  if (channelPtr == NULL) {
57    _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
58                          "GetNetworkStatistics() failed to locate channel");
59    return -1;
60  }
61
62  return channelPtr->GetNetworkStatistics(stats);
63}
64
65int VoENetEqStatsImpl::GetDecodingCallStatistics(
66    int channel, AudioDecodingCallStats* stats) const {
67  if (!_shared->statistics().Initialized()) {
68    _shared->SetLastError(VE_NOT_INITED, kTraceError);
69    return -1;
70  }
71  voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
72  voe::Channel* channelPtr = ch.channel();
73  if (channelPtr == NULL) {
74    _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
75                          "GetDecodingCallStatistics() failed to locate "
76                          "channel");
77    return -1;
78  }
79
80  channelPtr->GetDecodingCallStatistics(stats);
81  return 0;
82}
83
84#endif  // #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
85
86}  // namespace webrtc
87