Index: webrtc/modules/audio_coding/codecs/audio_decoder.cc |
diff --git a/webrtc/modules/audio_coding/codecs/audio_decoder.cc b/webrtc/modules/audio_coding/codecs/audio_decoder.cc |
index 468af72894357ef75559add84781a3b522e117cf..86fb991db8f3225981db95ddb4f64a7db770d830 100644 |
--- a/webrtc/modules/audio_coding/codecs/audio_decoder.cc |
+++ b/webrtc/modules/audio_coding/codecs/audio_decoder.cc |
@@ -23,11 +23,11 @@ namespace { |
class LegacyFrame : public AudioDecoder::Frame { |
public: |
LegacyFrame(AudioDecoder* decoder, |
- rtc::Buffer* payload, |
+ rtc::Buffer&& payload, |
bool is_primary_payload) |
: decoder_(decoder), is_primary_payload_(is_primary_payload) { |
using std::swap; |
- swap(this->payload_, *payload); |
+ swap(this->payload_, payload); |
} |
size_t Duration() const override { |
@@ -85,9 +85,29 @@ std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( |
uint32_t timestamp, |
bool is_primary) { |
std::vector<ParseResult> results; |
- std::unique_ptr<Frame> frame( |
- new LegacyFrame(this, payload, is_primary)); |
- results.emplace_back(timestamp, is_primary, std::move(frame)); |
+ std::vector<PacketSplit> splits = SplitPacket(*payload); |
+ |
+ // Just take the payload if we don't have to split. |
+ if (splits.size() == 1 && |
+ splits[0].byte_offset == 0 && |
+ splits[0].num_bytes == payload->size() && |
+ splits[0].timestamp_offset == 0) { |
+ std::unique_ptr<Frame> frame( |
+ new LegacyFrame(this, std::move(*payload), is_primary)); |
+ results.emplace_back(timestamp + splits[0].timestamp_offset, is_primary, |
+ std::move(frame)); |
+ } else { |
+ for (const auto& split : splits) { |
+ RTC_CHECK(split.byte_offset + split.num_bytes <= payload->size()); |
hlundin-webrtc
2016/09/09 12:52:52
RTC_CHECK_LE
ossu
2016/09/12 11:26:37
Acknowledged.
|
+ rtc::Buffer new_payload(payload->data() + split.byte_offset, |
+ split.num_bytes); |
+ std::unique_ptr<Frame> frame( |
+ new LegacyFrame(this, std::move(new_payload), is_primary)); |
+ results.emplace_back(timestamp + split.timestamp_offset, is_primary, |
+ std::move(frame)); |
+ } |
+ } |
kwiberg-webrtc
2016/09/12 02:11:01
If you processed the pieces in the reverse order,
ossu
2016/09/12 11:26:37
It doesn't really matter which of the packets get
kwiberg-webrtc
2016/09/13 12:23:37
Well, if the first one gets it, you won't have to
|
+ |
return results; |
} |
@@ -141,6 +161,11 @@ int AudioDecoder::IncomingPacket(const uint8_t* payload, |
return 0; |
} |
+std::vector<AudioDecoder::PacketSplit> AudioDecoder::SplitPacket( |
+ rtc::ArrayView<const uint8_t> payload) const { |
+ return {PacketSplit{0, payload.size(), 0}}; |
+} |
+ |
int AudioDecoder::ErrorCode() { return 0; } |
int AudioDecoder::PacketDuration(const uint8_t* encoded, |