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 |
20 class FFmpegCdmAudioDecoder { | 26 class FFmpegCdmAudioDecoder { |
21 public: | 27 public: |
22 explicit FFmpegCdmAudioDecoder(cdm::Allocator* allocator); | 28 explicit FFmpegCdmAudioDecoder(cdm::Allocator* allocator); |
23 ~FFmpegCdmAudioDecoder(); | 29 ~FFmpegCdmAudioDecoder(); |
24 bool Initialize(const cdm::AudioDecoderConfig& config); | 30 bool Initialize(const cdm::AudioDecoderConfig& config); |
25 void Deinitialize(); | 31 void Deinitialize(); |
26 void Reset(); | 32 void Reset(); |
27 | 33 |
28 // Returns true when |config| is a valid audio decoder configuration. | 34 // Returns true when |config| is a valid audio decoder configuration. |
29 static bool IsValidConfig(const cdm::AudioDecoderConfig& config); | 35 static bool IsValidConfig(const cdm::AudioDecoderConfig& config); |
30 | 36 |
31 // Decodes |compressed_buffer|. Returns |cdm::kSuccess| after storing | 37 // Decodes |compressed_buffer|. Returns |cdm::kSuccess| after storing |
32 // output in |decoded_frames| when output is available. Returns | 38 // output in |decoded_frames| when output is available. Returns |
33 // |cdm::kNeedMoreData| when |compressed_frame| does not produce output. | 39 // |cdm::kNeedMoreData| when |compressed_frame| does not produce output. |
34 // Returns |cdm::kDecodeError| when decoding fails. | 40 // Returns |cdm::kDecodeError| when decoding fails. |
35 cdm::Status DecodeBuffer(const uint8_t* compressed_buffer, | 41 cdm::Status DecodeBuffer(const uint8_t* compressed_buffer, |
36 int32_t compressed_buffer_size, | 42 int32_t compressed_buffer_size, |
37 int64_t timestamp, | 43 int64_t timestamp, |
38 cdm::AudioFrames* decoded_frames); | 44 cdm::AudioFrames* decoded_frames); |
39 | 45 |
40 private: | 46 private: |
41 void ResetAudioTimingData(); | 47 void ResetTimestampState(); |
42 void ReleaseFFmpegResources(); | 48 void ReleaseFFmpegResources(); |
43 | 49 |
44 base::TimeDelta GetNextOutputTimestamp() const; | 50 base::TimeDelta GetNextOutputTimestamp() const; |
45 | 51 |
46 void SerializeInt64(int64_t value); | 52 void SerializeInt64(int64_t value); |
47 | 53 |
48 bool is_initialized_; | 54 bool is_initialized_; |
49 | 55 |
50 cdm::Allocator* const allocator_; | 56 cdm::Allocator* const allocator_; |
51 | 57 |
52 // FFmpeg structures owned by this object. | 58 // FFmpeg structures owned by this object. |
53 AVCodecContext* codec_context_; | 59 AVCodecContext* codec_context_; |
54 AVFrame* av_frame_; | 60 AVFrame* av_frame_; |
55 | 61 |
56 // Audio format. | 62 // Audio format. |
57 int bits_per_channel_; | 63 int bits_per_channel_; |
58 int samples_per_second_; | 64 int samples_per_second_; |
59 | 65 |
60 // Used for computing output timestamps. | 66 // Used for computing output timestamps. |
| 67 scoped_ptr<media::AudioTimestampHelper> output_timestamp_helper_; |
61 int bytes_per_frame_; | 68 int bytes_per_frame_; |
62 base::TimeDelta output_timestamp_base_; | |
63 int64_t total_frames_decoded_; | |
64 base::TimeDelta last_input_timestamp_; | 69 base::TimeDelta last_input_timestamp_; |
65 | 70 |
| 71 // We may need to convert the audio data coming out of FFmpeg from planar |
| 72 // float to integer. |
| 73 scoped_ptr<media::AudioBus> converter_bus_; |
| 74 |
66 // Number of output sample bytes to drop before generating output buffers. | 75 // Number of output sample bytes to drop before generating output buffers. |
67 // This is required for handling negative timestamps when decoding Vorbis | 76 // This is required for handling negative timestamps when decoding Vorbis |
68 // audio, for example. | 77 // audio, for example. |
69 int output_bytes_to_drop_; | 78 int output_bytes_to_drop_; |
70 | 79 |
71 typedef std::vector<uint8_t> SerializedAudioFrames; | 80 typedef std::vector<uint8_t> SerializedAudioFrames; |
72 SerializedAudioFrames serialized_audio_frames_; | 81 SerializedAudioFrames serialized_audio_frames_; |
73 | 82 |
74 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmAudioDecoder); | 83 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmAudioDecoder); |
75 }; | 84 }; |
76 | 85 |
77 } // namespace webkit_media | 86 } // namespace webkit_media |
78 | 87 |
79 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_ | 88 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_ |
OLD | NEW |