OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 MEDIA_FILTERS_AUDIO_FILE_READER_H_ | 5 #ifndef MEDIA_FILTERS_AUDIO_FILE_READER_H_ |
6 #define MEDIA_FILTERS_AUDIO_FILE_READER_H_ | 6 #define MEDIA_FILTERS_AUDIO_FILE_READER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "media/base/audio_codecs.h" | 12 #include "media/base/audio_codecs.h" |
12 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
13 #include "media/ffmpeg/ffmpeg_deleters.h" | 14 #include "media/ffmpeg/ffmpeg_deleters.h" |
14 #include "media/filters/ffmpeg_glue.h" | 15 #include "media/filters/ffmpeg_glue.h" |
15 | 16 |
16 struct AVCodecContext; | 17 struct AVCodecContext; |
17 struct AVPacket; | 18 struct AVPacket; |
18 struct AVStream; | 19 struct AVStream; |
(...skipping 12 matching lines...) Expand all Loading... |
31 // simply maintains a weak reference to it. | 32 // simply maintains a weak reference to it. |
32 explicit AudioFileReader(FFmpegURLProtocol* protocol); | 33 explicit AudioFileReader(FFmpegURLProtocol* protocol); |
33 virtual ~AudioFileReader(); | 34 virtual ~AudioFileReader(); |
34 | 35 |
35 // Open() reads the audio data format so that the sample_rate(), | 36 // Open() reads the audio data format so that the sample_rate(), |
36 // channels(), GetDuration(), and GetNumberOfFrames() methods can be called. | 37 // channels(), GetDuration(), and GetNumberOfFrames() methods can be called. |
37 // It returns |true| on success. | 38 // It returns |true| on success. |
38 bool Open(); | 39 bool Open(); |
39 void Close(); | 40 void Close(); |
40 | 41 |
41 // After a call to Open(), attempts to fully fill |audio_bus| with decoded | 42 // After a call to Open(), attempts to decode the entire data, |
42 // audio data. Any unfilled frames will be zeroed out. | 43 // updating |decodedAudioPackets| with each decoded packet in order. |
43 // |audio_data| must be of the same size as channels(). | 44 // The caller must convert these packets into one complete set of |
44 // The audio data will be decoded as floating-point linear PCM with | 45 // decoded audio data. The audio data will be decoded as |
45 // a nominal range of -1.0 -> +1.0. | 46 // floating-point linear PCM with a nominal range of -1.0 -> +1.0. |
46 // Returns the number of sample-frames actually read which will always be | 47 // Returns the number of sample-frames actually read which will |
47 // <= audio_bus->frames() | 48 // always be the total size of all the frames in |
48 int Read(AudioBus* audio_bus); | 49 // |decodedAudioPackets|. |
| 50 int Read(std::vector<std::unique_ptr<AudioBus>>* decoded_audio_packets); |
49 | 51 |
50 // These methods can be called once Open() has been called. | 52 // These methods can be called once Open() has been called. |
51 int channels() const { return channels_; } | 53 int channels() const { return channels_; } |
52 int sample_rate() const { return sample_rate_; } | 54 int sample_rate() const { return sample_rate_; } |
53 | 55 |
| 56 // Returns true if (an estimated) duration of the audio data is |
| 57 // known. Must be called after Open(); |
| 58 bool HasKnownDuration() const; |
| 59 |
54 // Please note that GetDuration() and GetNumberOfFrames() attempt to be | 60 // Please note that GetDuration() and GetNumberOfFrames() attempt to be |
55 // accurate, but are only estimates. For some encoded formats, the actual | 61 // accurate, but are only estimates. For some encoded formats, the actual |
56 // duration of the file can only be determined once all the file data has been | 62 // duration of the file can only be determined once all the file data has been |
57 // read. The Read() method returns the actual number of sample-frames it has | 63 // read. The Read() method returns the actual number of sample-frames it has |
58 // read. | 64 // read. |
59 base::TimeDelta GetDuration() const; | 65 base::TimeDelta GetDuration() const; |
60 int GetNumberOfFrames() const; | 66 int GetNumberOfFrames() const; |
61 | 67 |
62 // The methods below are helper methods which allow AudioFileReader to double | 68 // The methods below are helper methods which allow AudioFileReader to double |
63 // as a test utility for demuxing audio files. | 69 // as a test utility for demuxing audio files. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 102 |
97 // AVSampleFormat initially requested; not Chrome's SampleFormat. | 103 // AVSampleFormat initially requested; not Chrome's SampleFormat. |
98 int av_sample_format_; | 104 int av_sample_format_; |
99 | 105 |
100 DISALLOW_COPY_AND_ASSIGN(AudioFileReader); | 106 DISALLOW_COPY_AND_ASSIGN(AudioFileReader); |
101 }; | 107 }; |
102 | 108 |
103 } // namespace media | 109 } // namespace media |
104 | 110 |
105 #endif // MEDIA_FILTERS_AUDIO_FILE_READER_H_ | 111 #endif // MEDIA_FILTERS_AUDIO_FILE_READER_H_ |
OLD | NEW |