15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/codec/audio_decoder_verbatim.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/proto/audio.pb.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting {
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AudioDecoderVerbatim::AudioDecoderVerbatim() {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AudioDecoderVerbatim::~AudioDecoderVerbatim() {
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_ptr<AudioPacket> AudioDecoderVerbatim::Decode(
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_ptr<AudioPacket> packet) {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return a null scoped_ptr if we get a corrupted packet.
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if ((packet->encoding() != AudioPacket::ENCODING_RAW) ||
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (packet->data_size() != 1) ||
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (packet->sampling_rate() == AudioPacket::SAMPLING_RATE_INVALID) ||
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (packet->bytes_per_sample() != AudioPacket::BYTES_PER_SAMPLE_2) ||
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (packet->channels() != AudioPacket::CHANNELS_STEREO) ||
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      (packet->data(0).size() %
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       (AudioPacket::CHANNELS_STEREO * AudioPacket::BYTES_PER_SAMPLE_2) != 0)) {
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LOG(WARNING) << "Verbatim decoder received an invalid packet.";
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return scoped_ptr<AudioPacket>();
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return packet.Pass();
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace remoting
35