blob: 0520918f9f1971bb1983f90d8267d39fc86ad87e [file] [log] [blame]
henrik.lundin@webrtc.orgc1c92912014-12-16 13:41:36 +00001/*
2 * Copyright (c) 2014 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/modules/audio_coding/codecs/audio_encoder.h"
Peter Boströmd7b7ae82015-12-08 13:41:35 +010012
henrik.lundin@webrtc.orgf45c8ca2015-02-05 18:29:39 +000013#include "webrtc/base/checks.h"
Peter Boströmd7b7ae82015-12-08 13:41:35 +010014#include "webrtc/base/trace_event.h"
henrik.lundin@webrtc.orgc1c92912014-12-16 13:41:36 +000015
16namespace webrtc {
17
kwiberg12cfc9b2015-09-08 05:57:53 -070018AudioEncoder::EncodedInfo::EncodedInfo() = default;
henrik.lundin@webrtc.orgc1c92912014-12-16 13:41:36 +000019
kwiberg12cfc9b2015-09-08 05:57:53 -070020AudioEncoder::EncodedInfo::~EncodedInfo() = default;
21
22int AudioEncoder::RtpTimestampRateHz() const {
23 return SampleRateHz();
henrik.lundin@webrtc.orgc1c92912014-12-16 13:41:36 +000024}
25
kwiberg288886b2015-11-06 01:21:35 -080026AudioEncoder::EncodedInfo AudioEncoder::Encode(
27 uint32_t rtp_timestamp,
28 rtc::ArrayView<const int16_t> audio,
ossu10a029e2016-03-01 00:41:31 -080029 rtc::Buffer* encoded) {
30 TRACE_EVENT0("webrtc", "AudioEncoder::Encode");
31 RTC_CHECK_EQ(audio.size(),
32 static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
33
34 const size_t old_size = encoded->size();
35 EncodedInfo info = EncodeInternal(rtp_timestamp, audio, encoded);
36 RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes);
37 return info;
38}
39
40AudioEncoder::EncodedInfo AudioEncoder::Encode(
41 uint32_t rtp_timestamp,
42 rtc::ArrayView<const int16_t> audio,
43 size_t max_encoded_bytes,
44 uint8_t* encoded) {
45 return DEPRECATED_Encode(rtp_timestamp, audio, max_encoded_bytes, encoded);
46}
47
48AudioEncoder::EncodedInfo AudioEncoder::DEPRECATED_Encode(
49 uint32_t rtp_timestamp,
50 rtc::ArrayView<const int16_t> audio,
kwiberg288886b2015-11-06 01:21:35 -080051 size_t max_encoded_bytes,
52 uint8_t* encoded) {
Peter Boströmd7b7ae82015-12-08 13:41:35 +010053 TRACE_EVENT0("webrtc", "AudioEncoder::Encode");
kwiberg288886b2015-11-06 01:21:35 -080054 RTC_CHECK_EQ(audio.size(),
55 static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
jmarusic@webrtc.org9afaee72015-03-19 08:50:26 +000056 EncodedInfo info =
57 EncodeInternal(rtp_timestamp, audio, max_encoded_bytes, encoded);
henrikg91d6ede2015-09-17 00:24:34 -070058 RTC_CHECK_LE(info.encoded_bytes, max_encoded_bytes);
jmarusic@webrtc.org9afaee72015-03-19 08:50:26 +000059 return info;
henrik.lundin@webrtc.orgf45c8ca2015-02-05 18:29:39 +000060}
61
ossu10a029e2016-03-01 00:41:31 -080062AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal(
63 uint32_t rtp_timestamp,
64 rtc::ArrayView<const int16_t> audio,
65 rtc::Buffer* encoded)
66{
67 EncodedInfo info;
68 encoded->AppendData(MaxEncodedBytes(), [&] (rtc::ArrayView<uint8_t> encoded) {
69 info = EncodeInternal(rtp_timestamp, audio,
70 encoded.size(), encoded.data());
71 return info.encoded_bytes;
72 });
73 return info;
74}
75
76AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal(
77 uint32_t rtp_timestamp,
78 rtc::ArrayView<const int16_t> audio,
79 size_t max_encoded_bytes,
80 uint8_t* encoded)
81{
82 rtc::Buffer temp_buffer;
83 EncodedInfo info = EncodeInternal(rtp_timestamp, audio, &temp_buffer);
84 RTC_DCHECK_LE(temp_buffer.size(), max_encoded_bytes);
85 std::memcpy(encoded, temp_buffer.data(), info.encoded_bytes);
86 return info;
87}
88
kwiberg12cfc9b2015-09-08 05:57:53 -070089bool AudioEncoder::SetFec(bool enable) {
90 return !enable;
henrik.lundin@webrtc.org478cedc2015-01-27 18:24:45 +000091}
92
kwiberg12cfc9b2015-09-08 05:57:53 -070093bool AudioEncoder::SetDtx(bool enable) {
94 return !enable;
95}
96
97bool AudioEncoder::SetApplication(Application application) {
98 return false;
99}
100
kwiberg3f5f1c22015-09-08 23:15:33 -0700101void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {}
kwiberg12cfc9b2015-09-08 05:57:53 -0700102
103void AudioEncoder::SetProjectedPacketLossRate(double fraction) {}
104
105void AudioEncoder::SetTargetBitrate(int target_bps) {}
106
henrik.lundin@webrtc.orgc1c92912014-12-16 13:41:36 +0000107} // namespace webrtc