OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_ | 5 #ifndef WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_ |
6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_ | 6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "webkit/media/crypto/ppapi/cdm/content_decryption_module.h" | 14 #include "webkit/media/crypto/ppapi/cdm/content_decryption_module.h" |
14 | 15 |
15 struct AVCodecContext; | 16 struct AVCodecContext; |
16 struct AVFrame; | 17 struct AVFrame; |
17 | 18 |
| 19 namespace media { |
| 20 class AudioBus; |
| 21 class AudioTimestampHelper; |
| 22 } |
| 23 |
18 namespace webkit_media { | 24 namespace webkit_media { |
19 | 25 |
| 26 // TODO(xhwang): This class is partially cloned from media::FFmpegAudioDecoder. |
| 27 // When media::FFmpegAudioDecoder is updated, it's a pain to keep this class |
| 28 // in sync with media::FFmpegAudioDecoder. We need a long term sustainable |
| 29 // solution for this. See http://crbug.com/169203 |
20 class FFmpegCdmAudioDecoder { | 30 class FFmpegCdmAudioDecoder { |
21 public: | 31 public: |
22 explicit FFmpegCdmAudioDecoder(cdm::Allocator* allocator); | 32 explicit FFmpegCdmAudioDecoder(cdm::Allocator* allocator); |
23 ~FFmpegCdmAudioDecoder(); | 33 ~FFmpegCdmAudioDecoder(); |
24 bool Initialize(const cdm::AudioDecoderConfig& config); | 34 bool Initialize(const cdm::AudioDecoderConfig& config); |
25 void Deinitialize(); | 35 void Deinitialize(); |
26 void Reset(); | 36 void Reset(); |
27 | 37 |
28 // Returns true when |config| is a valid audio decoder configuration. | 38 // Returns true when |config| is a valid audio decoder configuration. |
29 static bool IsValidConfig(const cdm::AudioDecoderConfig& config); | 39 static bool IsValidConfig(const cdm::AudioDecoderConfig& config); |
30 | 40 |
31 // Decodes |compressed_buffer|. Returns |cdm::kSuccess| after storing | 41 // Decodes |compressed_buffer|. Returns |cdm::kSuccess| after storing |
32 // output in |decoded_frames| when output is available. Returns | 42 // output in |decoded_frames| when output is available. Returns |
33 // |cdm::kNeedMoreData| when |compressed_frame| does not produce output. | 43 // |cdm::kNeedMoreData| when |compressed_frame| does not produce output. |
34 // Returns |cdm::kDecodeError| when decoding fails. | 44 // Returns |cdm::kDecodeError| when decoding fails. |
35 cdm::Status DecodeBuffer(const uint8_t* compressed_buffer, | 45 cdm::Status DecodeBuffer(const uint8_t* compressed_buffer, |
36 int32_t compressed_buffer_size, | 46 int32_t compressed_buffer_size, |
37 int64_t timestamp, | 47 int64_t timestamp, |
38 cdm::AudioFrames* decoded_frames); | 48 cdm::AudioFrames* decoded_frames); |
39 | 49 |
40 private: | 50 private: |
41 void ResetAudioTimingData(); | 51 void ResetTimestampState(); |
42 void ReleaseFFmpegResources(); | 52 void ReleaseFFmpegResources(); |
43 | 53 |
44 base::TimeDelta GetNextOutputTimestamp() const; | 54 base::TimeDelta GetNextOutputTimestamp() const; |
45 | 55 |
46 void SerializeInt64(int64_t value); | 56 void SerializeInt64(int64_t value); |
47 | 57 |
48 bool is_initialized_; | 58 bool is_initialized_; |
49 | 59 |
50 cdm::Allocator* const allocator_; | 60 cdm::Allocator* const allocator_; |
51 | 61 |
52 // FFmpeg structures owned by this object. | 62 // FFmpeg structures owned by this object. |
53 AVCodecContext* codec_context_; | 63 AVCodecContext* codec_context_; |
54 AVFrame* av_frame_; | 64 AVFrame* av_frame_; |
55 | 65 |
56 // Audio format. | 66 // Audio format. |
57 int bits_per_channel_; | 67 int bits_per_channel_; |
58 int samples_per_second_; | 68 int samples_per_second_; |
59 | 69 |
60 // Used for computing output timestamps. | 70 // Used for computing output timestamps. |
| 71 scoped_ptr<media::AudioTimestampHelper> output_timestamp_helper_; |
61 int bytes_per_frame_; | 72 int bytes_per_frame_; |
62 base::TimeDelta output_timestamp_base_; | |
63 int64_t total_frames_decoded_; | |
64 base::TimeDelta last_input_timestamp_; | 73 base::TimeDelta last_input_timestamp_; |
65 | 74 |
| 75 // We may need to convert the audio data coming out of FFmpeg from planar |
| 76 // float to integer. |
| 77 scoped_ptr<media::AudioBus> converter_bus_; |
| 78 |
66 // Number of output sample bytes to drop before generating output buffers. | 79 // Number of output sample bytes to drop before generating output buffers. |
67 // This is required for handling negative timestamps when decoding Vorbis | 80 // This is required for handling negative timestamps when decoding Vorbis |
68 // audio, for example. | 81 // audio, for example. |
69 int output_bytes_to_drop_; | 82 int output_bytes_to_drop_; |
70 | 83 |
71 typedef std::vector<uint8_t> SerializedAudioFrames; | 84 typedef std::vector<uint8_t> SerializedAudioFrames; |
72 SerializedAudioFrames serialized_audio_frames_; | 85 SerializedAudioFrames serialized_audio_frames_; |
73 | 86 |
74 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmAudioDecoder); | 87 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmAudioDecoder); |
75 }; | 88 }; |
76 | 89 |
77 } // namespace webkit_media | 90 } // namespace webkit_media |
78 | 91 |
79 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_ | 92 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_ |
OLD | NEW |