blob: 35a01df4bc016b65d2fb89125a17c6f5460b2706 (
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
|
// Copyright 2013 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_CDM_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_
#define MEDIA_CDM_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "media/cdm/ppapi/api/content_decryption_module.h"
struct AVCodecContext;
struct AVFrame;
namespace media {
class AudioBus;
class AudioTimestampHelper;
class ScopedPtrAVFreeContext;
class ScopedPtrAVFreeFrame;
}
namespace media {
// TODO(xhwang): This class is partially cloned from FFmpegAudioDecoder. When
// FFmpegAudioDecoder is updated, it's a pain to keep this class in sync with
// FFmpegAudioDecoder. We need a long term sustainable solution for this. See
// http://crbug.com/169203
class FFmpegCdmAudioDecoder {
public:
explicit FFmpegCdmAudioDecoder(cdm::Host* host);
~FFmpegCdmAudioDecoder();
bool Initialize(const cdm::AudioDecoderConfig& config);
void Deinitialize();
void Reset();
// Returns true when |config| is a valid audio decoder configuration.
static bool IsValidConfig(const cdm::AudioDecoderConfig& config);
// Decodes |compressed_buffer|. Returns |cdm::kSuccess| after storing
// output in |decoded_frames| when output is available. Returns
// |cdm::kNeedMoreData| when |compressed_frame| does not produce output.
// Returns |cdm::kDecodeError| when decoding fails.
//
// A null |compressed_buffer| will attempt to flush the decoder of any
// remaining frames. |compressed_buffer_size| and |timestamp| are ignored.
cdm::Status DecodeBuffer(const uint8_t* compressed_buffer,
int32_t compressed_buffer_size,
int64_t timestamp,
cdm::AudioFrames_1* decoded_frames);
private:
void ResetTimestampState();
void ReleaseFFmpegResources();
base::TimeDelta GetNextOutputTimestamp() const;
void SerializeInt64(int64_t value);
bool is_initialized_;
cdm::Host* const host_;
// FFmpeg structures owned by this object.
scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
// Audio format.
int bits_per_channel_;
int samples_per_second_;
int channels_;
// 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_;
// We may need to convert the audio data coming out of FFmpeg from planar
// float to integer.
scoped_ptr<AudioBus> converter_bus_;
// Number of output sample bytes to drop before generating output buffers.
// This is required for handling negative timestamps when decoding Vorbis
// audio, for example.
int output_bytes_to_drop_;
typedef std::vector<uint8_t> SerializedAudioFrames;
SerializedAudioFrames serialized_audio_frames_;
DISALLOW_COPY_AND_ASSIGN(FFmpegCdmAudioDecoder);
};
} // namespace media
#endif // MEDIA_CDM_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_
|