blob: 99fef1b943b12620a48e0cb586bec60c1946b441 (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Copyright (c) 2012 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 <list>
#include "base/callback.h"
#include "media/base/audio_decoder.h"
#include "media/base/demuxer_stream.h"
struct AVCodecContext;
struct AVFrame;
namespace base {
class MessageLoopProxy;
}
namespace media {
class AudioBus;
class AudioTimestampHelper;
class DataBuffer;
class DecoderBuffer;
struct QueuedAudioBuffer;
class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder {
public:
explicit FFmpegAudioDecoder(
const scoped_refptr<base::MessageLoopProxy>& message_loop);
// AudioDecoder implementation.
virtual void Initialize(const scoped_refptr<DemuxerStream>& stream,
const PipelineStatusCB& status_cb,
const StatisticsCB& statistics_cb) OVERRIDE;
virtual void Read(const ReadCB& read_cb) OVERRIDE;
virtual int bits_per_channel() OVERRIDE;
virtual ChannelLayout channel_layout() OVERRIDE;
virtual int samples_per_second() OVERRIDE;
virtual void Reset(const base::Closure& closure) OVERRIDE;
protected:
virtual ~FFmpegAudioDecoder();
private:
// Reads from the demuxer stream with corresponding callback method.
void ReadFromDemuxerStream();
void BufferReady(DemuxerStream::Status status,
const scoped_refptr<DecoderBuffer>& input);
bool ConfigureDecoder();
void ReleaseFFmpegResources();
void ResetTimestampState();
void RunDecodeLoop(const scoped_refptr<DecoderBuffer>& input,
bool skip_eos_append);
scoped_refptr<base::MessageLoopProxy> message_loop_;
scoped_refptr<DemuxerStream> demuxer_stream_;
StatisticsCB statistics_cb_;
AVCodecContext* codec_context_;
// Decoded audio format.
int bits_per_channel_;
ChannelLayout channel_layout_;
int channels_;
int samples_per_second_;
// AVSampleFormat initially requested; not Chrome's SampleFormat.
int av_sample_format_;
// Used for computing output timestamps.
scoped_ptr<AudioTimestampHelper> output_timestamp_helper_;
int bytes_per_frame_;
base::TimeDelta last_input_timestamp_;
// Number of output sample bytes to drop before generating
// output buffers.
int output_bytes_to_drop_;
// Holds decoded audio.
AVFrame* av_frame_;
ReadCB read_cb_;
// Since multiple frames may be decoded from the same packet we need to queue
// them up and hand them out as we receive Read() calls.
std::list<QueuedAudioBuffer> queued_audio_;
// We may need to convert the audio data coming out of FFmpeg from planar
// float to integer.
scoped_ptr<AudioBus> converter_bus_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder);
};
} // namespace media
#endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_
|