summaryrefslogtreecommitdiffstats
path: root/media/filters/ffmpeg_audio_decoder.h
blob: 0a7a915eb53af08621976ff9651af9518e68b63b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2009 The Chromium Authors. All rights reserved.  Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.

#ifndef MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_
#define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_

#include "media/filters/decoder_base.h"

struct AVCodecContext;

namespace media {

// Forward declaration for scoped_ptr_malloc.
class ScopedPtrAVFree;

class FFmpegAudioDecoder : public DecoderBase<AudioDecoder, Buffer> {
 public:
  FFmpegAudioDecoder();
  virtual ~FFmpegAudioDecoder();

 protected:
  virtual void DoInitialize(DemuxerStream* demuxer_stream, bool* success,
                            Task* done_cb);

  virtual void DoSeek(base::TimeDelta time, Task* done_cb);

  virtual void DoDecode(Buffer* input);

 private:
  // Calculates the duration of an audio buffer based on the sample rate,
  // channels and bits per sample given the size in bytes.
  base::TimeDelta CalculateDuration(size_t size);

  // A FFmpeg defined structure that holds decoder information, this variable
  // is initialized in OnInitialize().
  AVCodecContext* codec_context_;

  // Estimated timestamp for next packet. Useful for packets without timestamps.
  base::TimeDelta estimated_next_timestamp_;

  // Data buffer to carry decoded raw PCM samples. This buffer is created by
  // av_malloc() and is used throughout the lifetime of this class.
  scoped_ptr_malloc<uint8, ScopedPtrAVFree> output_buffer_;

  static const size_t kOutputBufferSize;

  DISALLOW_COPY_AND_ASSIGN(FFmpegAudioDecoder);
};

}  // namespace media

#endif  // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_