Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: webrtc/api/audio_codec/audio_decoder.cc

Issue 2668523004: Move AudioDecoder and related stuff to the api/ directory (Closed)
Patch Set: sort #includes + git cl format Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/api/audio_codec/audio_decoder.cc
diff --git a/webrtc/modules/audio_coding/codecs/audio_decoder.cc b/webrtc/api/audio_codec/audio_decoder.cc
similarity index 66%
rename from webrtc/modules/audio_coding/codecs/audio_decoder.cc
rename to webrtc/api/audio_codec/audio_decoder.cc
index afa5115d5a1740036c566ded3c9c9019b78bb233..8697ac3f67f8f1225dfdc50265547f41b8478815 100644
--- a/webrtc/modules/audio_coding/codecs/audio_decoder.cc
+++ b/webrtc/api/audio_codec/audio_decoder.cc
@@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
+#include "webrtc/api/audio_codec/audio_decoder.h"
#include <assert.h>
the sun 2017/02/02 21:02:29 We should use DCHECK here. But perhaps it is bett
kwiberg-webrtc 2017/02/03 09:50:11 Yes, exactly. I'm (mostly) just moving this file,
#include <memory>
@@ -18,10 +18,39 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/sanitizer.h"
#include "webrtc/base/trace_event.h"
-#include "webrtc/modules/audio_coding/codecs/legacy_encoded_audio_frame.h"
namespace webrtc {
+namespace {
+
+class EncFrame final : public AudioDecoder::EncodedAudioFrame {
ossu 2017/02/01 15:05:26 Please pick a better name, even if it's just tempo
kwiberg-webrtc 2017/02/01 20:15:02 Will "EncodedFrame" do? That's what it is, and wha
ossu 2017/02/06 12:54:16 No, I don't think that expresses what this is, rea
kwiberg-webrtc 2017/02/06 14:19:36 OK, I'll pick a name like that. Maybe OldStyle* or
ossu 2017/02/06 14:44:06 Legacy might clash (at least mentally) with the ot
+ public:
+ EncFrame(AudioDecoder* decoder, rtc::Buffer&& payload)
+ : decoder_(decoder), payload_(std::move(payload)) {}
+
+ size_t Duration() const override {
+ const int ret = decoder_->PacketDuration(payload_.data(), payload_.size());
+ return ret < 0 ? 0 : static_cast<size_t>(ret);
+ }
+
+ rtc::Optional<DecodeResult> Decode(
+ rtc::ArrayView<int16_t> decoded) const override {
+ auto speech_type = AudioDecoder::kSpeech;
+ const int ret = decoder_->Decode(
+ payload_.data(), payload_.size(), decoder_->SampleRateHz(),
+ decoded.size() * sizeof(int16_t), decoded.data(), &speech_type);
+ return ret < 0 ? rtc::Optional<DecodeResult>()
+ : rtc::Optional<DecodeResult>(
+ {static_cast<size_t>(ret), speech_type});
+ }
+
+ private:
+ AudioDecoder* const decoder_;
the sun 2017/02/02 21:02:29 So does the decoder own all its frames, so they ar
kwiberg-webrtc 2017/02/03 09:50:11 The docs for ParsePayload, which returns these, sa
ossu 2017/02/06 12:54:16 I'd argue that is unreasonable to have a frame out
+ const rtc::Buffer payload_;
+};
+
+} // namespace
+
AudioDecoder::ParseResult::ParseResult() = default;
AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default;
AudioDecoder::ParseResult::ParseResult(uint32_t timestamp,
@@ -41,14 +70,17 @@ std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload(
uint32_t timestamp) {
std::vector<ParseResult> results;
std::unique_ptr<EncodedAudioFrame> frame(
- new LegacyEncodedAudioFrame(this, std::move(payload)));
+ new EncFrame(this, std::move(payload)));
results.emplace_back(timestamp, 0, std::move(frame));
return results;
}
-int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len,
- int sample_rate_hz, size_t max_decoded_bytes,
- int16_t* decoded, SpeechType* speech_type) {
+int AudioDecoder::Decode(const uint8_t* encoded,
+ size_t encoded_len,
+ int sample_rate_hz,
+ size_t max_decoded_bytes,
+ int16_t* decoded,
+ SpeechType* speech_type) {
TRACE_EVENT0("webrtc", "AudioDecoder::Decode");
rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len));
int duration = PacketDuration(encoded, encoded_len);
@@ -60,9 +92,12 @@ int AudioDecoder::Decode(const uint8_t* encoded, size_t encoded_len,
speech_type);
}
-int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
- int sample_rate_hz, size_t max_decoded_bytes,
- int16_t* decoded, SpeechType* speech_type) {
+int AudioDecoder::DecodeRedundant(const uint8_t* encoded,
+ size_t encoded_len,
+ int sample_rate_hz,
+ size_t max_decoded_bytes,
+ int16_t* decoded,
+ SpeechType* speech_type) {
TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant");
rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len));
int duration = PacketDurationRedundant(encoded, encoded_len);
@@ -76,13 +111,16 @@ int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len,
int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded,
size_t encoded_len,
- int sample_rate_hz, int16_t* decoded,
+ int sample_rate_hz,
+ int16_t* decoded,
SpeechType* speech_type) {
return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded,
speech_type);
}
-bool AudioDecoder::HasDecodePlc() const { return false; }
+bool AudioDecoder::HasDecodePlc() const {
+ return false;
+}
size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) {
return 0;
@@ -96,7 +134,9 @@ int AudioDecoder::IncomingPacket(const uint8_t* payload,
return 0;
the sun 2017/02/02 21:02:29 Remove as many default implementations of overrida
kwiberg-webrtc 2017/02/03 09:50:11 I agree. But not in this CL.
}
-int AudioDecoder::ErrorCode() { return 0; }
+int AudioDecoder::ErrorCode() {
+ return 0;
+}
int AudioDecoder::PacketDuration(const uint8_t* encoded,
size_t encoded_len) const {

Powered by Google App Engine
This is Rietveld 408576698