1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_
6 #define MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/base/audio_bus.h"
11 #include "media/cast/cast_config.h"
12 #include "media/cast/cast_environment.h"
13 #include "media/cast/transport/cast_transport_config.h"
20 // Callback passed to DecodeFrame, to deliver decoded audio data from the
21 // decoder. The number of samples in |audio_bus| may vary, and |audio_bus|
22 // can be NULL when errors occur. |is_continuous| is normally true, but will
23 // be false if the decoder has detected a frame skip since the last decode
24 // operation; and the client should take steps to smooth audio discontinuities
26 typedef base::Callback<void(scoped_ptr<AudioBus> audio_bus,
27 bool is_continuous)> DecodeFrameCallback;
29 AudioDecoder(const scoped_refptr<CastEnvironment>& cast_environment,
30 const AudioReceiverConfig& audio_config);
31 virtual ~AudioDecoder();
33 // Returns STATUS_AUDIO_INITIALIZED if the decoder was successfully
34 // constructed from the given AudioReceiverConfig. If this method returns any
35 // other value, calls to DecodeFrame() will not succeed.
36 CastInitializationStatus InitializationResult() const;
38 // Decode the payload in |encoded_frame| asynchronously. |callback| will be
39 // invoked on the CastEnvironment::MAIN thread with the result.
41 // In the normal case, |encoded_frame->frame_id| will be
42 // monotonically-increasing by 1 for each successive call to this method.
43 // When it is not, the decoder will assume one or more frames have been
44 // dropped (e.g., due to packet loss), and will perform recovery actions.
45 void DecodeFrame(scoped_ptr<transport::EncodedAudioFrame> encoded_frame,
46 const DecodeFrameCallback& callback);
53 const scoped_refptr<CastEnvironment> cast_environment_;
54 scoped_refptr<ImplBase> impl_;
56 DISALLOW_COPY_AND_ASSIGN(AudioDecoder);
62 #endif // MEDIA_CAST_AUDIO_RECEIVER_AUDIO_DECODER_H_